Search in sources :

Example 76 with ValidationResultBuilder

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)));
}
Also used : Role(com.amazonaws.services.identitymanagement.model.Role) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) GetRoleRequest(com.amazonaws.services.identitymanagement.model.GetRoleRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Example 77 with ValidationResultBuilder

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()))));
}
Also used : Role(com.amazonaws.services.identitymanagement.model.Role) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SimulatePrincipalPolicyRequest(com.amazonaws.services.identitymanagement.model.SimulatePrincipalPolicyRequest) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SimulatePrincipalPolicyResult(com.amazonaws.services.identitymanagement.model.SimulatePrincipalPolicyResult) EvaluationResult(com.amazonaws.services.identitymanagement.model.EvaluationResult) Test(org.junit.jupiter.api.Test)

Example 78 with ValidationResultBuilder

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());
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 79 with ValidationResultBuilder

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));
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Example 80 with ValidationResultBuilder

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))));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AdlsGen2Config(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2Config) StorageAccount(com.microsoft.azure.management.storage.StorageAccount) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Identity(com.microsoft.azure.management.msi.Identity) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) PagedList(com.microsoft.azure.PagedList) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Map(java.util.Map) Spy(org.mockito.Spy) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Subscription(com.microsoft.azure.management.resources.Subscription) AzureStorage(com.sequenceiq.cloudbreak.cloud.azure.AzureStorage) AdlsGen2ConfigGenerator(com.sequenceiq.cloudbreak.telemetry.fluent.cloud.AdlsGen2ConfigGenerator) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) Mockito.verify(org.mockito.Mockito.verify) CloudAdlsGen2View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudAdlsGen2View) Mockito(org.mockito.Mockito) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) FileSystemType(com.sequenceiq.common.model.FileSystemType) Optional(java.util.Optional) CloudIdentityType(com.sequenceiq.common.model.CloudIdentityType) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) RoleAssignmentInner(com.microsoft.azure.management.graphrbac.implementation.RoleAssignmentInner) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Identity(com.microsoft.azure.management.msi.Identity) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.Test)

Aggregations

ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)169 Test (org.junit.jupiter.api.Test)107 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)67 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)62 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)35 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)33 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)33 Test (org.junit.Test)20 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)10 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Credential (com.sequenceiq.environment.credential.domain.Credential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)6 Role (com.amazonaws.services.identitymanagement.model.Role)6 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)6