use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnectionTest method testGetSSHCertRecord.
@Test
public void testGetSSHCertRecord() throws Exception {
Mockito.when(mockResultSet.next()).thenReturn(true);
Mockito.doReturn("host1,host2").when(mockResultSet).getString(JDBCSSHRecordStoreConnection.DB_COLUMN_PRINCIPALS);
Mockito.doReturn("10.10.10.11").when(mockResultSet).getString(JDBCSSHRecordStoreConnection.DB_COLUMN_CLIENT_IP);
Mockito.doReturn("10.10.10.12").when(mockResultSet).getString(JDBCSSHRecordStoreConnection.DB_COLUMN_PRIVATE_IP);
JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn);
SSHCertRecord certRecord = jdbcConn.getSSHCertRecord("instance-id", "athenz.api");
assertEquals(certRecord.getInstanceId(), "instance-id");
assertEquals(certRecord.getService(), "athenz.api");
assertEquals(certRecord.getPrincipals(), "host1,host2");
assertEquals(certRecord.getClientIP(), "10.10.10.11");
assertEquals(certRecord.getPrivateIP(), "10.10.10.12");
jdbcConn.close();
}
use of com.yahoo.athenz.common.server.ssh.SSHCertRecord in project athenz by yahoo.
the class JDBCSSHRecordStoreConnectionTest method testInsertSSHRecordAlreadyExists.
@Test
public void testInsertSSHRecordAlreadyExists() throws Exception {
JDBCSSHRecordStoreConnection jdbcConn = new JDBCSSHRecordStoreConnection(mockConn);
SSHCertRecord certRecord = new SSHCertRecord();
certRecord.setInstanceId("id1");
certRecord.setService("athenz.api");
certRecord.setPrivateIP("10.10.10.11");
certRecord.setClientIP("10.10.10.12");
certRecord.setPrincipals("host1");
Mockito.doThrow(new SQLException("entry already exits", "state", 1062)).doReturn(1).when(mockPrepStmt).executeUpdate();
boolean requestSuccess = jdbcConn.insertSSHCertRecord(certRecord);
assertTrue(requestSuccess);
// we should have all operation done once for insert and one for update
Mockito.verify(mockPrepStmt, times(1)).setString(1, "id1");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "athenz.api");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "host1");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "10.10.10.12");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "10.10.10.11");
Mockito.verify(mockPrepStmt, times(1)).setString(1, "host1");
Mockito.verify(mockPrepStmt, times(1)).setString(2, "10.10.10.12");
Mockito.verify(mockPrepStmt, times(1)).setString(3, "10.10.10.11");
Mockito.verify(mockPrepStmt, times(1)).setString(4, "id1");
Mockito.verify(mockPrepStmt, times(1)).setString(5, "athenz.api");
jdbcConn.close();
}
Aggregations