Search in sources :

Example 41 with X509CertRecord

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

the class JDBCCertRecordStoreConnectionTest method testUpdateX509RecordException.

@Test
public void testUpdateX509RecordException() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Date now = new Date();
    X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
    certRecord.setExpiryTime(now);
    certRecord.setHostName("hostname");
    Mockito.doThrow(new SQLException("error", "state", 503)).when(mockPrepStmt).executeUpdate();
    try {
        jdbcConn.updateX509CertRecord(certRecord);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 500);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zts.ResourceException) Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 42 with X509CertRecord

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

the class JDBCCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestamp.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestamp() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Mockito.when(mockPrepStmt.executeUpdate()).thenReturn(// 3 members updated
    3).thenReturn(// On second call, no members were updated
    0);
    long currentTime = System.currentTimeMillis();
    Timestamp ts = new Timestamp(currentTime);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_TIME)).thenReturn(ts).thenReturn(ts).thenReturn(ts);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_LAST_NOTIFIED_SERVER)).thenReturn("server0").thenReturn("server1").thenReturn("server2");
    Mockito.when(mockResultSet.next()).thenReturn(// this one is for server1
    true).thenReturn(// this one is for server2
    true).thenReturn(// this one is for server3
    true).thenReturn(// end
    false);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_SERVICE)).thenReturn(null);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_HOSTNAME)).thenReturn(null);
    Mockito.when(mockResultSet.getString(JDBCCertRecordStoreConnection.DB_COLUMN_INSTANCE_ID)).thenReturn(null);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_EXPIRY_TIME)).thenReturn(ts);
    Mockito.when(mockResultSet.getBoolean(JDBCCertRecordStoreConnection.DB_COLUMN_CLIENT_CERT)).thenReturn(false);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_CURRENT_TIME)).thenReturn(ts);
    Mockito.when(mockResultSet.getTimestamp(JDBCCertRecordStoreConnection.DB_COLUMN_PREV_TIME)).thenReturn(ts);
    List<X509CertRecord> unrefreshedCertificateRecords = jdbcConn.updateUnrefreshedCertificatesNotificationTimestamp("localhost", currentTime, "provider");
    assertNotNull(unrefreshedCertificateRecords);
    assertEquals(unrefreshedCertificateRecords.size(), 3);
    for (int i = 0; i < unrefreshedCertificateRecords.size(); ++i) {
        assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedServer(), "server" + i);
        assertEquals(unrefreshedCertificateRecords.get(i).getLastNotifiedTime(), new Date(currentTime));
    }
    jdbcConn.close();
}
Also used : Timestamp(java.sql.Timestamp) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 43 with X509CertRecord

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

the class JDBCCertRecordStoreConnectionTest method testInsertX509RecordException.

@Test
public void testInsertX509RecordException() throws Exception {
    JDBCCertRecordStoreConnection jdbcConn = new JDBCCertRecordStoreConnection(mockConn);
    Date now = new Date();
    X509CertRecord certRecord = getRecordWithNonNullableColumns(now);
    certRecord.setExpiryTime(now);
    certRecord.setHostName("hostname");
    Mockito.doThrow(new SQLException("error", "state", 503)).when(mockPrepStmt).executeUpdate();
    try {
        jdbcConn.insertX509CertRecord(certRecord);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 500);
    }
    jdbcConn.close();
}
Also used : SQLException(java.sql.SQLException) ResourceException(com.yahoo.athenz.zts.ResourceException) Date(java.util.Date) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 44 with X509CertRecord

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

the class JDBCCertRecordStoreConnectionTest method testUpdateX509Record.

@Test
public void testUpdateX509Record() 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.updateX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    verifyUpdateNonNullableColumns(now);
    Mockito.verify(mockPrepStmt, times(1)).setTimestamp(7, new java.sql.Timestamp(now.getTime()));
    Mockito.verify(mockPrepStmt, times(1)).setString(8, "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 45 with X509CertRecord

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

the class DynamoDBCertRecordStoreConnectionTest method testGetX509CertRecordNullableColumns.

@Test
public void testGetX509CertRecordNullableColumns() {
    Date now = new Date();
    mockNonNullableColumns(now, true);
    Mockito.doReturn(true).when(item).isNull("lastNotifiedTime");
    Mockito.doReturn(true).when(item).isNull("lastNotifiedServer");
    Mockito.doReturn(true).when(item).isNull("expiryTime");
    Mockito.doReturn(true).when(item).isNull("hostName");
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    dbConn.setOperationTimeout(10);
    X509CertRecord certRecord = dbConn.getX509CertRecord("athenz.provider", "1234", "cn");
    assertNonNullableColumns(now, certRecord);
    assertNull(certRecord.getLastNotifiedTime());
    assertNull(certRecord.getLastNotifiedServer());
    assertNull(certRecord.getExpiryTime());
    assertNull(certRecord.getHostName());
    dbConn.close();
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

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