Search in sources :

Example 16 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ZTSClientNotificationSender(com.yahoo.athenz.zts.ZTSClientNotificationSender) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Test(org.testng.annotations.Test)

Example 17 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 18 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) SSHRecordStore(com.yahoo.athenz.common.server.ssh.SSHRecordStore) Test(org.testng.annotations.Test)

Example 19 with PrivateKeyStore

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) {
    }
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 20 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Aggregations

PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)36 Test (org.testng.annotations.Test)35 ResourceException (com.yahoo.athenz.zts.ResourceException)8 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)6 ServerPrivateKey (com.yahoo.athenz.auth.ServerPrivateKey)3 WorkloadRecordStore (com.yahoo.athenz.common.server.workload.WorkloadRecordStore)3 ZTSClientNotificationSender (com.yahoo.athenz.zts.ZTSClientNotificationSender)3 ZTSClientNotificationSenderImpl (com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl)3 CertRecordStore (com.yahoo.athenz.common.server.cert.CertRecordStore)2 SSHRecordStore (com.yahoo.athenz.common.server.ssh.SSHRecordStore)2 ObjectStore (com.yahoo.athenz.zms.store.ObjectStore)2 FilePrivateKeyStore (com.yahoo.athenz.auth.impl.FilePrivateKeyStore)1 ChangeLogStore (com.yahoo.athenz.common.server.store.ChangeLogStore)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 SecureRandom (java.security.SecureRandom)1 KeyManager (javax.net.ssl.KeyManager)1 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)1