use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBClientFetcherImplTest method testGetAuthenticatedClient.
@Test
public void testGetAuthenticatedClient() {
// public
String certPath = Resources.getResource("gdpr.aws.core.cert.pem").getPath();
// private
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://dev.zts.athenzcompany.com:4443/zts/v1");
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);
// Also try with min and max expiry set
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);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBSSHRecordStoreFactoryTest method testCreateMissingTableName.
@Test
public void testCreateMissingTableName() {
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
System.clearProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME);
TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory();
try {
factory.create(keyStore);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
}
System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, "");
try {
factory.create(keyStore);
fail();
} catch (ResourceException ex) {
assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
}
System.clearProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBSSHRecordStoreFactoryTest method testCreate.
@Test
public void testCreate() {
System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory();
SSHRecordStore store = factory.create(keyStore);
assertNotNull(store);
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBSSHRecordStoreFactoryTest method testCreateAmzClient.
@Test
public void testCreateAmzClient() {
System.setProperty(ZTSConsts.ZTS_PROP_SSH_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table");
PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
TestDynamoDBSSHRecordStoreFactory factory = new TestDynamoDBSSHRecordStoreFactory();
try {
factory.create(keyStore);
} catch (Exception ignored) {
}
}
use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.
the class DynamoDBClientSettingsTest method testCredentialsProvided.
@Test
public void testCredentialsProvided() {
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");
DynamoDBClientSettings dynamoDBClientSettings = new DynamoDBClientSettings(keyStore);
assertTrue(dynamoDBClientSettings.areCredentialsProvided());
assertEquals("test.keypath", dynamoDBClientSettings.getKeyPath());
assertEquals("test.certpath", dynamoDBClientSettings.getCertPath());
assertEquals("test.domain", dynamoDBClientSettings.getDomainName());
assertEquals("test.region", dynamoDBClientSettings.getRegion());
assertEquals("test.role", dynamoDBClientSettings.getRoleName());
assertEquals("test.truststore", dynamoDBClientSettings.getTrustStore());
assertEquals("decryptedPassword", dynamoDBClientSettings.getTrustStorePassword());
assertEquals("test.ztsurl", dynamoDBClientSettings.getZtsURL());
// Now verify that when keyStore isn't provided, trustStorePassword will be null
dynamoDBClientSettings = new DynamoDBClientSettings(null);
assertNull(dynamoDBClientSettings.getTrustStorePassword());
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);
}
Aggregations