feat(ses): paginate the identity, configuration set and custom verification template lists (#4781)

* feat(ses): paginate the identity, configuration set and custom verification template lists

Move paging into the SES services, so each resource's cursor lives with its
list and the v1 and v2 operations of the same resource share it. Page
ListIdentities/ListEmailIdentities, ListConfigurationSets (v1 and v2) and
ListCustomVerificationEmailTemplates (v1 and v2) with the probed defaults,
bounds and messages: identities default to 25 on v2, configuration sets and
custom verification templates to 50, and a v1 page size outside the bound is
served the probed size instead of refused.

* fix(ses): refuse a list token replayed in another region

A list token carried only the resource kind and the cursor, so the same list
in another region read it as a position and could answer an empty last page.
Real SES refuses such a token with the operation's unreadable-token error
(probed on the identity and configuration-set lists), so the token namespace
now includes the region. The v1 and v2 lists of one resource still share
tokens within a region.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-30 23:29:35 -05:00
1 parent 275d874fed
commit ea41b775aa
26 files changed
+1099 -85

No files matched your search

@@ -0,0 +1,105 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.ses.model.ConfigurationSet;
import software.amazon.awssdk.services.ses.model.ListConfigurationSetsRequest;
import software.amazon.awssdk.services.ses.model.ListConfigurationSetsResponse;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetRequest;
import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetRequest;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
// The v1 and v2 SDKs both define ListConfigurationSetsRequest/Response: v1's are imported, v2's qualified.
@DisplayName("SES configuration set list paging")
class SesConfigurationSetPagingTest {
private static SesClient sesV1;
private static SesV2Client sesV2;
private static List<String> names;
@BeforeAll
static void setup() {
sesV1 = TestFixtures.sesClient();
sesV2 = TestFixtures.sesV2Client();
String prefix = "sdk-page-" + TestFixtures.uniqueName() + "-";
names = List.of(prefix + "b", prefix + "c", prefix + "a");
for (String name : names) {
sesV2.createConfigurationSet(CreateConfigurationSetRequest.builder()
.configurationSetName(name).build());
}
}
@AfterAll
static void cleanup() {
if (sesV2 != null) {
for (String name : names) {
try {
sesV2.deleteConfigurationSet(DeleteConfigurationSetRequest.builder()
.configurationSetName(name).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover configuration set does not affect other tests.
}
}
sesV2.close();
}
if (sesV1 != null) {
sesV1.close();
}
}
@Test
@DisplayName("V2 paginator walks one-item pages over every configuration set once")
void v2PaginatorWalksEveryConfigurationSetOnce() {
List<String> listed = new ArrayList<>();
for (software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsResponse page
: sesV2.listConfigurationSetsPaginator(
software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsRequest.builder()
.pageSize(1).build())) {
assertThat(page.configurationSets()).hasSizeLessThanOrEqualTo(1);
listed.addAll(page.configurationSets());
}
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("V1 MaxItems pages over every configuration set once and ends without a token")
void v1PagesOverEveryConfigurationSetOnce() {
List<String> listed = new ArrayList<>();
String token = null;
do {
ListConfigurationSetsResponse page = sesV1.listConfigurationSets(ListConfigurationSetsRequest.builder()
.maxItems(1).nextToken(token).build());
assertThat(page.configurationSets()).hasSizeLessThanOrEqualTo(1);
page.configurationSets().stream().map(ConfigurationSet::name).forEach(listed::add);
token = page.nextToken();
} while (token != null);
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("A V1 token continues the V2 list")
void v1TokenContinuesTheV2List() {
ListConfigurationSetsResponse first = sesV1.listConfigurationSets(ListConfigurationSetsRequest.builder()
.maxItems(1).build());
assertThat(first.nextToken()).isNotNull();
software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsResponse rest =
sesV2.listConfigurationSets(software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsRequest
.builder().nextToken(first.nextToken()).build());
assertThat(rest.configurationSets()).doesNotContain(first.configurationSets().get(0).name());
}
}
@@ -108,7 +108,8 @@ class SesConfigurationSetTest {
@Order(4)
void v2ListConfigurationSetsIncludesCreated() {
software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsResponse response =
sesV2.listConfigurationSets(software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsRequest.builder().build());
sesV2.listConfigurationSets(software.amazon.awssdk.services.sesv2.model.ListConfigurationSetsRequest.builder()
.pageSize(1000).build());
assertThat(response.configurationSets()).contains(v2Name);
}
@@ -169,7 +170,7 @@ class SesConfigurationSetTest {
@Order(13)
void v1ListConfigurationSetsIncludesCreated() {
ListConfigurationSetsResponse response = sesV1.listConfigurationSets(
ListConfigurationSetsRequest.builder().build());
ListConfigurationSetsRequest.builder().maxItems(1000).build());
assertThat(response.configurationSets())
.anyMatch(cs -> v1Name.equals(cs.name()));
}
@@ -0,0 +1,116 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.ses.model.CustomVerificationEmailTemplate;
import software.amazon.awssdk.services.ses.model.ListCustomVerificationEmailTemplatesRequest;
import software.amazon.awssdk.services.ses.model.ListCustomVerificationEmailTemplatesResponse;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
import software.amazon.awssdk.services.sesv2.model.CustomVerificationEmailTemplateMetadata;
import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
// The v1 and v2 SDKs both define ListCustomVerificationEmailTemplatesResponse: v1's is imported, v2's qualified.
@DisplayName("SES custom verification email template list paging")
class SesCustomVerificationEmailTemplatePagingTest {
private static SesClient sesV1;
private static SesV2Client sesV2;
private static String from;
private static List<String> names;
@BeforeAll
static void setup() {
sesV1 = TestFixtures.sesClient();
sesV2 = TestFixtures.sesV2Client();
String prefix = "sdk-page-" + TestFixtures.uniqueName() + "-";
from = prefix + "sender@floci-cvet.test";
names = List.of(prefix + "b", prefix + "c", prefix + "a");
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(from).build());
for (String name : names) {
sesV2.createCustomVerificationEmailTemplate(b -> b
.templateName(name).fromEmailAddress(from).templateSubject("Verify")
.templateContent("<html><body>verify</body></html>")
.successRedirectionURL("https://example.com/ok")
.failureRedirectionURL("https://example.com/fail"));
}
}
@AfterAll
static void cleanup() {
if (sesV2 != null) {
for (String name : names) {
try {
sesV2.deleteCustomVerificationEmailTemplate(b -> b.templateName(name));
} catch (Exception ignored) {
// Best-effort cleanup; a leftover template does not affect other tests.
}
}
try {
sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(from).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover identity does not affect other tests.
}
sesV2.close();
}
if (sesV1 != null) {
sesV1.close();
}
}
@Test
@DisplayName("V2 paginator walks one-item pages over every template once")
void v2PaginatorWalksEveryTemplateOnce() {
List<String> listed = new ArrayList<>();
for (software.amazon.awssdk.services.sesv2.model.ListCustomVerificationEmailTemplatesResponse page
: sesV2.listCustomVerificationEmailTemplatesPaginator(b -> b.pageSize(1))) {
assertThat(page.customVerificationEmailTemplates()).hasSizeLessThanOrEqualTo(1);
page.customVerificationEmailTemplates().stream()
.map(CustomVerificationEmailTemplateMetadata::templateName).forEach(listed::add);
}
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("V1 MaxResults pages over every template once and ends without a token")
void v1PagesOverEveryTemplateOnce() {
List<String> listed = new ArrayList<>();
String token = null;
do {
ListCustomVerificationEmailTemplatesResponse page = sesV1.listCustomVerificationEmailTemplates(
ListCustomVerificationEmailTemplatesRequest.builder().maxResults(1).nextToken(token).build());
assertThat(page.customVerificationEmailTemplates()).hasSizeLessThanOrEqualTo(1);
page.customVerificationEmailTemplates().stream()
.map(CustomVerificationEmailTemplate::templateName).forEach(listed::add);
token = page.nextToken();
} while (token != null);
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("A V1 token continues the V2 list")
void v1TokenContinuesTheV2List() {
ListCustomVerificationEmailTemplatesResponse first = sesV1.listCustomVerificationEmailTemplates(
ListCustomVerificationEmailTemplatesRequest.builder().maxResults(1).build());
assertThat(first.nextToken()).isNotNull();
List<String> rest = sesV2.listCustomVerificationEmailTemplates(b -> b.nextToken(first.nextToken()))
.customVerificationEmailTemplates().stream()
.map(CustomVerificationEmailTemplateMetadata::templateName).toList();
assertThat(rest).doesNotContain(first.customVerificationEmailTemplates().get(0).templateName());
}
}
@@ -222,8 +222,9 @@ class SesIdentityAttributesTest {
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(email).build());
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(domain).build());
try {
// Other classes share this Floci, so ask for a page large enough to hold every identity.
List<IdentityInfo> identities = sesV2.listEmailIdentities(
ListEmailIdentitiesRequest.builder().build()).emailIdentities();
ListEmailIdentitiesRequest.builder().pageSize(1000).build()).emailIdentities();
IdentityInfo emailIdentity = identities.stream()
.filter(i -> email.equals(i.identityName())).findFirst().orElseThrow();
IdentityInfo domainIdentity = identities.stream()
@@ -0,0 +1,102 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.services.ses.SesClient;
import software.amazon.awssdk.services.ses.model.ListIdentitiesRequest;
import software.amazon.awssdk.services.ses.model.ListIdentitiesResponse;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;
import software.amazon.awssdk.services.sesv2.model.IdentityInfo;
import software.amazon.awssdk.services.sesv2.model.ListEmailIdentitiesRequest;
import software.amazon.awssdk.services.sesv2.model.ListEmailIdentitiesResponse;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayName("SES identity list paging")
class SesIdentityPagingTest {
private static SesClient sesV1;
private static SesV2Client sesV2;
private static List<String> names;
@BeforeAll
static void setup() {
sesV1 = TestFixtures.sesClient();
sesV2 = TestFixtures.sesV2Client();
String prefix = "sdk-page-" + TestFixtures.uniqueName() + "-";
names = List.of(prefix + "b.test", prefix + "c.test", prefix + "a.test");
for (String name : names) {
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(name).build());
}
}
@AfterAll
static void cleanup() {
if (sesV2 != null) {
for (String name : names) {
try {
sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(name).build());
} catch (Exception ignored) {
// Best-effort cleanup; a leftover identity does not affect other tests.
}
}
sesV2.close();
}
if (sesV1 != null) {
sesV1.close();
}
}
@Test
@DisplayName("V2 paginator walks small pages over every identity once")
void v2PaginatorWalksEveryIdentityOnce() {
List<String> listed = new ArrayList<>();
for (ListEmailIdentitiesResponse page : sesV2.listEmailIdentitiesPaginator(
ListEmailIdentitiesRequest.builder().pageSize(5).build())) {
assertThat(page.emailIdentities()).hasSizeLessThanOrEqualTo(5);
page.emailIdentities().forEach(identity -> listed.add(identity.identityName()));
}
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("V1 MaxItems pages over every identity once and ends without a token")
void v1PagesOverEveryIdentityOnce() {
List<String> listed = new ArrayList<>();
String token = null;
do {
ListIdentitiesResponse page = sesV1.listIdentities(ListIdentitiesRequest.builder()
.maxItems(5).nextToken(token).build());
assertThat(page.identities()).hasSizeLessThanOrEqualTo(5);
listed.addAll(page.identities());
token = page.nextToken();
} while (token != null);
assertThat(listed).doesNotHaveDuplicates();
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
}
@Test
@DisplayName("A V1 token continues the V2 list")
void v1TokenContinuesTheV2List() {
ListIdentitiesResponse first = sesV1.listIdentities(ListIdentitiesRequest.builder()
.maxItems(1).build());
assertThat(first.nextToken()).isNotNull();
ListEmailIdentitiesResponse rest = sesV2.listEmailIdentities(ListEmailIdentitiesRequest.builder()
.nextToken(first.nextToken()).build());
assertThat(rest.emailIdentities()).extracting(IdentityInfo::identityName)
.doesNotContain(first.identities().get(0));
}
}