use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AwsIamServiceTest method roleServiceFailureException.
@Test
public void roleServiceFailureException() {
when(iam.getRole(any(GetRoleRequest.class))).thenThrow(ServiceFailureException.class);
String roleArn = "account/potentialRole";
ValidationResultBuilder validationRequestBuilder = new ValidationResultBuilder();
Role role = awsIamService.getRole(iam, roleArn, validationRequestBuilder);
assertThat(role).isNull();
ValidationResult validationResult = validationRequestBuilder.build();
assertThat(validationResult.hasError()).isTrue();
assertThat(validationResult.getErrors()).isEqualTo(Collections.singletonList(String.format("Role (%s) doesn't exists on AWS side. " + "Please check if you've used the correct Role when setting up Data Access.", roleArn)));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AwsIDBrokerAssumeRoleValidatorTest method checkCannotAssumeRoles.
@Test
public void checkCannotAssumeRoles() {
Role instanceProfileRole = new Role();
InstanceProfile instanceProfile = new InstanceProfile().withArn("instanceProfileArn").withRoles(instanceProfileRole);
Role role = new Role().withArn("roleArn");
Collection<Role> roles = Collections.singletonList(role);
EvaluationResult evalResult = new EvaluationResult().withEvalDecision(PolicyEvaluationDecisionType.ImplicitDeny);
when(iam.simulatePrincipalPolicy(any(SimulatePrincipalPolicyRequest.class))).thenReturn(new SimulatePrincipalPolicyResult().withEvaluationResults(evalResult));
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
assertThat(awsIDBrokerAssumeRoleValidator.canAssumeRoles(iam, instanceProfile, roles, validationResultBuilder)).isFalse();
ValidationResult validationResult = validationResultBuilder.build();
assertThat(validationResult.hasError()).isTrue();
assertThat(validationResult.getErrors()).isEqualTo(Collections.singletonList(String.format("Data Access Instance profile (%s) doesn't have permissions to assume the role(s): %s. " + "Please check if you've used the correct Instance profile when setting up Data Access.", instanceProfile.getArn(), Collections.singletonList(role.getArn()))));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWhenLoggerStorageAccountScopeThenNoError.
@Test
public void testValidateObjectStorageWhenLoggerStorageAccountScopeThenNoError() {
SpiFileSystem fileSystem = setupSpiFileSystem(false);
new RoleASsignmentBuilder(client).withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, ABFS_STORAGE_ACCOUNT_NAME);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithSingleResourceGroupAndNoResourceGroupRoleAssignment.
@Test
public void testValidateObjectStorageWithSingleResourceGroupAndNoResourceGroupRoleAssignment() {
SpiFileSystem fileSystem = setupSpiFileSystem(false);
new RoleASsignmentBuilder(client).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, "", null, RESOURCE_GROUP_NAME, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
verify(client, times(0)).listRoleAssignments();
verify(client, times(1)).listRoleAssignmentsByScopeInner(RESOURCE_GROUP_ID);
assertTrue(validationResult.hasError());
assertEquals(2, validationResult.getErrors().size());
assertEquals(validationResult.getErrors().get(1), String.format("Identity with id %s has no role assignment. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY));
assertEquals(validationResult.getErrors().get(0), String.format("Identity with id %s has no role assignment on scope(s) [/subscriptions/%s, %s]. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY, SUBSCRIPTION_ID, RESOURCE_GROUP_ID));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageNoMappedRoles.
@Test
public void testValidateObjectStorageNoMappedRoles() {
SpiFileSystem fileSystem = setupSpiFileSystem(true);
PagedList<Identity> identityPagedList = Mockito.spy(PagedList.class);
when(assumer.id()).thenReturn(USER_IDENTITY_1);
when(logger.id()).thenReturn(GROUP_IDENTITY_1);
identityPagedList.add(assumer);
identityPagedList.add(logger);
when(client.listIdentities()).thenReturn(identityPagedList);
final String wrongAssumerIdentityPrincipalid = "489e3729-aed1-4d54-a95b-b231b70d383f";
final String wrongLoggerIdentityPrincipalid = "61a70b9b-7331-4fa3-8717-2652fc70434e";
new RoleASsignmentBuilder(client).withAssignment(wrongAssumerIdentityPrincipalid, SUBSCRIPTION_FULL_ID).withAssignment(wrongLoggerIdentityPrincipalid, STORAGE_RESOURCE_GROUP_NAME);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, STORAGE_LOCATION_RANGER, null, null, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertTrue(validationResult.hasError());
assertEquals(5, validationResult.getErrors().size());
List<String> actual = validationResult.getErrors();
assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s has no role assignment.", USER_IDENTITY_1))));
assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s has no role assignment on scope", GROUP_IDENTITY_1))));
assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s has no role assignment on scope", USER_IDENTITY_1))));
}
Aggregations