fix(rds): page DescribeDBClusterParameterGroups with MaxRecords and Marker (#7735)

This commit is contained in:
Koushik Dutta authored and GitHub committed 2026-11-07 09:57:24 -04:00
1 parent 3c66249375
commit 5fe30ee5eb
3 files changed
+101 -4

No files matched your search

@@ -1763,13 +1763,23 @@ public class RdsQueryHandler {
MultivaluedMap<String, String> params, String region) {
String filterName = params.getFirst("DBClusterParameterGroupName");
try {
Collection<DbClusterParameterGroup> result =
service.listDbClusterParameterGroups(filterName, region);
Integer maxRecords = parseOptionalInt(params.getFirst("MaxRecords"));
if (maxRecords != null && (maxRecords < 20 || maxRecords > 100)) {
throw new AwsException("InvalidParameterValue", "MaxRecords must be between 20 and 100.", 400);
}
int offset = parseMarker(params.getFirst("Marker"));
List<DbClusterParameterGroup> all = new ArrayList<>(
service.listDbClusterParameterGroups(filterName, region));
int from = Math.min(offset, all.size());
int to = Math.min(from + (maxRecords != null ? maxRecords : 100), all.size());
XmlBuilder xml = new XmlBuilder().start("DBClusterParameterGroups");
for (DbClusterParameterGroup g : result) {
for (DbClusterParameterGroup g : all.subList(from, to)) {
xml.start("DBClusterParameterGroup").raw(clusterParamGroupInnerXml(g)).end("DBClusterParameterGroup");
}
xml.end("DBClusterParameterGroups").start("Marker").end("Marker");
xml.end("DBClusterParameterGroups");
if (to < all.size()) {
xml.elem("Marker", String.valueOf(to));
}
return Response.ok(AwsQueryResponse.envelope("DescribeDBClusterParameterGroups", AwsNamespaces.RDS, xml.build())).build();
} catch (AwsException e) {
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.RDS, e.getHttpStatus());
@@ -3,15 +3,20 @@ package io.floci.aws.services.rds;
import io.floci.aws.testing.RdsMockProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.DBClusterParameterGroup;
import software.amazon.awssdk.services.rds.model.DescribeDbClusterParameterGroupsResponse;
import software.amazon.awssdk.services.rds.model.RdsException;
import java.util.List;
import static io.floci.aws.testing.RdsRequests.rdsClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@QuarkusTest
@@ -53,6 +58,33 @@ class RdsDefaultClusterParameterArnIntegrationTest {
}
}
@Test
void describeDbClusterParameterGroupsPagesWithMaxRecordsAndMarkerAndValidatesBounds() {
try (RdsClient client = rdsClient("us-east-1", "111111111111")) {
DescribeDbClusterParameterGroupsResponse unpaged = client.describeDBClusterParameterGroups();
List<DBClusterParameterGroup> all = unpaged.dbClusterParameterGroups();
assertTrue(all.size() > 20);
assertNull(unpaged.marker());
DescribeDbClusterParameterGroupsResponse firstPage = client.describeDBClusterParameterGroups(
request -> request.maxRecords(20));
assertEquals(all.subList(0, 20), firstPage.dbClusterParameterGroups());
assertEquals("20", firstPage.marker());
DescribeDbClusterParameterGroupsResponse secondPage = client.describeDBClusterParameterGroups(
request -> request.maxRecords(20).marker(firstPage.marker()));
assertEquals(all.subList(20, all.size()), secondPage.dbClusterParameterGroups());
assertNull(secondPage.marker());
for (int invalid : List.of(19, 101)) {
RdsException exception = assertThrows(RdsException.class, () ->
client.describeDBClusterParameterGroups(request -> request.maxRecords(invalid)));
assertEquals(400, exception.statusCode());
assertEquals("InvalidParameterValue", exception.awsErrorDetails().errorCode());
}
}
}
private static String arn(String partition, String region, String account, String name) {
return "arn:" + partition + ":rds:" + region + ":" + account + ":cluster-pg:" + name;
}
@@ -1540,6 +1540,61 @@ class RdsQueryHandlerTest {
String body = (String) response.getEntity();
assertTrue(body.contains("<DBClusterParameterGroup>"), "Expected <DBClusterParameterGroup> element in response");
assertFalse(body.contains("<member><DBClusterParameterGroupName>"), "Did not expect <member> wrapping DBClusterParameterGroup");
assertFalse(body.contains("<Marker>"), "Did not expect <Marker> on terminal page");
}
@Test
void describeDbClusterParameterGroups_paginatesAndOmitsTerminalMarker() {
List<DbClusterParameterGroup> all = new ArrayList<>();
for (int i = 0; i < 23; i++) {
all.add(new DbClusterParameterGroup(String.format("cpg-%02d", i), "aurora-postgresql16", "desc"));
}
when(service.listDbClusterParameterGroups(null, null)).thenReturn(all);
MultivaluedMap<String, String> firstParams = params();
firstParams.add("MaxRecords", "20");
Response firstResponse = handler.handle("DescribeDBClusterParameterGroups", firstParams);
assertEquals(200, firstResponse.getStatus());
String firstBody = (String) firstResponse.getEntity();
assertTrue(firstBody.contains("<DBClusterParameterGroupName>cpg-00</DBClusterParameterGroupName>"));
assertTrue(firstBody.contains("<DBClusterParameterGroupName>cpg-19</DBClusterParameterGroupName>"));
assertFalse(firstBody.contains("<DBClusterParameterGroupName>cpg-20</DBClusterParameterGroupName>"));
assertTrue(firstBody.contains("<Marker>20</Marker>"));
MultivaluedMap<String, String> secondParams = params();
secondParams.add("MaxRecords", "20");
secondParams.add("Marker", "20");
Response secondResponse = handler.handle("DescribeDBClusterParameterGroups", secondParams);
assertEquals(200, secondResponse.getStatus());
String secondBody = (String) secondResponse.getEntity();
assertFalse(secondBody.contains("<DBClusterParameterGroupName>cpg-19</DBClusterParameterGroupName>"));
assertTrue(secondBody.contains("<DBClusterParameterGroupName>cpg-20</DBClusterParameterGroupName>"));
assertTrue(secondBody.contains("<DBClusterParameterGroupName>cpg-22</DBClusterParameterGroupName>"));
assertFalse(secondBody.contains("<Marker>"));
}
@ParameterizedTest
@ValueSource(strings = {"19", "101", "abc"})
void describeDbClusterParameterGroups_rejectsInvalidMaxRecords(String maxRecords) {
MultivaluedMap<String, String> queryParams = params();
queryParams.add("MaxRecords", maxRecords);
Response response = handler.handle("DescribeDBClusterParameterGroups", queryParams);
assertEquals(400, response.getStatus());
assertTrue(((String) response.getEntity()).contains("<Code>InvalidParameterValue</Code>"));
}
@ParameterizedTest
@ValueSource(strings = {"-1", "abc"})
void describeDbClusterParameterGroups_rejectsInvalidMarker(String marker) {
MultivaluedMap<String, String> queryParams = params();
queryParams.add("Marker", marker);
Response response = handler.handle("DescribeDBClusterParameterGroups", queryParams);
assertEquals(400, response.getStatus());
assertTrue(((String) response.getEntity()).contains("<Code>InvalidParameterValue</Code>"));
}
@Test