Search in sources :

Example 16 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method editByNameParametersExistedAndValid.

@Test
void editByNameParametersExistedAndValid() {
    String dynamotable = "dynamotable";
    ParametersDto parameters = ParametersDto.builder().withAccountId(ACCOUNT_ID).withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName(dynamotable).build()).build();
    EnvironmentEditDto environmentDto = EnvironmentEditDto.builder().withAccountId(ACCOUNT_ID).withParameters(parameters).build();
    Environment environment = new Environment();
    environment.setAccountId(ACCOUNT_ID);
    AwsParameters awsParameters = new AwsParameters();
    awsParameters.setS3guardTableName("existingTable");
    BaseParameters baseParameters = awsParameters;
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(environmentFlowValidatorService.validateParameters(any(), any())).thenReturn(validationResult);
    when(validationResult.hasError()).thenReturn(false);
    when(parametersService.findByEnvironment(any())).thenReturn(Optional.of(baseParameters));
    when(environmentService.findByNameAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(environment));
    when(parametersService.saveParameters(environment, parameters)).thenReturn(baseParameters);
    environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto);
    verify(parametersService).saveParameters(environment, parameters);
    assertEquals(baseParameters, environment.getParameters());
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters) Test(org.junit.jupiter.api.Test)

Example 17 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNeedToCreateSshKeyAndDeleteOldOne.

@Test
void testEditAuthenticationIfChangedWhenNeedToCreateSshKeyAndDeleteOldOne() {
    AuthenticationDto authenticationDto = AuthenticationDto.builder().withPublicKey("ssh-key").build();
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
    Environment environment = new Environment();
    EnvironmentAuthentication originalEnvironmentAuthentication = new EnvironmentAuthentication();
    originalEnvironmentAuthentication.setPublicKey("original-ssh-key");
    originalEnvironmentAuthentication.setManagedKey(true);
    originalEnvironmentAuthentication.setPublicKeyId("old-public-key-id");
    environment.setAuthentication(originalEnvironmentAuthentication);
    EnvironmentAuthentication newEnvironmentAuthentication = new EnvironmentAuthentication();
    newEnvironmentAuthentication.setPublicKey("new-ssh-key");
    when(environmentService.getValidatorService()).thenReturn(validatorService);
    when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
    when(authenticationDtoConverter.dtoToAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
    when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
    when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
    when(environmentResourceService.createAndUpdateSshKey(environment)).thenReturn(true);
    environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
    verify(environmentResourceService, times(1)).createAndUpdateSshKey(environment);
    verify(environmentResourceService, times(1)).deletePublicKey(environment, "old-public-key-id");
    assertEquals(environment.getAuthentication().getPublicKey(), "new-ssh-key");
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test)

Example 18 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentResourceServiceTest method testCreateAndUpdateSshKeyWhenTooLongWithTimestamp.

@Test
void testCreateAndUpdateSshKeyWhenTooLongWithTimestamp() {
    Environment environment = new Environment();
    environment.setName(StringUtils.repeat("*", 200));
    environment.setResourceCrn(StringUtils.repeat("*", 50));
    environment.setCloudPlatform("CP");
    environment.setLocation("location");
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setPublicKey("ssh-key");
    environment.setAuthentication(authentication);
    CloudConnector connector = mock(CloudConnector.class);
    PublicKeyConnector publicKeyConnector = mock(PublicKeyConnector.class);
    when(cloudPlatformConnectors.get(new CloudPlatformVariant(Platform.platform("CP"), Variant.variant("CP")))).thenReturn(connector);
    when(connector.publicKey()).thenReturn(publicKeyConnector);
    when(credentialToCloudCredentialConverter.convert(environment.getCredential())).thenReturn(mock(CloudCredential.class));
    when(clock.getCurrentTimeMillis()).thenReturn(1234L);
    environmentResourceServiceUnderTest.createAndUpdateSshKey(environment);
    String first = StringUtils.repeat("*", 200);
    String second = StringUtils.repeat("*", 50);
    assertEquals(first + "-" + second + "-123", environment.getAuthentication().getPublicKeyId());
    // the split size should be equals 3, because we concat the name, crn and timestamp
    assertEquals(3, environment.getAuthentication().getPublicKeyId().split("-").length);
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) Test(org.junit.jupiter.api.Test)

Example 19 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentResourceServiceTest method testCreateAndUpdateSshKeyWhenDoesNotCreated.

@Test
void testCreateAndUpdateSshKeyWhenDoesNotCreated() {
    Environment environment = new Environment();
    environment.setName("env-name");
    environment.setResourceCrn("res-crn");
    environment.setCloudPlatform("CP");
    environment.setLocation("location");
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setPublicKey("ssh-key");
    environment.setAuthentication(authentication);
    CloudConnector connector = mock(CloudConnector.class);
    when(cloudPlatformConnectors.get(new CloudPlatformVariant(Platform.platform("CP"), Variant.variant("CP")))).thenReturn(connector);
    when(connector.publicKey()).thenThrow(UnsupportedOperationException.class);
    when(credentialToCloudCredentialConverter.convert(environment.getCredential())).thenReturn(mock(CloudCredential.class));
    when(clock.getCurrentTimeMillis()).thenReturn(1L);
    environmentResourceServiceUnderTest.createAndUpdateSshKey(environment);
    assertNull(environment.getAuthentication().getPublicKeyId());
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) Test(org.junit.jupiter.api.Test)

Example 20 with Environment

use of com.sequenceiq.environment.environment.domain.Environment in project cloudbreak by hortonworks.

the class EnvironmentResourceServiceTest method testCreateAndUpdateSshKeyWhenPublicKeyIdExactMatchWith255.

@Test
void testCreateAndUpdateSshKeyWhenPublicKeyIdExactMatchWith255() {
    Environment environment = new Environment();
    environment.setName(StringUtils.repeat("*", 200));
    environment.setResourceCrn(StringUtils.repeat("*", 50));
    environment.setCloudPlatform("CP");
    environment.setLocation("location");
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setPublicKey("ssh-key");
    environment.setAuthentication(authentication);
    CloudConnector connector = mock(CloudConnector.class);
    PublicKeyConnector publicKeyConnector = mock(PublicKeyConnector.class);
    when(cloudPlatformConnectors.get(new CloudPlatformVariant(Platform.platform("CP"), Variant.variant("CP")))).thenReturn(connector);
    when(connector.publicKey()).thenReturn(publicKeyConnector);
    when(credentialToCloudCredentialConverter.convert(environment.getCredential())).thenReturn(mock(CloudCredential.class));
    when(clock.getCurrentTimeMillis()).thenReturn(123L);
    environmentResourceServiceUnderTest.createAndUpdateSshKey(environment);
    String first = StringUtils.repeat("*", 200);
    String second = StringUtils.repeat("*", 50);
    assertEquals(first + "-" + second + "-123", environment.getAuthentication().getPublicKeyId());
    // the split size should be equals 3, because we concat the name, crn and timestamp
    assertEquals(3, environment.getAuthentication().getPublicKeyId().split("-").length);
    assertEquals(255, environment.getAuthentication().getPublicKeyId().length());
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Environment(com.sequenceiq.environment.environment.domain.Environment) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) Test(org.junit.jupiter.api.Test)

Aggregations

Environment (com.sequenceiq.environment.environment.domain.Environment)187 Test (org.junit.jupiter.api.Test)145 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)48 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)42 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)29 Credential (com.sequenceiq.environment.credential.domain.Credential)26 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)24 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)21 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)16 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)15 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)14 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)13 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)12 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)11 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)11 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)11 Headers (reactor.bus.Event.Headers)11 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)10 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)10