fix(rds): return Source and ApplyMethod from DescribeDBParameters (#7018)

* fix(rds): return Source and ApplyMethod from DescribeDBParameters

DescribeDBParameters and DescribeDBClusterParameters now render Source=user
and the ApplyMethod sent on modify (default immediate). Apply methods are
stored per group, copied on copy, dropped on reset, and absent in older
persisted state.

* test(rds): cover apply-method copy, reset and reload for parameter groups

* test(rds): assert reset clears stored apply methods

* fix(rds): refuse ApplyMethod values outside immediate | pending-reboot

ModifyDBParameterGroup and ModifyDBClusterParameterGroup echoed back any
ApplyMethod string. The RDS model declares the ApplyMethod enum as
immediate | pending-reboot, so any other value (including a different
case) now fails with InvalidParameterValue (400) before the group is
touched. A missing ApplyMethod still defaults to immediate.

The value and apply-method loops shared everything but the member name,
so both now go through one parseParameterMember(params, member) helper.
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-10-30 14:34:34 -04:00
1 parent 06d4fcfa57
commit 2463708199
8 files changed
+286 -27

No files matched your search

@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.rds;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -10,6 +11,7 @@ import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static io.restassured.http.ContentType.URLENC;
import static org.hamcrest.Matchers.containsString;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The RDS model declares the {@code Parameters} list with {@code locationName: Parameter}, so the
@@ -112,6 +114,150 @@ class RdsParameterGroupWireEncodingIntegrationTest {
.body(containsString("<ParameterValue>1</ParameterValue>"));
}
/** The provider skips parameters without Source and hashes ApplyMethod, so both must round-trip. */
private static void assertSourceAndApplyMethod(String describeAction, String nameKey, String group,
String immediateParam, String pendingParam) {
XmlPath xml = query(describeAction).formParam(nameKey, group)
.when().post("/").then().statusCode(200).extract().xmlPath();
for (String[] p : new String[][] {{immediateParam, "immediate"}, {pendingParam, "pending-reboot"}}) {
String find = "**.find { it.ParameterName == '" + p[0] + "' }.";
assertEquals("user", xml.getString(find + "Source"), p[0]);
assertEquals(p[1], xml.getString(find + "ApplyMethod"), p[0]);
}
}
@Test
@Order(3)
void describeDbParametersReturnsSourceAndApplyMethod() {
assertSourceAndApplyMethod("DescribeDBParameters", "DBParameterGroupName", PG,
"max_connections", "work_mem");
}
@Test
@Order(4)
void describeDbClusterParametersReturnsSourceAndApplyMethod() {
query("ModifyDBClusterParameterGroup")
.formParam("DBClusterParameterGroupName", CLUSTER_PG)
.formParam("Parameters.Parameter.1.ParameterName", "shared_preload_libraries")
.formParam("Parameters.Parameter.1.ParameterValue", "pg_stat_statements")
.formParam("Parameters.Parameter.1.ApplyMethod", "pending-reboot")
.when().post("/").then().statusCode(200);
assertSourceAndApplyMethod("DescribeDBClusterParameters", "DBClusterParameterGroupName", CLUSTER_PG,
"rds.force_ssl", "shared_preload_libraries");
}
private static String applyMethodOf(String describeAction, String nameKey, String group, String param) {
return query(describeAction).formParam(nameKey, group)
.when().post("/").then().statusCode(200).extract().xmlPath()
.getString("**.find { it.ParameterName == '" + param + "' }.ApplyMethod");
}
/**
* Copy carries a pending-reboot ApplyMethod to the copy; a selected reset and ResetAllParameters
* each leave no stale method behind, so a re-modify without ApplyMethod reads back immediate.
* Everything is read back through Describe, not the mutating call's own response.
*/
private static void assertApplyMethodLifecycle(String kind, String family, String param, String value) {
String groupKey = "DB" + kind + "ParameterGroupName";
String describe = "DescribeDB" + kind + "Parameters";
String src = "lifecycle-src" + kind.toLowerCase();
String copy = "lifecycle-copy" + kind.toLowerCase();
query("CreateDB" + kind + "ParameterGroup").formParam(groupKey, src)
.formParam("DBParameterGroupFamily", family).formParam("Description", "lifecycle")
.when().post("/").then().statusCode(200);
query("ModifyDB" + kind + "ParameterGroup").formParam(groupKey, src)
.formParam("Parameters.Parameter.1.ParameterName", param)
.formParam("Parameters.Parameter.1.ParameterValue", value)
.formParam("Parameters.Parameter.1.ApplyMethod", "pending-reboot")
.when().post("/").then().statusCode(200);
query("CopyDB" + kind + "ParameterGroup")
.formParam("SourceDB" + kind + "ParameterGroupIdentifier", src)
.formParam("TargetDB" + kind + "ParameterGroupIdentifier", copy)
.formParam("TargetDB" + kind + "ParameterGroupDescription", "lifecycle copy")
.when().post("/").then().statusCode(200);
assertEquals("pending-reboot", applyMethodOf(describe, groupKey, copy, param), "copy");
// Selected reset, then re-modify with no ApplyMethod.
query("ResetDB" + kind + "ParameterGroup").formParam(groupKey, copy)
.formParam("Parameters.Parameter.1.ParameterName", param)
.formParam("Parameters.Parameter.1.ApplyMethod", "pending-reboot")
.when().post("/").then().statusCode(200);
query("ModifyDB" + kind + "ParameterGroup").formParam(groupKey, copy)
.formParam("Parameters.Parameter.1.ParameterName", param)
.formParam("Parameters.Parameter.1.ParameterValue", value)
.when().post("/").then().statusCode(200);
assertEquals("immediate", applyMethodOf(describe, groupKey, copy, param), "after selected reset");
// ResetAllParameters from a pending-reboot state, then re-modify with no ApplyMethod.
query("ModifyDB" + kind + "ParameterGroup").formParam(groupKey, copy)
.formParam("Parameters.Parameter.1.ParameterName", param)
.formParam("Parameters.Parameter.1.ParameterValue", value)
.formParam("Parameters.Parameter.1.ApplyMethod", "pending-reboot")
.when().post("/").then().statusCode(200);
query("ResetDB" + kind + "ParameterGroup").formParam(groupKey, copy)
.formParam("ResetAllParameters", "true")
.when().post("/").then().statusCode(200);
query("ModifyDB" + kind + "ParameterGroup").formParam(groupKey, copy)
.formParam("Parameters.Parameter.1.ParameterName", param)
.formParam("Parameters.Parameter.1.ParameterValue", value)
.when().post("/").then().statusCode(200);
assertEquals("immediate", applyMethodOf(describe, groupKey, copy, param), "after reset all");
for (String g : new String[] {src, copy}) {
query("DeleteDB" + kind + "ParameterGroup").formParam(groupKey, g).when().post("/");
}
}
@Test
@Order(5)
void dbParameterGroupApplyMethodSurvivesCopyAndIsClearedByReset() {
assertApplyMethodLifecycle("", "postgres15", "work_mem", "65536");
}
@Test
@Order(6)
void dbClusterParameterGroupApplyMethodSurvivesCopyAndIsClearedByReset() {
assertApplyMethodLifecycle("Cluster", "aurora-postgresql15", "shared_preload_libraries", "pg_stat_statements");
}
/**
* The RDS model's ApplyMethod enum is {@code immediate | pending-reboot}; anything else, including
* a different case, is refused with InvalidParameterValue and leaves the stored parameter untouched.
*/
private static void assertInvalidApplyMethodRejected(String kind, String group, String prefix,
String param, String storedValue, String storedMethod) {
String groupKey = "DB" + kind + "ParameterGroupName";
String describe = "DescribeDB" + kind + "Parameters";
for (String bad : new String[] {"later", "Immediate", "PENDING-REBOOT", ""}) {
query("ModifyDB" + kind + "ParameterGroup").formParam(groupKey, group)
.formParam(prefix + ".1.ParameterName", param)
.formParam(prefix + ".1.ParameterValue", "999")
.formParam(prefix + ".1.ApplyMethod", bad)
.when().post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
}
XmlPath xml = query(describe).formParam(groupKey, group)
.when().post("/").then().statusCode(200).extract().xmlPath();
String find = "**.find { it.ParameterName == '" + param + "' }.";
assertEquals(storedValue, xml.getString(find + "ParameterValue"), param);
assertEquals(storedMethod, xml.getString(find + "ApplyMethod"), param);
}
@Test
@Order(7)
void modifyDbParameterGroupRejectsUnknownApplyMethod() {
assertInvalidApplyMethodRejected("", PG, "Parameters.Parameter", "work_mem", "65536", "pending-reboot");
}
@Test
@Order(8)
void modifyDbClusterParameterGroupRejectsUnknownApplyMethod() {
assertInvalidApplyMethodRejected("Cluster", CLUSTER_PG, "Parameters.member", "rds.force_ssl", "1", "immediate");
}
@Test
@Order(9)
void cleanUp() {
@@ -907,14 +907,14 @@ class RdsQueryHandlerTest {
when(service.getDbParameterGroup("pg1", "us-west-2"))
.thenReturn(parameterGroup);
when(service.modifyDbParameterGroup(
"pg1", Map.of("max_connections", "200"), "us-west-2"))
"pg1", Map.of("max_connections", "200"), Map.of(), "us-west-2"))
.thenReturn(parameterGroup);
when(service.listDbClusterParameterGroups(null, "us-west-2"))
.thenReturn(List.of(clusterParameterGroup));
when(service.getDbClusterParameterGroup("cpg1", "us-west-2"))
.thenReturn(clusterParameterGroup);
when(service.modifyDbClusterParameterGroup(
"cpg1", Map.of("log_statement", "all"), "us-west-2"))
"cpg1", Map.of("log_statement", "all"), Map.of(), "us-west-2"))
.thenReturn(clusterParameterGroup);
MultivaluedMap<String, String> subnetParams = params();
@@ -947,12 +947,12 @@ class RdsQueryHandlerTest {
verify(service).deleteDbSubnetGroup("custom-group", "us-west-2");
verify(service).listDbParameterGroups(null, "us-west-2");
verify(service).modifyDbParameterGroup(
"pg1", Map.of("max_connections", "200"), "us-west-2");
"pg1", Map.of("max_connections", "200"), Map.of(), "us-west-2");
verify(service).getDbParameterGroup("pg1", "us-west-2");
verify(service).deleteDbParameterGroup("pg1", "us-west-2");
verify(service).listDbClusterParameterGroups(null, "us-west-2");
verify(service).modifyDbClusterParameterGroup(
"cpg1", Map.of("log_statement", "all"), "us-west-2");
"cpg1", Map.of("log_statement", "all"), Map.of(), "us-west-2");
verify(service).getDbClusterParameterGroup("cpg1", "us-west-2");
verify(service).deleteDbClusterParameterGroup("cpg1", "us-west-2");
}
@@ -1385,7 +1385,7 @@ class RdsQueryHandlerTest {
void modifyDbParameterGroup_ignoresParametersWithoutValue() {
DbParameterGroup group = new DbParameterGroup("pg1", "postgres15", "test group");
when(service.modifyDbParameterGroup(
eq("pg1"), eq(Map.of("max_connections", "200")), isNull()))
eq("pg1"), eq(Map.of("max_connections", "200")), eq(Map.of()), isNull()))
.thenReturn(group);
MultivaluedMap<String, String> p = params();
@@ -1396,7 +1396,7 @@ class RdsQueryHandlerTest {
handler.handle("ModifyDBParameterGroup", p);
verify(service).modifyDbParameterGroup(
"pg1", Map.of("max_connections", "200"), null);
"pg1", Map.of("max_connections", "200"), Map.of(), null);
}
@Test
@@ -1469,7 +1469,7 @@ class RdsQueryHandlerTest {
void modifyDbClusterParameterGroup_ignoresParametersWithoutValue() {
DbClusterParameterGroup group = new DbClusterParameterGroup("cpg1", "aurora-postgresql16", "test group");
when(service.modifyDbClusterParameterGroup(
eq("cpg1"), eq(Map.of("log_statement", "all")), isNull()))
eq("cpg1"), eq(Map.of("log_statement", "all")), eq(Map.of()), isNull()))
.thenReturn(group);
MultivaluedMap<String, String> p = params();
@@ -1480,7 +1480,7 @@ class RdsQueryHandlerTest {
handler.handle("ModifyDBClusterParameterGroup", p);
verify(service).modifyDbClusterParameterGroup(
"cpg1", Map.of("log_statement", "all"), null);
"cpg1", Map.of("log_statement", "all"), Map.of(), null);
}
@Test
@@ -4610,6 +4610,26 @@ class RdsServiceTest {
assertEquals(404, exception.getHttpStatus());
}
/** Not observable through Describe (re-modify rewrites the method), so assert the stored map. */
@Test
void resetClearsStoredApplyMethods() {
Map<String, String> params = Map.of("a", "1", "b", "2");
Map<String, String> methods = Map.of("a", "pending-reboot", "b", "pending-reboot");
rdsService.createDbParameterGroup("reset-pg", "mysql8.0", "d");
rdsService.modifyDbParameterGroup("reset-pg", params, methods, "us-east-1");
assertEquals(Set.of("b"), rdsService.resetDbParameterGroup("reset-pg", false, List.of("a"), "us-east-1")
.getApplyMethods().keySet());
assertTrue(rdsService.resetDbParameterGroup("reset-pg", true, List.of(), "us-east-1")
.getApplyMethods().isEmpty());
rdsService.createDbClusterParameterGroup("reset-cpg", "aurora-mysql8.0", "d");
rdsService.modifyDbClusterParameterGroup("reset-cpg", params, methods, "us-east-1");
assertEquals(Set.of("b"), rdsService.resetDbClusterParameterGroup("reset-cpg", false, List.of("a"), "us-east-1")
.getApplyMethods().keySet());
assertTrue(rdsService.resetDbClusterParameterGroup("reset-cpg", true, List.of(), "us-east-1")
.getApplyMethods().isEmpty());
}
@Test
void createDbClusterRejectsIncompatibleClusterParameterGroupFamily() {
rdsService.createDbClusterParameterGroup("cpg1", "aurora-mysql8.0", "test group");
@@ -4694,9 +4714,9 @@ class RdsServiceTest {
rdsService.createDbParameterGroup("regional-pg", "postgres16", "east", "us-east-1");
rdsService.createDbParameterGroup("regional-pg", "postgres16", "west", "us-west-2");
rdsService.modifyDbParameterGroup(
"regional-pg", Map.of("application_name", "east"), "us-east-1");
"regional-pg", Map.of("application_name", "east"), null, "us-east-1");
rdsService.modifyDbParameterGroup(
"regional-pg", Map.of("application_name", "west"), "us-west-2");
"regional-pg", Map.of("application_name", "west"), null, "us-west-2");
assertEquals("east", rdsService.getDbParameterGroup(
"regional-pg", "us-east-1").getParameters().get("application_name"));
@@ -4708,9 +4728,9 @@ class RdsServiceTest {
rdsService.createDbClusterParameterGroup(
"regional-cpg", "aurora-postgresql16", "west", "us-west-2");
rdsService.modifyDbClusterParameterGroup(
"regional-cpg", Map.of("log_statement", "none"), "us-east-1");
"regional-cpg", Map.of("log_statement", "none"), null, "us-east-1");
rdsService.modifyDbClusterParameterGroup(
"regional-cpg", Map.of("log_statement", "all"), "us-west-2");
"regional-cpg", Map.of("log_statement", "all"), null, "us-west-2");
assertEquals("none", rdsService.getDbClusterParameterGroup(
"regional-cpg", "us-east-1").getParameters().get("log_statement"));
@@ -0,0 +1,48 @@
package io.github.hectorvent.floci.services.rds.model;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** A record persisted before apply methods were stored must reload with an empty map, not null. */
class ParameterGroupApplyMethodsPersistenceTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
@Test
void parameterGroupWithoutApplyMethodsReloadsEmpty() throws Exception {
DbParameterGroup g = MAPPER.readValue(
"{\"dbParameterGroupName\":\"g\",\"parameters\":{\"a\":\"1\"}}", DbParameterGroup.class);
assertEquals(Map.of(), g.getApplyMethods());
assertEquals(Map.of(), MAPPER.readValue("{\"applyMethods\":null}", DbParameterGroup.class).getApplyMethods());
}
@Test
void parameterGroupApplyMethodsRoundTrip() throws Exception {
DbParameterGroup g = new DbParameterGroup("g", "postgres15", "d");
g.getApplyMethods().put("work_mem", "pending-reboot");
DbParameterGroup back = MAPPER.readValue(MAPPER.writeValueAsString(g), DbParameterGroup.class);
assertEquals(Map.of("work_mem", "pending-reboot"), back.getApplyMethods());
}
@Test
void clusterParameterGroupWithoutApplyMethodsReloadsEmpty() throws Exception {
DbClusterParameterGroup g = MAPPER.readValue(
"{\"dbClusterParameterGroupName\":\"g\",\"parameters\":{\"a\":\"1\"}}", DbClusterParameterGroup.class);
assertEquals(Map.of(), g.getApplyMethods());
assertEquals(Map.of(),
MAPPER.readValue("{\"applyMethods\":null}", DbClusterParameterGroup.class).getApplyMethods());
}
@Test
void clusterParameterGroupApplyMethodsRoundTrip() throws Exception {
DbClusterParameterGroup g = new DbClusterParameterGroup();
g.getApplyMethods().put("rds.force_ssl", "pending-reboot");
DbClusterParameterGroup back =
MAPPER.readValue(MAPPER.writeValueAsString(g), DbClusterParameterGroup.class);
assertEquals(Map.of("rds.force_ssl", "pending-reboot"), back.getApplyMethods());
}
}