diff --git a/docs/services/rds.md b/docs/services/rds.md index 2d2814edc3..5453ef6daa 100644 --- a/docs/services/rds.md +++ b/docs/services/rds.md @@ -177,12 +177,19 @@ checked against the instance's other window. Modifications apply immediately — `arn:aws:rds:::cluster-snapshot:`. RDS reserved instances aren't modeled (there's no reserved-instance API), so tagging doesn't apply to them. -## DB proxy boolean parameters +## Boolean parameters + +The following parameters accept `true` or `false` (case-insensitive). Other values, +including empty strings, return `InvalidParameterValue` before changing resources. + +| Actions | Parameters | When omitted | +|---|---|---| +| `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 | + +Malformed reset flags leave saved parameter overrides unchanged. -`CreateDBProxy` accepts `true` or `false` (case-insensitive) for `RequireTLS` and -`DebugLogging`, defaulting each omitted flag to `false`. Other values, including empty -strings, return `InvalidParameterValue` before a proxy is created. `ModifyDBProxy` -uses the same boolean parsing and preserves an omitted flag's current value. ## Event notification subscriptions diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java index 89de38974b..a572f43fca 100644 --- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java @@ -1288,7 +1288,7 @@ public class RdsQueryHandler { } try { DbParameterGroup group = service.resetDbParameterGroup(name, - Boolean.parseBoolean(params.getFirst("ResetAllParameters")), parameterNames(params), region); + Boolean.TRUE.equals(parseOptionalBoolean(params, "ResetAllParameters")), parameterNames(params), region); String result = new XmlBuilder() .elem("DBParameterGroupName", group.getDbParameterGroupName()) .build(); @@ -1443,7 +1443,7 @@ public class RdsQueryHandler { } try { DbClusterParameterGroup group = service.resetDbClusterParameterGroup(name, - Boolean.parseBoolean(params.getFirst("ResetAllParameters")), parameterNames(params), region); + Boolean.TRUE.equals(parseOptionalBoolean(params, "ResetAllParameters")), parameterNames(params), region); String result = new XmlBuilder() .elem("DBClusterParameterGroupName", group.getDbClusterParameterGroupName()) .build(); diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java index dd8845a770..3889e80d27 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsParameterGroupCopyResetIntegrationTest.java @@ -6,6 +6,10 @@ import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import java.util.List; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.URLENC; @@ -42,6 +46,48 @@ class RdsParameterGroupCopyResetIntegrationTest { .formParam("Version", "2014-10-31"); } + @ParameterizedTest + @CsvSource({ + "DBParameterGroup, postgres15, reset-boolean-instance", + "DBClusterParameterGroup, aurora-postgresql15, reset-boolean-cluster" + }) + void malformedResetAllPreservesParameterOverrides(String groupType, String family, String name) { + String nameParameter = groupType + "Name"; + String describeAction = groupType.equals("DBParameterGroup") + ? "DescribeDBParameters" : "DescribeDBClusterParameters"; + query("Create" + groupType) + .formParam(nameParameter, name) + .formParam("DBParameterGroupFamily", family) + .formParam("Description", "boolean regression") + .when().post("/").then().statusCode(200); + try { + query("Modify" + groupType) + .formParam(nameParameter, name) + .formParam("Parameters.member.1.ParameterName", "max_connections") + .formParam("Parameters.member.1.ParameterValue", "250") + .when().post("/").then().statusCode(200); + + for (String invalid : List.of("yes", "", "1", "0", " true", "false ", "not-a-boolean")) { + query("Reset" + groupType) + .formParam(nameParameter, name) + .formParam("ResetAllParameters", invalid) + .formParam("Parameters.Parameter.1.ParameterName", "max_connections") + .formParam("Parameters.Parameter.1.ApplyMethod", "immediate") + .when().post("/").then().statusCode(400) + .body(containsString("InvalidParameterValue")) + .body(containsString("ResetAllParameters must be true or false.")); + + query(describeAction).formParam(nameParameter, name) + .when().post("/").then().statusCode(200) + .body(containsString("max_connections")) + .body(containsString("250")); + } + } finally { + query("Delete" + groupType).formParam(nameParameter, name) + .when().post("/").then().statusCode(200); + } + } + @Test @Order(1) void copyDbParameterGroupCarriesFamilyOverridesAndTags() { diff --git a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java index e09e54c801..e7478e38b1 100644 --- a/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/rds/RdsQueryHandlerTest.java @@ -63,6 +63,70 @@ class RdsQueryHandlerTest { handler = new RdsQueryHandler(service, config, docDbHandler, neptuneHandler); } + @ParameterizedTest + @CsvSource({ + "ResetDBParameterGroup, DBParameterGroupName", + "ResetDBClusterParameterGroup, DBClusterParameterGroupName" + }) + void parameterResetRejectsMalformedBooleanBeforeServiceCalls(String action, String nameParameter) { + DbParameterGroup instanceGroup = new DbParameterGroup(); + instanceGroup.setDbParameterGroupName("custom-group"); + DbClusterParameterGroup clusterGroup = new DbClusterParameterGroup(); + clusterGroup.setDbClusterParameterGroupName("custom-group"); + when(service.resetDbParameterGroup(any(), anyBoolean(), anyList(), any())).thenReturn(instanceGroup); + when(service.resetDbClusterParameterGroup(any(), anyBoolean(), anyList(), any())).thenReturn(clusterGroup); + for (String invalid : List.of("yes", "", "1", "0", " true", "false ", "not-a-boolean")) { + MultivaluedMap p = params(); + p.putSingle(nameParameter, "custom-group"); + p.putSingle("ResetAllParameters", invalid); + p.putSingle("Parameters.Parameter.1.ParameterName", "max_connections"); + + Response response = handler.handle(action, p, "us-west-2"); + + assertEquals(400, response.getStatus(), action + ": " + invalid); + String body = (String) response.getEntity(); + assertTrue(body.contains("InvalidParameterValue")); + assertTrue(body.contains("ResetAllParameters must be true or false.")); + verifyNoInteractions(service); + } + } + + @ParameterizedTest + @NullSource + @ValueSource(strings = {"true", "false", "TrUe", "FaLsE"}) + void parameterResetPreservesBooleanValuesAndOmission(String value) { + boolean resetAll = Boolean.parseBoolean(value); + DbParameterGroup instanceGroup = new DbParameterGroup(); + instanceGroup.setDbParameterGroupName("custom-group"); + DbClusterParameterGroup clusterGroup = new DbClusterParameterGroup(); + clusterGroup.setDbClusterParameterGroupName("custom-group"); + List names = resetAll ? List.of() : List.of("max_connections"); + when(service.resetDbParameterGroup("custom-group", resetAll, names, "us-west-2")) + .thenReturn(instanceGroup); + when(service.resetDbClusterParameterGroup("custom-group", resetAll, names, "us-west-2")) + .thenReturn(clusterGroup); + for (String nameParameter : List.of("DBParameterGroupName", "DBClusterParameterGroupName")) { + String action = nameParameter.equals("DBParameterGroupName") + ? "ResetDBParameterGroup" : "ResetDBClusterParameterGroup"; + MultivaluedMap p = params(); + p.putSingle(nameParameter, "custom-group"); + if (value != null) { + p.putSingle("ResetAllParameters", value); + } + if (!resetAll) { + p.putSingle("Parameters.Parameter.1.ParameterName", "max_connections"); + } + + Response response = handler.handle(action, p, "us-west-2"); + + assertEquals(200, response.getStatus()); + assertTrue(((String) response.getEntity()).contains("<" + nameParameter + + ">custom-group")); + } + verify(service).resetDbParameterGroup("custom-group", resetAll, names, "us-west-2"); + verify(service).resetDbClusterParameterGroup("custom-group", resetAll, names, "us-west-2"); + } + @ParameterizedTest @CsvSource({ "CreateDBInstance, MultiAZ",