Search in sources :

Example 1 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetServiceIdentity.

@Test
public void testGetServiceIdentity() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(true);
    Mockito.doReturn("test description").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_DESCRIPTION);
    Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_MODIFIED);
    Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_EXECTUABLE);
    Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_GROUP);
    Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_SVC_USER);
    Mockito.doReturn("").when(mockResultSet).getString(ZMSConsts.DB_COLUMN_PROVIDER_ENDPOINT);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    ServiceIdentity service = jdbcConn.getServiceIdentity("my-domain", "service1");
    assertNotNull(service);
    assertEquals("my-domain.service1", service.getName());
    assertNull(service.getExecutable());
    assertNull(service.getGroup());
    assertNull(service.getUser());
    assertNull(service.getProviderEndpoint());
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "service1");
    jdbcConn.close();
}
Also used : ServiceIdentity(com.yahoo.athenz.zms.ServiceIdentity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 2 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testParseRoleMember.

@Test
public void testParseRoleMember() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    StringBuilder domain = new StringBuilder(512);
    StringBuilder name = new StringBuilder(512);
    assertTrue(jdbcConn.parsePrincipal("user.user", domain, name));
    assertEquals("user", domain.toString());
    assertEquals("user", name.toString());
    domain.setLength(0);
    name.setLength(0);
    assertTrue(jdbcConn.parsePrincipal("coretech.storage.service", domain, name));
    assertEquals("coretech.storage", domain.toString());
    assertEquals("service", name.toString());
    assertFalse(jdbcConn.parsePrincipal(".coretech", domain, name));
    assertFalse(jdbcConn.parsePrincipal("coretech.storage.service.", domain, name));
    assertFalse(jdbcConn.parsePrincipal("service", domain, name));
    assertFalse(jdbcConn.parsePrincipal("", domain, name));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 3 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetEntityNotFound.

@Test
public void testGetEntityNotFound() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(// for domain id
    true).thenReturn(false);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
    5);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Entity entity = jdbcConn.getEntity("my-domain", "entity1");
    assertNull(entity);
    jdbcConn.close();
}
Also used : Entity(com.yahoo.athenz.zms.Entity) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 4 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testGetRoleNotFound.

@Test
public void testGetRoleNotFound() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(false);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Role role = jdbcConn.getRole("my-domain", "role1");
    assertNull(role);
    jdbcConn.close();
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 5 with JDBCConnection

use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.

the class JDBCConnectionTest method testListResourceAccess.

@Test
public void testListResourceAccess() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(// up to here is role principals
    false).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(// up to here is role assertions
    false).thenReturn(// no trusted role
    false);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("user.user1").thenReturn("user.user2").thenReturn(// up to here is role principals
    "user.user3").thenReturn("dom1").thenReturn("dom1").thenReturn("dom2");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_DOMAIN_ID)).thenReturn("101").thenReturn("101").thenReturn(// up to here is role principals
    "102").thenReturn("101").thenReturn("101").thenReturn("102");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE_NAME)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_RESOURCE)).thenReturn("resource1").thenReturn("resource2").thenReturn("resource3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("update");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_EFFECT)).thenReturn("ALLOW");
    ResourceAccessList resourceAccessList = jdbcConn.listResourceAccess(null, "update", "user");
    List<ResourceAccess> resources = resourceAccessList.getResources();
    assertEquals(3, resources.size());
    boolean userUser1 = false;
    boolean userUser2 = false;
    boolean userUser3 = false;
    for (ResourceAccess rsrcAccess : resources) {
        switch(rsrcAccess.getPrincipal()) {
            case "user.user1":
                userUser1 = true;
                assertEquals(2, rsrcAccess.getAssertions().size());
                break;
            case "user.user2":
                userUser2 = true;
                assertEquals(2, rsrcAccess.getAssertions().size());
                break;
            case "user.user3":
                userUser3 = true;
                assertEquals(1, rsrcAccess.getAssertions().size());
                break;
        }
    }
    assertTrue(userUser1);
    assertTrue(userUser2);
    assertTrue(userUser3);
    jdbcConn.close();
}
Also used : ResourceAccess(com.yahoo.athenz.zms.ResourceAccess) ResourceAccessList(com.yahoo.athenz.zms.ResourceAccessList) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Aggregations

JDBCConnection (com.yahoo.athenz.zms.store.jdbc.JDBCConnection)307 Test (org.testng.annotations.Test)307 ResourceException (com.yahoo.athenz.zms.ResourceException)131 SQLException (java.sql.SQLException)125 Assertion (com.yahoo.athenz.zms.Assertion)16 PrincipalRole (com.yahoo.athenz.zms.PrincipalRole)15 Role (com.yahoo.athenz.zms.Role)14 PublicKeyEntry (com.yahoo.athenz.zms.PublicKeyEntry)11 ServiceIdentity (com.yahoo.athenz.zms.ServiceIdentity)11 AthenzDomain (com.yahoo.athenz.zms.store.AthenzDomain)11 Domain (com.yahoo.athenz.zms.Domain)10 Entity (com.yahoo.athenz.zms.Entity)8 Quota (com.yahoo.athenz.zms.Quota)8 Policy (com.yahoo.athenz.zms.Policy)7 ResourceAccessList (com.yahoo.athenz.zms.ResourceAccessList)7 ArrayList (java.util.ArrayList)7 RoleMember (com.yahoo.athenz.zms.RoleMember)6 Struct (com.yahoo.rdl.Struct)6 Timestamp (com.yahoo.rdl.Timestamp)6 DomainModifiedList (com.yahoo.athenz.zms.DomainModifiedList)5