use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenDontDeleteOldKey.
@Test
void testEditAuthenticationIfChangedWhenDontDeleteOldKey() {
AuthenticationDto authenticationDto = AuthenticationDto.builder().build();
EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withAuthentication(authenticationDto).build();
Environment environment = new Environment();
EnvironmentAuthentication originalEnvironmentAuthentication = new EnvironmentAuthentication();
originalEnvironmentAuthentication.setManagedKey(false);
originalEnvironmentAuthentication.setPublicKeyId("old-public-key-id");
environment.setAuthentication(originalEnvironmentAuthentication);
EnvironmentAuthentication newEnvironmentAuthentication = new EnvironmentAuthentication();
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(validatorService.validateAuthenticationModification(environmentEditDto, environment)).thenReturn(validationResult);
when(environmentResourceService.isExistingSshKeyUpdateSupported(environment)).thenReturn(true);
when(environmentResourceService.isRawSshKeyUpdateSupported(environment)).thenReturn(false);
when(authenticationDtoConverter.dtoToAuthentication(authenticationDto)).thenReturn(newEnvironmentAuthentication);
environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
verify(environmentResourceService, times(0)).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 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");
}
use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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);
}
use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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());
}
use of com.sequenceiq.environment.environment.domain.EnvironmentAuthentication 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());
}
Aggregations