mirror of
https://github.com/floci-io/floci.git
synced 2026-11-29 16:35:29 -05:00
fix(eventbridge): page ListRules with Limit and NextToken (#6223)
ListRules ignored Limit and NextToken and always returned every matching rule. It now pages through the bus's rules in name order using the shared Pagination cursor, keeping NamePrefix and EventBusName filtering intact. - Limit defaults to 100, the documented per-page maximum; an integral value outside 1 to 100, including one wider than an int, is a ValidationException. - A string, boolean or fractional Limit is a SerializationException rather than being coerced into a page size. - NextToken is returned only when more rules remain. - A token Floci did not mint is rejected with HTTP 400 InvalidToken, as the API reference documents for a bad pagination token. Fixes #6220
This commit is contained in:
1 parent
71cc704319
commit
007ac9268e
6 files changed
+330
-3
No files matched your search
@@ -7,6 +7,7 @@ import software.amazon.awssdk.services.eventbridge.model.ResourceNotFoundExcepti
|
||||
import software.amazon.awssdk.services.sqs.SqsClient;
|
||||
import software.amazon.awssdk.services.sqs.model.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -381,6 +382,61 @@ class EventBridgeTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(37)
|
||||
void listRulesPagesWithLimitAndNextToken() {
|
||||
String prefix = TestFixtures.uniqueName("eb-page") + "-";
|
||||
List<String> names = List.of(prefix + "a", prefix + "b", prefix + "c");
|
||||
try {
|
||||
for (String name : names) {
|
||||
eb.putRule(PutRuleRequest.builder()
|
||||
.name(name)
|
||||
.eventBusName(busName)
|
||||
.eventPattern("{\"source\":[\"paging\"]}")
|
||||
.build());
|
||||
}
|
||||
|
||||
List<String> seen = new ArrayList<>();
|
||||
String token = null;
|
||||
do {
|
||||
ListRulesResponse page = eb.listRules(ListRulesRequest.builder()
|
||||
.eventBusName(busName)
|
||||
.namePrefix(prefix)
|
||||
.limit(1)
|
||||
.nextToken(token)
|
||||
.build());
|
||||
assertThat(page.rules()).hasSize(1);
|
||||
seen.add(page.rules().get(0).name());
|
||||
token = page.nextToken();
|
||||
} while (token != null);
|
||||
|
||||
assertThat(seen).containsExactlyElementsOf(names);
|
||||
} finally {
|
||||
for (String name : names) {
|
||||
try {
|
||||
eb.deleteRule(DeleteRuleRequest.builder().name(name).eventBusName(busName).build());
|
||||
} catch (ResourceNotFoundException ignored) {
|
||||
// The rule was never created because an earlier putRule failed; nothing to clean up.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(38)
|
||||
void listRulesRejectsOutOfRangeLimitAndUnknownToken() {
|
||||
assertThatThrownBy(() -> eb.listRules(ListRulesRequest.builder().limit(101).build()))
|
||||
.isInstanceOfSatisfying(EventBridgeException.class, e -> {
|
||||
assertThat(e.statusCode()).isEqualTo(400);
|
||||
assertThat(e.awsErrorDetails().errorCode()).isEqualTo("ValidationException");
|
||||
});
|
||||
assertThatThrownBy(() -> eb.listRules(ListRulesRequest.builder().limit(1).nextToken("not-a-token!").build()))
|
||||
.isInstanceOfSatisfying(EventBridgeException.class, e -> {
|
||||
assertThat(e.statusCode()).isEqualTo(400);
|
||||
assertThat(e.awsErrorDetails().errorCode()).isEqualTo("InvalidToken");
|
||||
});
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user