Search in sources :

Example 1 with CredentialVerificationContext

use of com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext in project cloudbreak by hortonworks.

the class AwsCredentialConnectorTest method testVerifyIfRoleBasedCredentialVerificationShouldReturnVerifiedStatusWhenItIsCredentialCreationAndRoleIsNotAssumableWithoutExternalId.

@Test
public void testVerifyIfRoleBasedCredentialVerificationShouldReturnVerifiedStatusWhenItIsCredentialCreationAndRoleIsNotAssumableWithoutExternalId() throws AwsPermissionMissingException, IOException {
    URL url = Resources.getResource("definitions/aws-environment-minimal-policy.json");
    String awsEnvPolicy = Resources.toString(url, UTF_8);
    String encodedAwsEnvPolicy = Base64.getEncoder().encodeToString(awsEnvPolicy.getBytes());
    String roleArn = "someRoleArn";
    when(awsPlatformParameters.getEnvironmentMinimalPoliciesJson()).thenReturn(Map.of(PolicyType.PUBLIC, encodedAwsEnvPolicy, PolicyType.GOV, encodedAwsEnvPolicy));
    when(credentialView.getRoleArn()).thenReturn(roleArn);
    AmazonClientException amazonClientException = new AmazonClientException(ROLE_IS_NOT_ASSUMABLE_ERROR_MESSAGE_INDICATOR);
    when(credentialClient.retrieveSessionCredentialsWithoutExternalId(any())).thenThrow(amazonClientException);
    CloudCredentialStatus result = underTest.verify(authenticatedContext, new CredentialVerificationContext(Boolean.TRUE));
    assertNotNull(result);
    assertEquals(CredentialStatus.VERIFIED, result.getStatus());
    assertNull(result.getException());
    verify(awsCredentialVerifier, times(1)).validateAws(any(), any());
    verify(awsCredentialVerifier, times(1)).validateAws(credentialView, encodedAwsEnvPolicy);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) CredentialVerificationContext(com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext) URL(java.net.URL) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Example 2 with CredentialVerificationContext

use of com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext in project cloudbreak by hortonworks.

the class AwsCredentialConnectorTest method testVerifyIfRoleBasedCredentialVerificationShouldReturnFailedStatusWhenItIsCredentialCreationAndRoleAssumeFailsWithoutExternalId.

@Test
public void testVerifyIfRoleBasedCredentialVerificationShouldReturnFailedStatusWhenItIsCredentialCreationAndRoleAssumeFailsWithoutExternalId() throws AwsPermissionMissingException, IOException {
    URL url = Resources.getResource("definitions/aws-environment-minimal-policy.json");
    String awsEnvPolicy = Resources.toString(url, UTF_8);
    String encodedAwsEnvPolicy = Base64.getEncoder().encodeToString(awsEnvPolicy.getBytes());
    String roleArn = "someRoleArn";
    when(credentialView.getRoleArn()).thenReturn(roleArn);
    AmazonClientException amazonClientException = new AmazonClientException("Something unexpected happened");
    when(credentialClient.retrieveSessionCredentialsWithoutExternalId(any())).thenThrow(amazonClientException);
    CloudCredentialStatus result = underTest.verify(authenticatedContext, new CredentialVerificationContext(Boolean.TRUE));
    assertNotNull(result);
    assertEquals(CredentialStatus.FAILED, result.getStatus());
    assertEquals(amazonClientException, result.getException());
    verify(awsCredentialVerifier, times(0)).validateAws(any(), any());
    verify(awsCredentialVerifier, times(0)).validateAws(credentialView, encodedAwsEnvPolicy);
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) CredentialVerificationContext(com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext) URL(java.net.URL) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Example 3 with CredentialVerificationContext

use of com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext in project cloudbreak by hortonworks.

the class AwsCredentialConnectorTest method testVerifyIfRoleBasedCredentialVerificationShouldFailWhenItIsCredentialCreationAndRoleIsAssumableWithoutExternalId.

@Test
public void testVerifyIfRoleBasedCredentialVerificationShouldFailWhenItIsCredentialCreationAndRoleIsAssumableWithoutExternalId() throws AwsPermissionMissingException, IOException {
    URL url = Resources.getResource("definitions/aws-environment-minimal-policy.json");
    String awsEnvPolicy = Resources.toString(url, UTF_8);
    String encodedAwsEnvPolicy = Base64.getEncoder().encodeToString(awsEnvPolicy.getBytes());
    String roleArn = "someRoleArn";
    when(awsPlatformParameters.getEnvironmentMinimalPoliciesJson()).thenReturn(Map.of(PolicyType.PUBLIC, encodedAwsEnvPolicy, PolicyType.GOV, encodedAwsEnvPolicy));
    when(credentialView.getRoleArn()).thenReturn(roleArn);
    CloudCredentialStatus result = underTest.verify(authenticatedContext, new CredentialVerificationContext(Boolean.TRUE));
    assertNotNull(result);
    assertEquals(CredentialStatus.FAILED, result.getStatus());
    assertEquals(AwsConfusedDeputyException.class, result.getException().getClass());
    verify(awsCredentialVerifier, times(0)).validateAws(any(), any());
    verify(awsCredentialVerifier, times(0)).validateAws(credentialView, encodedAwsEnvPolicy);
}
Also used : CredentialVerificationContext(com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext) URL(java.net.URL) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus) Test(org.junit.Test)

Aggregations

CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)3 CredentialVerificationContext (com.sequenceiq.cloudbreak.cloud.model.credential.CredentialVerificationContext)3 URL (java.net.URL)3 Test (org.junit.Test)3 AmazonClientException (com.amazonaws.AmazonClientException)2