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());
}
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;
}
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);
}
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");
}
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");
}
Aggregations