Search in sources :

Example 36 with X509CertRecord

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

the class DynamoDBCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestampUpdateDynamoDBException.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestampUpdateDynamoDBException() {
    DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
    Date now = new Date(1591706189000L);
    long nowL = now.getTime();
    long fiveDaysAgo = nowL - 5 * 24 * 60 * 60 * 1000;
    Map<String, AttributeValue> reNotified = ZTSTestUtils.generateAttributeValues("home.test.service3", "reNotified", Long.toString(fiveDaysAgo), Long.toString(fiveDaysAgo), "testServer", null, "testHost2");
    Item item1 = ItemUtils.toItem(reNotified);
    ItemCollection<QueryOutcome> itemCollection = Mockito.mock(ItemCollection.class);
    IteratorSupport<Item, QueryOutcome> iteratorSupport = Mockito.mock(IteratorSupport.class);
    when(itemCollection.iterator()).thenReturn(iteratorSupport);
    when(iteratorSupport.hasNext()).thenReturn(true, false);
    when(iteratorSupport.next()).thenReturn(item1);
    Mockito.doReturn(itemCollection).when(currentTimeIndex).query(any(QuerySpec.class));
    ItemCollection<QueryOutcome> itemCollection2 = Mockito.mock(ItemCollection.class);
    IteratorSupport<Item, QueryOutcome> iteratorSupport2 = Mockito.mock(IteratorSupport.class);
    when(itemCollection2.iterator()).thenReturn(iteratorSupport2);
    when(iteratorSupport2.hasNext()).thenReturn(true, false);
    when(iteratorSupport2.next()).thenReturn(item1);
    Mockito.doReturn(itemCollection2).when(hostNameIndex).query(any(QuerySpec.class));
    Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).updateItem(any(UpdateItemSpec.class));
    List<X509CertRecord> result = dbConn.updateUnrefreshedCertificatesNotificationTimestamp("serverTest", 1591706189000L, "providerTest");
    assertEquals(result.size(), 0);
    dbConn.close();
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) Test(org.testng.annotations.Test)

Example 37 with X509CertRecord

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

the class DynamoDBCertRecordStoreConnectionTest method testInsertX509RecordNullableColumns.

@Test
public void testInsertX509RecordNullableColumns() {
    DynamoDBCertRecordStoreConnection dbConn = new DynamoDBCertRecordStoreConnection(dynamoDB, tableName, currentTimeIndexName, hostNameIndexName);
    Date now = new Date();
    String dateIsoFormat = DynamoDBUtils.getIso8601FromDate(now);
    X509CertRecord certRecord = getRecordNonNullableColumns(now);
    certRecord.setLastNotifiedTime(null);
    certRecord.setLastNotifiedServer(null);
    certRecord.setExpiryTime(null);
    certRecord.setHostName(null);
    Item item = new Item().withPrimaryKey("primaryKey", "athenz.provider:cn:1234").withString("instanceId", certRecord.getInstanceId()).withString("provider", certRecord.getProvider()).withString("service", certRecord.getService()).withString("currentSerial", certRecord.getCurrentSerial()).withString("currentIP", certRecord.getCurrentIP()).withLong("currentTime", certRecord.getCurrentTime().getTime()).withString("currentDate", dateIsoFormat).withString("prevSerial", certRecord.getPrevSerial()).withString("prevIP", certRecord.getPrevIP()).withLong("prevTime", certRecord.getPrevTime().getTime()).withBoolean("clientCert", certRecord.getClientCert()).withLong("ttl", certRecord.getCurrentTime().getTime() / 1000L + 3660 * 720).with("lastNotifiedTime", null).with("lastNotifiedServer", null).with("expiryTime", null).with("hostName", null);
    Mockito.doReturn(putOutcome).when(table).putItem(item);
    boolean requestSuccess = dbConn.insertX509CertRecord(certRecord);
    assertTrue(requestSuccess);
    dbConn.close();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 38 with X509CertRecord

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

the class FileCertRecordStoreConnectionTest method testdeleteExpiredX509CertRecordsDelete.

@Test
public void testdeleteExpiredX509CertRecordsDelete() throws Exception {
    // make sure the directory does not exist
    File rootDir = new File("/tmp/zts-cert-tests");
    ZTSTestUtils.deleteDirectory(rootDir);
    rootDir.mkdirs();
    FileCertRecordStoreConnectionExt store = new FileCertRecordStoreConnectionExt(rootDir);
    X509CertRecord certRecord = new X509CertRecord();
    Date now = new Date();
    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);
    boolean result = store.insertX509CertRecord(certRecord);
    assertTrue(result);
    X509CertRecord certRecordCheck = store.getX509CertRecord("ostk", "instance-id", "cn");
    assertNotNull(certRecordCheck);
    Thread.sleep(1000);
    store.deleteExpiredX509CertRecords(0);
    certRecordCheck = store.getX509CertRecord("ostk", "instance-id", "cn");
    assertNotNull(certRecordCheck);
}
Also used : File(java.io.File) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 39 with X509CertRecord

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

the class FileCertRecordStoreConnectionTest method testX509CertOperations.

@Test
public void testX509CertOperations() {
    // make sure the directory does not exist
    ZTSTestUtils.deleteDirectory(new File("/tmp/zts-cert-tests"));
    FileCertRecordStore store = new FileCertRecordStore(new File("/tmp/zts-cert-tests"));
    FileCertRecordStoreConnection con = (FileCertRecordStoreConnection) store.getConnection();
    assertNotNull(con);
    con.setOperationTimeout(10);
    // first verify that we don't have the entry
    X509CertRecord certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
    assertNull(certRecordCheck);
    // now write the entry
    X509CertRecord certRecord = new X509CertRecord();
    Date now = new Date();
    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);
    boolean result = con.insertX509CertRecord(certRecord);
    assertTrue(result);
    // now read the entry again
    certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
    assertNotNull(certRecordCheck);
    assertEquals(certRecordCheck.getCurrentIP(), "current-ip");
    assertEquals(certRecordCheck.getCurrentSerial(), "current-serial");
    assertEquals(certRecordCheck.getCurrentTime(), now);
    assertEquals(certRecordCheck.getInstanceId(), "instance-id");
    assertEquals(certRecordCheck.getPrevIP(), "prev-ip");
    assertEquals(certRecordCheck.getPrevSerial(), "prev-serial");
    assertEquals(certRecordCheck.getPrevTime(), now);
    assertEquals(certRecordCheck.getProvider(), "ostk");
    assertEquals(certRecordCheck.getService(), "cn");
    // now update the entry
    certRecord.setCurrentIP("updated-ip");
    certRecord.setCurrentSerial("updated-serial");
    result = con.updateX509CertRecord(certRecord);
    assertTrue(result);
    certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
    assertNotNull(certRecordCheck);
    assertEquals(certRecordCheck.getCurrentIP(), "updated-ip");
    assertEquals(certRecordCheck.getCurrentSerial(), "updated-serial");
    assertEquals(certRecordCheck.getCurrentTime(), now);
    assertEquals(certRecordCheck.getInstanceId(), "instance-id");
    assertEquals(certRecordCheck.getPrevIP(), "prev-ip");
    assertEquals(certRecordCheck.getPrevSerial(), "prev-serial");
    assertEquals(certRecordCheck.getPrevTime(), now);
    assertEquals(certRecordCheck.getProvider(), "ostk");
    assertEquals(certRecordCheck.getService(), "cn");
    // now delete the entry
    con.deleteX509CertRecord("ostk", "instance-id", "cn");
    certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
    assertNull(certRecordCheck);
    con.close();
}
Also used : File(java.io.File) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 40 with X509CertRecord

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

the class FileCertRecordStoreConnectionTest method testUpdateUnrefreshedCertificatesNotificationTimestamp.

@Test
public void testUpdateUnrefreshedCertificatesNotificationTimestamp() {
    ZTSTestUtils.deleteDirectory(new File("/tmp/zts-cert-tests"));
    FileCertRecordStore store = new FileCertRecordStore(new File("/tmp/zts-cert-tests"));
    FileCertRecordStoreConnection con = (FileCertRecordStoreConnection) store.getConnection();
    assertNotNull(con);
    long timestamp = System.currentTimeMillis();
    List<X509CertRecord> records = con.updateUnrefreshedCertificatesNotificationTimestamp("localhost", timestamp, "provider");
    // For File store, unrefreshed certs unimplemented. Assert empty collection
    assertEquals(records, new ArrayList<>());
}
Also used : File(java.io.File) 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