use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameSecurityAccessChangeHasSecurityGroupsError.
@Test
void editByNameSecurityAccessChangeHasSecurityGroupsError() {
ValidationResult validationResultError = ValidationResult.builder().error("sec group error").build();
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(validationResultError);
BadRequestException actual = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
assertEquals("sec group error", actual.getMessage());
verify(environmentService, times(0)).editSecurityAccess(eq(value), eq(securityAccessDto));
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameSecurityAccessChangeHasSecurityAccessError.
@Test
void editByNameSecurityAccessChangeHasSecurityAccessError() {
ValidationResult validationResultError = ValidationResult.builder().error("sec access error").build();
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(validationResultError);
BadRequestException actual = assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
assertEquals("sec access error", actual.getMessage());
verify(environmentService, times(0)).editSecurityAccess(eq(value), eq(securityAccessDto));
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenDefaultSecGroupAdded.
@Test
void testValidateSecurityAccessModificationWhenDefaultSecGroupAdded() {
Environment environment = new Environment();
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withDefaultSecurityGroupId("sec-group").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenKnoxSecGroupAdded.
@Test
void testValidateSecurityAccessModificationWhenKnoxSecGroupAdded() {
Environment environment = new Environment();
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withSecurityGroupIdForKnox("knox-sec-group").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertFalse(validationResult.hasError());
}
use of com.sequenceiq.environment.environment.dto.SecurityAccessDto in project cloudbreak by hortonworks.
the class EnvironmentValidatorServiceTest method testValidateSecurityAccessModificationWhenCidrAndDefaultSecurityGroupAddedInRequest.
@Test
void testValidateSecurityAccessModificationWhenCidrAndDefaultSecurityGroupAddedInRequest() {
Environment environment = new Environment();
SecurityAccessDto securityAccessDto = SecurityAccessDto.builder().withCidr("cidr").withDefaultSecurityGroupId("sec-group").build();
ValidationResult validationResult = underTest.validateSecurityAccessModification(securityAccessDto, environment);
assertTrue(validationResult.hasError());
assertEquals("The CIDR could not be updated in the environment", validationResult.getFormattedErrors());
}
Aggregations