Search in sources :

Example 11 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenHasPublicKeyIdButNotExists.

@Test
void testValidateAuthenticationModificationWhenHasPublicKeyIdButNotExists() {
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").build()).build();
    PublicKeyConnector connector = mock(PublicKeyConnector.class);
    when(environmentResourceService.isPublicKeyIdExists(environment, "pub-key-id")).thenReturn(false);
    when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.of(connector));
    ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
    assertEquals("The publicKeyId with name of 'pub-key-id' does not exist on the provider.", validationResult.getFormattedErrors());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenNotAwsAndHasPublicKeyId.

@Test
void testValidateAuthenticationModificationWhenNotAwsAndHasPublicKeyId() {
    Environment environment = new Environment();
    environment.setCloudPlatform("AZURE");
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").build()).build();
    when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.empty());
    ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
    assertEquals("The change of publicKeyId is not supported on AZURE", validationResult.getFormattedErrors());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenPublicKeyAndPublicKeyIdIsEmptyAsWell.

@Test
void testValidateAuthenticationModificationWhenPublicKeyAndPublicKeyIdIsEmptyAsWell() {
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().build()).build();
    ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
    assertEquals("You should define either the publicKey or the publicKeyId.", validationResult.getFormattedErrors());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentValidatorServiceTest method testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell.

@Test
void testValidateAuthenticationModificationWhenHasPublicKeyAndPublicKeyIdAsWell() {
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(AuthenticationDto.builder().withPublicKeyId("pub-key-id").withPublicKey("ssh-key").build()).build();
    PublicKeyConnector connector = mock(PublicKeyConnector.class);
    when(environmentResourceService.isPublicKeyIdExists(environment, "pub-key-id")).thenReturn(true);
    when(environmentResourceService.getPublicKeyConnector(environment.getCloudPlatform())).thenReturn(Optional.of(connector));
    when(publicKeyValidator.validatePublicKey(anyString())).thenReturn(ValidationResult.empty());
    ValidationResult validationResult = underTest.validateAuthenticationModification(environmentEditDto, environment);
    assertEquals("You should define either publicKey or publicKeyId only, but not both.", validationResult.getFormattedErrors());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with EnvironmentEditDto

use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.

the class EnvironmentController method editByName.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.EDIT_ENVIRONMENT)
public DetailedEnvironmentResponse editByName(@ResourceName String environmentName, @NotNull EnvironmentEditRequest request) {
    EnvironmentEditDto editDto = environmentApiConverter.initEditDto(request);
    EnvironmentDto result = environmentModificationService.editByName(environmentName, editDto);
    return environmentResponseConverter.dtoToDetailedResponse(result);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Aggregations

EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)32 Environment (com.sequenceiq.environment.environment.domain.Environment)29 Test (org.junit.jupiter.api.Test)29 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)9 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)7 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)6 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)5 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)5 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)5 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)5 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)5 GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)5 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)5 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)4 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)3