fix(docdb): accept an existing security group on CreateDBCluster and ModifyDBCluster (#2991)

* fix(docdb): accept an existing security group on CreateDBCluster and ModifyDBCluster

The security group lookup passed null for group names, which
Ec2Service.describeSecurityGroups does not accept, so any existing group
id answered an internal error while a made-up one was refused correctly
before that filter ran.

Closes #2990

* test(docdb): clean up the EC2 fixtures of the security-group bats case

* test(docdb): tear down the security-group case's EC2 fixtures even when it fails

* test(docdb): delete the case's VPC even when its security group was never created
This commit is contained in:
Michal Schreiber authored and GitHub committed 2026-09-04 10:33:20 -04:00
1 parent 352d89ff2d
commit 91d7ab8935
3 files changed
+65 -2

No files matched your search

@@ -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 {
@Inject
KmsService 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>"));
}
@Test
void settingsGivenOnCreateComeBackFromDescribeAndModifyChangesThem() {
String keyArn = kmsService.createKey("docdb settings", "us-east-1").getArn();