use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testGetX509CertRecordNotFoundException.
@Test
public void testGetX509CertRecordNotFoundException() {
Mockito.doThrow(new AmazonDynamoDBException("item not found")).when(table).getItem("primaryKey", "athenz.provider:cn:1234");
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
X509CertRecord certRecord = dbConn.getX509CertRecord("athenz.provider", "1234", "cn");
assertNull(certRecord);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method getRecordNonNullableColumns.
private X509CertRecord getRecordNonNullableColumns(Date now) {
X509CertRecord certRecord = new X509CertRecord();
certRecord.setService("cn");
certRecord.setProvider("athenz.provider");
certRecord.setInstanceId("1234");
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;
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testInsertX509Record.
@Test
public void testInsertX509Record() {
DynamoDBCertRecordStoreConnection dbConn = new DynamoDBCertRecordStoreConnection(dynamoDB, tableName, currentTimeIndexName, hostNameIndexName);
Date now = new Date();
String dateIsoFormat = DynamoDBUtils.getIso8601FromDate(now);
X509CertRecord certRecord = getRecordNonNullableColumns(now);
certRecord.setLastNotifiedTime(now);
certRecord.setLastNotifiedServer("last-notified-server");
certRecord.setExpiryTime(now);
certRecord.setHostName("hostname");
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).withLong("lastNotifiedTime", certRecord.getLastNotifiedTime().getTime()).withString("lastNotifiedServer", certRecord.getLastNotifiedServer()).withLong("expiryTime", certRecord.getExpiryTime().getTime()).withString("hostName", certRecord.getHostName());
Mockito.doReturn(putOutcome).when(table).putItem(item);
boolean requestSuccess = dbConn.insertX509CertRecord(certRecord);
assertTrue(requestSuccess);
ArgumentCaptor<Item> itemCaptor = ArgumentCaptor.forClass(Item.class);
Mockito.verify(table, times(1)).putItem(itemCaptor.capture());
List<Item> allValues = itemCaptor.getAllValues();
assertEquals(1, allValues.size());
assertEquals(allValues.get(0).get("primaryKey"), item.get("primaryKey"));
assertEquals(allValues.get(0).get("provider"), item.get("provider"));
assertEquals(allValues.get(0).get("instanceId"), item.get("instanceId"));
assertEquals(allValues.get(0).get("service"), item.get("service"));
assertEquals(allValues.get(0).get("expiryTime"), item.get("expiryTime"));
assertEquals(allValues.get(0).get("hostName"), item.get("hostName"));
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class DynamoDBCertRecordStoreConnectionTest method testUpdateX509RecordException.
@Test
public void testUpdateX509RecordException() {
Date now = new Date();
X509CertRecord certRecord = getRecordNonNullableColumns(now);
Mockito.doThrow(new AmazonDynamoDBException("invalid operation")).when(table).updateItem(any(UpdateItemSpec.class));
DynamoDBCertRecordStoreConnection dbConn = getDBConnection();
boolean requestSuccess = dbConn.updateX509CertRecord(certRecord);
assertFalse(requestSuccess);
dbConn.close();
}
use of com.yahoo.athenz.common.server.cert.X509CertRecord in project athenz by yahoo.
the class FileCertRecordStoreConnectionTest method testdeleteExpiredX509CertRecords.
@Test
public void testdeleteExpiredX509CertRecords() throws Exception {
// 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);
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);
X509CertRecord certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
assertNotNull(certRecordCheck);
Thread.sleep(1000);
con.deleteExpiredX509CertRecords(0);
certRecordCheck = con.getX509CertRecord("ostk", "instance-id", "cn");
assertNull(certRecordCheck);
con.close();
}
Aggregations