fix(scheduler): honor MaxResults and NextToken in ListScheduleGroups and ListSchedules (#7187)

Both list operations now page through the shared Pagination helper, return NextToken only while items remain, and answer an out-of-range MaxResults or a foreign or malformed NextToken with ValidationException. NamePrefix, State and ScheduleGroup filtering apply before paging.

Fixes #6720

Let the namespaced Pagination overload take the reject-empty-token flag that
paginateUnencoded already uses, and drop SchedulerService.requireNonEmptyToken.
Explain why the compatibility test's best-effort cleanup ignores failures.
This commit is contained in:
Daniël van Ziel authored and GitHub committed 2026-11-09 01:53:04 -04:00
1 parent b93afa9e89
commit 4e5c60cd58
8 files changed
+340 -11

No files matched your search

@@ -219,6 +219,22 @@ class PaginationTest {
assertThat(bounded(1, "").items(), contains("a"));
}
@Test
void boundedNamespacedPaging_refusesEmptyAndLongTokensWhenTokenMustBeNonEmpty() {
String longToken = Base64.getUrlEncoder().withoutPadding()
.encodeToString(("ns:" + "a".repeat(100)).getBytes(StandardCharsets.UTF_8));
AwsException empty = assertInvalid(() -> Pagination.paginate(ITEMS, Function.identity(), 1, "",
2, 3, 32, "InvalidInput", "ns", true));
assertEquals("Pagination token must be between 1 and 32 characters.", empty.getMessage());
AwsException tooLong = assertInvalid(() -> Pagination.paginate(ITEMS, Function.identity(), 1, longToken,
2, 3, 32, "InvalidInput", "ns", true));
assertEquals("Pagination token must not exceed 32 characters.", tooLong.getMessage());
PaginatedResult<String> first = Pagination.paginate(ITEMS, Function.identity(), 1, null,
2, 3, 32, "InvalidInput", "ns", true);
assertThat(Pagination.paginate(ITEMS, Function.identity(), 1, first.nextToken(),
2, 3, 32, "InvalidInput", "ns", true).items(), contains("b"));
}
@Test
void boundedNamespacedPaging_refusesMalformedAndForeignTokens() {
assertInvalid(() -> bounded(1, "!!!"));
@@ -1195,4 +1195,77 @@ class SchedulerIntegrationTest {
.body("__type", containsString("SerializationException"));
}
}
@Test
@Order(45)
void listScheduleGroupsPagesWithMaxResultsAndNextToken() {
for (String name : List.of("paging-group-a", "paging-group-b")) {
given().contentType("application/json").body("{}")
.when().post("/schedule-groups/" + name)
.then().statusCode(200);
}
String token = given().queryParam("NamePrefix", "paging-group-").queryParam("MaxResults", 1)
.when().get("/schedule-groups")
.then().statusCode(200)
.body("ScheduleGroups.Name", contains("paging-group-a"))
.body("NextToken", notNullValue())
.extract().path("NextToken");
given().queryParam("NamePrefix", "paging-group-").queryParam("MaxResults", 1)
.queryParam("NextToken", token)
.when().get("/schedule-groups")
.then().statusCode(200)
.body("ScheduleGroups.Name", contains("paging-group-b"))
.body("$", not(hasKey("NextToken")));
}
@Test
@Order(46)
void listSchedulesPagesWithMaxResultsAndNextToken() {
String body = """
{"ScheduleExpression":"rate(1 hour)","FlexibleTimeWindow":{"Mode":"OFF"},
"GroupName":"paging-group-a",
"Target":{"Arn":"arn:aws:sqs:us-east-1:000000000000:queue",
"RoleArn":"arn:aws:iam::000000000000:role/scheduler-role"}}
""";
for (String name : List.of("paging-1", "paging-2")) {
given().contentType("application/json").body(body)
.when().post("/schedules/" + name)
.then().statusCode(200);
}
String token = given().queryParam("ScheduleGroup", "paging-group-a").queryParam("MaxResults", 1)
.when().get("/schedules")
.then().statusCode(200)
.body("Schedules.Name", contains("paging-1"))
.body("NextToken", notNullValue())
.extract().path("NextToken");
given().queryParam("ScheduleGroup", "paging-group-a").queryParam("MaxResults", 1)
.queryParam("NextToken", token)
.when().get("/schedules")
.then().statusCode(200)
.body("Schedules.Name", contains("paging-2"))
.body("$", not(hasKey("NextToken")));
}
@Test
@Order(47)
void listOperationsRejectInvalidMaxResultsAndNextToken() {
for (String path : List.of("/schedule-groups", "/schedules")) {
for (String maxResults : List.of("0", "101", "abc")) {
given().queryParam("MaxResults", maxResults)
.when().get(path)
.then().statusCode(400)
.body("__type", containsString("ValidationException"));
}
for (String nextToken : List.of("bogus-token", "")) {
given().queryParam("NextToken", nextToken)
.when().get(path)
.then().statusCode(400)
.body("__type", containsString("ValidationException"));
}
}
}
}
@@ -1,6 +1,7 @@
package io.floci.aws.services.scheduler;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.services.scheduler.model.DeadLetterConfig;
@@ -726,6 +727,112 @@ class SchedulerServiceTest {
assertEquals("disabled-1", result.get(0).getName());
}
@Test
void listScheduleGroupsPagesWithNextToken() {
service.createScheduleGroup("page-a", null, REGION);
service.createScheduleGroup("page-b", null, REGION);
PaginatedResult<ScheduleGroup> first = service.listScheduleGroups("page-", 1, null, REGION);
assertEquals(List.of("page-a"), first.items().stream().map(ScheduleGroup::getName).toList());
assertNotNull(first.nextToken());
PaginatedResult<ScheduleGroup> second = service.listScheduleGroups("page-", 1, first.nextToken(), REGION);
assertEquals(List.of("page-b"), second.items().stream().map(ScheduleGroup::getName).toList());
assertNull(second.nextToken());
}
@Test
void listSchedulesPagesWithinGroupAndState() {
service.createScheduleGroup("paged", null, REGION);
for (String name : List.of("p-1", "p-2", "p-3")) {
ScheduleRequest req = newRequest(name, "paged", "rate(1 hour)",
new FlexibleTimeWindow("OFF", null),
new Target("arn:t", "arn:aws:iam::000000000000:role/r", null, null));
req.setState("p-2".equals(name) ? "DISABLED" : "ENABLED");
service.createSchedule(req, REGION);
}
PaginatedResult<Schedule> first = service.listSchedules("paged", "p-", "ENABLED", 1, null, REGION);
assertEquals(List.of("p-1"), first.items().stream().map(Schedule::getName).toList());
assertNotNull(first.nextToken());
PaginatedResult<Schedule> second = service.listSchedules("paged", "p-", "ENABLED", 1,
first.nextToken(), REGION);
assertEquals(List.of("p-3"), second.items().stream().map(Schedule::getName).toList());
assertNull(second.nextToken());
}
@Test
void listSchedulesPagesAcrossGroups() {
service.createScheduleGroup("g-a", null, REGION);
service.createScheduleGroup("g-b", null, REGION);
for (String group : List.of("g-a", "g-b")) {
service.createSchedule(newRequest("same", group, "rate(1 hour)",
new FlexibleTimeWindow("OFF", null),
new Target("arn:t", "arn:aws:iam::000000000000:role/r", null, null)), REGION);
}
PaginatedResult<Schedule> first = service.listSchedules(null, null, null, 1, null, REGION);
PaginatedResult<Schedule> second = service.listSchedules(null, null, null, 1, first.nextToken(), REGION);
assertEquals("g-a", first.items().get(0).getGroupName());
assertEquals("g-b", second.items().get(0).getGroupName());
assertNull(second.nextToken());
}
@Test
void listOperationsRejectOutOfRangeMaxResults() {
for (Integer maxResults : List.of(0, 101)) {
AwsException groups = assertThrows(AwsException.class, () ->
service.listScheduleGroups(null, maxResults, null, REGION));
assertEquals("ValidationException", groups.getErrorCode());
assertEquals(400, groups.getHttpStatus());
AwsException schedules = assertThrows(AwsException.class, () ->
service.listSchedules(null, null, null, maxResults, null, REGION));
assertEquals("ValidationException", schedules.getErrorCode());
}
}
@Test
void listOperationsRejectForeignOrBogusNextToken() {
service.createScheduleGroup("tok-a", null, REGION);
service.createScheduleGroup("tok-b", null, REGION);
String groupToken = service.listScheduleGroups(null, 1, null, REGION).nextToken();
AwsException bogus = assertThrows(AwsException.class, () ->
service.listScheduleGroups(null, 1, "not-a-token", REGION));
assertEquals("ValidationException", bogus.getErrorCode());
assertEquals(400, bogus.getHttpStatus());
AwsException foreign = assertThrows(AwsException.class, () ->
service.listSchedules(null, null, null, 1, groupToken, REGION));
assertEquals("ValidationException", foreign.getErrorCode());
AwsException emptyGroups = assertThrows(AwsException.class, () ->
service.listScheduleGroups(null, 1, "", REGION));
assertEquals("ValidationException", emptyGroups.getErrorCode());
assertEquals(400, emptyGroups.getHttpStatus());
assertEquals("Pagination token must be between 1 and 2048 characters.", emptyGroups.getMessage());
AwsException emptySchedules = assertThrows(AwsException.class, () ->
service.listSchedules(null, null, null, 1, "", REGION));
assertEquals("ValidationException", emptySchedules.getErrorCode());
assertEquals(400, emptySchedules.getHttpStatus());
assertEquals("Pagination token must be between 1 and 2048 characters.", emptySchedules.getMessage());
}
@Test
void listOperationsRejectOverLengthNextToken() {
String overLength = "x".repeat(2049);
AwsException groups = assertThrows(AwsException.class, () ->
service.listScheduleGroups(null, 1, overLength, REGION));
assertEquals("ValidationException", groups.getErrorCode());
assertEquals(400, groups.getHttpStatus());
assertEquals("Pagination token must not exceed 2048 characters.", groups.getMessage());
AwsException schedules = assertThrows(AwsException.class, () ->
service.listSchedules(null, null, null, 1, overLength, REGION));
assertEquals("ValidationException", schedules.getErrorCode());
assertEquals(400, schedules.getHttpStatus());
assertEquals("Pagination token must not exceed 2048 characters.", schedules.getMessage());
}
@Test
void createScheduleWithDeadLetterConfig() {
Target target = new Target("arn:aws:lambda:us-east-1:000000000000:function:my-func",