Search in sources :

Example 6 with AccountTelemetry

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

the class AccountTelemetryServiceTest method testValidateRules.

@Test
public void testValidateRules() {
    // GIVEN
    AccountTelemetry telemetry = new AccountTelemetry();
    List<AnonymizationRule> rules = new ArrayList<>();
    AnonymizationRule rule = new AnonymizationRule();
    rule.setReplacement("[REDACTED]");
    String pattern = "\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}[^\\w]\\d{4}";
    String encodedPattern = new String(Base64.getEncoder().encode(pattern.getBytes()));
    rule.setValue(encodedPattern);
    rules.add(rule);
    telemetry.setRules(rules);
    // WHEN
    underTest.validateAnonymizationRules(telemetry);
}
Also used : AnonymizationRule(com.sequenceiq.common.api.telemetry.model.AnonymizationRule) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 7 with AccountTelemetry

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

the class EnvironmentApiConverterTest method testInitCreationDto.

@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE", "GCP" })
void testInitCreationDto(CloudPlatform cloudPlatform) {
    EnvironmentRequest request = createEnvironmentRequest(cloudPlatform);
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(cloudPlatform.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "test-aws", cloudPlatform.name())).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals("test-aws", actual.getAccountId());
    assertEquals(USER_CRN, actual.getCreator());
    assertEquals(request.getName(), actual.getName());
    assertEquals(request.getDescription(), actual.getDescription());
    assertEquals(request.getCredentialName(), actual.getCredential().getCredentialName());
    assertEquals(request, actual.getCredential());
    assertEquals(freeIpaCreationDto, actual.getFreeIpaCreation());
    assertLocation(request.getLocation(), actual.getLocation());
    assertEquals(environmentTelemetry, actual.getTelemetry());
    assertEquals(1, actual.getRegions().size());
    assertAuthentication(request.getAuthentication(), actual.getAuthentication());
    assertEquals(request.getAdminGroupName(), actual.getAdminGroupName());
    assertEquals(request.getTags(), actual.getTags());
    assertExperimentalFeatures(request, actual.getExperimentalFeatures());
    assertParameters(request, actual.getParameters(), cloudPlatform);
    assertEquals(request.getProxyConfigName(), actual.getProxyConfigName());
    assertEquals(networkDto, actual.getNetwork());
    assertSecurityAccess(request.getSecurityAccess(), actual.getSecurityAccess());
    verify(credentialService).getCloudPlatformByCredential(anyString(), anyString(), any());
    verify(freeIpaConverter).convert(request.getFreeIpa(), "test-aws", cloudPlatform.name());
    verify(accountTelemetry).getFeatures();
    verify(accountTelemetryService).getOrDefault(any());
    verify(telemetryApiConverter).convert(eq(request.getTelemetry()), any(), anyString());
    verify(tunnelConverter).convert(request.getTunnel());
    verify(networkRequestToDtoConverter).convert(request.getNetwork());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with AccountTelemetry

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

the class EnvironmentApiConverterTest method testGcpResourceEncryptionParametersAndGcpRequest.

@Test
void testGcpResourceEncryptionParametersAndGcpRequest() {
    EnvironmentRequest request = createEnvironmentRequest(GCP);
    request.setGcp(GcpEnvironmentParameters.builder().withResourceEncryptionParameters(GcpResourceEncryptionParameters.builder().withEncryptionKey("dummy-encryption-key").build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(GCP.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals("dummy-encryption-key", actual.getParameters().getGcpParametersDto().getGcpResourceEncryptionParametersDto().getEncryptionKey());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with AccountTelemetry

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

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndAzureRequestWithSingleUsageAndName.

@Test
void testAzureSingleRgEnabledAndAzureRequestWithSingleUsageAndName() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withName("myResourceGroup").withResourceGroupUsage(ResourceGroupUsage.SINGLE).build()).build());
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ResourceGroupUsagePattern.USE_SINGLE, actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
    assertEquals("myResourceGroup", actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getName());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with AccountTelemetry

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

the class EnvironmentApiConverterTest method testAwsDiskEncryptionParametersAndAwsRequest.

@Test
void testAwsDiskEncryptionParametersAndAwsRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AWS);
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AWS.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(backupConverter.convert(eq(request.getBackup()))).thenReturn(environmentBackup);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ENCRYPTION_KEY_ARN, actual.getParameters().getAwsParametersDto().getAwsDiskEncryptionParametersDto().getEncryptionKeyArn());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)17 Test (org.junit.jupiter.api.Test)11 Features (com.sequenceiq.common.api.telemetry.model.Features)10 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)8 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)8 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)7 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 FreeIpaCreationDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationDto)7 AnonymizationRule (com.sequenceiq.common.api.telemetry.model.AnonymizationRule)4 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)4 ArrayList (java.util.ArrayList)3 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 CheckPermissionByAccount (com.sequenceiq.authorization.annotation.CheckPermissionByAccount)1 CrnResourceDescriptor (com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor)1 RegionAwareCrnGenerator (com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 EnvironmentEditRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentEditRequest)1