mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(rds): store and return VpcSecurityGroupIds, windows and DeletionProtection on DB clusters (#8042)
Store and return VpcSecurityGroupIds and the preferred backup and maintenance windows on create, modify, restore and CloudFormation cluster paths, validating them before any mutating call. A cluster that names no group gets its VPC's default group. The window resolution moves into BackupWindows, shared with DB instances and DocumentDB. An update whose template no longer carries DeletionProtection leaves the stored value alone, as the provider's null does, instead of turning it off.
This commit is contained in:
1 parent
2b9ed9cd55
commit
347e2abd89
14 files changed
+798
-124
No files matched your search
+151
@@ -7,6 +7,8 @@ import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -266,6 +268,155 @@ class CloudFormationRdsAssociatedRolesIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterWithNoTemplateGroupsGetsTheVpcDefaultAndADroppedListGoesBackToIt() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-sg-" + suffix;
|
||||
String clusterId = "cfn-sg-cluster-" + suffix;
|
||||
String cluster = """
|
||||
{"Resources": {"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
"MasterUsername": "dbadmin", "MasterUserPassword": "%s"%s}}}}
|
||||
""";
|
||||
try {
|
||||
stack("CreateStack", stackName, cluster.formatted(clusterId, "password123", ""));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
List<String> defaultGroup = clusterGroups(clusterId);
|
||||
assertEquals(1, defaultGroup.size(), defaultGroup.toString());
|
||||
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "password123",
|
||||
", \"VpcSecurityGroupIds\": [\"sg-named\"]"));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(List.of("sg-named"), clusterGroups(clusterId));
|
||||
|
||||
// A list the previous template declared and this one drops goes back to the VPC default.
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "password456", ""));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(defaultGroup, clusterGroups(clusterId));
|
||||
} finally {
|
||||
stack("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateLeavesGroupsSetOutsideTheStackAndDroppedSettingsKeepTheirValues() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-sg-out-" + suffix;
|
||||
String clusterId = "cfn-sg-out-" + suffix;
|
||||
String cluster = """
|
||||
{"Resources": {"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
"MasterUsername": "dbadmin", "MasterUserPassword": "%s"%s}}}}
|
||||
""";
|
||||
try {
|
||||
stack("CreateStack", stackName, cluster.formatted(clusterId, "password123",
|
||||
", \"DeletionProtection\": true, \"PreferredBackupWindow\": \"03:00-04:00\","
|
||||
+ " \"PreferredMaintenanceWindow\": \"mon:05:00-mon:06:00\""));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", clusterId)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-outside")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "password456", ""));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(List.of("sg-outside"), clusterGroups(clusterId));
|
||||
XmlPath xml = rds("DescribeDBClusters").formParam("DBClusterIdentifier", clusterId)
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
assertEquals("true", xml.getString("**.find { it.name() == 'DeletionProtection' }"));
|
||||
assertEquals("03:00-04:00", xml.getString("**.find { it.name() == 'PreferredBackupWindow' }"));
|
||||
assertEquals("mon:05:00-mon:06:00",
|
||||
xml.getString("**.find { it.name() == 'PreferredMaintenanceWindow' }"));
|
||||
} finally {
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", clusterId)
|
||||
.formParam("DeletionProtection", "false").when().post("/");
|
||||
stack("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExplicitEmptyGroupListKeepsTheDefaultOnCreateAndRestoresItOnUpdate() {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-sg-empty-" + suffix;
|
||||
String clusterId = "cfn-sg-empty-" + suffix;
|
||||
String cluster = """
|
||||
{"Resources": {"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
"MasterUsername": "dbadmin", "MasterUserPassword": "password123",
|
||||
"VpcSecurityGroupIds": %s}}}}
|
||||
""";
|
||||
try {
|
||||
List<String> vpcDefault = vpcDefaultGroup(suffix);
|
||||
stack("CreateStack", stackName, cluster.formatted(clusterId, "[]"));
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(vpcDefault, clusterGroups(clusterId));
|
||||
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "[\"sg-named\"]"));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(List.of("sg-named"), clusterGroups(clusterId));
|
||||
|
||||
stack("UpdateStack", stackName, cluster.formatted(clusterId, "[]"));
|
||||
assertEquals("UPDATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(vpcDefault, clusterGroups(clusterId));
|
||||
} finally {
|
||||
stack("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {", \"VpcSecurityGroupIds\": [\"sg-second\"]", ""})
|
||||
void aGroupChangeIsUndoneWhenALaterResourceFailsTheUpdate(String updatedGroups) {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String stackName = "cfn-rds-sg-undo-" + suffix;
|
||||
String clusterId = "cfn-sg-undo-" + suffix;
|
||||
String cluster = """
|
||||
"Cluster": {"Type": "AWS::RDS::DBCluster", "Properties": {
|
||||
"DBClusterIdentifier": "%s", "Engine": "aurora-postgresql",
|
||||
"MasterUsername": "dbadmin", "MasterUserPassword": "password123"%s}}""";
|
||||
// A member carrying its own roles is refused, after the cluster has been updated.
|
||||
String failingMember = """
|
||||
, "Member": {"Type": "AWS::RDS::DBInstance", "Properties": {
|
||||
"DBClusterIdentifier": {"Ref": "Cluster"}, "Engine": "aurora-postgresql",
|
||||
"DBInstanceClass": "db.r6g.large",
|
||||
"AssociatedRoles": [{"RoleArn": "%s", "FeatureName": "s3Import"}]}}""".formatted(EXPORT_ROLE);
|
||||
try {
|
||||
stack("CreateStack", stackName, "{\"Resources\": {"
|
||||
+ cluster.formatted(clusterId, ", \"VpcSecurityGroupIds\": [\"sg-first\"]") + "}}");
|
||||
assertEquals("CREATE_COMPLETE", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
|
||||
stack("UpdateStack", stackName, "{\"Resources\": {"
|
||||
+ cluster.formatted(clusterId, updatedGroups) + failingMember + "}}");
|
||||
// The cluster's other settings have no rollback, so the stack reports the rollback failed.
|
||||
assertEquals("UPDATE_ROLLBACK_FAILED", CfnStackWaits.awaitTerminal(stackName).status());
|
||||
assertEquals(List.of("sg-first"), clusterGroups(clusterId));
|
||||
} finally {
|
||||
stack("DeleteStack", stackName, null);
|
||||
CfnStackWaits.awaitStackDeleted(stackName);
|
||||
}
|
||||
}
|
||||
|
||||
/** The group a cluster created with none lands on, read from a throwaway cluster. */
|
||||
private static List<String> vpcDefaultGroup(String suffix) {
|
||||
String id = "cfn-sg-ref-" + suffix;
|
||||
rds("CreateDBCluster").formParam("DBClusterIdentifier", id).formParam("Engine", "aurora-postgresql")
|
||||
.formParam("MasterUsername", "dbadmin").formParam("MasterUserPassword", "password123")
|
||||
.when().post("/").then().statusCode(200);
|
||||
try {
|
||||
return clusterGroups(id);
|
||||
} finally {
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", id).formParam("SkipFinalSnapshot", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> clusterGroups(String clusterId) {
|
||||
XmlPath xml = rds("DescribeDBClusters").formParam("DBClusterIdentifier", clusterId)
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
return xml.getList("**.findAll { it.name() == 'VpcSecurityGroupId' }", String.class);
|
||||
}
|
||||
|
||||
private static String template(String clusterId, String instanceId, String clusterRoles) {
|
||||
return """
|
||||
{"Resources": {
|
||||
|
||||
@@ -292,6 +292,40 @@ class RdsCfnProvisionerTest {
|
||||
null, null, null, false, null, null, false, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterPassesTemplateGroupsProtectionAndWindowsToTheRequestSettings() {
|
||||
DbCluster cluster = mock(DbCluster.class);
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql",
|
||||
"VpcSecurityGroupIds":["sg-a","sg-b"],"DeletionProtection":true,
|
||||
"PreferredBackupWindow":"03:00-04:00","PreferredMaintenanceWindow":"Mon:05:00-Mon:06:00"}
|
||||
""");
|
||||
verify(rdsService).setDbClusterRequestSettings("mycluster", "us-east-1", List.of("sg-a", "sg-b"),
|
||||
"03:00-04:00", "Mon:05:00-Mon:06:00");
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterWithoutTemplateGroupsLeavesGroupsToTheServiceDefault() {
|
||||
DbCluster cluster = mock(DbCluster.class);
|
||||
when(cluster.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(rdsService.createDbCluster(any(), any(), any(), any(), any(), any(), anyBoolean(), any(),
|
||||
any(), any(), anyBoolean(), any(), any(), any(), any(), anyBoolean(), any(), any(),
|
||||
anyBoolean(), any(), anyBoolean()))
|
||||
.thenReturn(cluster);
|
||||
|
||||
provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql"}
|
||||
""");
|
||||
verify(rdsService).setDbClusterRequestSettings(eq("mycluster"), eq("us-east-1"), isNull(),
|
||||
nullable(String.class), nullable(String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterEnableHttpEndpointIsAppliedOnCreateAndUpdate() {
|
||||
createDbClusterEchoesRequestedId();
|
||||
@@ -336,6 +370,25 @@ class RdsCfnProvisionerTest {
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateWindowOverlappingTheStoredOneFailsBeforeTheClusterIsModified() {
|
||||
DbCluster existing = mock(DbCluster.class);
|
||||
when(existing.getDbClusterIdentifier()).thenReturn("mycluster");
|
||||
when(existing.getPreferredMaintenanceWindow()).thenReturn("mon:05:00-mon:06:00");
|
||||
when(rdsService.getDbCluster("mycluster")).thenReturn(existing);
|
||||
when(rdsService.modifyDbCluster(eq("mycluster"), any(), any(), any(), any(), any(), any())).thenReturn(existing);
|
||||
|
||||
StackResource r = provisionExisting("Cluster", "AWS::RDS::DBCluster", """
|
||||
{"DBClusterIdentifier":"mycluster","Engine":"aurora-postgresql","MasterUserPassword":"changed",
|
||||
"PreferredBackupWindow":"05:00-06:00"}
|
||||
""", "us-east-1", "mycluster", Map.of("DBClusterIdentifier", "mycluster"));
|
||||
|
||||
assertEquals("CREATE_FAILED", r.getStatus());
|
||||
assertTrue(r.getStatusReason().contains("must not overlap"), r.getStatusReason());
|
||||
verify(rdsService, never()).modifyDbCluster(any(), any(), any(), any(), any(), any(), any());
|
||||
verify(rdsService, never()).setDbClusterRequestSettings(any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbClusterEnableHttpEndpointOnANonAuroraEngineFailsBeforeCreating() {
|
||||
StackResource r = provision("Cluster", "AWS::RDS::DBCluster", """
|
||||
|
||||
+309
@@ -0,0 +1,309 @@
|
||||
package io.floci.aws.services.rds;
|
||||
|
||||
import io.floci.aws.core.common.BackupWindows;
|
||||
import io.floci.aws.testing.RdsMockProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.RdsRequests.createAuroraPostgresCluster;
|
||||
import static io.floci.aws.testing.RdsRequests.rds;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* VpcSecurityGroupIds, PreferredBackupWindow and PreferredMaintenanceWindow given to CreateDBCluster
|
||||
* and ModifyDBCluster are stored on the cluster and read back through DescribeDBClusters, instead of a
|
||||
* fixed sg-00000000 membership and fixed windows, and a request refused for a malformed value changes
|
||||
* nothing.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestProfile(RdsMockProfile.class)
|
||||
class RdsClusterVpcSecurityGroupsIntegrationTest {
|
||||
|
||||
private static final String ID = "vpc-sg-cluster-" + System.nanoTime();
|
||||
|
||||
private static List<String> groupIds(String xml) {
|
||||
try {
|
||||
NodeList nodes = DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
|
||||
.getElementsByTagName("VpcSecurityGroupId");
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
ids.add(nodes.item(i).getTextContent());
|
||||
}
|
||||
return ids;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("unparseable RDS response: " + xml, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> describedGroupIds() {
|
||||
return groupIds(rds("DescribeDBClusters").formParam("DBClusterIdentifier", ID)
|
||||
.when().post("/").then().statusCode(200).extract().asString());
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanUp() {
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
// after the cluster, which may reference it; absent in most tests
|
||||
rds("DeleteDBClusterParameterGroup").formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.when().post("/");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createStoresRequestedGroupsAndModifyReplacesThem() {
|
||||
String created = createAuroraPostgresCluster(ID)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-abcdef01")
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
assertEquals(List.of("sg-abcdef01"), groupIds(created));
|
||||
assertEquals(List.of("sg-abcdef01"), describedGroupIds());
|
||||
|
||||
rds("ModifyDBCluster")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", "sg-11111111")
|
||||
.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.2", "sg-22222222")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals(List.of("sg-11111111", "sg-22222222"), describedGroupIds());
|
||||
|
||||
// A modify that does not name VpcSecurityGroupIds leaves them alone.
|
||||
rds("ModifyDBCluster")
|
||||
.formParam("DBClusterIdentifier", ID)
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals(List.of("sg-11111111", "sg-22222222"), describedGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void omittedGroupsDefaultToTheVpcsDefaultSecurityGroup() {
|
||||
String created = createAuroraPostgresCluster(ID).when().post("/").then().statusCode(200).extract().asString();
|
||||
List<String> groups = describedGroupIds();
|
||||
assertEquals(1, groups.size());
|
||||
assertNotEquals("sg-00000000", groups.get(0));
|
||||
assertTrue(groups.get(0).startsWith("sg-"));
|
||||
assertEquals(groups, groupIds(created));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"snapshot", "pitr"})
|
||||
void restoredClusterHoldsRequestedOrDefaultGroupsAndModifyLeavesThem(String path) {
|
||||
String restored = ID + "-restored";
|
||||
String snapshot = ID + "-snap";
|
||||
try {
|
||||
createAuroraPostgresCluster(ID).when().post("/").then().statusCode(200);
|
||||
rds("CreateDBClusterSnapshot").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("DBClusterSnapshotIdentifier", snapshot).post("/").then().statusCode(200);
|
||||
for (String group : new String[] {null, "sg-abcdef01"}) {
|
||||
RequestSpecification restore = "snapshot".equals(path)
|
||||
? rds("RestoreDBClusterFromSnapshot").formParam("SnapshotIdentifier", snapshot)
|
||||
.formParam("Engine", "aurora-postgresql")
|
||||
: rds("RestoreDBClusterToPointInTime").formParam("SourceDBClusterIdentifier", ID)
|
||||
.formParam("UseLatestRestorableTime", "true");
|
||||
restore.formParam("DBClusterIdentifier", restored);
|
||||
if (group != null) {
|
||||
restore.formParam("VpcSecurityGroupIds.VpcSecurityGroupId.1", group);
|
||||
}
|
||||
List<String> reported = groupIds(restore.post("/").then().statusCode(200).extract().asString());
|
||||
if (group != null) {
|
||||
assertEquals(List.of(group), reported);
|
||||
} else {
|
||||
assertEquals(1, reported.size());
|
||||
assertNotEquals("sg-00000000", reported.get(0));
|
||||
}
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", restored)
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true").post("/").then().statusCode(200);
|
||||
assertEquals(reported, groupIds(rds("DescribeDBClusters")
|
||||
.formParam("DBClusterIdentifier", restored).post("/").then().statusCode(200)
|
||||
.extract().asString()));
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", restored)
|
||||
.formParam("SkipFinalSnapshot", "true").post("/");
|
||||
}
|
||||
} finally {
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", restored)
|
||||
.formParam("SkipFinalSnapshot", "true").post("/");
|
||||
rds("DeleteDBClusterSnapshot").formParam("DBClusterSnapshotIdentifier", snapshot).post("/");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void maintenanceWindowDayNamesReadBackLowerCase() {
|
||||
String created = createAuroraPostgresCluster(ID)
|
||||
.formParam("PreferredMaintenanceWindow", "Mon:00:00-Mon:03:00")
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
assertEquals(true, created.contains("<PreferredMaintenanceWindow>mon:00:00-mon:03:00<"));
|
||||
assertEquals("mon:00:00-mon:03:00", described("PreferredMaintenanceWindow"));
|
||||
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredMaintenanceWindow", "TUE:07:00-Tue:08:00")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals("tue:07:00-tue:08:00", described("PreferredMaintenanceWindow"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyOfAMissingClusterIsDbClusterNotFound() {
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", "no-such-cluster")
|
||||
.when().post("/").then().statusCode(404)
|
||||
.body(containsString("<Code>DBClusterNotFoundFault</Code>"))
|
||||
.body(containsString("<Message>DBCluster not found</Message>"));
|
||||
}
|
||||
|
||||
private static String described(String tag) {
|
||||
String xml = rds("DescribeDBClusters").formParam("DBClusterIdentifier", ID)
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
try {
|
||||
return DocumentBuilderFactory.newInstance().newDocumentBuilder()
|
||||
.parse(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))
|
||||
.getElementsByTagName(tag).item(0).getTextContent();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("no " + tag + " in RDS response: " + xml, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void windowsAreStoredAndDefaulted() {
|
||||
createAuroraPostgresCluster(ID).when().post("/").then().statusCode(200);
|
||||
assertEquals("mon:00:00-mon:03:00", described("PreferredMaintenanceWindow"));
|
||||
assertEquals("04:00-06:00", described("PreferredBackupWindow"));
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
|
||||
String created = createAuroraPostgresCluster(ID)
|
||||
.formParam("PreferredBackupWindow", "05:00-06:00")
|
||||
.formParam("PreferredMaintenanceWindow", "tue:07:00-tue:08:00")
|
||||
.when().post("/").then().statusCode(200).extract().asString();
|
||||
assertEquals(true, created.contains("<PreferredBackupWindow>05:00-06:00</PreferredBackupWindow>"));
|
||||
assertEquals("05:00-06:00", described("PreferredBackupWindow"));
|
||||
assertEquals("tue:07:00-tue:08:00", described("PreferredMaintenanceWindow"));
|
||||
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredBackupWindow", "03:00-04:00")
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertEquals("03:00-04:00", described("PreferredBackupWindow"));
|
||||
assertEquals("tue:07:00-tue:08:00", described("PreferredMaintenanceWindow"));
|
||||
}
|
||||
|
||||
private static int clusterCount() {
|
||||
return rds("DescribeDBClusters").when().post("/").then().statusCode(200).extract().asString()
|
||||
.split("<DBClusterIdentifier>" + ID + "</DBClusterIdentifier>", -1).length - 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidWindowsAreRefusedAndLeaveNoClusterBehind() {
|
||||
createAuroraPostgresCluster(ID).formParam("PreferredBackupWindow", "garbage").when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals(0, clusterCount());
|
||||
createAuroraPostgresCluster(ID).formParam("PreferredBackupWindow", "05:00-06:00")
|
||||
.formParam("PreferredMaintenanceWindow", "mon:05:30-mon:06:30")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals(0, clusterCount());
|
||||
|
||||
createAuroraPostgresCluster(ID).formParam("PreferredBackupWindow", "05:00-06:00").when().post("/").then().statusCode(200);
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredBackupWindow", "garbage").when().post("/").then().statusCode(400);
|
||||
assertEquals("05:00-06:00", described("PreferredBackupWindow"));
|
||||
}
|
||||
|
||||
private static void assertOverlapRefused(ValidatableResponse r) {
|
||||
r.statusCode(400).body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void windowGivenAloneIsPairedWithAClearOneOnCreateAndRefusedOnModify() {
|
||||
// default maintenance mon:00:00-mon:03:00 overlaps 01:00-02:00, so a clear one is derived
|
||||
createAuroraPostgresCluster(ID).formParam("PreferredBackupWindow", "01:00-02:00").when().post("/").then().statusCode(200);
|
||||
assertEquals("01:00-02:00", described("PreferredBackupWindow"));
|
||||
String maint = described("PreferredMaintenanceWindow");
|
||||
assertEquals(false, BackupWindows.overlap("01:00-02:00", maint), maint);
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
|
||||
// default backup 04:00-06:00 overlaps mon:04:30-mon:05:30
|
||||
createAuroraPostgresCluster(ID).formParam("PreferredMaintenanceWindow", "mon:04:30-mon:05:30")
|
||||
.when().post("/").then().statusCode(200);
|
||||
String backup = described("PreferredBackupWindow");
|
||||
assertEquals(false, BackupWindows.overlap(backup, "mon:04:30-mon:05:30"), backup);
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
|
||||
// never-set windows count as the defaults on modify
|
||||
createAuroraPostgresCluster(ID).when().post("/").then().statusCode(200);
|
||||
assertOverlapRefused(rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredBackupWindow", "01:00-02:00").when().post("/").then());
|
||||
assertOverlapRefused(rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("PreferredMaintenanceWindow", "mon:04:30-mon:05:30").when().post("/").then());
|
||||
assertEquals("04:00-06:00", described("PreferredBackupWindow"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyWithABadWindowChangesNothing() {
|
||||
createAuroraPostgresCluster(ID).when().post("/").then().statusCode(200);
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("BackupRetentionPeriod", "9").formParam("PreferredBackupWindow", "garbage")
|
||||
.when().post("/").then().statusCode(400);
|
||||
assertEquals("1", described("BackupRetentionPeriod"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithMalformedDeletionProtectionLeavesNoClusterBehind() {
|
||||
createAuroraPostgresCluster(ID).formParam("DeletionProtection", "garbage").when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals(0, clusterCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyWithMalformedDeletionProtectionChangesNothing() {
|
||||
rds("CreateDBClusterParameterGroup").formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.formParam("DBParameterGroupFamily", "aurora-postgresql15").formParam("Description", "d")
|
||||
.when().post("/").then().statusCode(200);
|
||||
createAuroraPostgresCluster(ID).formParam("MasterUserPassword", "original-password1")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-old").when().post("/").then().statusCode(200);
|
||||
String groupBefore = described("DBClusterParameterGroup");
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("DeletionProtection", "garbage").formParam("BackupRetentionPeriod", "9")
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.formParam("MasterUserPassword", "changed-password2")
|
||||
.formParam("VpcSecurityGroupIds.member.1", "sg-new")
|
||||
.formParam("DBClusterParameterGroupName", "pg-rejected")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals("1", described("BackupRetentionPeriod"));
|
||||
assertEquals("false", described("IAMDatabaseAuthenticationEnabled"));
|
||||
assertEquals("false", described("DeletionProtection"));
|
||||
assertEquals(List.of("sg-old"), describedGroupIds());
|
||||
assertEquals(groupBefore, described("DBClusterParameterGroup"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createWithEmptySecurityGroupMemberLeavesNoClusterBehind() {
|
||||
createAuroraPostgresCluster(ID).formParam("VpcSecurityGroupIds.member.1", "").when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals(0, clusterCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyWithEmptySecurityGroupMemberChangesNothing() {
|
||||
createAuroraPostgresCluster(ID).formParam("VpcSecurityGroupIds.member.1", "sg-old").when().post("/").then().statusCode(200);
|
||||
rds("ModifyDBCluster").formParam("DBClusterIdentifier", ID)
|
||||
.formParam("VpcSecurityGroupIds.member.1", "").formParam("BackupRetentionPeriod", "9")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
assertEquals("1", described("BackupRetentionPeriod"));
|
||||
assertEquals(List.of("sg-old"), describedGroupIds());
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,9 @@ class RdsQueryHandlerTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = mock(RdsService.class);
|
||||
when(service.getDbCluster(any(), any())).thenAnswer(inv -> makeCluster(inv.getArgument(0)));
|
||||
when(service.setDbClusterRequestSettings(any(), any(), any(), any(), any()))
|
||||
.thenAnswer(inv -> makeCluster(inv.getArgument(0)));
|
||||
when(service.instanceCertificate(any())).thenReturn(
|
||||
new RdsService.InstanceCertificate("rds-ca-rsa2048-g1", Instant.parse("2061-05-25T23:34:57Z")));
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
@@ -912,7 +915,7 @@ class RdsQueryHandlerTest {
|
||||
any(DbInstanceSettings.class), isNull(), any(DbInstanceScalingChanges.class), isNull(), isNull());
|
||||
verify(service).rebootDbInstance("mydb", "us-west-2");
|
||||
verify(service).listDbClusters(null, "us-west-2");
|
||||
verify(service).getDbCluster("mycluster", "us-west-2");
|
||||
verify(service, times(2)).getDbCluster("mycluster", "us-west-2");
|
||||
verify(service).deleteDbCluster("mycluster", "us-west-2", true);
|
||||
verify(service).modifyDbCluster("mycluster", null, null,
|
||||
null, null, null, null, null, null, false, false, "us-west-2");
|
||||
@@ -924,6 +927,7 @@ class RdsQueryHandlerTest {
|
||||
cluster.setMasterUserSecretArn("arn:aws:secretsmanager:us-east-1:000000000000:secret:rds!cluster-ABC");
|
||||
cluster.setMasterUserSecretStatus("active");
|
||||
cluster.setMasterUserSecretKmsKeyId("kms-key-1");
|
||||
when(service.setDbClusterRequestSettings(any(), any(), any(), any(), any())).thenReturn(cluster);
|
||||
when(service.createDbCluster(eq("mycluster"), eq("aurora-postgresql"), any(),
|
||||
eq("omni_admin"), isNull(), eq("omni"), eq(false), isNull(),
|
||||
isNull(), isNull(), eq(false), any(),
|
||||
@@ -1032,6 +1036,7 @@ class RdsQueryHandlerTest {
|
||||
@CsvSource({"true,true", "true,false", "false,true", "false,false"})
|
||||
void modifyDbClusterForwardsRotationAndApplyImmediately(boolean rotatePassword, boolean applyImmediately) {
|
||||
DbCluster cluster = makeCluster("mycluster");
|
||||
when(service.setDbClusterRequestSettings(any(), any(), any(), any(), any())).thenReturn(cluster);
|
||||
when(service.modifyDbCluster("mycluster", null, null, null, null, null,
|
||||
null, null, null, rotatePassword, applyImmediately, "us-west-2")).thenReturn(cluster);
|
||||
MultivaluedMap<String, String> p = params();
|
||||
|
||||
@@ -1791,6 +1791,43 @@ class RdsServiceTest {
|
||||
.getVpcSecurityGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clusterCreatedWithNoGroupsGetsTheVpcDefaultAndModifyOnlyStoresWhatItNames() {
|
||||
SecurityGroup defaultGroup = new SecurityGroup();
|
||||
defaultGroup.setGroupId("sg-default");
|
||||
when(ec2Service.defaultSecurityGroupOf(eq("us-east-1"), any())).thenReturn(Optional.of(defaultGroup));
|
||||
DbCluster created = rdsService.createDbCluster("sg-cluster", "aurora-postgresql", null,
|
||||
"admin", "password", "dbname", false, null);
|
||||
assertEquals(List.of("sg-default"), created.getVpcSecurityGroupIds());
|
||||
|
||||
// an unrelated Modify leaves a null-groups request alone
|
||||
assertEquals(List.of("sg-default"), rdsService.setDbClusterRequestSettings(
|
||||
"sg-cluster", "us-east-1", null, null, null).getVpcSecurityGroupIds());
|
||||
rdsService.setDbClusterRequestSettings("sg-cluster", "us-east-1", List.of(), null, null);
|
||||
assertEquals(List.of(), rdsService.getDbCluster("sg-cluster").getVpcSecurityGroupIds());
|
||||
// ... and does not re-assign the default to a cluster stored with no groups
|
||||
rdsService.setDbClusterRequestSettings("sg-cluster", "us-east-1", null, null, null);
|
||||
assertEquals(List.of(), rdsService.getDbCluster("sg-cluster").getVpcSecurityGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void restoredAndGlobalMemberClustersGetTheVpcDefaultGroup() {
|
||||
SecurityGroup defaultGroup = new SecurityGroup();
|
||||
defaultGroup.setGroupId("sg-default");
|
||||
when(ec2Service.defaultSecurityGroupOf(eq("us-east-1"), any())).thenReturn(Optional.of(defaultGroup));
|
||||
|
||||
clusterSnapshotOfNewCluster("csnap");
|
||||
assertEquals(List.of("sg-default"), rdsService.restoreDbClusterFromSnapshot("restored-sg", "csnap",
|
||||
"aurora-postgresql", null, null, null, null, null, null, null, null, false, null, "us-east-1")
|
||||
.getVpcSecurityGroupIds());
|
||||
|
||||
rdsService.createGlobalCluster("sg-global", null, "aurora-postgresql", "16.3",
|
||||
"dbname", false, false, Map.of(), "us-east-1");
|
||||
assertEquals(List.of("sg-default"), rdsService.createDbClusterInGlobalCluster("sg-global", "global-member",
|
||||
"aurora-postgresql", null, "admin", "password", "dbname", false, null, null, null, false,
|
||||
"us-east-1", null, null, null, false, null, null, false).getVpcSecurityGroupIds());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAndModifyDbInstancePersistPubliclyAccessible() {
|
||||
DbInstance instance = rdsService.createDbInstance("pubdb", "postgres", "13",
|
||||
|
||||
Reference in new issue
Block a user