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");
}
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);
}
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);
}
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);
}
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);
}
Aggregations