DynamoDBCertRecordStoreFactory implements CertRecordStoreFactory { @Override public CertRecordStore create(PrivateKeyStore keyStore) { final String tableName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME); if (tableName == null || tableName.isEmpty()) { LOGGER.error("Cert Store DynamoDB table name not specified"); throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB table name not specified"); } final String indexName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME); if (indexName == null || indexName.isEmpty()) { LOGGER.error("Cert Store DynamoDB index current-time not specified"); throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB index current-time not specified"); } ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl(); AmazonDynamoDB client = getDynamoDBClient(ztsClientNotificationSender, keyStore); return new DynamoDBCertRecordStore(client, tableName, indexName, ztsClientNotificationSender); }  @Override CertRecordStore create(PrivateKeyStore keyStore);  }
@Test public void testCreate() { System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table"); System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME, "Athenz-ZTS-Current-Time-Index"); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); TestDynamoDBCertRecordStoreFactory factory = new TestDynamoDBCertRecordStoreFactory(); CertRecordStore store = factory.create(keyStore); assertNotNull(store); System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME); System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME); }
@Test public void testCreateAmzClient() { System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table"); System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME, "Athenz-ZTS-Current-Time-Index"); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); TestDynamoDBCertRecordStoreFactory factory = new TestDynamoDBCertRecordStoreFactory(); try { factory.create(keyStore); } catch (Exception ignored) { } System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME); System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME); }
@Test public void testCreateMissingTableName() { PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME); TestDynamoDBCertRecordStoreFactory factory = new TestDynamoDBCertRecordStoreFactory(); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, ""); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME); }
@Test public void testCreateMissingIndexName() { PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table"); System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME); DynamoDBCertRecordStoreFactory factory = new DynamoDBCertRecordStoreFactory(); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME, ""); try { factory.create(keyStore); fail(); } catch (ResourceException ex) { assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE); } System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME); }