use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.
the class AutoRefreshCredentialProviderTest method testAssertCredentialCachingBehavior.
/**
* The getAwsCredential method should return the cached credential if the session hasn't expired. If the session expired, a new credential should be
* generated.
*
* @throws Exception
*/
@Test
public void testAssertCredentialCachingBehavior() throws Exception {
AutoRefreshCredentialProvider autoRefreshCredentialProvider = new AutoRefreshCredentialProvider() {
@Override
public AwsCredential getNewAwsCredential() throws Exception {
AwsCredential awsCredential = new AwsCredential();
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis() + 1000);
awsCredential.setAwsSessionExpirationTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
return awsCredential;
}
};
AwsCredential firstAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
AwsCredential secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
assertEquals(firstAwsCredential, secondAwsCredential);
Thread.sleep(1000);
secondAwsCredential = autoRefreshCredentialProvider.getAwsCredential();
assertNotEquals(firstAwsCredential, secondAwsCredential);
}
use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.
the class MockHttpClientOperationsImpl method getStorageUnitDownloadCredentialResponse.
private void getStorageUnitDownloadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException {
StorageUnitDownloadCredential storageUnitDownloadCredential = new StorageUnitDownloadCredential();
AwsCredential awsCredential = new AwsCredential();
awsCredential.setAwsAccessKey(uri.toString());
storageUnitDownloadCredential.setAwsCredential(awsCredential);
response.setEntity(getHttpEntity(storageUnitDownloadCredential));
}
use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.
the class UploaderWebClientTest method testGetBusinessObjectDataUploadCredential1.
@Test
public void testGetBusinessObjectDataUploadCredential1() throws Exception {
DataBridgeBaseManifestDto manifest = new DataBridgeBaseManifestDto();
manifest.setNamespace("test1");
manifest.setBusinessObjectDefinitionName("test2");
manifest.setBusinessObjectFormatUsage("test3");
manifest.setBusinessObjectFormatFileType("test4");
manifest.setBusinessObjectFormatVersion("test5");
manifest.setPartitionValue("test6");
manifest.setSubPartitionValues(Arrays.asList("test7", "test8"));
String storageName = "test8";
Integer businessObjectDataVersion = 1234;
Boolean createNewVersion = false;
uploaderWebClient.getRegServerAccessParamsDto().setUseSsl(false);
BusinessObjectDataUploadCredential businessObjectDataUploadCredential = uploaderWebClient.getBusinessObjectDataUploadCredential(manifest, storageName, businessObjectDataVersion, createNewVersion);
Assert.assertNotNull(businessObjectDataUploadCredential);
AwsCredential awsCredential = businessObjectDataUploadCredential.getAwsCredential();
Assert.assertNotNull(awsCredential);
Assert.assertEquals("http://testWebServiceHostname:1234/herd-app/rest/businessObjectData/upload/credential/namespaces/test1" + "/businessObjectDefinitionNames/test2/businessObjectFormatUsages/test3/businessObjectFormatFileTypes/test4/businessObjectFormatVersions/test5" + "/partitionValues/test6?storageName=test8&subPartitionValues=test7%7Ctest8&businessObjectDataVersion=1234&createNewVersion=false", awsCredential.getAwsAccessKey());
}
use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.
the class S3DaoTest method testGetAWSCredentialsProviderAssertAdditionalProviderIsSet.
/**
* A case where additional credentials provider is given in the request params. The credentials returned should be an AWS session credential where the
* values are from the provided custom credentials provider.
*/
@Test
public void testGetAWSCredentialsProviderAssertAdditionalProviderIsSet() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
try {
String s3BucketName = "s3BucketName";
String s3KeyPrefix = "s3KeyPrefix";
String awsAccessKey = "awsAccessKey";
String awsSecretKey = "awsSecretKey";
String awsSessionToken = "awsSessionToken";
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
s3FileTransferRequestParamsDto.setS3BucketName(s3BucketName);
s3FileTransferRequestParamsDto.setS3KeyPrefix(s3KeyPrefix);
s3FileTransferRequestParamsDto.setAdditionalAwsCredentialsProviders(Arrays.asList(new HerdAWSCredentialsProvider() {
@Override
public AwsCredential getAwsCredential() {
return new AwsCredential(awsAccessKey, awsSecretKey, awsSessionToken, null);
}
}));
when(mockS3Operations.putObject(any(), any())).then(new Answer<PutObjectResult>() {
@SuppressWarnings("unchecked")
@Override
public PutObjectResult answer(InvocationOnMock invocation) throws Throwable {
AmazonS3Client amazonS3Client = invocation.getArgument(1);
AWSCredentialsProviderChain awsCredentialsProviderChain = (AWSCredentialsProviderChain) ReflectionTestUtils.getField(amazonS3Client, "awsCredentialsProvider");
List<AWSCredentialsProvider> credentialsProviders = (List<AWSCredentialsProvider>) ReflectionTestUtils.getField(awsCredentialsProviderChain, "credentialsProviders");
assertEquals(2, credentialsProviders.size());
// refresh() does nothing, but gives code coverage
credentialsProviders.get(0).refresh();
/*
* We can't inspect the field directly since the class definition is private.
* Instead we call the getCredentials() and verify that it returns the credentials staged as part of this test.
*/
AWSCredentials credentials = awsCredentialsProviderChain.getCredentials();
assertEquals(BasicSessionCredentials.class, credentials.getClass());
BasicSessionCredentials basicSessionCredentials = (BasicSessionCredentials) credentials;
assertEquals(awsAccessKey, basicSessionCredentials.getAWSAccessKeyId());
assertEquals(awsSecretKey, basicSessionCredentials.getAWSSecretKey());
assertEquals(awsSessionToken, basicSessionCredentials.getSessionToken());
return new PutObjectResult();
}
});
s3Dao.createDirectory(s3FileTransferRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
}
}
use of org.finra.herd.model.api.xml.AwsCredential in project herd by FINRAOS.
the class MockHttpClientOperationsImpl method getBusinessObjectDataUploadCredentialResponse.
private void getBusinessObjectDataUploadCredentialResponse(MockCloseableHttpResponse response, URI uri) throws UnsupportedCharsetException, JAXBException {
BusinessObjectDataUploadCredential businessObjectDataUploadCredential = new BusinessObjectDataUploadCredential();
AwsCredential awsCredential = new AwsCredential();
awsCredential.setAwsAccessKey(uri.toString());
businessObjectDataUploadCredential.setAwsCredential(awsCredential);
response.setEntity(getHttpEntity(businessObjectDataUploadCredential));
}
Aggregations