DynamoDBClientFetcherImpl implements DynamoDBClientFetcher { @Override public DynamoDBClientAndCredentials getDynamoDBClient(ZTSClientNotificationSender ztsClientNotificationSender, PrivateKeyStore keyStore) { DynamoDBClientSettings dynamoDBClientSettings = new DynamoDBClientSettings(keyStore); if (dynamoDBClientSettings.areCredentialsProvided()) { LOGGER.info("DynamoDB Client will use temporary AWS credentials"); return getAuthenticatedDynamoDBClient(dynamoDBClientSettings, ztsClientNotificationSender); } else { LOGGER.info("DynamoDB client will use existing AWS authentication"); AmazonDynamoDB client = AmazonDynamoDBClientBuilder .standard() .withRegion(getAWSRegion(dynamoDBClientSettings.getRegion())) .build(); return new DynamoDBClientAndCredentials(client, null); } } DynamoDBClientFetcherImpl();  DynamoDBClientFetcherImpl(String defaultAwsRegion); @Override DynamoDBClientAndCredentials getDynamoDBClient(ZTSClientNotificationSender ztsClientNotificationSender, PrivateKeyStore keyStore);  }
@Test public void testGetClientWitSpecifiedRegion() { System.setProperty(ZTS_PROP_DYNAMODB_REGION, "test.region"); DynamoDBClientFetcher dynamoDBClientFetcher = DynamoDBClientFetcherFactory.getDynamoDBClientFetcher(); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); ZTSClientNotificationSender ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSender.class); AmazonDynamoDB dynamoDBClient = dynamoDBClientFetcher.getDynamoDBClient(ztsClientNotificationSender, keyStore).getAmazonDynamoDB(); assertNotNull(dynamoDBClient); System.clearProperty(ZTS_PROP_DYNAMODB_REGION); }
@Test public void testGetClientWithDefaultRegion() { DynamoDBClientFetcher dynamoDBClientFetcher = new DynamoDBClientFetcherImpl("testRegion"); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); ZTSClientNotificationSender ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSender.class); AmazonDynamoDB dynamoDBClient = dynamoDBClientFetcher.getDynamoDBClient(ztsClientNotificationSender, keyStore).getAmazonDynamoDB(); assertNotNull(dynamoDBClient); }
@Test public void testGetAuthenticatedClient() { String certPath = Resources.getResource("gdpr.aws.core.cert.pem").getPath(); String keyPath = Resources.getResource("unit_test_gdpr.aws.core.key.pem").getPath(); System.setProperty(ZTS_PROP_DYNAMODB_KEY_PATH, keyPath); System.setProperty(ZTS_PROP_DYNAMODB_CERT_PATH, certPath); System.setProperty(ZTS_PROP_DYNAMODB_DOMAIN, "test.domain"); System.setProperty(ZTS_PROP_DYNAMODB_REGION, "test.region"); System.setProperty(ZTS_PROP_DYNAMODB_ROLE, "test.role"); System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE, "test.truststore"); System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD, "test.truststore.password"); System.setProperty(ZTS_PROP_DYNAMODB_ZTS_URL, "https: DynamoDBClientFetcherImpl dynamoDBClientFetcher = new DynamoDBClientFetcherImpl(); PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class); when(keyStore.getApplicationSecret(Mockito.eq(""), Mockito.eq("test.truststore.password"))).thenReturn("mockPassword"); ZTSClientNotificationSender ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSender.class); AmazonDynamoDB dynamoDBClient = dynamoDBClientFetcher.getDynamoDBClient(ztsClientNotificationSender, keyStore).getAmazonDynamoDB(); assertNotNull(dynamoDBClient); System.setProperty(ZTS_PROP_DYNAMODB_MIN_EXPIRY_TIME, "10"); System.setProperty(ZTS_PROP_DYNAMODB_MAX_EXPIRY_TIME, "100"); dynamoDBClient = dynamoDBClientFetcher.getDynamoDBClient(ztsClientNotificationSender, keyStore).getAmazonDynamoDB(); assertNotNull(dynamoDBClient); System.clearProperty(ZTS_PROP_DYNAMODB_KEY_PATH); System.clearProperty(ZTS_PROP_DYNAMODB_CERT_PATH); System.clearProperty(ZTS_PROP_DYNAMODB_DOMAIN); System.clearProperty(ZTS_PROP_DYNAMODB_REGION); System.clearProperty(ZTS_PROP_DYNAMODB_ROLE); System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE); System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_PASSWORD); System.clearProperty(ZTS_PROP_DYNAMODB_ZTS_URL); }