Search in sources :

Example 1 with CloudDatabaseServerSslCertificate

use of com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method databaseServerGeneralSslRootCertificatesTestWhenSuccess.

@Test
void databaseServerGeneralSslRootCertificatesTestWhenSuccess() {
    Certificate certificate1 = mock(Certificate.class);
    when(certificate1.getCertificateIdentifier()).thenReturn("cert1");
    Certificate certificate2 = mock(Certificate.class);
    when(certificate2.getCertificateIdentifier()).thenReturn("cert2");
    AmazonRdsClient amazonRdsClient = mock(AmazonRdsClient.class);
    when(amazonRdsClient.describeCertificates(any(DescribeCertificatesRequest.class))).thenReturn(List.of(certificate1, certificate2));
    when(awsClient.createRdsClient(any(AwsCredentialView.class), eq(REGION_NAME))).thenReturn(amazonRdsClient);
    CloudDatabaseServerSslCertificates cloudDatabaseServerSslCertificates = underTest.databaseServerGeneralSslRootCertificates(cloudCredential, region);
    assertThat(cloudDatabaseServerSslCertificates).isNotNull();
    Set<CloudDatabaseServerSslCertificate> sslCertificates = cloudDatabaseServerSslCertificates.getSslCertificates();
    assertThat(sslCertificates).isNotNull();
    assertThat(sslCertificates).hasSize(2);
    verifySslRootCertificate(sslCertificates, "cert1");
    verifySslRootCertificate(sslCertificates, "cert2");
}
Also used : DescribeCertificatesRequest(com.amazonaws.services.rds.model.DescribeCertificatesRequest) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) AmazonRdsClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient) CloudDatabaseServerSslCertificates(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificates) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) Certificate(com.amazonaws.services.rds.model.Certificate) Test(org.junit.jupiter.api.Test)

Example 2 with CloudDatabaseServerSslCertificate

use of com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificatePrescriptionServiceTest method prescribeSslCertificateIfNeededTestWhenSslAwsCloudProviderOwnedCertIdPrescribed.

@Test
void prescribeSslCertificateIfNeededTestWhenSslAwsCloudProviderOwnedCertIdPrescribed() {
    initDBStack(CloudPlatform.AWS.name(), createSslConfig(SslCertificateType.CLOUD_PROVIDER_OWNED, CERT_ID_1));
    when(cloudPlatformConnectors.get(cloudPlatformVariant)).thenReturn(cloudConnector);
    when(cloudConnector.platformResources()).thenReturn(platformResources);
    Set<CloudDatabaseServerSslCertificate> sslCertificates = Set.of(new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, CERT_ID_1), new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, CERT_ID_2));
    when(platformResources.databaseServerGeneralSslRootCertificates(cloudCredential, region)).thenReturn(new CloudDatabaseServerSslCertificates(sslCertificates));
    when(cloudContext.getPlatformVariant()).thenReturn(cloudPlatformVariant);
    when(cloudContext.getLocation()).thenReturn(location);
    underTest.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
    assertThat(databaseServer.getStringParameter(DatabaseServer.SSL_CERTIFICATE_IDENTIFIER)).isEqualTo(CERT_ID_1);
    verify(cloudConnector).platformResources();
}
Also used : CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) CloudDatabaseServerSslCertificates(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CloudDatabaseServerSslCertificate

use of com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificatePrescriptionServiceTest method prescribeSslCertificateIfNeededTestWhenSslAwsCloudProviderOwnedDefaultCertId.

@Test
void prescribeSslCertificateIfNeededTestWhenSslAwsCloudProviderOwnedDefaultCertId() {
    initDBStack(CloudPlatform.AWS.name(), createSslConfig(SslCertificateType.CLOUD_PROVIDER_OWNED, CERT_ID_1));
    when(cloudPlatformConnectors.get(cloudPlatformVariant)).thenReturn(cloudConnector);
    when(cloudConnector.platformResources()).thenReturn(platformResources);
    Set<CloudDatabaseServerSslCertificate> sslCertificates = Set.of(new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, CERT_ID_1));
    when(platformResources.databaseServerGeneralSslRootCertificates(cloudCredential, region)).thenReturn(new CloudDatabaseServerSslCertificates(sslCertificates));
    when(cloudContext.getPlatformVariant()).thenReturn(cloudPlatformVariant);
    when(cloudContext.getLocation()).thenReturn(location);
    underTest.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
    assertThat(databaseServer.getStringParameter(DatabaseServer.SSL_CERTIFICATE_IDENTIFIER)).isNull();
    verify(cloudConnector).platformResources();
}
Also used : CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) CloudDatabaseServerSslCertificates(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificates) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CloudDatabaseServerSslCertificate

use of com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificateSyncServiceTest method syncSslCertificateIfNeededTestWhenFailureSslAwsCloudProviderOwnedMismatchingActiveSslRootCertificateInvalidCertificateEntryBlankPem.

@Test
void syncSslCertificateIfNeededTestWhenFailureSslAwsCloudProviderOwnedMismatchingActiveSslRootCertificateInvalidCertificateEntryBlankPem() throws Exception {
    DBStack dbStack = getDBStack(createSslConfig(SslCertificateType.CLOUD_PROVIDER_OWNED, CERT_ID_1));
    dbStack.setCloudPlatform(CloudPlatform.AWS.name());
    setupCloudConnectorMock();
    when(resourceConnector.getDatabaseServerActiveSslRootCertificate(authenticatedContext, databaseStack)).thenReturn(new CloudDatabaseServerSslCertificate(CloudDatabaseServerSslCertificateType.ROOT, CERT_ID_2));
    SslCertificateEntry cert = new SslCertificateEntry(CERT_VERSION, CERT_ID_2, "", x509Cert);
    when(databaseServerSslCertificateConfig.getCertByCloudPlatformAndRegionAndCloudProviderIdentifier(CloudPlatform.AWS.name(), REGION, CERT_ID_2)).thenReturn(cert);
    IllegalStateException illegalStateException = assertThrows(IllegalStateException.class, () -> underTest.syncSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack));
    assertThat(illegalStateException).hasMessage(String.format("Blank PEM in SSL certificate with CloudProviderIdentifier \"%s\" for cloud platform \"%s\"", CERT_ID_2, CloudPlatform.AWS.name()));
    verify(dbStackService, never()).save(any(DBStack.class));
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) SslCertificateEntry(com.sequenceiq.redbeams.configuration.SslCertificateEntry) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CloudDatabaseServerSslCertificate

use of com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate in project cloudbreak by hortonworks.

the class DatabaseServerSslCertificateSyncService method syncSslCertificateIfNeeded.

public void syncSslCertificateIfNeeded(CloudContext cloudContext, CloudCredential cloudCredential, DBStack dbStack, DatabaseStack databaseStack) throws Exception {
    SslConfig sslConfig = dbStack.getSslConfig();
    String cloudPlatform = dbStack.getCloudPlatform();
    if (sslConfig != null && SslCertificateType.CLOUD_PROVIDER_OWNED.equals(sslConfig.getSslCertificateType()) && CloudPlatform.AWS.name().equals(cloudPlatform)) {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        CloudDatabaseServerSslCertificate activeSslRootCertificate = connector.resources().getDatabaseServerActiveSslRootCertificate(ac, databaseStack);
        if (activeSslRootCertificate == null) {
            LOGGER.warn("Database server or its SSL certificate does not exist in cloud platform \"{}\" for {}. Skipping synchronization.", cloudPlatform, cloudContext);
        } else {
            syncSslCertificateAws(cloudContext, dbStack, activeSslRootCertificate);
        }
    } else {
        LOGGER.info("SSL not enabled or unsupported cloud platform \"{}\": SslConfig={}. Skipping SSL certificate synchronization for database stack {}", cloudPlatform, sslConfig, cloudContext);
    }
}
Also used : SslConfig(com.sequenceiq.redbeams.domain.stack.SslConfig) CloudDatabaseServerSslCertificate(com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)

Aggregations

CloudDatabaseServerSslCertificate (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificate)14 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)5 Certificate (com.amazonaws.services.rds.model.Certificate)3 DescribeCertificatesRequest (com.amazonaws.services.rds.model.DescribeCertificatesRequest)3 AmazonRdsClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonRdsClient)3 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CloudDatabaseServerSslCertificates (com.sequenceiq.cloudbreak.cloud.model.database.CloudDatabaseServerSslCertificates)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2 ListTablesRequest (com.amazonaws.services.dynamodbv2.model.ListTablesRequest)2 ListTablesResult (com.amazonaws.services.dynamodbv2.model.ListTablesResult)2 DescribeInstanceTypeOfferingsRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypeOfferingsRequest)2 DescribeInstanceTypesRequest (com.amazonaws.services.ec2.model.DescribeInstanceTypesRequest)2 DescribeInstanceTypesResult (com.amazonaws.services.ec2.model.DescribeInstanceTypesResult)2 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)2 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)2 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)2