Search in sources :

Example 11 with PrivateKeyStore

use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.

the class ZTSUtilsTest method testGetApplicationSecret.

@Test
public void testGetApplicationSecret() {
    assertEquals(ZTSUtils.getApplicationSecret(null, "appname", "pass"), "pass");
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    Mockito.when(keyStore.getApplicationSecret(null, "pass")).thenReturn("app234");
    assertEquals(ZTSUtils.getApplicationSecret(keyStore, null, "pass"), "app234");
    Mockito.when(keyStore.getApplicationSecret("appname", "passname")).thenReturn("app123");
    assertEquals(ZTSUtils.getApplicationSecret(keyStore, "appname", "passname"), "app123");
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) Test(org.testng.annotations.Test)

Example 12 with PrivateKeyStore

use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreFactoryTest method testCreateAmzClient.

@Test
public void testCreateAmzClient() {
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME, "Workload-Table");
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME, "Workload-Service-Index");
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME, "Workload-Ip-Index");
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory();
    try {
        factory.create(keyStore);
    } catch (Exception ignored) {
    }
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_SERVICE_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_INDEX_IP_NAME);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 13 with PrivateKeyStore

use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.

the class DynamoDBWorkloadRecordStoreFactoryTest method testCreateMissingTableName.

@Test
public void testCreateMissingTableName() {
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    System.clearProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME);
    DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory factory = new DynamoDBWorkloadRecordStoreFactoryTest.TestDynamoDBWorkloadRecordStoreFactory();
    try {
        factory.create(keyStore);
        Assert.fail();
    } catch (ResourceException ex) {
        Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
    }
    System.setProperty(ZTSConsts.ZTS_PROP_WORKLOAD_DYNAMODB_TABLE_NAME, "");
    try {
        factory.create(keyStore);
        Assert.fail();
    } catch (ResourceException ex) {
        Assert.assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
    }
    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 14 with PrivateKeyStore

use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.

the class DynamoDBCertRecordStoreFactoryTest method testCreateMissingTableName.

@Test
public void testCreateMissingTableName() {
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME);
    TestDynamoDBCertRecordStoreFactory factory = new TestDynamoDBCertRecordStoreFactory();
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
    }
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, "");
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
    }
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ResourceException(com.yahoo.athenz.zts.ResourceException) Test(org.testng.annotations.Test)

Example 15 with PrivateKeyStore

use of com.yahoo.athenz.auth.PrivateKeyStore in project athenz by yahoo.

the class DynamoDBCertRecordStoreFactoryTest method testCreateMissingIndexName.

@Test
public void testCreateMissingIndexName() {
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME, "Athenz-ZTS-Table");
    PrivateKeyStore keyStore = Mockito.mock(PrivateKeyStore.class);
    // First, don't set any index - will fail on ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME index
    DynamoDBCertRecordStoreFactory factory = new DynamoDBCertRecordStoreFactory();
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
        assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index current-time not specified");
    }
    // Set it to empty value, will still fail
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME, "");
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
        assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index current-time not specified");
    }
    // Set it to correct value, now will fail on host
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME, "Athenz-ZTS-Current-Time-Index");
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
        assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index host-name not specified");
    }
    // Set it to empty value, will still fail
    System.setProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_HOST_NAME, "");
    try {
        factory.create(keyStore);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), ResourceException.SERVICE_UNAVAILABLE);
        assertEquals(ex.getMessage(), "ResourceException (503): DynamoDB index host-name not specified");
    }
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_HOST_NAME);
    System.clearProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME);
}
Also used : PrivateKeyStore(com.yahoo.athenz.auth.PrivateKeyStore) ResourceException(com.yahoo.athenz.zts.ResourceException) 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