Search in sources :

Example 81 with JDBCConnection

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

the class JDBCConnectionTest method testUpdateRoleInvalidRoleDomain.

@Test
public void testUpdateRoleInvalidRoleDomain() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Role role = new Role().setName("my-domain2:role.role1");
    try {
        jdbcConn.updateRole("my-domain", role);
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : Role(com.yahoo.athenz.zms.Role) PrincipalRole(com.yahoo.athenz.zms.PrincipalRole) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 82 with JDBCConnection

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

the class JDBCConnectionTest method testCountEntitiesException.

@Test
public void testCountEntitiesException() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    // return domain id
    Mockito.doReturn(5).when(mockResultSet).getInt(1);
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
    true);
    Mockito.when(mockPrepStmt.executeQuery()).thenReturn(mockResultSet).thenThrow(new SQLException("failed operation", "state", 1001));
    try {
        jdbcConn.countEntities("my-domain");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) ResourceException(com.yahoo.athenz.zms.ResourceException) SQLException(java.sql.SQLException) Test(org.testng.annotations.Test)

Example 83 with JDBCConnection

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

the class JDBCConnectionTest method testListRoleAuditLogs.

@Test
public void testListRoleAuditLogs() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Mockito.when(mockResultSet.next()).thenReturn(// domain id success
    true).thenReturn(// role id success
    true).thenReturn(// 2 log entries
    true).thenReturn(true).thenReturn(false);
    Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
    5).thenReturn(// role id
    7);
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ACTION)).thenReturn("ADD").thenReturn("DELETE");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_MEMBER)).thenReturn("user.member1").thenReturn("user.member2");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_ADMIN)).thenReturn("user.admin1").thenReturn("user.admin2");
    Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_AUDIT_REF)).thenReturn("").thenReturn("audit-ref");
    Mockito.doReturn(new java.sql.Timestamp(1454358916)).when(mockResultSet).getTimestamp(ZMSConsts.DB_COLUMN_CREATED);
    List<RoleAuditLog> logs = jdbcConn.listRoleAuditLogs("my-domain", "role1");
    assertNotNull(logs);
    assertEquals(2, logs.size());
    assertEquals("ADD", logs.get(0).getAction());
    assertEquals("user.admin1", logs.get(0).getAdmin());
    assertEquals("user.member1", logs.get(0).getMember());
    assertNull(logs.get(0).getAuditRef());
    assertEquals("DELETE", logs.get(1).getAction());
    assertEquals("user.admin2", logs.get(1).getAdmin());
    assertEquals("user.member2", logs.get(1).getMember());
    assertEquals("audit-ref", logs.get(1).getAuditRef());
    jdbcConn.close();
}
Also used : RoleAuditLog(com.yahoo.athenz.zms.RoleAuditLog) JDBCConnection(com.yahoo.athenz.zms.store.jdbc.JDBCConnection) Test(org.testng.annotations.Test)

Example 84 with JDBCConnection

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

the class JDBCConnectionTest method testUpdateDomainNullFields.

@Test
public void testUpdateDomainNullFields() throws Exception {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    Domain domain = new Domain().setName("my-domain").setEnabled(true).setAuditEnabled(false);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.updateDomain(domain);
    assertTrue(requestSuccess);
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(4, true);
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(5, false);
    Mockito.verify(mockPrepStmt, times(1)).setString(6, "");
    Mockito.verify(mockPrepStmt, times(1)).setInt(7, 0);
    Mockito.verify(mockPrepStmt, times(1)).setString(8, "");
    Mockito.verify(mockPrepStmt, times(1)).setString(9, "my-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)

Example 85 with JDBCConnection

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

the class JDBCConnectionTest method testAddRoleAssertionsEmptyList.

@Test
public void testAddRoleAssertionsEmptyList() throws SQLException {
    JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
    List<Assertion> principalAssertions = new ArrayList<>();
    jdbcConn.addRoleAssertions(principalAssertions, null, null);
    assertEquals(0, principalAssertions.size());
    jdbcConn.addRoleAssertions(principalAssertions, new ArrayList<Assertion>(), null);
    assertEquals(0, principalAssertions.size());
    jdbcConn.close();
}
Also used : Assertion(com.yahoo.athenz.zms.Assertion) ArrayList(java.util.ArrayList) 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