mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 14:30:28 -05:00
feat(ses): paginate the contact, dedicated IP pool, suppressed destination and receipt rule set lists (#4877)
* feat(ses): paginate the contact, dedicated IP pool, suppressed destination and receipt rule set lists Page ListContactLists, ListContacts, ListDedicatedIpPools, GetDedicatedIps, ListSuppressedDestinations and v1 ListReceiptRuleSets with the probed bounds and messages. ListContacts serves 50 by default and receipt rule sets 100, the figure the model documents; the lists whose default could not be measured serve up to 1000. Where SES's own order is not stable Floci keeps the order its unpaged lists already had. A suppressed-destination token is bound to the reason filter and tenant it was taken with, as on SES. * test(ses): isolate the contact paging compat test and cover v1 receipt rule set paging on the wire The contact paging compatibility test cleared every contact list in the account before and after it ran; it now runs as its own account and removes only the list it created. A new integration test pages 101 receipt rule sets through the Query API, where the earlier coverage only reached the service. * docs(ses): note that SES lists receipt rule sets by name Floci pages ListReceiptRuleSets in the creation order its unpaged list already had; the paging paragraph now says SES lists them by name.
This commit is contained in:
1 parent
3e2d310eae
commit
bb3dd2de92
22 files changed
+989
-52
No files matched your search
+82
@@ -0,0 +1,82 @@
|
||||
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.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.Contact;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateContactListRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateContactRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteContactListRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListContactListsRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListContactsRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListContactsResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
|
||||
// Runs as its own account, so the one contact list it needs leaves every other test's list alone.
|
||||
@DisplayName("SES v2 contact and contact list paging")
|
||||
class SesContactPagingTest {
|
||||
|
||||
private static final String ACCOUNT_ID = "777788889999";
|
||||
private static final String LIST = "compat-paging-list";
|
||||
private static final List<String> ADDRESSES =
|
||||
List.of("page-b@example.com", "page-c@example.com", "page-a@example.com");
|
||||
|
||||
private static SesV2Client sesV2;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Uses an emulator account picked by the access key");
|
||||
sesV2 = TestFixtures.sesV2Client(ACCOUNT_ID);
|
||||
deleteList();
|
||||
sesV2.createContactList(CreateContactListRequest.builder().contactListName(LIST).build());
|
||||
for (String address : ADDRESSES) {
|
||||
sesV2.createContact(CreateContactRequest.builder()
|
||||
.contactListName(LIST).emailAddress(address).build());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sesV2 != null) {
|
||||
deleteList();
|
||||
sesV2.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteList() {
|
||||
try {
|
||||
sesV2.deleteContactList(DeleteContactListRequest.builder().contactListName(LIST).build());
|
||||
} catch (Exception ignored) {
|
||||
// Absent on a clean run; a list left by an interrupted run is the only other case.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Paginator walks one-item pages over every contact once")
|
||||
void paginatorWalksEveryContactOnce() {
|
||||
List<String> listed = new ArrayList<>();
|
||||
for (ListContactsResponse page : sesV2.listContactsPaginator(
|
||||
ListContactsRequest.builder().contactListName(LIST).pageSize(1).build())) {
|
||||
assertThat(page.contacts()).hasSizeLessThanOrEqualTo(1);
|
||||
page.contacts().stream().map(Contact::emailAddress).forEach(listed::add);
|
||||
}
|
||||
|
||||
assertThat(listed).containsExactlyInAnyOrderElementsOf(ADDRESSES);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Contact list paginator returns the one list")
|
||||
void contactListPaginatorReturnsTheList() {
|
||||
assertThat(sesV2.listContactListsPaginator(ListContactListsRequest.builder().pageSize(1).build())
|
||||
.stream().flatMap(page -> page.contactLists().stream()).map(cl -> cl.contactListName()))
|
||||
.containsExactly(LIST);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
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.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateDedicatedIpPoolRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteDedicatedIpPoolRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetDedicatedIpsRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListDedicatedIpPoolsRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListDedicatedIpPoolsResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DisplayName("SES v2 dedicated IP pool list paging")
|
||||
class SesDedicatedIpPoolPagingTest {
|
||||
|
||||
private static SesV2Client sesV2;
|
||||
private static List<String> names;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sesV2 = TestFixtures.sesV2Client();
|
||||
String prefix = "sdk-page-" + TestFixtures.uniqueName() + "-";
|
||||
names = List.of(prefix + "b", prefix + "c", prefix + "a");
|
||||
for (String name : names) {
|
||||
sesV2.createDedicatedIpPool(CreateDedicatedIpPoolRequest.builder().poolName(name).build());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sesV2 != null) {
|
||||
for (String name : names) {
|
||||
try {
|
||||
sesV2.deleteDedicatedIpPool(DeleteDedicatedIpPoolRequest.builder().poolName(name).build());
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort cleanup; a leftover pool does not affect other tests.
|
||||
}
|
||||
}
|
||||
sesV2.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Paginator walks one-item pages over every pool once")
|
||||
void paginatorWalksEveryPoolOnce() {
|
||||
List<String> listed = new ArrayList<>();
|
||||
for (ListDedicatedIpPoolsResponse page : sesV2.listDedicatedIpPoolsPaginator(
|
||||
ListDedicatedIpPoolsRequest.builder().pageSize(1).build())) {
|
||||
assertThat(page.dedicatedIpPools()).hasSizeLessThanOrEqualTo(1);
|
||||
listed.addAll(page.dedicatedIpPools());
|
||||
}
|
||||
|
||||
assertThat(listed).doesNotHaveDuplicates();
|
||||
assertThat(listed.stream().filter(names::contains)).containsExactlyInAnyOrderElementsOf(names);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("GetDedicatedIps paginator ends on an empty page")
|
||||
void getDedicatedIpsPaginatorEnds() {
|
||||
assertThat(sesV2.getDedicatedIpsPaginator(GetDedicatedIpsRequest.builder().pageSize(1).build())
|
||||
.stream().flatMap(page -> page.dedicatedIps().stream())).isEmpty();
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
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.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteSuppressedDestinationRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.InvalidNextTokenException;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListSuppressedDestinationsRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.ListSuppressedDestinationsResponse;
|
||||
import software.amazon.awssdk.services.sesv2.model.PutSuppressedDestinationRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.SuppressedDestinationSummary;
|
||||
import software.amazon.awssdk.services.sesv2.model.SuppressionListReason;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
@DisplayName("SES v2 suppression list paging")
|
||||
class SesSuppressionListPagingTest {
|
||||
|
||||
private static SesV2Client sesV2;
|
||||
private static List<String> bounces;
|
||||
private static String complaint;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sesV2 = TestFixtures.sesV2Client();
|
||||
String prefix = "sdk-page-" + TestFixtures.uniqueName() + "-";
|
||||
bounces = List.of(prefix + "b@example.com", prefix + "a@example.com");
|
||||
complaint = prefix + "c@example.com";
|
||||
for (String address : bounces) {
|
||||
put(address, SuppressionListReason.BOUNCE);
|
||||
}
|
||||
put(complaint, SuppressionListReason.COMPLAINT);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sesV2 != null) {
|
||||
List<String> all = new ArrayList<>(bounces);
|
||||
all.add(complaint);
|
||||
for (String address : all) {
|
||||
try {
|
||||
sesV2.deleteSuppressedDestination(DeleteSuppressedDestinationRequest.builder()
|
||||
.emailAddress(address).build());
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort cleanup; a leftover destination does not affect other tests.
|
||||
}
|
||||
}
|
||||
sesV2.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Paginator walks one-item pages of one reason over every destination once")
|
||||
void paginatorWalksEveryFilteredDestinationOnce() {
|
||||
List<String> listed = new ArrayList<>();
|
||||
for (ListSuppressedDestinationsResponse page : sesV2.listSuppressedDestinationsPaginator(
|
||||
ListSuppressedDestinationsRequest.builder()
|
||||
.reasons(SuppressionListReason.BOUNCE).pageSize(1).build())) {
|
||||
assertThat(page.suppressedDestinationSummaries()).hasSizeLessThanOrEqualTo(1);
|
||||
page.suppressedDestinationSummaries().stream()
|
||||
.map(SuppressedDestinationSummary::emailAddress).forEach(listed::add);
|
||||
}
|
||||
|
||||
assertThat(listed).doesNotHaveDuplicates().doesNotContain(complaint);
|
||||
assertThat(listed.stream().filter(bounces::contains)).containsExactlyInAnyOrderElementsOf(bounces);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("A token taken with one reason filter is refused without it")
|
||||
void tokenIsBoundToItsFilter() {
|
||||
ListSuppressedDestinationsResponse first = sesV2.listSuppressedDestinations(
|
||||
ListSuppressedDestinationsRequest.builder()
|
||||
.reasons(SuppressionListReason.BOUNCE).pageSize(1).build());
|
||||
assertThat(first.nextToken()).isNotNull();
|
||||
|
||||
assertThatThrownBy(() -> sesV2.listSuppressedDestinations(
|
||||
ListSuppressedDestinationsRequest.builder().nextToken(first.nextToken()).build()))
|
||||
.isInstanceOf(InvalidNextTokenException.class)
|
||||
.hasMessageContaining("Token is invalid.");
|
||||
}
|
||||
|
||||
private static void put(String address, SuppressionListReason reason) {
|
||||
sesV2.putSuppressedDestination(PutSuppressedDestinationRequest.builder()
|
||||
.emailAddress(address).reason(reason).build());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user