Search in sources :

Example 1 with ZTSClientNotificationSenderImpl

use of com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl in project athenz by yahoo.

the class DynamoDBSSHRecordStoreFactoryTest 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");
    DynamoDBSSHRecordStoreFactory factory = new DynamoDBSSHRecordStoreFactory();
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSenderImpl.class);
    PrivateKeyStore privateKeyStore = Mockito.mock(PrivateKeyStore.class);
    AmazonDynamoDB dynamoDBClient = factory.getDynamoDBClient(ztsClientNotificationSender, privateKeyStore);
    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 2 with ZTSClientNotificationSenderImpl

use of com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl in project athenz by yahoo.

the class DynamoDBCertRecordStoreFactoryTest 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");
    DynamoDBCertRecordStoreFactory factory = new DynamoDBCertRecordStoreFactory();
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = Mockito.mock(ZTSClientNotificationSenderImpl.class);
    PrivateKeyStore privateKeyStore = Mockito.mock(PrivateKeyStore.class);
    AmazonDynamoDB dynamoDBClient = factory.getDynamoDBClient(ztsClientNotificationSender, privateKeyStore);
    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 3 with ZTSClientNotificationSenderImpl

use of com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl in project athenz by yahoo.

the class DynamoDBCertRecordStoreTest method testEnableNotifications.

@Test
public void testEnableNotifications() {
    DynamoDBCertRecordStore store = new DynamoDBCertRecordStore(dbClient, "Athenz-ZTS-Table", "Athenz-ZTS-Current-Time-Index", "Athenz-ZTS-Host-Name-Index", null);
    boolean isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
    store = new DynamoDBCertRecordStore(dbClient, "Athenz-ZTS-Table", "Athenz-ZTS-Current-Time-Index", "Athenz-ZTS-Host-Name-Index", ztsClientNotificationSender);
    isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
    String serverName = "testServer";
    isEnabled = store.enableNotifications(notificationManager, rolesProvider, serverName);
    assertTrue(isEnabled);
}
Also used : ZTSClientNotificationSenderImpl(com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl) NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 4 with ZTSClientNotificationSenderImpl

use of com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl in project athenz by yahoo.

the class DynamoDBSSHRecordStoreTest method testEnableNotifications.

@Test
public void testEnableNotifications() {
    DynamoDBSSHRecordStore store = new DynamoDBSSHRecordStore(dbClient, "Athenz-ZTS-Table", null);
    boolean isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
    store = new DynamoDBSSHRecordStore(dbClient, "Athenz-ZTS-Table", ztsClientNotificationSender);
    isEnabled = store.enableNotifications(null, null, null);
    assertFalse(isEnabled);
    NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    RolesProvider rolesProvider = Mockito.mock(RolesProvider.class);
    String serverName = "testServer";
    isEnabled = store.enableNotifications(notificationManager, rolesProvider, serverName);
    assertTrue(isEnabled);
}
Also used : ZTSClientNotificationSenderImpl(com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl) NotificationManager(com.yahoo.athenz.common.server.notification.NotificationManager) RolesProvider(com.yahoo.athenz.common.server.db.RolesProvider) Test(org.testng.annotations.Test)

Example 5 with ZTSClientNotificationSenderImpl

use of com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl in project athenz by yahoo.

the class DynamoDBCertRecordStoreFactory method create.

@Override
public CertRecordStore create(PrivateKeyStore keyStore) {
    final String tableName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_TABLE_NAME);
    if (tableName == null || tableName.isEmpty()) {
        LOGGER.error("Cert Store DynamoDB table name not specified");
        throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB table name not specified");
    }
    final String currentTimeIndexName = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_CURRENT_TIME_NAME);
    if (currentTimeIndexName == null || currentTimeIndexName.isEmpty()) {
        LOGGER.error("Cert Store DynamoDB index current-time not specified");
        throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB index current-time not specified");
    }
    final String hostNameIndex = System.getProperty(ZTSConsts.ZTS_PROP_CERT_DYNAMODB_INDEX_HOST_NAME);
    if (hostNameIndex == null || hostNameIndex.isEmpty()) {
        LOGGER.error("Cert Store DynamoDB index host-name not specified");
        throw new ResourceException(ResourceException.SERVICE_UNAVAILABLE, "DynamoDB index host-name not specified");
    }
    ZTSClientNotificationSenderImpl ztsClientNotificationSender = new ZTSClientNotificationSenderImpl();
    AmazonDynamoDB client = getDynamoDBClient(ztsClientNotificationSender, keyStore);
    return new DynamoDBCertRecordStore(client, tableName, currentTimeIndexName, hostNameIndex, ztsClientNotificationSender);
}
Also used : ZTSClientNotificationSenderImpl(com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl) ResourceException(com.yahoo.athenz.zts.ResourceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Aggregations

ZTSClientNotificationSenderImpl (com.yahoo.athenz.zts.notification.ZTSClientNotificationSenderImpl)7 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)5 Test (org.testng.annotations.Test)5 PrivateKeyStore (com.yahoo.athenz.auth.PrivateKeyStore)3 RolesProvider (com.yahoo.athenz.common.server.db.RolesProvider)2 NotificationManager (com.yahoo.athenz.common.server.notification.NotificationManager)2 ResourceException (com.yahoo.athenz.zts.ResourceException)2