use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testListResourceAccessNotRegisteredRolePrincipals.
@Test
public void testListResourceAccessNotRegisteredRolePrincipals() throws SQLException {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// no role principals
Mockito.when(mockResultSet.next()).thenReturn(false);
try {
jdbcConn.listResourceAccess("user.user1", "update", "user");
fail();
} catch (ResourceException ex) {
assertEquals(ResourceException.NOT_FOUND, ex.getCode());
}
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testRollbackException.
@Test
public void testRollbackException() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, false);
assertFalse(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).setAutoCommit(false);
Mockito.doThrow(new SQLException("failed operation", "state", 1001)).when(mockConn).rollback();
jdbcConn.rollbackChanges();
assertTrue(jdbcConn.transactionCompleted);
Mockito.verify(mockConn, times(1)).rollback();
Mockito.verify(mockConn, times(1)).setAutoCommit(true);
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testGetPublicKeyEntry.
@Test
public void testGetPublicKeyEntry() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// service id
7);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for service id
true).thenReturn(// for key
true);
Mockito.when(mockResultSet.getString(ZMSConsts.DB_COLUMN_KEY_VALUE)).thenReturn("Value1");
PublicKeyEntry publicKey = jdbcConn.getPublicKeyEntry("my-domain", "service1", "zone1", false);
assertNotNull(publicKey);
assertEquals("Value1", publicKey.getKey());
assertEquals("zone1", publicKey.getId());
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testDeletePrincipalSubDomainFailure.
@Test
public void testDeletePrincipalSubDomainFailure() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
// domain delete is success, but sub-domain is failure
// thus the result must be successful
Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(1).thenReturn(0);
Mockito.when(mockResultSet.next()).thenReturn(true);
boolean requestSuccess = jdbcConn.deletePrincipal("user.jake", true);
assertTrue(requestSuccess);
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.jake.%");
jdbcConn.close();
}
use of com.yahoo.athenz.zms.store.jdbc.JDBCConnection in project athenz by yahoo.
the class JDBCConnectionTest method testInsertRoleMemberUpdate.
@Test
public void testInsertRoleMemberUpdate() throws Exception {
JDBCConnection jdbcConn = new JDBCConnection(mockConn, true);
Mockito.when(mockResultSet.getInt(1)).thenReturn(// domain id
5).thenReturn(// role id
7).thenReturn(// principal id
9);
Mockito.when(mockResultSet.next()).thenReturn(// this one is for domain id
true).thenReturn(// this one is for role id
true).thenReturn(// validate principle domain
true).thenReturn(// principal id
true).thenReturn(// member exists
true);
Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
RoleMember roleMember = new RoleMember().setMemberName("user.user1");
Timestamp expiration = Timestamp.fromCurrentTime();
roleMember.setExpiration(expiration);
java.sql.Timestamp javaExpiration = new java.sql.Timestamp(expiration.toDate().getTime());
boolean requestSuccess = jdbcConn.insertRoleMember("my-domain", "role1", roleMember, "user.admin", "audit-ref");
// this is combined for all operations above
Mockito.verify(mockPrepStmt, times(1)).setString(1, "my-domain");
Mockito.verify(mockPrepStmt, times(1)).setInt(1, 5);
Mockito.verify(mockPrepStmt, times(1)).setString(2, "role1");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "user.user1");
// we need additional operation for the audit log
Mockito.verify(mockPrepStmt, times(2)).setInt(1, 7);
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 9);
// update operation
Mockito.verify(mockPrepStmt, times(1)).setTimestamp(1, javaExpiration);
Mockito.verify(mockPrepStmt, times(1)).setInt(2, 7);
Mockito.verify(mockPrepStmt, times(1)).setInt(3, 9);
// the rest of the audit log details
Mockito.verify(mockPrepStmt, times(1)).setString(2, "user.admin");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "user.user1");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "UPDATE");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "audit-ref");
assertTrue(requestSuccess);
jdbcConn.close();
}
Aggregations