use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBClientFetcherImplTest method testGetClientWithDefaultRegion.
@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);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBClientFetcherImplTest method testGetClientWitSpecifiedRegion.
@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);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreFactoryTest method testGetDynamoDBClient.
@Test
public void testGetDynamoDBClient() {
System.setProperty(ZTS_PROP_DYNAMODB_KEY_PATH, "test.keypath");
System.setProperty(ZTS_PROP_DYNAMODB_CERT_PATH, "test.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, "test.ztsurl");
System.setProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME, "test.appname");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
when(keyStore.getApplicationSecret(Mockito.eq("test.appname"), Mockito.eq("test.truststore.password"))).thenReturn("decryptedPassword");
DynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactory();
ZTSClientNotificationSenderImpl ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSenderImpl.class);
PrivateKeyStore privateKeyStore = Mockito.mock(PrivateKeyStore.class);
AmazonDynamoDB dynamoDBClient = factory.getDynamoDBClient(ztsClientNotificationSender, privateKeyStore);
Assert.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);
System.clearProperty(ZTS_PROP_DYNAMODB_TRUSTSTORE_APPNAME);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBWorkloadRecordStoreFactoryTest method testCreateMissingIndexName.
@Test
public void testCreateMissingIndexName() {
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME, "Workloads-Table");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
// First, don't set any index - will fail on ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME index
DynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactory();
try {
factory.create(keyStore);
Assert.fail();
} catch (ResourceException ex) {
Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
Assert.assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index workload-service-index not specified");
}
// Set it to empty value, will still fail
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME, "");
try {
factory.create(keyStore);
Assert.fail();
} catch (ResourceException ex) {
Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
Assert.assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index workload-service-index not specified");
}
// Set it to correct value, now will fail on host
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME, "Workload-Service-Index");
try {
factory.create(keyStore);
Assert.fail();
} catch (ResourceException ex) {
Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
Assert.assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index workload-ip-index not specified");
}
// Set it to empty value, will still fail
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME, "");
try {
factory.create(keyStore);
Assert.fail();
} catch (ResourceException ex) {
Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
Assert.assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index workload-ip-index not specified");
}
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class FileWorkloadRecordStoreFactoryTest method testCreate.
@Test
public void testCreate() {
String tempDirPath = System.getProperty("java.io.tmpdir");
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_FILE_STORE_PATH, tempDirPath);
System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_FILE_STORE_NAME, "workloads-store-unittests");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
FileWorkloadRecordStoreFactory factory = new FileWorkloadRecordStoreFactory();
WorkloadRecordStore store = factory.create(keyStore);
assertTrue(store instanceof FileWorkloadRecordStore);
new File(tempDirPath + "/" + "workloads-store-unittests").delete();
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_FILE_STORE_PATH);
System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_FILE_STORE_NAME);
}
Aggregations