Search in sources :

Example 26 with PrivateKeyStore

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);
}
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 27 with PrivateKeyStore

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);
}
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 28 with PrivateKeyStore

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

Example 29 with PrivateKeyStore

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

Example 30 with PrivateKeyStore

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);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) WorkloadRecordStore(com.yahoo.athenz.common.server.workload.WorkloadRecordStore) File(java.io.File) 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