Search in sources :

Example 26 with EnvironmentAuthentication

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

the class AuthenticationDtoConverterTest method testAuthenticationToDto.

@Test
void testAuthenticationToDto() {
    EnvironmentAuthentication environment = new EnvironmentAuthentication();
    environment.setId(123L);
    environment.setLoginUserName(LOGIN);
    environment.setPublicKey(PUBLIC_KEY);
    environment.setPublicKeyId(PUBLIC_KEY_ID);
    environment.setManagedKey(true);
    AuthenticationDto result = underTest.authenticationToDto(environment);
    verify(publicKeyValidator, Mockito.times(0)).validatePublicKey(anyString());
    assertEquals(environment.getLoginUserName(), result.getLoginUserName());
    assertEquals(environment.getPublicKey(), result.getPublicKey());
    assertEquals(environment.getPublicKeyId(), result.getPublicKeyId());
    assertEquals(environment.isManagedKey(), result.isManagedKey());
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Test(org.junit.jupiter.api.Test)

Example 27 with EnvironmentAuthentication

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

the class EnvironmentDtoConverterTest method testEnvironmentToEnvironmentDtoFreeIpaCreationWithoutAwsParameters.

@Test
public void testEnvironmentToEnvironmentDtoFreeIpaCreationWithoutAwsParameters() {
    Environment source = new Environment();
    source.setFreeIpaInstanceType("large");
    source.setFreeIpaImageId("imageid");
    source.setFreeIpaImageCatalog("imagecatalog");
    source.setFreeIpaInstanceCountByGroup(1);
    source.setFreeIpaEnableMultiAz(true);
    source.setCreateFreeIpa(true);
    source.setCloudPlatform("AWS");
    source.setAuthentication(new EnvironmentAuthentication());
    EnvironmentDto environmentDto = underTest.environmentToDto(source);
    FreeIpaCreationDto freeIpaCreation = environmentDto.getFreeIpaCreation();
    assertNotNull(freeIpaCreation);
    assertEquals("large", freeIpaCreation.getInstanceType());
    assertEquals("imageid", freeIpaCreation.getImageId());
    assertEquals("imagecatalog", freeIpaCreation.getImageCatalog());
    assertEquals(1, freeIpaCreation.getInstanceCountByGroup());
    assertTrue(freeIpaCreation.isEnableMultiAz());
    assertTrue(freeIpaCreation.getCreate());
    assertNull(freeIpaCreation.getAws());
}
Also used : EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 28 with EnvironmentAuthentication

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

the class EnvironmentCreationServiceTest method testEncryptionKeyValidationError.

@Test
void testEncryptionKeyValidationError() {
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("GCP").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("GCP");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with EnvironmentAuthentication

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

the class EnvironmentCreationServiceTest method testCreateAzureDisabled.

@Test
void testCreateAzureDisabled() {
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("AZURE").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("AZURE");
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
    when(environmentService.save(any())).thenReturn(environment);
    when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(false);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
    verify(validatorService, Mockito.times(1)).validatePublicKey(any());
    verify(environmentService, never()).save(any());
    verify(environmentResourceService, never()).createAndSetNetwork(any(), any(), any(), any(), any());
    verify(reactorFlowManager, never()).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(USER), anyString());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with EnvironmentAuthentication

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

the class EnvironmentCreationServiceTest method testCreate.

@Test
void testCreate() {
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
    String environmentCrn = "crn";
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCreator(CRN).withAccountId(ACCOUNT_ID).withCrn(environmentCrn).withAuthentication(AuthenticationDto.builder().build()).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), eq(ACCOUNT_ID))).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
    when(environmentService.save(any())).thenReturn(environment);
    environmentCreationServiceUnderTest.create(environmentCreationDto);
    verify(validatorService, Mockito.times(1)).validatePublicKey(any());
    verify(environmentService).save(any());
    verify(parametersService).saveParameters(eq(environment), eq(parametersDto));
    verify(environmentResourceService).createAndSetNetwork(any(), any(), any(), any(), any());
    verify(reactorFlowManager).triggerCreationFlow(eq(1L), eq(ENVIRONMENT_NAME), eq(CRN), anyString());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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