Search in sources :

Example 6 with ResourceAccess

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();
}
Also used : ResourceAccess(com.yahoo.athenz.zms.ResourceAccess) Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 7 with ResourceAccess

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();
}
Also used : ResourceAccess(com.yahoo.athenz.zms.ResourceAccess) ResourceAccessList(com.yahoo.athenz.zms.ResourceAccessList) Assertion(com.yahoo.athenz.zms.Assertion) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

ResourceAccess (com.yahoo.athenz.zms.ResourceAccess)7 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)5 JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)5 Test (org.testng.annotations.Test)5 Assertion (com.yahoo.athenz.zms.Assertion)4 ArrayList (java.util.ArrayList)3 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1