diff --git a/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java b/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java index 1429ae1423..9b90872b76 100644 --- a/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java +++ b/src/main/java/io/floci/aws/services/rds/RdsQueryHandler.java @@ -1763,13 +1763,23 @@ public class RdsQueryHandler { MultivaluedMap params, String region) { String filterName = params.getFirst("DBClusterParameterGroupName"); try { - Collection 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 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()); diff --git a/src/test/java/io/floci/aws/services/rds/RdsDefaultClusterParameterArnIntegrationTest.java b/src/test/java/io/floci/aws/services/rds/RdsDefaultClusterParameterArnIntegrationTest.java index b45274a6bf..874892aff6 100644 --- a/src/test/java/io/floci/aws/services/rds/RdsDefaultClusterParameterArnIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/rds/RdsDefaultClusterParameterArnIntegrationTest.java @@ -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 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; } diff --git a/src/test/java/io/floci/aws/services/rds/RdsQueryHandlerTest.java b/src/test/java/io/floci/aws/services/rds/RdsQueryHandlerTest.java index a5fc0e22ed..743fc9b127 100644 --- a/src/test/java/io/floci/aws/services/rds/RdsQueryHandlerTest.java +++ b/src/test/java/io/floci/aws/services/rds/RdsQueryHandlerTest.java @@ -1540,6 +1540,61 @@ class RdsQueryHandlerTest { String body = (String) response.getEntity(); assertTrue(body.contains(""), "Expected element in response"); assertFalse(body.contains(""), "Did not expect wrapping DBClusterParameterGroup"); + assertFalse(body.contains(""), "Did not expect on terminal page"); + } + + @Test + void describeDbClusterParameterGroups_paginatesAndOmitsTerminalMarker() { + List 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 firstParams = params(); + firstParams.add("MaxRecords", "20"); + Response firstResponse = handler.handle("DescribeDBClusterParameterGroups", firstParams); + assertEquals(200, firstResponse.getStatus()); + String firstBody = (String) firstResponse.getEntity(); + assertTrue(firstBody.contains("cpg-00")); + assertTrue(firstBody.contains("cpg-19")); + assertFalse(firstBody.contains("cpg-20")); + assertTrue(firstBody.contains("20")); + + MultivaluedMap 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("cpg-19")); + assertTrue(secondBody.contains("cpg-20")); + assertTrue(secondBody.contains("cpg-22")); + assertFalse(secondBody.contains("")); + } + + @ParameterizedTest + @ValueSource(strings = {"19", "101", "abc"}) + void describeDbClusterParameterGroups_rejectsInvalidMaxRecords(String maxRecords) { + MultivaluedMap queryParams = params(); + queryParams.add("MaxRecords", maxRecords); + + Response response = handler.handle("DescribeDBClusterParameterGroups", queryParams); + + assertEquals(400, response.getStatus()); + assertTrue(((String) response.getEntity()).contains("InvalidParameterValue")); + } + + @ParameterizedTest + @ValueSource(strings = {"-1", "abc"}) + void describeDbClusterParameterGroups_rejectsInvalidMarker(String marker) { + MultivaluedMap queryParams = params(); + queryParams.add("Marker", marker); + + Response response = handler.handle("DescribeDBClusterParameterGroups", queryParams); + + assertEquals(400, response.getStatus()); + assertTrue(((String) response.getEntity()).contains("InvalidParameterValue")); } @Test