use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNeedToDeleteOldKey.
@Test
void testEditAuthenticationIfChangedWhenNeedToDeleteOldKey() {
AuthenticationDto authenticationDto = AuthenticationDto.builder().build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
Environment environment = new Environment();
EnvironmentAuthentication originalEnvironmentAuthentication = new EnvironmentAuthentication();
originalEnvironmentAuthentication.setManagedKey(true);
originalEnvironmentAuthentication.setPublicKeyId("old-public-key-id");
environment.setAuthentication(originalEnvironmentAuthentication);
EnvironmentAuthentication newEnvironmentAuthentication = new EnvironmentAuthentication();
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
when(authenticationDtoConverter.dtoToAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
verify(environmentResourceService, times(1)).deletePublicKey(environment, "old-public-key-id");
verify(environmentResourceService, times(0)).createAndUpdateSshKey(environment);
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNeedToSshKeyUpdateSupportedAndNewSshKeyApplied.
@Test
void testEditAuthenticationIfChangedWhenNeedToSshKeyUpdateSupportedAndNewSshKeyApplied() {
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(false);
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(false);
when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(true);
when(authenticationDtoConverter.dtoToSshUpdatedAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
assertEquals(environment.getAuthentication().getPublicKey(), "new-ssh-key");
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto 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.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method editByNameParametersExistedAndNotValid.
@Test
void editByNameParametersExistedAndNotValid() {
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(true);
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);
assertThrows(BadRequestException.class, () -> environmentModificationServiceUnderTest.editByName(ENVIRONMENT_NAME, environmentDto));
verify(parametersService, never()).saveParameters(environment, parameters);
}
use of com.sequenceiq.environment.environment.dto.EnvironmentEditDto in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNotCreatedAndRevertToOldOne.
@Test
void testEditAuthenticationIfChangedWhenNotCreatedAndRevertToOldOne() {
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(false);
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(false);
environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
verify(environmentResourceService, times(1)).createAndUpdateSshKey(environment);
verify(environmentResourceService, times(0)).deletePublicKey(environment, "old-public-key-id");
assertEquals(environment.getAuthentication().getPublicKey(), "original-ssh-key");
}
Aggregations