use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class Ec2DaoTest method testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances.
@Test
public void testGetLatestSpotPricesSpotPriceHistoryContainDuplicateTypeInstances() {
// Initialize inputs.
Collection<String> instanceTypes = Arrays.asList(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.INSTANCE_TYPE_2);
Collection<String> productDescriptions = Arrays.asList("b", "c");
// Set up mock.
mock(RetryPolicyFactory.class);
Ec2Operations ec2Operations = mock(Ec2Operations.class);
((Ec2DaoImpl) ec2Dao).setEc2Operations(ec2Operations);
DescribeSpotPriceHistoryResult describeSpotPriceHistoryResult = new DescribeSpotPriceHistoryResult();
List<SpotPrice> spotPrices = new ArrayList<>();
spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_1, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
spotPrices.add(new MockSpotPrice(MockEc2OperationsImpl.INSTANCE_TYPE_1, MockEc2OperationsImpl.AVAILABILITY_ZONE_2, MockEc2OperationsImpl.SPOT_PRICE_HIGH).toAwsObject());
describeSpotPriceHistoryResult.setSpotPriceHistory(spotPrices);
when(ec2Operations.describeSpotPriceHistory(any(), any())).thenReturn(describeSpotPriceHistoryResult);
// Execute MUT.
List<SpotPrice> result = ec2Dao.getLatestSpotPrices(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions, new AwsParamsDto());
// Verify that the dependency was called with the correct parameters.
verify(ec2Operations).describeSpotPriceHistory(any(), equalsDescribeSpotPriceHistoryRequest(MockEc2OperationsImpl.AVAILABILITY_ZONE_1, instanceTypes, productDescriptions));
// Verify that result contains only one spot price entry.
assertEquals(1, CollectionUtils.size(result));
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class KmsDaoTest method testDecryptInvalidCipher.
@Test
public void testDecryptInvalidCipher() {
try {
// Try to decrypt an invalid ciphertext.
kmsDao.decrypt(new AwsParamsDto(), MockKmsOperationsImpl.MOCK_CIPHER_TEXT_INVALID);
fail("Suppose to throw an InvalidCiphertextException when cipher text is invalid.");
} catch (Exception e) {
assertEquals(InvalidCiphertextException.class, e.getClass());
}
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class KmsDaoTest method testDecrypt.
@Test
public void testDecrypt() {
// Decrypt the test ciphertext.
AwsParamsDto testAwsParamsDto = new AwsParamsDto();
testAwsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST);
testAwsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT);
// Decrypt the test ciphertext.
String resultPlainText = kmsDao.decrypt(testAwsParamsDto, MockKmsOperationsImpl.MOCK_CIPHER_TEXT);
// Validate the results.
assertEquals(MockKmsOperationsImpl.MOCK_PLAIN_TEXT, resultPlainText);
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class SnsDaoTest method testPublish.
@Test
public void testPublish() {
// Publish an SNS message without proxy.
assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao.publish(new AwsParamsDto(), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS));
// Publish an SNS message using proxy settings.
assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao.publish(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, NO_MESSAGE_HEADERS));
// Publish an SNS message with message headers.
assertEquals(new PublishResult().withMessageId(MESSAGE_ID), snsDao.publish(new AwsParamsDto(), AWS_SNS_TOPIC_ARN, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE))));
}
use of org.finra.herd.model.dto.AwsParamsDto in project herd by FINRAOS.
the class StsDaoTest method testGetTemporarySecurityCredentials.
@Test
public void testGetTemporarySecurityCredentials() {
// Create an AWS parameters DTO with proxy settings.
AwsParamsDto awsParamsDto = new AwsParamsDto();
awsParamsDto.setHttpProxyHost(HTTP_PROXY_HOST);
awsParamsDto.setHttpProxyPort(HTTP_PROXY_PORT);
// Specify the duration, in seconds, of the role session.
int awsRoleDurationSeconds = INTEGER_VALUE;
// Create an IAM policy.
Policy policy = new Policy(STRING_VALUE);
// Create a retry policy.
RetryPolicy retryPolicy = new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION, PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, INTEGER_VALUE, true);
// Create the expected assume role request.
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest().withRoleArn(AWS_ROLE_ARN).withRoleSessionName(SESSION_NAME).withPolicy(policy.toJson()).withDurationSeconds(awsRoleDurationSeconds);
// Create AWS credentials for API authentication.
Credentials credentials = new Credentials();
credentials.setAccessKeyId(AWS_ASSUMED_ROLE_ACCESS_KEY);
credentials.setSecretAccessKey(AWS_ASSUMED_ROLE_SECRET_KEY);
credentials.setSessionToken(AWS_ASSUMED_ROLE_SESSION_TOKEN);
// Create an assume role result.
AssumeRoleResult assumeRoleResult = new AssumeRoleResult();
assumeRoleResult.setCredentials(credentials);
// Mock the external calls.
when(retryPolicyFactory.getRetryPolicy()).thenReturn(retryPolicy);
when(stsOperations.assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest))).thenReturn(assumeRoleResult);
// Call the method under test.
Credentials result = stsDaoImpl.getTemporarySecurityCredentials(awsParamsDto, SESSION_NAME, AWS_ROLE_ARN, awsRoleDurationSeconds, policy);
// Verify the external calls.
verify(retryPolicyFactory).getRetryPolicy();
verify(stsOperations).assumeRole(any(AWSSecurityTokenServiceClient.class), eq(assumeRoleRequest));
verifyNoMoreInteractionsHelper();
// Validate the returned object.
assertEquals(credentials, result);
}
Aggregations