Search in sources :

Example 6 with AWSClientManager

use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager 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());
}
Also used : AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) AWSSecurityTokenServiceException(com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Example 7 with AWSClientManager

use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager 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());
}
Also used : AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) AWSSecurityTokenServiceException(com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Aggregations

AWSSecurityTokenServiceException (com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException)7 AWSClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager)7 TestContext (com.vmware.xenon.common.test.TestContext)7 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)7 CompletionException (java.util.concurrent.CompletionException)7 Test (org.junit.Test)7 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)5 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)5 ARN_KEY (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY)5 EXTERNAL_ID_KEY (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY)5 AwsClientType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType)5 AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY)5 AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY)5 AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY)5 AWSClientManagerFactory (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory)5 AWSClientManagerFactory.getClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientManager)5 AWSClientManagerFactory.getClientReferenceCount (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientReferenceCount)5 AWSClientManagerFactory.returnClientManager (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.returnClientManager)5 BasicReusableHostTestCase (com.vmware.xenon.common.BasicReusableHostTestCase)5 CommandLineArgumentParser (com.vmware.xenon.common.CommandLineArgumentParser)5