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");
}
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();
}
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();
}
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));
}
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);
}
}
Aggregations