Search in sources :

Example 16 with EnvironmentAuthentication

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

the class AuthenticationDtoConverterTest method testDtoToSshUpdatedAuthenticationWhenValidSshKey.

@Test
void testDtoToSshUpdatedAuthenticationWhenValidSshKey() {
    String testKey = "ssh-rsa AAAASASFAS3532== banana@apple.com";
    AuthenticationDto dto = AuthenticationDto.builder().withLoginUserName(LOGIN).withPublicKey(testKey).withPublicKeyId(PUBLIC_KEY_ID).withManagedKey(true).build();
    EnvironmentAuthentication actual = underTest.dtoToSshUpdatedAuthentication(dto);
    assertEquals("ssh-rsa AAAASASFAS3532== login", actual.getPublicKey());
    assertNull(actual.getLoginUserName());
    assertNull(actual.getPublicKeyId());
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 17 with EnvironmentAuthentication

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

the class AuthenticationDtoConverter method dtoToSshUpdatedAuthentication.

public EnvironmentAuthentication dtoToSshUpdatedAuthentication(AuthenticationDto authenticationDto) {
    EnvironmentAuthentication environmentAuthentication = new EnvironmentAuthentication();
    if (isValidSshKey(authenticationDto.getPublicKey())) {
        List<String> parts = Arrays.asList(StringUtils.split(authenticationDto.getPublicKey(), " "));
        environmentAuthentication.setPublicKey(String.format("%s %s %s", parts.get(0), parts.get(1), authenticationDto.getLoginUserName()));
    }
    return environmentAuthentication;
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)

Example 18 with EnvironmentAuthentication

use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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);
}
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 19 with EnvironmentAuthentication

use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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");
}
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 20 with EnvironmentAuthentication

use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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");
}
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)

Aggregations

EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)32 Test (org.junit.jupiter.api.Test)27 Environment (com.sequenceiq.environment.environment.domain.Environment)24 Credential (com.sequenceiq.environment.credential.domain.Credential)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)7 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)5 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)5 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)5 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)5 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)5 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)5 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)5 PublicKeyConnector (com.sequenceiq.cloudbreak.cloud.PublicKeyConnector)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Headers (reactor.bus.Event.Headers)3