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();
}
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();
}
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);
}
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();
}
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<>());
}
Aggregations