Light, fluffy, and always free - The AWS Local Emulator alternative
fix(docdb): accept an existing security group on CreateDBCluster and ModifyDBCluster (#2991)
Michal Schreiber91d7ab8935a3
diff --git a/compatibility-tests/sdk-test-awscli/test/rds.bats b/compatibility-tests/sdk-test-awscli/test/rds.batsindex 79ef180f03..0d6a206eef 100644--- a/compatibility-tests/sdk-test-awscli/test/rds.bats+++ b/compatibility-tests/sdk-test-awscli/test/rds.bats@@ -14,6 +14,14 @@ teardown() {aws_cmd secretsmanager delete-secret --secret-id "$MANAGED_SECRET_ARN" \--force-delete-without-recovery >/dev/null 2>&1 || truefi+ # EC2 fixtures of the docdb security-group case, whether or not its assertions passed+ if [ -n "${SG_ID:-}" ]; then+ aws_cmd docdb delete-db-cluster --db-cluster-identifier "$CLUSTER_ID" --skip-final-snapshot >/dev/null 2>&1 || true+ aws_cmd ec2 delete-security-group --group-id "$SG_ID" >/dev/null 2>&1 || true+ fi+ if [ -n "${VPC_ID:-}" ]; then+ aws_cmd ec2 delete-vpc --vpc-id "$VPC_ID" >/dev/null 2>&1 || true+ fi}@test "RDS: create db instance returns resource identifiers" {@@ -233,6 +241,24 @@ teardown() {assert_output --partial 'DBClusterNotFoundFault'}+@test "docdb: a security group that exists is accepted on create" {+ CLUSTER_ID="bats-docdb-sg-$(unique_name)"+ run aws_cmd ec2 create-vpc --cidr-block 10.42.0.0/16+ assert_success+ VPC_ID=$(json_get "$output" '.Vpc.VpcId')+ run aws_cmd ec2 create-security-group --group-name "$CLUSTER_ID" --description d --vpc-id "$VPC_ID"+ assert_success+ SG_ID=$(json_get "$output" '.GroupId')++ run aws_cmd docdb create-db-cluster --db-cluster-identifier "$CLUSTER_ID" --engine docdb \+ --master-username docdbadmin --master-user-password "secret99password" \+ --vpc-security-group-ids "$SG_ID"+ assert_success+ run aws_cmd docdb describe-db-clusters --db-cluster-identifier "$CLUSTER_ID"+ assert_success+ assert_output --partial "\"VpcSecurityGroupId\": \"$SG_ID\""+}+@test "docdb: cluster settings given on create are returned by describe" {CLUSTER_ID="bats-docdb-settings-$(unique_name)"run aws_cmd kms create-key --description "$CLUSTER_ID"diff --git a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.javaindex 53c824f1f3..6ec1a63077 100644--- a/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java+++ b/src/main/java/io/github/hectorvent/floci/services/docdb/DocDbService.java@@ -325,7 +325,7 @@ public class DocDbService {throw new IllegalStateException("DocDbService was built without an Ec2Service");}for (String groupId : securityGroups) {- boolean known = ec2Service.describeSecurityGroups(region, List.of(groupId), null, Map.of())+ boolean known = ec2Service.describeSecurityGroups(region, List.of(groupId), List.of(), Map.of()).stream().anyMatch(sg -> groupId.equals(sg.getGroupId()));if (!known) {throw new AwsException("InvalidParameterValue",diff --git a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbClusterSettingsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbClusterSettingsIntegrationTest.javaindex 9af118446f..e7019e98a3 100644--- a/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbClusterSettingsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/docdb/DocDbClusterSettingsIntegrationTest.java@@ -1,5 +1,7 @@package io.github.hectorvent.floci.services.docdb;+import io.github.hectorvent.floci.services.ec2.Ec2Service;+import io.github.hectorvent.floci.services.ec2.model.SecurityGroup;import io.github.hectorvent.floci.services.kms.KmsService;import io.quarkus.test.junit.QuarkusTest;import jakarta.inject.Inject;@@ -16,7 +18,7 @@ import static org.hamcrest.Matchers.containsString;/*** The settings a DocumentDB cluster is created with come back from DescribeDBClusters, as on a- * live account — through the Query protocol, with a real KMS key from the KMS store and the+ * live account: through the Query protocol, with a real KMS key from the KMS store and the* default subnet group, parameter group and security group.*/@QuarkusTest@@ -35,6 +37,9 @@ class DocDbClusterSettingsIntegrationTest {@InjectKmsService kmsService;+ @Inject+ Ec2Service ec2Service;+private static io.restassured.specification.RequestSpecification rds(String action) {return given().header("Authorization","AWS4-HMAC-SHA256 Credential=test/20260615/us-east-1/rds/aws4_request, "@@ -50,6 +55,38 @@ class DocDbClusterSettingsIntegrationTest {rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID).formParam("SkipFinalSnapshot", "true").when().post("/");}+ /**+ * A security group that exists is the case a live stack always sends, and the one a probe+ * with a made-up id never reaches, because an unknown id is refused before its record is+ * consulted. 2.0.1 answered it with an internal error.+ */+ @Test+ void anExistingSecurityGroupIsAcceptedOnCreateAndModify() {+ String vpcId = ec2Service.createVpc("us-east-1", "10.9.0.0/16", false).getVpcId();+ SecurityGroup first = ec2Service.createSecurityGroup("us-east-1", "docdb-first", "d", vpcId);+ SecurityGroup second = ec2Service.createSecurityGroup("us-east-1", "docdb-second", "d", vpcId);++ rds("CreateDBCluster")+ .formParam("DBClusterIdentifier", ID)+ .formParam("Engine", "docdb")+ .formParam("MasterUsername", "u")+ .formParam("MasterUserPassword", "secret99password")+ .formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", first.getGroupId())+ .when().post("/").then().statusCode(200)+ .body(containsString("<VpcSecurityGroupId>" + first.getGroupId() + "</VpcSecurityGroupId>"));++ rds("ModifyDBCluster")+ .formParam("DBClusterIdentifier", ID)+ .formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", first.getGroupId())+ .formParam("VpcSecurityGroupIds.VpcSecurityGroupId.2", second.getGroupId())+ .when().post("/").then().statusCode(200);++ rds("DescribeDBClusters").formParam("DBClusterIdentifier", ID)+ .when().post("/").then().statusCode(200)+ .body(containsString("<VpcSecurityGroupId>" + first.getGroupId() + "</VpcSecurityGroupId>"))+ .body(containsString("<VpcSecurityGroupId>" + second.getGroupId() + "</VpcSecurityGroupId>"));+ }+@Testvoid settingsGivenOnCreateComeBackFromDescribeAndModifyChangesThem() {String keyArn = kmsService.createKey("docdb settings", "us-east-1").getArn();