Search in sources :

Example 16 with JDBCConnection

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

the class JDBCConnectionTest method testGetTrustedRoles.

@Test
public void testGetTrustedRoles() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_NAME)).thenReturn("trole1").thenReturn("trole2").thenReturn("trole3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_DOMAIN_ID)).thenReturn("101").thenReturn("102").thenReturn("103");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ROLE)).thenReturn("role1").thenReturn("role1").thenReturn("role3");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ASSERT_DOMAIN_ID)).thenReturn("101").thenReturn("101").thenReturn("103");
    Map<String, List<String>> trustedRoles = jdbcConn.getTrustedRoles("getTrustedRoles");
    assertEquals(2, trustedRoles.size());
    List<String> roles = trustedRoles.get("101:role1");
    assertEquals(2, roles.size());
    assertEquals("101:trole1", roles.get(0));
    assertEquals("102:trole2", roles.get(1));
    roles = trustedRoles.get("103:role3");
    assertEquals(1, roles.size());
    assertEquals("103:trole3", roles.get(0));
    jdbcConn.close();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) DomainModifiedList(com.yahoo.athenz.zms.DomainModifiedList) ResourceAccessList(com.yahoo.athenz.zms.ResourceAccessList) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 17 with JDBCConnection

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

the class JDBCConnectionTest method testPrepareRoleAssertionsStatementWithAction.

@Test
public void testPrepareRoleAssertionsStatementWithAction() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    jdbcConn.prepareRoleAssertionsStatement("create");
    Mockito.verify(mockPrepStmt, times(1)).setString(Matchers.eq(1), Matchers.eq("create"));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 18 with JDBCConnection

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

the class JDBCConnectionTest method testListRoleMembersInvalidDomain.

@Test
public void testListRoleMembersInvalidDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(// invalid domain
    false);
    try {
        jdbcConn.listRoleMembers("my-domain", "role1");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 19 with JDBCConnection

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

the class JDBCConnectionTest method testPrepareRolePrinciaplsStatementEmptyPrincipal.

@Test
public void testPrepareRolePrinciaplsStatementEmptyPrincipal() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    jdbcConn.prepareRolePrincipalsStatement("", "user", false);
    jdbcConn.prepareRolePrincipalsStatement(null, "user", false);
    Mockito.verify(mockPrepStmt, times(0)).setString(Matchers.isA(Integer.class), Matchers.isA(String.class));
    jdbcConn.close();
}
Also used : JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 20 with JDBCConnection

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

the class JDBCConnectionTest method testGetDomainNotFound.

@Test
public void testGetDomainNotFound() throws Exception {
    Mockito.when(mockResultSet.next()).thenReturn(false);
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Domain domain = jdbcConn.getDomain("my-domain");
    assertNull(domain);
    jdbcConn.close();
}
Also used : AthenzDomain(com.yahoo.athenz.zms.store.AthenzDomain) Domain(com.yahoo.athenz.zms.Domain) 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