use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class LongRunEndToEndStatsAggregationTest method initResourcePoolAndComputeHost.
/**
* Creates the state associated with the resource pool, compute host and the VM to be created.
*
* @throws Throwable
*/
private void initResourcePoolAndComputeHost() throws Throwable {
// Create a resource pool where the VM will be housed
ResourcePoolState resourcePool = createAWSResourcePool(this.host);
AuthCredentialsServiceState auth = createAWSAuthentication(this.host, this.accessKey, this.secretKey);
this.endpointState = TestAWSSetupUtils.createAWSEndpointState(this.host, auth.documentSelfLink, resourcePool.documentSelfLink);
// create a compute host for the AWS EC2 VM
this.computeHost = createAWSComputeHost(this.host, this.endpointState, null, /*zoneId*/
this.useAllRegions ? null : regionId, this.isAwsClientMock, this.awsMockEndpointReference, null);
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class AWSSubnetTaskServiceTest method setUp.
@Override
@Before
public void setUp() throws Throwable {
CommandLineArgumentParser.parseFromProperties(this);
try {
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = this.secretKey;
creds.privateKeyId = this.accessKey;
this.client = AWSUtils.getAsyncClient(creds, this.regionId, getExecutor());
this.host.setTimeoutSeconds(this.timeoutSeconds);
this.awsTestContext = new HashMap<>();
setUpTestVpc(this.client, this.awsTestContext, this.isMock);
this.endpointState = createEndpointState();
this.networkState = createNetworkState();
} catch (Throwable e) {
this.host.log("Error starting up services for the test %s", e.getMessage());
throw new Exception(e);
}
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestAWSClientManagement method testAwsS3ClientManagement.
@Test
public void testAwsS3ClientManagement() throws Throwable {
// Ensure that we start with a clean state.
AWSClientManagerFactory.cleanUp(AwsClientType.S3_TRANSFER_MANAGER);
// Get a reference to the client manager in the test
AWSClientManager s3ClientManager = getClientManager(AwsClientType.S3_TRANSFER_MANAGER);
assertEquals(1, getClientReferenceCount(AwsClientType.S3_TRANSFER_MANAGER));
AuthCredentialsServiceState testCreds = new AuthCredentialsServiceState();
testCreds.privateKey = this.accessKey;
testCreds.privateKeyId = this.secretKey;
final AmazonS3Client[] s3Client = new AmazonS3Client[1];
TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
s3ClientManager.getOrCreateS3TransferManagerAsync(testCreds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
waitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(i -> waitContext.complete());
waitContext.await();
assertEquals(1, s3ClientManager.getCacheCount());
// Return the references from the test
returnClientManager(s3ClientManager, AwsClientType.S3_TRANSFER_MANAGER);
assertEquals(0, getClientReferenceCount(AwsClientType.S3_TRANSFER_MANAGER));
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestAWSClientManagement method testEc2ClientInvalidArnKey.
@Test
public void testEc2ClientInvalidArnKey() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn + "-invalid");
this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
AWSSecurityTokenServiceException[] expectedException = new AWSSecurityTokenServiceException[1];
TestContext waitContext = new TestContext(1, Duration.ofSeconds(60L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
expectedException[0] = (AWSSecurityTokenServiceException) t.getCause();
waitContext.complete();
throw new CompletionException(t);
});
waitContext.await();
Assert.assertNull(this.client);
Assert.assertEquals(Operation.STATUS_CODE_FORBIDDEN, expectedException[0].getStatusCode());
Assert.assertEquals("AccessDenied", expectedException[0].getErrorCode());
}
use of com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState in project photon-model by vmware.
the class TestAWSClientManagement method testEc2ClientInvalidExternalId.
@Test
public void testEc2ClientInvalidExternalId() throws Throwable {
this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
this.host.setTimeoutSeconds(60);
// Getting a reference to client managers in the test
AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
ec2ClientManager.cleanUpArnCache();
assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
this.creds = new AuthCredentialsServiceState();
this.creds.customProperties = new HashMap<>();
this.creds.customProperties.put(ARN_KEY, this.arn);
this.creds.customProperties.put(EXTERNAL_ID_KEY, "invalid");
AWSSecurityTokenServiceException[] expectedException = new AWSSecurityTokenServiceException[1];
TestContext waitContext = new TestContext(1, Duration.ofSeconds(60L));
ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
expectedException[0] = (AWSSecurityTokenServiceException) t.getCause();
waitContext.complete();
throw new CompletionException(t);
});
waitContext.await();
Assert.assertNull(this.client);
Assert.assertEquals(Operation.STATUS_CODE_FORBIDDEN, expectedException[0].getStatusCode());
Assert.assertEquals("AccessDenied", expectedException[0].getErrorCode());
}
Aggregations