use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenEnvironmentIsBeingCreatedThenPrivateEndpointValidationsRun.
@Test
void testValidateDuringFlowWhenEnvironmentIsBeingCreatedThenPrivateEndpointValidationsRun() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
environmentValidationDto.setValidationType(ValidationType.ENVIRONMENT_CREATION);
underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
verify(azureNetworkLinkService, atLeastOnce()).validateExistingNetworkLink(any(), any(), any());
verify(azureCloudSubnetParametersService, atLeastOnce()).isPrivateEndpointNetworkPoliciesDisabled(any());
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNoNetworkCidrAndNetworkId.
@Test
void testValidateDuringRequestWhenNoNetworkCidrAndNetworkId() {
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkCidrAndNoAzureParams.
@Test
void testValidateDuringRequestWhenNetworkCidrAndNoAzureParams() {
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, null, null, null, "0.0.0.0/0", null);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertFalse(validationResult.hasError(), validationResult.getFormattedErrors());
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotResourceGroupId.
@Test
void testValidateDuringRequestWhenTheAzureNetworkParamsDoesNotResourceGroupId() {
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, false);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, validationResultBuilder);
NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("If networkId is specified, then resourceGroupName must be specified too."));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesEnabled.
@Test
void testValidateDuringFlowWhenPrivateEndpointAndPrivateEndpointNetworkPoliciesEnabled() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("networkId", "networkResourceGroupName");
NetworkDto networkDto = NetworkTestUtils.getNetworkDtoBuilder(azureParams, null, null, azureParams.getNetworkId(), null, 1, RegistrationType.EXISTING).withServiceEndpointCreation(ServiceEndpointCreation.ENABLED_PRIVATE_ENDPOINT).build();
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(true));
when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
assertTrue(validationResultBuilder.build().hasError());
NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("It is not possible to create private endpoints for existing network with id 'networkId' in resource group 'networkResourceGroupName': " + "Azure requires at least one subnet with private endpoint network policies (eg. NSGs) disabled. Please disable private endpoint " + "network policies in at least one of the following subnets and retry: 'subnet-one'. Refer to Microsoft documentation at: " + "https://docs.microsoft.com/en-us/azure/private-link/disable-private-endpoint-network-policy"));
}
Aggregations