use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.
@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
NetworkDto networkDto = mock(NetworkDto.class);
AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
ParametersDto parametersDto = mock(ParametersDto.class);
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
Credential credential = mock(Credential.class);
BaseNetwork baseNetwork = new GcpNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
Environment environment = new Environment();
environment.setCloudPlatform("GCP");
environment.setCredential(credential);
EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyButDefaultSecGroupAddedOnly.
@Test
void testValidateSecurityAccessModificationWhenEnvCidrIsNotEmptyButDefaultSecGroupAddedOnly() {
Environment environment = new Environment();
environment.setCidr("cidr");
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withDefaultSecurityGroupId("sec-group").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertTrue(validationResult.hasError());
assertEquals("The CIDR can be replaced with the default and knox security groups, please add to the request", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenCidrAddedOnlyInRequest.
@Test
void testValidateSecurityAccessModificationWhenCidrAddedOnlyInRequest() {
Environment environment = new Environment();
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withCidr("cidr").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertTrue(validationResult.hasError());
assertEquals("1. Please add the default or knox security groups, we cannot edit with empty value.\n" + "2. The CIDR could not be updated in the environment", validationResult.getFormattedErrors());
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameSecurityAccessChange.
@Test
void editByNameSecurityAccessChange() {
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withCidr("test").build();
EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withSecurityAccess(securityAccessDto).build();
Environment value = new Environment();
when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(value));
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateSecurityAccessModification(any(), any())).thenReturn(validationResult);
when(validatorService.validateSecurityGroups(any(), any())).thenReturn(validationResult);
environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
verify(environmentService).editSecurityAccess(eq(value), eq(securityAccessDto));
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class AwsEnvironmentSecurityGroupValidator method validate.
@Override
public void validate(EnvironmentValidationDto environmentValidationDto, ValidationResult.ValidationResultBuilder resultBuilder) {
EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
SecurityAccessDto securityAccessDto = environmentDto.getSecurityAccess();
if (securityAccessDto != null) {
if (onlyOneSecurityGroupIdDefined(securityAccessDto)) {
LOGGER.error("Only one existing security group definied by the user: {}", securityAccessDto);
resultBuilder.error(securityGroupIdsMustBePresent());
} else if (isSecurityGroupIdDefined(securityAccessDto)) {
LOGGER.info("Both existing security group defined: {}", securityAccessDto);
NetworkDto networkDto = environmentDto.getNetwork();
if (RegistrationType.CREATE_NEW == networkDto.getRegistrationType()) {
LOGGER.error("Both existing security group defined and user wants to create a new network with cidr: {}", networkDto.getNetworkCidr());
resultBuilder.error(networkIdMustBePresent(getCloudPlatform().name()));
return;
}
if (!Strings.isNullOrEmpty(securityAccessDto.getDefaultSecurityGroupId())) {
LOGGER.info("Validate Security group {} that is related to {} network", securityAccessDto.getDefaultSecurityGroupId(), networkDto.getAws());
checkSecurityGroupVpc(environmentDto, resultBuilder, environmentDto.getSecurityAccess().getDefaultSecurityGroupId());
}
if (!Strings.isNullOrEmpty(securityAccessDto.getSecurityGroupIdForKnox())) {
LOGGER.info("Validate Security group {} that is related to {} network", securityAccessDto.getSecurityGroupIdForKnox(), networkDto.getAws());
checkSecurityGroupVpc(environmentDto, resultBuilder, environmentDto.getSecurityAccess().getSecurityGroupIdForKnox());
}
}
}
}
Aggregations