Search in sources :

Example 21 with EnvironmentAuthentication

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

the class EnvironmentModificationServiceTest method testEditAuthenticationIfChangedWhenNeedToCreateSshKey.

@Test
void testEditAuthenticationIfChangedWhenNeedToCreateSshKey() {
    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(true);
    environmentModificationServiceUnderTest.editAuthenticationIfChanged(environmentEditDto, environment);
    verify(environmentResourceService, times(1)).createAndUpdateSshKey(environment);
    verify(environmentResourceService, times(0)).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 22 with EnvironmentAuthentication

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

the class EnvironmentResourceServiceTest method testCreateAndUpdateSshKeyWhenTooLongWithoutTimestamp.

@Test
void testCreateAndUpdateSshKeyWhenTooLongWithoutTimestamp() {
    Environment environment = new Environment();
    environment.setName(StringUtils.repeat("*", 200));
    environment.setResourceCrn(StringUtils.repeat("*", 100));
    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(1L);
    environmentResourceServiceUnderTest.createAndUpdateSshKey(environment);
    String first = StringUtils.repeat("*", 200);
    String second = StringUtils.repeat("*", 54);
    assertEquals(first + "-" + second, environment.getAuthentication().getPublicKeyId());
    // the split size should be equals 2, because we concat the name and crn only
    assertEquals(2, 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 23 with EnvironmentAuthentication

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

the class EnvironmentResourceServiceTest method testCreateAndUpdateSshKeyWhenCreatedAndSet.

@Test
void testCreateAndUpdateSshKeyWhenCreatedAndSet() {
    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);
    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(1L);
    environmentResourceServiceUnderTest.createAndUpdateSshKey(environment);
    assertEquals("env-name-res-crn-1", 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) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) Test(org.junit.jupiter.api.Test)

Example 24 with EnvironmentAuthentication

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

the class PublicKeyCreationHandlerTest method acceptTestEnvironmentShouldNotBeUpdatedWhenSshKeyHasNotBeenCreated.

@Test
void acceptTestEnvironmentShouldNotBeUpdatedWhenSshKeyHasNotBeenCreated() {
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Headers.class));
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setManagedKey(true);
    Environment environment = new Environment();
    environment.setAuthentication(authentication);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    when(environmentResourceService.createAndUpdateSshKey(environment)).thenReturn(Boolean.FALSE);
    underTest.accept(environmentDtoEvent);
    verify(eventSender).sendEvent(baseNamedFlowEvent.capture(), headersArgumentCaptor.capture());
    verify(environmentService, never()).save(any());
    verifyEnvCreationEvent();
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Headers(reactor.bus.Event.Headers) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 25 with EnvironmentAuthentication

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

the class PublicKeyCreationHandlerTest method acceptTestEnvironmentShouldBeUpdatedWhenSshKeyHasBeenCreated.

@Test
void acceptTestEnvironmentShouldBeUpdatedWhenSshKeyHasBeenCreated() {
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Headers.class));
    EnvironmentAuthentication authentication = new EnvironmentAuthentication();
    authentication.setManagedKey(true);
    Environment environment = new Environment();
    environment.setAuthentication(authentication);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
    when(environmentResourceService.createAndUpdateSshKey(environment)).thenReturn(Boolean.TRUE);
    underTest.accept(environmentDtoEvent);
    verify(eventSender).sendEvent(baseNamedFlowEvent.capture(), headersArgumentCaptor.capture());
    verify(environmentService, times(1)).save(environment);
    verifyEnvCreationEvent();
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Headers(reactor.bus.Event.Headers) Environment(com.sequenceiq.environment.environment.domain.Environment) 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