JDBCSSHRecordStoreConnection implements SSHRecordStoreConnection { @Override public SSHCertRecord getSSHCertRecord(String instanceId, String service) { final String caller = "getSSHCertRecord"; SSHCertRecord sshCertRecord = null; try (PreparedStatement ps = con.prepareStatement(SQL_GET_SSH_RECORD)) { ps.setString(1, instanceId); ps.setString(2, service); try (ResultSet rs = executeQuery(ps, caller)) { if (rs.next()) { sshCertRecord = new SSHCertRecord(); sshCertRecord.setInstanceId(instanceId); sshCertRecord.setService(service); sshCertRecord.setClientIP(rs.getString(DB_COLUMN_CLIENT_IP)); sshCertRecord.setPrincipals(rs.getString(DB_COLUMN_PRINCIPALS)); sshCertRecord.setPrivateIP(rs.getString(DB_COLUMN_PRIVATE_IP)); } } } catch (SQLException ex) { throw sqlError(ex, caller); } return sshCertRecord; } JDBCSSHRecordStoreConnection(Connection con); @Override void setOperationTimeout(int queryTimeout); @Override void close(); @Override SSHCertRecord getSSHCertRecord(String instanceId, String service); @Override boolean updateSSHCertRecord(SSHCertRecord sshCertRecord); @Override boolean insertSSHCertRecord(SSHCertRecord sshCertRecord); @Override boolean deleteSSHCertRecord(String instanceId, String service); @Override int deleteExpiredSSHCertRecords(int expiryTimeMins); static final String DB_COLUMN_INSTANCE_ID; static final String DB_COLUMN_SERVICE; static final String DB_COLUMN_CLIENT_IP; static final String DB_COLUMN_PRIVATE_IP; static final String DB_COLUMN_PRINCIPALS; }
@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(); }