mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -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
+136
@@ -0,0 +1,136 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of {@code ListContactLists} and {@code ListContacts}. Runs in its own region so the one
|
||||
* contact list a region may hold is the list created here.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesContactPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-2/ses/aws4_request";
|
||||
private static final String OTHER_REGION_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
|
||||
private static final String LIST = "page-list";
|
||||
private static final String CONTACTS = "/v2/email/contact-lists/" + LIST + "/contacts";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createAListAndContactsOutOfAddressOrder() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"ContactListName\":\"" + LIST + "\"}")
|
||||
.when().post("/v2/email/contact-lists").then().statusCode(200);
|
||||
for (String name : new String[] {"page-b", "page-c", "page-a"}) {
|
||||
create(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void contacts_walkByAddressAndEndOnANullToken() {
|
||||
String token = list("{\"PageSize\":1}").statusCode(200)
|
||||
.body("Contacts.EmailAddress", contains("page-a@example.com"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
list("{\"PageSize\":2,\"NextToken\":\"" + token + "\"}").statusCode(200)
|
||||
.body("Contacts.EmailAddress", contains("page-b@example.com", "page-c@example.com"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void contacts_outOfRangeSizesAndUnreadableTokensAreRefused() {
|
||||
for (int size : new int[] {0, 1001}) {
|
||||
list("{\"PageSize\":" + size + "}").statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
}
|
||||
for (String token : new String[] {"garbage", ""}) {
|
||||
list("{\"NextToken\":\"" + token + "\"}").statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Provided NextToken is invalid"));
|
||||
}
|
||||
list("{\"PageSize\":0,\"NextToken\":\"garbage\"}").statusCode(400)
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void contacts_aTokenIsReadBeforeTheListIsLookedUp() {
|
||||
String token = list("{\"PageSize\":1}").statusCode(200).extract().path("NextToken");
|
||||
|
||||
given().contentType("application/json").header("Authorization", OTHER_REGION_AUTH)
|
||||
.body("{\"NextToken\":\"" + token + "\"}")
|
||||
.when().post(CONTACTS + "/list").then().statusCode(400)
|
||||
.body("message", equalTo("Provided NextToken is invalid"));
|
||||
given().contentType("application/json").header("Authorization", OTHER_REGION_AUTH).body("{}")
|
||||
.when().post(CONTACTS + "/list").then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void contactLists_pageAndRefuseAContactsToken() {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/contact-lists").then().statusCode(200)
|
||||
.body("ContactLists.ContactListName", contains(LIST))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 1001)
|
||||
.when().get("/v2/email/contact-lists").then().statusCode(400)
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
String contactsToken = list("{\"PageSize\":1}").statusCode(200).extract().path("NextToken");
|
||||
for (String token : new String[] {"garbage", "", contactsToken}) {
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", token)
|
||||
.when().get("/v2/email/contact-lists").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Provided NextToken is invalid"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void contacts_withoutAPageSizeServeFifty() {
|
||||
for (int i = 0; i < 48; i++) {
|
||||
create("more-%02d".formatted(i));
|
||||
}
|
||||
|
||||
String token = list("{}").statusCode(200)
|
||||
.body("Contacts", hasSize(50))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
list("{\"NextToken\":\"" + token + "\"}").statusCode(200)
|
||||
.body("Contacts.EmailAddress", contains("page-c@example.com"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
private static void create(String name) {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + name + "@example.com\"}")
|
||||
.when().post(CONTACTS).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static ValidatableResponse list(String body) {
|
||||
return given().contentType("application/json").header("Authorization", AUTH).body(body)
|
||||
.when().post(CONTACTS + "/list").then();
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of {@code ListDedicatedIpPools} and {@code GetDedicatedIps}. Runs in its own region so
|
||||
* the pools created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesDedicatedIpPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-3/ses/aws4_request";
|
||||
private static final String OTHER_REGION_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
|
||||
private static final String POOLS = "/v2/email/dedicated-ip-pools";
|
||||
private static final String IPS = "/v2/email/dedicated-ips";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createPoolsOutOfNameOrder() {
|
||||
for (String name : new String[] {"page-b", "page-c", "page-a"}) {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"PoolName\": \"" + name + "\"}")
|
||||
.when().post(POOLS).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void pools_walkByNameAndEndOnANullToken() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get(POOLS).then().statusCode(200)
|
||||
.body("DedicatedIpPools", contains("page-a"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 2).queryParam("NextToken", token)
|
||||
.when().get(POOLS).then().statusCode(200)
|
||||
.body("DedicatedIpPools", contains("page-b", "page-c"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void pools_outOfRangeSizesAndUnreadableTokensAreRefused() {
|
||||
for (int size : new int[] {0, 1001}) {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", size)
|
||||
.when().get(POOLS).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The page size must be in [1, 1000] range."));
|
||||
}
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", "garbage")
|
||||
.when().get(POOLS).then().statusCode(400)
|
||||
.body("message", equalTo("Invalid next token."));
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", "")
|
||||
.when().get(POOLS).then().statusCode(200)
|
||||
.body("DedicatedIpPools", contains("page-a", "page-b", "page-c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void aPoolTokenIsRefusedInAnotherRegionAndByTheIpList() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get(POOLS).then().statusCode(200).extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", OTHER_REGION_AUTH).queryParam("NextToken", token)
|
||||
.when().get(POOLS).then().statusCode(400)
|
||||
.body("message", equalTo("Invalid next token."));
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", token)
|
||||
.when().get(IPS).then().statusCode(400)
|
||||
.body("message", equalTo("Invalid next token."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void dedicatedIps_areEmptyButStillCheckThePageSize() {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get(IPS).then().statusCode(200)
|
||||
.body("DedicatedIps", empty())
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 1001)
|
||||
.when().get(IPS).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The page size must be in [1, 1000] range."));
|
||||
}
|
||||
}
|
||||
@@ -133,6 +133,27 @@ class SesListPagingTest {
|
||||
assertThat(page(SesListPaging.V1_LIST_IDENTITIES, 1, token).items(), contains("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTokenFromAnotherScope_isRefusedAsUnreadable() {
|
||||
SesListPaging paging = SesListPaging.V2_LIST_SUPPRESSED_DESTINATIONS;
|
||||
String token = paging.page(REGION, "BOUNCE", ITEMS, Function.identity(), 1, null).nextToken();
|
||||
|
||||
assertThat(paging.page(REGION, "BOUNCE", ITEMS, Function.identity(), 1, token).items(), contains("b"));
|
||||
assertError("InvalidNextTokenException", "Token is invalid.",
|
||||
() -> paging.page(REGION, "COMPLAINT", ITEMS, Function.identity(), 1, token));
|
||||
assertError("InvalidNextTokenException", "Token is invalid.",
|
||||
() -> paging.page(REGION, ITEMS, Function.identity(), 1, token));
|
||||
}
|
||||
|
||||
@Test
|
||||
void contactsDefaultToFiftyAndTheUnmeasuredListsToTheirBound() {
|
||||
assertEquals(50, SesListPaging.V2_LIST_CONTACTS.pageSize(null));
|
||||
assertEquals(1000, SesListPaging.V2_LIST_CONTACT_LISTS.pageSize(null));
|
||||
assertEquals(1000, SesListPaging.V2_LIST_DEDICATED_IP_POOLS.pageSize(null));
|
||||
assertEquals(1000, SesListPaging.V2_GET_DEDICATED_IPS.pageSize(null));
|
||||
assertEquals(1000, SesListPaging.V2_LIST_SUPPRESSED_DESTINATIONS.pageSize(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidToken_messagesQuoteTheToken() {
|
||||
assertError("BadRequestException", "Invalid PageToken <garbage>.",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaService;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
@@ -20,6 +21,7 @@ import java.util.function.Predicate;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -883,4 +885,24 @@ class SesReceiptRuleServiceTest {
|
||||
assertEquals("LimitExceeded", e.getErrorCode());
|
||||
assertEquals("Too many filters", e.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listReceiptRuleSets_servesAHundredAPageAndResumesFromTheToken() {
|
||||
for (int i = 0; i < 101; i++) {
|
||||
service.createReceiptRuleSet("page-%03d".formatted(i), REGION);
|
||||
}
|
||||
|
||||
PaginatedResult<ReceiptRuleSet> first = service.listReceiptRuleSets(REGION,
|
||||
SesListPaging.V1_LIST_RECEIPT_RULE_SETS, null);
|
||||
assertEquals(100, first.items().size());
|
||||
PaginatedResult<ReceiptRuleSet> rest = service.listReceiptRuleSets(REGION,
|
||||
SesListPaging.V1_LIST_RECEIPT_RULE_SETS, first.nextToken());
|
||||
assertEquals(1, rest.items().size());
|
||||
assertNull(rest.nextToken());
|
||||
|
||||
List<String> paged = new ArrayList<>();
|
||||
first.items().forEach(ruleSet -> paged.add(ruleSet.getName()));
|
||||
rest.items().forEach(ruleSet -> paged.add(ruleSet.getName()));
|
||||
assertEquals(service.listReceiptRuleSets(REGION).stream().map(ReceiptRuleSet::getName).toList(), paged);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.emptyOrNullString;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Paging of v1 {@code ListReceiptRuleSets} on the Query wire: 100 rule sets a page and a token on
|
||||
* every page but the last. Runs in its own region so the rule sets created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesReceiptRuleSetPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/il-central-1/email/aws4_request";
|
||||
private static final String ROOT = "ListReceiptRuleSetsResponse.ListReceiptRuleSetsResult.";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createAHundredAndOneRuleSets() {
|
||||
for (int i = 0; i < 101; i++) {
|
||||
req("CreateReceiptRuleSet").formParam("RuleSetName", "page-%03d".formatted(i))
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void servesAHundredThenTheRestOldestFirstAndOmitsTheTokenOnTheLastPage() {
|
||||
XmlPath first = req("ListReceiptRuleSets").when().post("/").then().statusCode(200)
|
||||
.extract().xmlPath();
|
||||
List<String> names = new ArrayList<>(first.getList(ROOT + "RuleSets.member.Name"));
|
||||
assertThat(names, hasSize(100));
|
||||
String token = first.getString(ROOT + "NextToken");
|
||||
assertThat(token, not(emptyOrNullString()));
|
||||
|
||||
XmlPath rest = req("ListReceiptRuleSets").formParam("NextToken", token)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(not(containsString("<NextToken>")))
|
||||
.extract().xmlPath();
|
||||
assertThat(rest.getList(ROOT + "RuleSets.member.Name"), contains("page-100"));
|
||||
names.addAll(rest.getList(ROOT + "RuleSets.member.Name"));
|
||||
|
||||
List<String> created = new ArrayList<>();
|
||||
for (int i = 0; i < 101; i++) {
|
||||
created.add("page-%03d".formatted(i));
|
||||
}
|
||||
assertEquals(created, names);
|
||||
}
|
||||
|
||||
private static RequestSpecification req(String action) {
|
||||
return given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", action);
|
||||
}
|
||||
}
|
||||
+12
@@ -68,6 +68,18 @@ class SesReceiptRuleSetV1IntegrationTest {
|
||||
.body(containsString("<Name>" + RS + "</Name>"));
|
||||
}
|
||||
|
||||
// Unordered on purpose: it holds whether or not the rule set above still exists.
|
||||
@Test
|
||||
void listReceiptRuleSets_treatsAnEmptyTokenAsAbsentAndRefusesAnyOther() {
|
||||
req("ListReceiptRuleSets").formParam("NextToken", "")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("ListReceiptRuleSetsResponse"));
|
||||
req("ListReceiptRuleSets").formParam("NextToken", "garbage")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("<Message>Invalid page token: garbage</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void describeNonExistent_returnsRuleSetDoesNotExist() {
|
||||
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of {@code ListSuppressedDestinations}, on the account list and on a tenant's. Runs in its
|
||||
* own region so the destinations created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSuppressedDestinationPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/me-south-1/ses/aws4_request";
|
||||
private static final String OTHER_REGION_AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
|
||||
private static final String PATH = "/v2/email/suppression/addresses";
|
||||
private static final String ADDRESSES = "SuppressedDestinationSummaries.EmailAddress";
|
||||
private static final String TENANT = "page-tenant";
|
||||
|
||||
// Put in address order, so oldest first and the address tie-break agree whatever the clock does.
|
||||
@Test
|
||||
@Order(1)
|
||||
void suppressDestinations() {
|
||||
put("page-a@example.com", "BOUNCE", null);
|
||||
put("page-b@example.com", "COMPLAINT", null);
|
||||
put("page-c@example.com", "BOUNCE", null);
|
||||
put("page-d@example.com", "BOUNCE", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void walksOldestFirstAndEndsOnANullToken() {
|
||||
String token = v2().queryParam("PageSize", 1)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("page-a@example.com"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
v2().queryParam("PageSize", 3).queryParam("NextToken", token)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("page-b@example.com", "page-c@example.com", "page-d@example.com"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void theReasonFilterIsAppliedBeforeThePageIsCut() {
|
||||
String token = v2().queryParam("Reason", "BOUNCE").queryParam("PageSize", 2)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("page-a@example.com", "page-c@example.com"))
|
||||
.extract().path("NextToken");
|
||||
|
||||
v2().queryParam("Reason", "BOUNCE").queryParam("PageSize", 2).queryParam("NextToken", token)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("page-d@example.com"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void aTokenIsBoundToItsFilterAndRegion() {
|
||||
String token = v2().queryParam("Reason", "BOUNCE").queryParam("PageSize", 1)
|
||||
.when().get(PATH).then().statusCode(200).extract().path("NextToken");
|
||||
|
||||
assertTokenRefused(v2().queryParam("NextToken", token));
|
||||
assertTokenRefused(v2().queryParam("Reason", "COMPLAINT").queryParam("NextToken", token));
|
||||
assertTokenRefused(given().header("Authorization", OTHER_REGION_AUTH)
|
||||
.queryParam("Reason", "BOUNCE").queryParam("NextToken", token));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void outOfRangeSizesAndUnreadableTokensAreRefused() {
|
||||
for (int size : new int[] {0, 1001}) {
|
||||
v2().queryParam("PageSize", size)
|
||||
.when().get(PATH).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo(
|
||||
"Page size " + size + " is invalid, expected a number between 1 and 1000"));
|
||||
}
|
||||
assertTokenRefused(v2().queryParam("NextToken", "garbage"));
|
||||
assertTokenRefused(v2().queryParam("NextToken", ""));
|
||||
v2().queryParam("PageSize", 0).queryParam("NextToken", "garbage")
|
||||
.when().get(PATH).then().statusCode(400)
|
||||
.body("message", equalTo("Page size 0 is invalid, expected a number between 1 and 1000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void aTenantListPagesOnItsOwnTokens() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"TenantName\":\"" + TENANT + "\"}")
|
||||
.when().post("/v2/email/tenants").then().statusCode(200);
|
||||
put("tenant-a@example.com", "BOUNCE", TENANT);
|
||||
put("tenant-b@example.com", "BOUNCE", TENANT);
|
||||
|
||||
String tenantToken = v2().queryParam("TenantName", TENANT).queryParam("PageSize", 1)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("tenant-a@example.com"))
|
||||
.extract().path("NextToken");
|
||||
v2().queryParam("TenantName", TENANT).queryParam("NextToken", tenantToken)
|
||||
.when().get(PATH).then().statusCode(200)
|
||||
.body(ADDRESSES, contains("tenant-b@example.com"))
|
||||
.body("NextToken", nullValue());
|
||||
|
||||
assertTokenRefused(v2().queryParam("NextToken", tenantToken));
|
||||
String accountToken = v2().queryParam("PageSize", 1)
|
||||
.when().get(PATH).then().statusCode(200).extract().path("NextToken");
|
||||
assertTokenRefused(v2().queryParam("TenantName", TENANT).queryParam("NextToken", accountToken));
|
||||
}
|
||||
|
||||
private static void assertTokenRefused(RequestSpecification request) {
|
||||
request.when().get(PATH).then().statusCode(400)
|
||||
.body("__type", equalTo("InvalidNextTokenException"))
|
||||
.body("message", equalTo("Token is invalid."));
|
||||
}
|
||||
|
||||
private static RequestSpecification v2() {
|
||||
return given().header("Authorization", AUTH);
|
||||
}
|
||||
|
||||
private static void put(String address, String reason, String tenant) {
|
||||
String tenantMember = tenant == null ? "" : ",\"TenantName\":\"" + tenant + "\"";
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + address + "\",\"Reason\":\"" + reason + "\"" + tenantMember + "}")
|
||||
.when().put(PATH).then().statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user