Search in sources :

Example 1 with SecurityAccessDto

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));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test)

Example 2 with 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));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) BadRequestException(javax.ws.rs.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test)

Example 3 with 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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SecurityAccessDto

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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SecurityAccessDto

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());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)17 Environment (com.sequenceiq.environment.environment.domain.Environment)11 Test (org.junit.jupiter.api.Test)11 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)5 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)4 BadRequestException (javax.ws.rs.BadRequestException)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)2 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)2 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)2 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)2 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)2 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)2 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)2