use of com.yahoo.athenz.zms.ResourceAccess in project athenz by yahoo.
the class JDBCConnectionTest method testGetResourceAccessObject.
@Test
public void testGetResourceAccessObject() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
ResourceAccess rsrcAccess = jdbcConn.getResourceAccessObject("user.user1", null);
assertEquals("user.user1", rsrcAccess.getPrincipal());
List<Assertion> assertions = rsrcAccess.getAssertions();
assertTrue(assertions.isEmpty());
List<Assertion> roleAssertions = new ArrayList<>();
Assertion assertion = new Assertion().setAction("update").setRole("role").setResource("resource");
roleAssertions.add(assertion);
rsrcAccess = jdbcConn.getResourceAccessObject("user.user2", roleAssertions);
assertEquals("user.user2", rsrcAccess.getPrincipal());
assertions = rsrcAccess.getAssertions();
assertEquals(1, assertions.size());
Assertion testAssertion = assertions.get(0);
assertEquals("update", testAssertion.getAction());
assertEquals("role", testAssertion.getRole());
assertEquals("resource", testAssertion.getResource());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.ResourceAccess in project athenz by yahoo.
the class JDBCConnectionTest method testListResourceAccessRegisteredRolePrincipals.
@Test
public void testListResourceAccessRegisteredRolePrincipals() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// no role principals
Mockito.when(mockResultSet.next()).thenReturn(// no role principal return
false).thenReturn(// valid principal id
true);
Mockito.doReturn(7).when(mockResultSet).getInt(1);
ResourceAccessList resourceAccessList = jdbcConn.listResourceAccess("user.user1", "update", "user");
// we should get an empty assertion set for the principal
List<ResourceAccess> resources = resourceAccessList.getResources();
assertEquals(1, resources.size());
ResourceAccess rsrcAccess = resources.get(0);
assertEquals("user.user1", rsrcAccess.getPrincipal());
List<Assertion> assertions = rsrcAccess.getAssertions();
assertTrue(assertions.isEmpty());
jdbcConn.close();
}
Aggregations