mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
275d874fed
commit
ea41b775aa
26 files changed
+1099
-85
No files matched your search
+147
@@ -0,0 +1,147 @@
|
||||
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 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.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of the v1 and v2 {@code ListConfigurationSets} lists, which share one token namespace.
|
||||
* Runs in its own region so the configuration sets created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesConfigurationSetPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-west-1/ses/aws4_request";
|
||||
private static final String V1_ROOT = "ListConfigurationSetsResponse.ListConfigurationSetsResult.";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createConfigurationSetsOutOfNameOrder() {
|
||||
for (String name : new String[] {"page-b", "page-c", "page-a"}) {
|
||||
create(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void v2_walksByNameAndEndsOnANullToken() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(200)
|
||||
.body("ConfigurationSets", contains("page-a"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 2).queryParam("NextToken", token)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(200)
|
||||
.body("ConfigurationSets", contains("page-b", "page-c"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void v1_walksByNameAndOmitsTheTokenOnTheLastPage() {
|
||||
XmlPath first = listV1("1", null);
|
||||
assertThat(first.getList(V1_ROOT + "ConfigurationSets.member.Name"), contains("page-a"));
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListConfigurationSets").formParam("MaxItems", "2")
|
||||
.formParam("NextToken", first.getString(V1_ROOT + "NextToken"))
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<Name>page-c</Name>"))
|
||||
.body(not(containsString("<NextToken>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void tokensCarryOverBetweenV1AndV2() {
|
||||
String v1Token = listV1("1", null).getString(V1_ROOT + "NextToken");
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", v1Token)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(200)
|
||||
.body("ConfigurationSets", contains("page-b", "page-c"));
|
||||
|
||||
String v2Token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(200)
|
||||
.extract().path("NextToken");
|
||||
assertThat(listV1(null, v2Token).getList(V1_ROOT + "ConfigurationSets.member.Name"),
|
||||
contains("page-b", "page-c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void outOfRangeSizesAndUnreadableTokensFollowEachApi() {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 0)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", "garbage")
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(400)
|
||||
.body("message", equalTo("invalid nextToken garbage"));
|
||||
|
||||
// v1 serves an out-of-range MaxItems rather than refusing it, and names no reason for a
|
||||
// token it cannot read.
|
||||
assertThat(listV1("0", null).getList(V1_ROOT + "ConfigurationSets.member.Name"),
|
||||
contains("page-a", "page-b", "page-c"));
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListConfigurationSets").formParam("NextToken", "garbage")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(not(containsString("<Message>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void withoutAPageSizeOrOutOfRangeBothApisServeFifty() {
|
||||
for (int i = 0; i < 48; i++) {
|
||||
create("more-%02d".formatted(i));
|
||||
}
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/v2/email/configuration-sets").then().statusCode(200)
|
||||
.body("ConfigurationSets", hasSize(50))
|
||||
.body("NextToken", notNullValue());
|
||||
|
||||
for (String maxItems : new String[] {null, "0", "1001"}) {
|
||||
XmlPath v1 = listV1(maxItems, null);
|
||||
assertThat(v1.getList(V1_ROOT + "ConfigurationSets.member.Name"), hasSize(50));
|
||||
assertThat(v1.getString(V1_ROOT + "NextToken"), not(emptyOrNullString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void create(String name) {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"ConfigurationSetName\": \"" + name + "\"}")
|
||||
.when().post("/v2/email/configuration-sets").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static XmlPath listV1(String maxItems, String nextToken) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListConfigurationSets");
|
||||
if (maxItems != null) {
|
||||
request.formParam("MaxItems", maxItems);
|
||||
}
|
||||
if (nextToken != null) {
|
||||
request.formParam("NextToken", nextToken);
|
||||
}
|
||||
return request.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -62,18 +62,16 @@ class SesConfigurationSetServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_isPerRegion_sortedByCreation() {
|
||||
void list_isPerRegion_sortedByName() {
|
||||
service.create(cs("b-cs"), REGION);
|
||||
service.create(cs("a-cs"), REGION);
|
||||
service.create(cs("other"), "eu-west-1");
|
||||
// create() stamps Instant.now(), which can collide within one clock tick and fall back to
|
||||
// the name tie-break; pin distinct timestamps through the escape hatch so the
|
||||
// creation-order assertion stays deterministic.
|
||||
// Creation time no longer decides the order, so pin b-cs as the older one and expect the
|
||||
// name order regardless.
|
||||
stampCreated("b-cs", Instant.parse("2026-01-01T00:00:00Z"));
|
||||
stampCreated("a-cs", Instant.parse("2026-01-02T00:00:00Z"));
|
||||
List<ConfigurationSet> list = service.list(REGION);
|
||||
assertEquals(2, list.size());
|
||||
assertEquals("b-cs", list.get(0).getName());
|
||||
assertEquals(List.of("a-cs", "b-cs"), list.stream().map(ConfigurationSet::getName).toList());
|
||||
}
|
||||
|
||||
private void stampCreated(String name, Instant timestamp) {
|
||||
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
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 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.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of the v1 and v2 {@code ListCustomVerificationEmailTemplates} lists, which share one token
|
||||
* namespace. Runs in its own region so the templates created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesCustomVerificationEmailTemplatePagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-south-1/ses/aws4_request";
|
||||
private static final String BASE = "/v2/email/custom-verification-email-templates";
|
||||
private static final String FROM = "cvet-page-sender@floci.test";
|
||||
private static final String V1_ROOT =
|
||||
"ListCustomVerificationEmailTemplatesResponse.ListCustomVerificationEmailTemplatesResult.";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTemplatesOutOfNameOrder() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailIdentity\": \"" + FROM + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
for (String name : new String[] {"page-b", "page-c", "page-a"}) {
|
||||
create(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void v2_walksByNameAndEndsOnANullToken() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get(BASE).then().statusCode(200)
|
||||
.body("CustomVerificationEmailTemplates.TemplateName", contains("page-a"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 2).queryParam("NextToken", token)
|
||||
.when().get(BASE).then().statusCode(200)
|
||||
.body("CustomVerificationEmailTemplates.TemplateName", contains("page-b", "page-c"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void v1_walksByNameAndOmitsTheTokenOnTheLastPage() {
|
||||
XmlPath first = listV1("1", null);
|
||||
assertThat(first.getList(V1_ROOT + "CustomVerificationEmailTemplates.member.TemplateName"),
|
||||
contains("page-a"));
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListCustomVerificationEmailTemplates").formParam("MaxResults", "2")
|
||||
.formParam("NextToken", first.getString(V1_ROOT + "NextToken"))
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<TemplateName>page-c</TemplateName>"))
|
||||
.body(not(containsString("<NextToken>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void tokensCarryOverBetweenV1AndV2() {
|
||||
String v1Token = listV1("1", null).getString(V1_ROOT + "NextToken");
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", v1Token)
|
||||
.when().get(BASE).then().statusCode(200)
|
||||
.body("CustomVerificationEmailTemplates.TemplateName", contains("page-b", "page-c"));
|
||||
|
||||
String v2Token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get(BASE).then().statusCode(200)
|
||||
.extract().path("NextToken");
|
||||
assertThat(listV1(null, v2Token).getList(V1_ROOT + "CustomVerificationEmailTemplates.member.TemplateName"),
|
||||
contains("page-b", "page-c"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void outOfRangeSizesAndUnreadableTokensFollowEachApi() {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 51)
|
||||
.when().get(BASE).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("The page size must be between 1 and 50"));
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", "garbage")
|
||||
.when().get(BASE).then().statusCode(400)
|
||||
.body("message", equalTo("Invalid nextToken <garbage>."));
|
||||
|
||||
assertThat(listV1("0", null).getList(V1_ROOT + "CustomVerificationEmailTemplates.member.TemplateName"),
|
||||
contains("page-a", "page-b", "page-c"));
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListCustomVerificationEmailTemplates").formParam("NextToken", "garbage")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("<Message>Invalid nextToken <garbage>.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void withoutAPageSizeOrOutOfRangeBothApisServeFifty() {
|
||||
for (int i = 0; i < 48; i++) {
|
||||
create("more-%02d".formatted(i));
|
||||
}
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get(BASE).then().statusCode(200)
|
||||
.body("CustomVerificationEmailTemplates", hasSize(50))
|
||||
.body("NextToken", notNullValue());
|
||||
|
||||
for (String maxResults : new String[] {null, "0", "51"}) {
|
||||
XmlPath v1 = listV1(maxResults, null);
|
||||
assertThat(v1.getList(V1_ROOT + "CustomVerificationEmailTemplates.member"), hasSize(50));
|
||||
assertThat(v1.getString(V1_ROOT + "NextToken"), not(emptyOrNullString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static void create(String name) {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "%s",
|
||||
"FromEmailAddress": "%s",
|
||||
"TemplateSubject": "Verify",
|
||||
"TemplateContent": "<html><body>verify</body></html>",
|
||||
"SuccessRedirectionURL": "https://example.com/ok",
|
||||
"FailureRedirectionURL": "https://example.com/fail"
|
||||
}
|
||||
""".formatted(name, FROM))
|
||||
.when().post(BASE).then().statusCode(200);
|
||||
}
|
||||
|
||||
private static XmlPath listV1(String maxResults, String nextToken) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListCustomVerificationEmailTemplates");
|
||||
if (maxResults != null) {
|
||||
request.formParam("MaxResults", maxResults);
|
||||
}
|
||||
if (nextToken != null) {
|
||||
request.formParam("NextToken", nextToken);
|
||||
}
|
||||
return request.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
}
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
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 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.equalTo;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Paging of the v1 {@code ListIdentities} and v2 {@code ListEmailIdentities} lists, which share one
|
||||
* token namespace. Runs in its own region so the identities created here are the whole list.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesIdentityPagingIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-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 V1_ROOT = "ListIdentitiesResponse.ListIdentitiesResult.";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createIdentitiesOutOfNameOrder() {
|
||||
for (String identity : new String[] {"page-b.test", "zz@page.test", "page-c.test", "page-a.test"}) {
|
||||
create(identity);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void v2_walksByNameAndEndsOnANullToken() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.body("EmailIdentities.IdentityName", contains("page-a.test"))
|
||||
.body("NextToken", notNullValue())
|
||||
.extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 3).queryParam("NextToken", token)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.body("EmailIdentities.IdentityName", contains("page-b.test", "page-c.test", "zz@page.test"))
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void v1_walksByNameAndOmitsTheTokenOnTheLastPage() {
|
||||
XmlPath first = listV1("1", null, null);
|
||||
assertThat(first.getList(V1_ROOT + "Identities.member"), contains("page-a.test"));
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListIdentities").formParam("MaxItems", "3")
|
||||
.formParam("NextToken", first.getString(V1_ROOT + "NextToken"))
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<member>zz@page.test</member>"))
|
||||
.body(not(containsString("<NextToken>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void v1_aTokenTakenWithATypeFilterContinuesAListWithoutIt() {
|
||||
String token = listV1("1", null, "Domain").getString(V1_ROOT + "NextToken");
|
||||
|
||||
assertThat(listV1(null, token, null).getList(V1_ROOT + "Identities.member"),
|
||||
contains("page-b.test", "page-c.test", "zz@page.test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void tokensCarryOverBetweenV1AndV2() {
|
||||
String v1Token = listV1("1", null, null).getString(V1_ROOT + "NextToken");
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", v1Token)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.body("EmailIdentities.IdentityName", contains("page-b.test", "page-c.test", "zz@page.test"));
|
||||
|
||||
String v2Token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.extract().path("NextToken");
|
||||
assertThat(listV1(null, v2Token, null).getList(V1_ROOT + "Identities.member"),
|
||||
contains("page-b.test", "page-c.test", "zz@page.test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void outOfRangeSizesAndUnreadableTokensAreRefused() {
|
||||
given().header("Authorization", AUTH).queryParam("PageSize", 1001)
|
||||
.when().get("/v2/email/identities").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo(
|
||||
"Value 1001 for parameter PageSize is invalid. PageSize must be between 1 and 1000."));
|
||||
given().header("Authorization", AUTH).queryParam("NextToken", "garbage")
|
||||
.when().get("/v2/email/identities").then().statusCode(400)
|
||||
.body("message", equalTo("Invalid NextToken <garbage>."));
|
||||
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListIdentities").formParam("MaxItems", "0")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString(
|
||||
"<Message>Value 0 for parameter MaxItems is invalid. MaxItems must be between 1 and 1000.</Message>"));
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListIdentities").formParam("NextToken", "garbage")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Message>Invalid NextToken <garbage>.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void aTokenIsRefusedInAnotherRegion() {
|
||||
String token = given().header("Authorization", AUTH).queryParam("PageSize", 1)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.extract().path("NextToken");
|
||||
|
||||
given().header("Authorization", OTHER_REGION_AUTH).queryParam("NextToken", token)
|
||||
.when().get("/v2/email/identities").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid NextToken <" + token + ">."));
|
||||
given().contentType("application/x-www-form-urlencoded").header("Authorization", OTHER_REGION_AUTH)
|
||||
.formParam("Action", "ListIdentities").formParam("NextToken", token)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("<Message>Invalid NextToken <" + token + ">.</Message>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void withoutAPageSizeV2ServesTwentyFiveAndV1ServesEverything() {
|
||||
for (int i = 0; i < 22; i++) {
|
||||
create("more-%02d.test".formatted(i));
|
||||
}
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/v2/email/identities").then().statusCode(200)
|
||||
.body("EmailIdentities", hasSize(25))
|
||||
.body("NextToken", notNullValue());
|
||||
|
||||
XmlPath v1 = listV1(null, null, null);
|
||||
assertThat(v1.getList(V1_ROOT + "Identities.member"), hasSize(26));
|
||||
assertThat(v1.getString(V1_ROOT + "NextToken"), emptyOrNullString());
|
||||
}
|
||||
|
||||
private static void create(String identity) {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailIdentity\": \"" + identity + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
}
|
||||
|
||||
private static XmlPath listV1(String maxItems, String nextToken, String identityType) {
|
||||
RequestSpecification request = given()
|
||||
.contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", "ListIdentities");
|
||||
if (maxItems != null) {
|
||||
request.formParam("MaxItems", maxItems);
|
||||
}
|
||||
if (nextToken != null) {
|
||||
request.formParam("NextToken", nextToken);
|
||||
}
|
||||
if (identityType != null) {
|
||||
request.formParam("IdentityType", identityType);
|
||||
}
|
||||
return request.when().post("/").then().statusCode(200).extract().xmlPath();
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,8 @@ class SesIdentityServiceTest {
|
||||
service.verifyEmailIdentity("alice@example.com", REGION);
|
||||
service.save(new Identity("example.com", "Domain"), REGION);
|
||||
service.verifyEmailIdentity("other@example.com", "eu-west-1");
|
||||
assertEquals(2, service.listIdentities(null, REGION).size());
|
||||
assertEquals(List.of("alice@example.com", "example.com"),
|
||||
service.listIdentities(null, REGION).stream().map(Identity::getIdentity).toList());
|
||||
assertEquals(List.of("example.com"),
|
||||
service.listIdentities("Domain", REGION).stream().map(Identity::getIdentity).toList());
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class SesListPagingTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final List<String> ITEMS = List.of("a", "b", "c");
|
||||
|
||||
@Test
|
||||
@@ -43,6 +44,70 @@ class SesListPagingTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageSize_sharedResourceDefaultsFollowTheProbe() {
|
||||
assertEquals(25, SesListPaging.V2_LIST_EMAIL_IDENTITIES.pageSize(null));
|
||||
assertEquals(1000, SesListPaging.V1_LIST_IDENTITIES.pageSize(null));
|
||||
assertEquals(50, SesListPaging.V2_LIST_CONFIGURATION_SETS.pageSize(null));
|
||||
assertEquals(50, SesListPaging.V1_LIST_CONFIGURATION_SETS.pageSize(null));
|
||||
assertEquals(50, SesListPaging.V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES.pageSize(null));
|
||||
assertEquals(50, SesListPaging.V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES.pageSize(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageSize_v1ConfigurationSetsAndCvetsServeFiftyForAnOutOfRangeValue() {
|
||||
for (int size : new int[] {0, -1, 1001, Integer.MAX_VALUE}) {
|
||||
assertEquals(50, SesListPaging.V1_LIST_CONFIGURATION_SETS.pageSize(size));
|
||||
assertEquals(50, SesListPaging.V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES.pageSize(size));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageSize_sharedResourceOutOfRangeMessages() {
|
||||
assertError("BadRequestException",
|
||||
"Value 1001 for parameter PageSize is invalid. PageSize must be between 1 and 1000.",
|
||||
() -> SesListPaging.V2_LIST_EMAIL_IDENTITIES.pageSize(1001));
|
||||
assertError("InvalidParameterValue",
|
||||
"Value 0 for parameter MaxItems is invalid. MaxItems must be between 1 and 1000.",
|
||||
() -> SesListPaging.V1_LIST_IDENTITIES.pageSize(0));
|
||||
assertError("BadRequestException", "The page size must be between 1 and 1000",
|
||||
() -> SesListPaging.V2_LIST_CONFIGURATION_SETS.pageSize(0));
|
||||
assertError("BadRequestException", "The page size must be between 1 and 50",
|
||||
() -> SesListPaging.V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES.pageSize(51));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedResourceTokens_crossBetweenV1AndV2ButNotBetweenKinds() {
|
||||
String identityToken = page(SesListPaging.V1_LIST_IDENTITIES, 1, null).nextToken();
|
||||
assertThat(page(SesListPaging.V2_LIST_EMAIL_IDENTITIES, 1, identityToken).items(), contains("b"));
|
||||
|
||||
String configSetToken = page(SesListPaging.V2_LIST_CONFIGURATION_SETS, 1, null).nextToken();
|
||||
assertThat(page(SesListPaging.V1_LIST_CONFIGURATION_SETS, 1, configSetToken).items(), contains("b"));
|
||||
|
||||
String cvetToken = page(SesListPaging.V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES, 1, null).nextToken();
|
||||
assertThat(page(SesListPaging.V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES, 1, cvetToken).items(),
|
||||
contains("b"));
|
||||
|
||||
assertError("BadRequestException", "invalid nextToken " + identityToken,
|
||||
() -> page(SesListPaging.V2_LIST_CONFIGURATION_SETS, 1, identityToken));
|
||||
assertError("InvalidParameterValue", null,
|
||||
() -> page(SesListPaging.V1_LIST_CONFIGURATION_SETS, 1, identityToken));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidToken_sharedResourceMessages() {
|
||||
assertError("BadRequestException", "Invalid NextToken <garbage>.",
|
||||
() -> page(SesListPaging.V2_LIST_EMAIL_IDENTITIES, 1, "garbage"));
|
||||
assertError("InvalidParameterValue", "Invalid NextToken <garbage>.",
|
||||
() -> page(SesListPaging.V1_LIST_IDENTITIES, 1, "garbage"));
|
||||
assertError("BadRequestException", "invalid nextToken garbage",
|
||||
() -> page(SesListPaging.V2_LIST_CONFIGURATION_SETS, 1, "garbage"));
|
||||
assertError("BadRequestException", "Invalid nextToken <garbage>.",
|
||||
() -> page(SesListPaging.V2_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES, 1, "garbage"));
|
||||
assertError("InvalidParameterValue", "Invalid nextToken <garbage>.",
|
||||
() -> page(SesListPaging.V1_LIST_CUSTOM_VERIFICATION_EMAIL_TEMPLATES, 1, "garbage"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void templateTokens_areSharedBetweenV1AndV2AndRefusedByExportJobs() {
|
||||
String v1Token = page(SesListPaging.V1_LIST_TEMPLATES, 1, null).nextToken();
|
||||
@@ -52,6 +117,17 @@ class SesListPagingTest {
|
||||
() -> page(SesListPaging.V2_LIST_EXPORT_JOBS, 1, v1Token));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTokenFromAnotherRegion_isRefusedAsUnreadable() {
|
||||
String token = page(SesListPaging.V2_LIST_EMAIL_IDENTITIES, 1, null).nextToken();
|
||||
|
||||
assertError("BadRequestException", "Invalid NextToken <" + token + ">.",
|
||||
() -> SesListPaging.V2_LIST_EMAIL_IDENTITIES.page("us-west-2", ITEMS, Function.identity(), 1, token));
|
||||
assertError("InvalidParameterValue", "Invalid NextToken <" + token + ">.",
|
||||
() -> SesListPaging.V1_LIST_IDENTITIES.page("us-west-2", ITEMS, Function.identity(), 1, token));
|
||||
assertThat(page(SesListPaging.V1_LIST_IDENTITIES, 1, token).items(), contains("b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidToken_messagesQuoteTheToken() {
|
||||
assertError("BadRequestException", "Invalid PageToken <garbage>.",
|
||||
@@ -110,13 +186,13 @@ class SesListPagingTest {
|
||||
@Test
|
||||
void pageSize_isReportedBeforeTheToken() {
|
||||
assertError("BadRequestException", "PageSize must be between 1 and 100",
|
||||
() -> SesListPaging.V2_LIST_EXPORT_JOBS.page(ITEMS, Function.identity(), 0, ""));
|
||||
() -> SesListPaging.V2_LIST_EXPORT_JOBS.page(REGION, ITEMS, Function.identity(), 0, ""));
|
||||
assertError("BadRequestException", "The page size must be between 1 and 100",
|
||||
() -> SesListPaging.V2_LIST_EMAIL_TEMPLATES.page(ITEMS, Function.identity(), 0, "garbage"));
|
||||
() -> SesListPaging.V2_LIST_EMAIL_TEMPLATES.page(REGION, ITEMS, Function.identity(), 0, "garbage"));
|
||||
}
|
||||
|
||||
private static PaginatedResult<String> page(SesListPaging paging, int size, String token) {
|
||||
return paging.page(ITEMS, Function.identity(), size, token);
|
||||
return paging.page(REGION, ITEMS, Function.identity(), size, token);
|
||||
}
|
||||
|
||||
private static void assertError(String code, String message, Runnable call) {
|
||||
|
||||
@@ -20,8 +20,6 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -117,14 +115,17 @@ class SesTemplateServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_isPerRegion() {
|
||||
service.createTemplate(template("a"), REGION);
|
||||
service.createTemplate(template("b"), REGION);
|
||||
service.createTemplate(template("other"), "eu-west-1");
|
||||
void list_isPerRegion_newestFirst() {
|
||||
SesTemplateService ticking = new SesTemplateService(new InMemoryStorage<>(), new ObjectMapper(),
|
||||
new SecureRandom(), new MutableClock());
|
||||
for (String name : List.of("a", "b", "c", "d", "e")) {
|
||||
ticking.createTemplate(template(name), REGION);
|
||||
}
|
||||
ticking.createTemplate(template("other"), "eu-west-1");
|
||||
|
||||
List<String> names = service.listTemplates(REGION).stream()
|
||||
List<String> names = ticking.listTemplates(REGION).stream()
|
||||
.map(EmailTemplate::getTemplateName).toList();
|
||||
assertThat(names, containsInAnyOrder("a", "b"));
|
||||
assertEquals(List.of("e", "d", "c", "b", "a"), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -86,9 +86,11 @@ class SesV2IntegrationTest {
|
||||
@Test
|
||||
@Order(4)
|
||||
void listEmailIdentities() {
|
||||
// Other classes share this region, so ask for a page large enough to hold every identity.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("PageSize", 1000)
|
||||
.when()
|
||||
.get("/v2/email/identities")
|
||||
.then()
|
||||
|
||||
Reference in new issue
Block a user