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);
}
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);
}
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);
}
Aggregations