use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndNoSslCertificateIdentifier.
@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndNoPortAndUsingSslEnforcementAndNoSslCertificateIdentifier(String templatePath) throws IOException {
// GIVEN
String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
// WHEN
RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withUseSslEnforcement(true).withSslCertificateIdentifierDefined(false).withTemplate(awsCloudFormationTemplate);
String result = cloudFormationTemplateBuilder.build(modelContext);
// THEN
assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
assertThat(result).doesNotContain("\"PortParameter\": {");
assertThat(result).contains("\"DBParameterGroupNameParameter\": {");
assertThat(result).contains("\"DBParameterGroupFamilyParameter\": {");
assertThat(result).doesNotContain("\"SslCertificateIdentifierParameter\": {");
assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
assertThat(result).doesNotContain("\"VPCIdParameter\": {");
assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
assertThat(result).doesNotContain("\"FromPort\"");
assertThat(result).doesNotContain("\"ToPort\"");
assertThat(result).doesNotContain("\"CidrIp\" :");
assertThat(result).contains("\"DBParameterGroup\": {");
assertThat(result).contains("\"Parameters\": { \"rds.force_ssl\": \"1\" },");
assertThat(result).contains("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
assertThat(result).doesNotContain("\"CACertificateIdentifier\": { \"Ref\": \"SslCertificateIdentifierParameter\" },");
assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
assertThat(result).contains("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndHavingPort.
@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndHavingPort(String templatePath) throws IOException {
// GIVEN
String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
// WHEN
RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withHasPort(true).withTemplate(awsCloudFormationTemplate);
String result = cloudFormationTemplateBuilder.build(modelContext);
// THEN
assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
assertThat(result).contains("\"PortParameter\": {");
assertThat(result).doesNotContain("\"DBParameterGroupNameParameter\": {");
assertThat(result).doesNotContain("\"DBParameterGroupFamilyParameter\": {");
assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
assertThat(result).doesNotContain("\"VPCIdParameter\": {");
assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
assertThat(result).doesNotContain("\"FromPort\"");
assertThat(result).doesNotContain("\"ToPort\"");
assertThat(result).doesNotContain("\"CidrIp\" :");
assertThat(result).doesNotContain("\"DBParameterGroup\": {");
assertThat(result).doesNotContain("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
assertThat(result).contains("\"Port\": { \"Ref\": \"PortParameter\" },");
assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
assertThat(result).doesNotContain("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.
the class AwsRdsLaunchServiceTest method launchTestUseSslEnforcementInternal.
private void launchTestUseSslEnforcementInternal(boolean useSslEnforcement, boolean sslCertificateIdentifierDefined) {
when(cfStackUtil.getOutputs(STACK_NAME_CF, cfRetryClient)).thenReturn(useSslEnforcement ? CF_OUTPUTS_WITH_DB_PARAMETER_GROUP : CF_OUTPUTS_WITHOUT_DB_PARAMETER_GROUP);
List<CloudResourceStatus> cloudResourceStatuses = underTest.launch(authenticatedContext, createDatabaseStack(useSslEnforcement, sslCertificateIdentifierDefined), resourceNotifier);
assertThat(cloudResourceStatuses).isNotNull();
assertThat(cloudResourceStatuses).hasSize(useSslEnforcement ? 6 : 5);
cloudResourceStatuses.forEach(status -> assertThat(status).isNotNull());
cloudResourceStatuses.forEach(status -> assertThat(status.getCloudResource()).isNotNull());
checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_HOSTNAME, OUT_HOSTNAME);
checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_PORT, OUT_PORT);
checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_INSTANCE, OUT_DB_INSTANCE);
checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_DB_SUBNET_GROUP, OUT_DB_SUBNET_GROUP);
if (useSslEnforcement) {
checkOutputResourceExists(cloudResourceStatuses, ResourceType.RDS_DB_PARAMETER_GROUP, OUT_DB_PARAMETER_GROUP);
} else {
checkOutputResourceIsAbsent(cloudResourceStatuses, ResourceType.RDS_DB_PARAMETER_GROUP, OUT_DB_PARAMETER_GROUP);
}
checkOutputResourceExists(cloudResourceStatuses, ResourceType.CLOUDFORMATION_STACK, STACK_NAME_CF);
verify(cloudFormationTemplateBuilder).build(rdsModelContextCaptor.capture());
RDSModelContext rdsModelContext = rdsModelContextCaptor.getValue();
assertThat(rdsModelContext).isNotNull();
Boolean useSslEnforcementResult = (Boolean) ReflectionTestUtils.getField(rdsModelContext, "useSslEnforcement");
assertThat(useSslEnforcementResult).isNotNull();
assertThat(useSslEnforcementResult.booleanValue()).isEqualTo(useSslEnforcement);
Boolean sslCertificateIdentifierDefinedResult = (Boolean) ReflectionTestUtils.getField(rdsModelContext, "sslCertificateIdentifierDefined");
assertThat(sslCertificateIdentifierDefinedResult).isNotNull();
assertThat(sslCertificateIdentifierDefinedResult.booleanValue()).isEqualTo(sslCertificateIdentifierDefined);
}
use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderDBTest method buildTestWhenHavingSecurityGroupAndNoPortAndNoSslEnforcementAndNoSslCertificateIdentifier.
@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenHavingSecurityGroupAndNoPortAndNoSslEnforcementAndNoSslCertificateIdentifier(String templatePath) throws IOException {
// GIVEN
String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
// WHEN
RDSModelContext modelContext = new RDSModelContext().withHasSecurityGroup(true).withUseSslEnforcement(false).withSslCertificateIdentifierDefined(false).withTemplate(awsCloudFormationTemplate);
String result = cloudFormationTemplateBuilder.build(modelContext);
// THEN
assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
assertThat(result).doesNotContain("\"PortParameter\": {");
assertThat(result).doesNotContain("\"DBParameterGroupNameParameter\": {");
assertThat(result).doesNotContain("\"DBParameterGroupFamilyParameter\": {");
assertThat(result).doesNotContain("\"SslCertificateIdentifierParameter\": {");
assertThat(result).contains("\"VPCSecurityGroupsParameter\": {");
assertThat(result).doesNotContain("\"DBSecurityGroupNameParameter\": {");
assertThat(result).doesNotContain("\"VPCIdParameter\": {");
assertThat(result).doesNotContain("\"VPCSecurityGroup\": {");
assertThat(result).doesNotContain("\"FromPort\"");
assertThat(result).doesNotContain("\"ToPort\"");
assertThat(result).doesNotContain("\"CidrIp\" :");
assertThat(result).doesNotContain("\"DBParameterGroup\": {");
assertThat(result).doesNotContain("\"DBParameterGroupName\": { \"Ref\": \"DBParameterGroup\" },");
assertThat(result).doesNotContain("\"CACertificateIdentifier\": { \"Ref\": \"SslCertificateIdentifierParameter\" },");
assertThat(result).doesNotContain("\"Port\": { \"Ref\": \"PortParameter\" },");
assertThat(result).contains("\"VPCSecurityGroups\": { \"Ref\": \"VPCSecurityGroupsParameter\" }");
assertThat(result).doesNotContain("\"VPCSecurityGroups\": [{ \"Ref\": \"VPCSecurityGroup\" }]");
assertThat(result).doesNotContain("\"CreatedDBParameterGroup\": { \"Value\": { \"Ref\": \"DBParameterGroup\" } },");
}
use of com.sequenceiq.cloudbreak.cloud.aws.CloudFormationTemplateBuilder.RDSModelContext in project cloudbreak by hortonworks.
the class CloudFormationTemplateBuilderDBTest method buildTestWhenKmsKeyIdAbsent.
@ParameterizedTest(name = "{0}")
@MethodSource("templatesPathDataProvider")
void buildTestWhenKmsKeyIdAbsent(String templatePath) throws IOException {
// GIVEN
String awsCloudFormationTemplate = factoryBean.getObject().getTemplate(templatePath, "UTF-8").toString();
// WHEN
RDSModelContext modelContext = new RDSModelContext().withIsKmsCustom(false).withTemplate(awsCloudFormationTemplate);
String result = cloudFormationTemplateBuilder.build(modelContext);
assertThat(JsonUtil.isValid(result)).overridingErrorMessage("Invalid JSON: " + result).isTrue();
assertThat(result).contains("\"StorageEncrypted\": true");
assertThat(result).doesNotContain("\"KmsKeyId\" : \"dummyKeyArn\"");
}
Aggregations