fix(rds): reject malformed cluster snapshot copy flags (#5472)

This commit is contained in:
David Phillips authored and GitHub committed 2026-10-11 19:44:08 -04:00
1 parent 1a0afce7ec
commit 1e92b7e17b
3 files changed
+47 -1

No files matched your search

+1
View File
@@ -187,6 +187,7 @@ including empty strings, return `InvalidParameterValue` before changing resource
| `CreateDBProxy` | `RequireTLS`, `DebugLogging` | Defaults to `false` |
| `ModifyDBProxy` | `RequireTLS`, `DebugLogging` | Preserves the current value |
| `ResetDBParameterGroup`, `ResetDBClusterParameterGroup` | `ResetAllParameters` | Defaults to `false`; named parameter resets keep their existing behavior |
| `CopyDBClusterSnapshot` | `CopyTags` | Defaults to `false`; explicit request tags still apply |
Malformed reset flags leave saved parameter overrides unchanged.
@@ -2300,7 +2300,7 @@ public class RdsQueryHandler {
if (missing != null) {
return missing;
}
boolean copyTags = "true".equalsIgnoreCase(params.getFirst("CopyTags"));
boolean copyTags = Boolean.TRUE.equals(parseOptionalBoolean(params, "CopyTags"));
DbClusterSnapshot copy = service.copyDbClusterSnapshot(sourceId, targetId, copyTags, parseTags(params), region);
return Response.ok(AwsQueryResponse.envelope("CopyDBClusterSnapshot", AwsNamespaces.RDS,
dbClusterSnapshotXml(copy))).build();
@@ -2284,6 +2284,51 @@ class RdsQueryHandlerTest {
verify(service, never()).startDbCluster(any(), any());
}
@ParameterizedTest
@ValueSource(strings = {"yes", "", "not-a-boolean"})
void copyClusterSnapshotRejectsMalformedCopyTagsBeforeServiceCall(String value) {
DbClusterSnapshot snapshot = new DbClusterSnapshot();
snapshot.setDbClusterSnapshotIdentifier("target");
when(service.copyDbClusterSnapshot(anyString(), anyString(), anyBoolean(), anyMap(), isNull()))
.thenReturn(snapshot);
MultivaluedMap<String, String> p = params();
p.putSingle("SourceDBClusterSnapshotIdentifier", "source");
p.putSingle("TargetDBClusterSnapshotIdentifier", "target");
p.putSingle("CopyTags", value);
Response response = handler.handle("CopyDBClusterSnapshot", p);
assertEquals(400, response.getStatus());
assertTrue(((String) response.getEntity()).contains("<Code>InvalidParameterValue</Code>"));
assertTrue(((String) response.getEntity()).contains("CopyTags must be true or false."));
verifyNoInteractions(service);
}
@ParameterizedTest
@NullSource
@ValueSource(strings = {"true", "false", "TrUe", "FaLsE"})
void copyClusterSnapshotPreservesCopyTagsValuesAndDefault(String value) {
DbClusterSnapshot snapshot = new DbClusterSnapshot();
snapshot.setDbClusterSnapshotIdentifier("target");
boolean copyTags = Boolean.parseBoolean(value);
when(service.copyDbClusterSnapshot(eq("source"), eq("target"), eq(copyTags),
eq(Map.of("owner", "team")), isNull())).thenReturn(snapshot);
MultivaluedMap<String, String> p = params();
p.putSingle("SourceDBClusterSnapshotIdentifier", "source");
p.putSingle("TargetDBClusterSnapshotIdentifier", "target");
p.putSingle("Tags.Tag.1.Key", "owner");
p.putSingle("Tags.Tag.1.Value", "team");
if (value != null) {
p.putSingle("CopyTags", value);
}
Response response = handler.handle("CopyDBClusterSnapshot", p);
assertEquals(200, response.getStatus());
assertTrue(((String) response.getEntity()).contains("<DBClusterSnapshotIdentifier>target"));
verify(service).copyDbClusterSnapshot("source", "target", copyTags, Map.of("owner", "team"), null);
}
@Test
void clusterSnapshotActions_dispatchAndRenderTheClusterSnapshot() {
DbClusterSnapshot snapshot = new DbClusterSnapshot();