Search in sources :

Example 51 with X509CertRecord

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 52 with X509CertRecord

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;
}
Also used : X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord)

Example 53 with X509CertRecord

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();
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 54 with X509CertRecord

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();
}
Also used : AmazonDynamoDBException(com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException) UpdateItemSpec(com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Test(org.testng.annotations.Test)

Example 55 with X509CertRecord

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();
}
Also used : File(java.io.File) X509CertRecord(com.yahoo.athenz.common.server.cert.X509CertRecord) Date(java.util.Date) 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