use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class CredStashHelperTest method testGetCredentialFromCredStash.
@Test
public void testGetCredentialFromCredStash() throws Exception {
// Build AWS parameters.
AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Build AWS client configuration.
ClientConfiguration clientConfiguration = new ClientConfiguration();
// Create CredStash encryption context map.
Map<String, String> credStashEncryptionContextMap = new HashMap<>();
credStashEncryptionContextMap.put(KEY, VALUE);
// Mock the CredStash.
CredStash credStash = mock(CredStash.class);
when(credStash.getCredential(USER_CREDENTIAL_NAME, credStashEncryptionContextMap)).thenReturn(PASSWORD);
// Mock the external calls.
when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_AWS_REGION_NAME)).thenReturn(AWS_REGION_NAME);
when(configurationHelper.getProperty(ConfigurationValue.CREDSTASH_TABLE_NAME)).thenReturn(TABLE_NAME);
when(awsHelper.getAwsParamsDto()).thenReturn(awsParamsDto);
when(awsHelper.getClientConfiguration(awsParamsDto)).thenReturn(clientConfiguration);
when(credStashFactory.getCredStash(AWS_REGION_NAME, TABLE_NAME, clientConfiguration)).thenReturn(credStash);
when(jsonHelper.unmarshallJsonToObject(Map.class, CREDSTASH_ENCRYPTION_CONTEXT)).thenReturn(credStashEncryptionContextMap);
// Call the method under test.
String result = credStashHelper.getCredentialFromCredStash(CREDSTASH_ENCRYPTION_CONTEXT, USER_CREDENTIAL_NAME);
// Verify the external calls.
verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_AWS_REGION_NAME);
verify(configurationHelper).getProperty(ConfigurationValue.CREDSTASH_TABLE_NAME);
verify(awsHelper).getAwsParamsDto();
verify(awsHelper).getClientConfiguration(awsParamsDto);
verify(credStashFactory).getCredStash(AWS_REGION_NAME, TABLE_NAME, clientConfiguration);
verify(jsonHelper).unmarshallJsonToObject(Map.class, CREDSTASH_ENCRYPTION_CONTEXT);
verify(credStash).getCredential(USER_CREDENTIAL_NAME, credStashEncryptionContextMap);
verifyNoMoreInteractions(credStash);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(PASSWORD, result);
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class AwsParamsDtoTest method testHashCode.
@Test
public void testHashCode() throws Exception {
AwsParamsDto dto1 = new AwsParamsDto();
dto1.setHttpProxyHost("localhost1");
dto1.setHttpProxyPort(8080);
AwsParamsDto dto2 = new AwsParamsDto();
dto2.setHttpProxyHost("localhost2");
dto2.setHttpProxyPort(8080);
AwsParamsDto dto3 = new AwsParamsDto();
dto3.setHttpProxyHost("localhost1");
dto3.setHttpProxyPort(8080);
assertTrue(dto1.hashCode() != dto2.hashCode());
assertTrue(dto1.hashCode() == dto3.hashCode());
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class AwsParamsDtoTest method testEquals.
@Test
public void testEquals() throws Exception {
AwsParamsDto dto1 = new AwsParamsDto();
dto1.setHttpProxyHost("localhost1");
dto1.setHttpProxyPort(8080);
AwsParamsDto dto2 = new AwsParamsDto();
dto2.setHttpProxyHost("localhost2");
dto2.setHttpProxyPort(8080);
AwsParamsDto dto3 = new AwsParamsDto();
dto3.setHttpProxyHost("localhost1");
dto3.setHttpProxyPort(8080);
assertTrue(!dto1.equals(dto2));
assertTrue(dto1.equals(dto3));
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class AwsClientFactoryTest method testGetEc2ClientCacheHitMiss.
@Test
public void testGetEc2ClientCacheHitMiss() {
// Create an AWS parameters DTO that contains both AWS credentials and proxy information.
AwsParamsDto awsParamsDto = new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
// Get an Amazon EC2 client.
AmazonEC2Client amazonEC2Client = awsClientFactory.getEc2Client(awsParamsDto);
// Confirm a cache hit.
assertEquals(amazonEC2Client, awsClientFactory.getEc2Client(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
// Confirm a cache miss due to AWS credentials.
assertNotEquals(amazonEC2Client, awsClientFactory.getEc2Client(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY_2, AWS_ASSUMED_ROLE_SECRET_KEY_2, AWS_ASSUMED_ROLE_SESSION_TOKEN_2, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));
// Confirm a cache miss due to http proxy information.
assertNotEquals(amazonEC2Client, awsClientFactory.getEc2Client(new AwsParamsDto(AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2)));
// Clear the cache.
cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();
// Confirm a cache miss due to cleared cache.
assertNotEquals(amazonEC2Client, awsClientFactory.getEc2Client(awsParamsDto));
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class EmrDaoTest method createEmrClusterAssertEncryptionDisabled.
@Test
public void createEmrClusterAssertEncryptionDisabled() throws Exception {
/*
* Use only minimum required options
*/
String clusterName = "clusterName";
EmrClusterDefinition emrClusterDefinition = new EmrClusterDefinition();
InstanceDefinitions instanceDefinitions = new InstanceDefinitions();
instanceDefinitions.setMasterInstances(new MasterInstanceDefinition(10, "masterInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
instanceDefinitions.setCoreInstances(new InstanceDefinition(20, "coreInstanceType", NO_EMR_CLUSTER_DEFINITION_EBS_CONFIGURATION, NO_INSTANCE_SPOT_PRICE, NO_INSTANCE_MAX_SEARCH_PRICE, NO_INSTANCE_ON_DEMAND_THRESHOLD));
emrClusterDefinition.setInstanceDefinitions(instanceDefinitions);
emrClusterDefinition.setNodeTags(Arrays.asList(new NodeTag("tagName", "tagValue")));
emrClusterDefinition.setEncryptionEnabled(false);
String clusterId = "clusterId";
when(mockEmrOperations.runEmrJobFlow(any(), any())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
RunJobFlowRequest runJobFlowRequest = invocation.getArgument(1);
// No bootstrap action should be added
assertEquals(0, runJobFlowRequest.getBootstrapActions().size());
return clusterId;
}
});
assertEquals(clusterId, emrDao.createEmrCluster(clusterName, emrClusterDefinition, new AwsParamsDto()));
}
Aggregations