Search in sources :

Example 56 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method testInsertX509Record.

@Test
public void testInsertX509Record() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Date now = new Date();
    X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
    certRecord.setLastNotifiedTime(now);
    certRecord.setLastNotifiedServer("last-notified-server");
    certRecord.setExpiryTime(now);
    certRecord.setHostName("hostname");
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    verifyInsertNonNullableColumns(now);
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(12, "hostname");
    jdbcConn.close();
}
Also used : Timestamp(java.sql.Timestamp) Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 57 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordNullableColumns.

@Test
public void testInsertX509RecordNullableColumns() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Date now = new Date();
    X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
    certRecord.setLastNotifiedTime(null);
    certRecord.setLastNotifiedServer(null);
    certRecord.setExpiryTime(null);
    certRecord.setHostName(null);
    Mockito.doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    verifyInsertNonNullableColumns(now);
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, null);
    Mockito.verify(mockPrepStmt, times(1)).setString(12, null);
    jdbcConn.close();
}
Also used : Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 58 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordAlreadyExists.

@Test
public void testInsertX509RecordAlreadyExists() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Date now = new Date();
    X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
    certRecord.setLastNotifiedTime(now);
    certRecord.setLastNotifiedServer("last-notified-server");
    certRecord.setExpiryTime(now);
    certRecord.setHostName("hostname");
    Mockito.doThrow(new SQLException("entry already exits", "state", 1062)).doReturn(1).when(mockPrepStmt).executeUpdate();
    boolean requestSuccess = jdbcConn.insertX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    // we should have all operation done once for insert and one for update
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "ostk");
    Mockito.verify(mockPrepStmt, times(1)).setString(2, "instance-id");
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "cn");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "current-serial");
    Mockito.verify(mockPrepStmt, times(1)).setString(6, "current-ip");
    Mockito.verify(mockPrepStmt, times(1)).setString(7, "prev-serial");
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(8, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(9, "prev-ip");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(10, false);
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(11, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(12, "hostname");
    Mockito.verify(mockPrepStmt, times(1)).setString(1, "current-serial");
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(2, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(3, "current-ip");
    Mockito.verify(mockPrepStmt, times(1)).setString(4, "prev-serial");
    Mockito.verify(mockPrepStmt, times(1)).setString(6, "prev-ip");
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(7, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(8, "hostname");
    Mockito.verify(mockPrepStmt, times(1)).setBoolean(9, false);
    Mockito.verify(mockPrepStmt, times(1)).setString(10, "ostk");
    Mockito.verify(mockPrepStmt, times(1)).setString(11, "instance-id");
    Mockito.verify(mockPrepStmt, times(1)).setString(12, "cn");
    // common between insert/update so count is 2 times
    Mockito.verify(mockPrepStmt, times(2)).setTimestamp(5, new java.sql.Timestamp(now.getTime()));
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) Timestamp(java.sql.Timestamp) Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 59 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method testGetX509CertRecordNullableColumns.

@Test
public void testGetX509CertRecordNullableColumns() throws Exception {
    Date now = new Date();
    Mockito.when(mockResultSet.next()).thenReturn(true);
    mockNonNullableColumns(now);
    Mockito.doReturn(null).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME);
    Mockito.doReturn(null).when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER);
    Mockito.doReturn(null).when(mockResultSet).getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME);
    Mockito.doReturn(null).when(mockResultSet).getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME);
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    X509CertRecord certRecord = jdbcConn.getX509CertRecord("ostk", "instance-id", "cn");
    assertNonNullableColumns(now, certRecord);
    assertNull(certRecord.getLastNotifiedTime());
    assertNull(certRecord.getLastNotifiedServer());
    assertNull(certRecord.getExpiryTime());
    assertNull(certRecord.getHostName());
    jdbcConn.close();
}
Also used : Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 60 with X509CertRecord

use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.

the class JDBCCertRecordStoreConnectionTest method getRecordWithNonNullableColumns.

private X509CertRecord getRecordWithNonNullableColumns(Date now) {
    X509CertRecord certRecord = new X509CertRecord();
    certRecord.setService("cn");
    certRecord.setProvider("ostk");
    certRecord.setInstanceId("instance-id");
    certRecord.setCurrentIP("current-ip");
    certRecord.setCurrentSerial("current-serial");
    certRecord.setCurrentTime(now);
    certRecord.setPrevIP("prev-ip");
    certRecord.setPrevSerial("prev-serial");
    certRecord.setPrevTime(now);
    certRecord.setClientCert(false);
    return certRecord;
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord)

Aggregations

X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)80 Test (org.testng.annotations.Test)64 DataStore (com.yahoo.athenz.zts.store.DataStore)25 InstanceCertManager (com.yahoo.athenz.zts.cert.InstanceCertManager)23 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)22 ZMSFileChangeLogStore (com.yahoo.athenz.common.server.store.impl.ZMSFileChangeLogStore)22 MockZMSFileChangeLogStore (com.yahoo.athenz.zts.store.MockZMSFileChangeLogStore)22 Path (java.nio.file.Path)22 X509Certificate (java.security.cert.X509Certificate)22 InstanceProvider (com.yahoo.athenz.instance.provider.InstanceProvider)18 InstanceConfirmation (com.yahoo.athenz.instance.provider.InstanceConfirmation)16 Date (java.util.Date)13 Notification (com.yahoo.athenz.common.server.notification.Notification)10 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)5 File (java.io.File)5 Timestamp (java.sql.Timestamp)5 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)4 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4