Search in sources :

Example 56 with SSHCertRecord

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();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Example 57 with SSHCertRecord

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();
}
Also used : SSHCertRecord(com.yahoo.athenz.common.server.ssh.SSHCertRecord) Test(org.testng.annotations.Test)

Aggregations

SSHCertRecord (com.yahoo.athenz.common.server.ssh.SSHCertRecord)57 Test (org.testng.annotations.Test)51 SSHSigner (com.yahoo.athenz.common.server.ssh.SSHSigner)14 HostnameResolver (com.yahoo.athenz.common.server.dns.HostnameResolver)12 Path (java.nio.file.Path)5 File (java.io.File)4 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)3 SSHRecordStoreConnection (com.yahoo.athenz.common.server.ssh.SSHRecordStoreConnection)3 IOException (java.io.IOException)3 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)2 Principal (com.yahoo.athenz.auth.Principal)2 PrincipalToken (com.yahoo.athenz.auth.token.PrincipalToken)2 CryptoException (com.yahoo.athenz.auth.util.CryptoException)2 Priority (com.yahoo.athenz.common.server.cert.Priority)2 StatusCheckException (com.yahoo.athenz.common.server.status.StatusCheckException)2 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)2 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)2 ResourceException (com.yahoo.athenz.zts.ResourceException)2