mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): answer SES v2 wire-type errors with AWS's messages (#6330)
* fix(ses): answer SES v2 wire-type errors with AWS's messages A scalar for a map member is "Expected map or null", a string, boolean, object or list for an integer member gets the Integer conversion message, and a number is narrowed to an int the way AWS reads it (1.5 is accepted, a value above the int range saturates before the range check). A body that is not a JSON object is a SerializationException instead of a BadRequest. * test(ses): give the new SES v2 tests their own order and share the non-object bodies
This commit is contained in:
1 parent
b806f76f1b
commit
eea87ca998
26 files changed
+324
-89
No files matched your search
+2
-1
@@ -63,7 +63,8 @@ class SesAccountMemberTypeIntegrationTest {
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("nonObjectBodyPaths")
|
||||
void nonObjectBody_isRejectedBeforeTheShapeCheck(String path) {
|
||||
assertError("PUT", path, "[]", "BadRequestException", "Request body must be a JSON object.");
|
||||
assertError("PUT", path, "[]", "SerializationException", LIST);
|
||||
assertError("PUT", path, "\"x\"", "SerializationException", null);
|
||||
}
|
||||
|
||||
static Stream<String> nonObjectBodyPaths() {
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ class SesBooleanCoercionV2IntegrationTest {
|
||||
String readField = suffix.equals("/dkim") ? "DkimAttributes.SigningEnabled" : "FeedbackForwardingStatus";
|
||||
String path = "/v2/email/identities/" + DOMAIN + suffix;
|
||||
send("PUT", path, "{\"" + member + "\":true}").statusCode(200);
|
||||
send("PUT", path, "[]").statusCode(400).body("__type", equalTo("BadRequestException"));
|
||||
send("PUT", path, "[]").statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
get("/v2/email/identities/" + DOMAIN).body(readField, equalTo(true));
|
||||
}
|
||||
}
|
||||
|
||||
+17
-4
@@ -333,8 +333,24 @@ class SesBulkV2IntegrationTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("wrongTypeSendBulkEmailBodies")
|
||||
@MethodSource("io.github.hectorvent.floci.services.ses.SesV2SerializationErrors#nonObjectBodies")
|
||||
@Order(12)
|
||||
void sendBulkEmail_nonObjectBody_isASerializationException(String body, String message) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/v2/email/outbound-bulk-emails")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("wrongTypeSendBulkEmailBodies")
|
||||
@Order(13)
|
||||
void sendBulkEmail_wrongMemberType_returnsSerializationException(String label, String body) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
@@ -350,9 +366,6 @@ class SesBulkV2IntegrationTest {
|
||||
static Stream<Arguments> malformedSendBulkEmailBodies() {
|
||||
String validDefaultTemplate = "\"DefaultContent\": {\"Template\": {\"TemplateName\": \"v2-bulk-welcome\", \"TemplateData\": \"{\\\"team\\\":\\\"floci\\\",\\\"name\\\":\\\"X\\\"}\"}}";
|
||||
return Stream.of(
|
||||
Arguments.of("body is array", "[1,2,3]"),
|
||||
Arguments.of("body is JSON null literal", "null"),
|
||||
Arguments.of("body is JSON string", "\"hello\""),
|
||||
Arguments.of("BulkEmailEntries element is null", """
|
||||
{
|
||||
"FromEmailAddress": "bulk@example.com",
|
||||
|
||||
+2
-2
@@ -30,7 +30,6 @@ class SesConfigurationSetMemberTypeIntegrationTest {
|
||||
private static final String MISSING_CS_PATH = CREATE + "/" + MISSING_CS;
|
||||
private static final String DESTINATIONS = MISSING_CS_PATH + "/event-destinations";
|
||||
private static final String UPDATE = "/v2/email/update-configuration-sets";
|
||||
private static final String NOT_AN_OBJECT = "Request body must be a JSON object.";
|
||||
|
||||
static Stream<Arguments> createConfigurationSetCases() {
|
||||
return Stream.of(
|
||||
@@ -180,7 +179,8 @@ class SesConfigurationSetMemberTypeIntegrationTest {
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("nonObjectBodyEndpoints")
|
||||
void nonObjectBody_isRejectedBeforeTheShapeCheck(String method, String path) {
|
||||
assertError(method, path, "[]", "BadRequestException", NOT_AN_OBJECT);
|
||||
assertError(method, path, "[]", "SerializationException", LIST);
|
||||
assertError(method, path, "\"x\"", "SerializationException", null);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
|
||||
+2
-1
@@ -260,7 +260,8 @@ class SesContactV2IntegrationTest {
|
||||
given().contentType("application/json").header("Authorization", SES_AUTH).body("[]")
|
||||
.when().post(CONTACTS + "/list")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
}
|
||||
|
||||
// Type coercion, verified against real AWS: a JSON string coerces to the Boolean UnsubscribeAll
|
||||
|
||||
+2
-1
@@ -207,7 +207,8 @@ class SesDkimSigningActionsIntegrationTest {
|
||||
void putDkimSigningAttributes_nonObjectBody_returns400() {
|
||||
given().contentType("application/json").header("Authorization", V2_AUTH).body("[]")
|
||||
.when().put("/v2/email/identities/dkim-nonobj.floci.test/dkim/signing")
|
||||
.then().statusCode(400).body("__type", equalTo("BadRequestException"));
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-2
@@ -245,7 +245,7 @@ class SesEmailIdentityConfigurationSetV2IntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void putConfigurationSet_whitespaceOnlyBody_returnsSerializationExceptionAndKeepsAssociation() {
|
||||
void putConfigurationSet_whitespaceOnlyOrArrayBody_returnsSerializationExceptionAndKeepsAssociation() {
|
||||
// Re-associate so we can confirm a whitespace-only body does NOT clear.
|
||||
given().contentType("application/json").header("Authorization", SES_AUTH)
|
||||
.body("{\"ConfigurationSetName\":\"" + CS + "\"}")
|
||||
@@ -258,8 +258,14 @@ class SesEmailIdentityConfigurationSetV2IntegrationTest {
|
||||
.when().put("/v2/email/identities/" + IDENTITY + "/configuration-set")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
given().contentType("application/json").header("Authorization", SES_AUTH)
|
||||
.body("[]")
|
||||
.when().put("/v2/email/identities/" + IDENTITY + "/configuration-set")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
|
||||
// The association is unchanged (the invalid body neither cleared nor updated it).
|
||||
// The association is unchanged (the invalid bodies neither cleared nor updated it).
|
||||
given().header("Authorization", SES_AUTH)
|
||||
.when().get("/v2/email/identities/" + IDENTITY)
|
||||
.then().statusCode(200)
|
||||
|
||||
@@ -98,4 +98,12 @@ class SesExportFiltersTest {
|
||||
|
||||
assertEquals(List.of("two@example.com"), destinations(kept));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fractionalMaxResultsIsReadAsTheIntTheRequestWasValidatedWith() {
|
||||
List<SesExportPayloads.InsightsRow> kept = SesExportFilters.apply(ROWS,
|
||||
source("{\"Exclude\": {\"TenantName\": [\"blue\"]}, \"MaxResults\": 1.5}"));
|
||||
|
||||
assertEquals(List.of("two@example.com"), destinations(kept));
|
||||
}
|
||||
}
|
||||
+16
-3
@@ -403,7 +403,8 @@ class SesExportJobV2IntegrationTest {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"PageSize\": \"ten\"}")
|
||||
.when().post("/v2/email/list-export-jobs").then().statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("STRING_VALUE can not be converted to an Integer"));
|
||||
// The body is deserialized before any member is validated, so a mistyped member wins.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"JobStatus\": \"BOGUS\", \"PageSize\": \"ten\"}")
|
||||
@@ -527,7 +528,8 @@ class SesExportJobV2IntegrationTest {
|
||||
|
||||
// A MaxResults of the wrong type is a deserialization error, not a value out of range.
|
||||
insightsWith("\"MaxResults\": \"100\",")
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"));
|
||||
.then().statusCode(400).body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("STRING_VALUE can not be converted to an Integer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -549,6 +551,17 @@ class SesExportJobV2IntegrationTest {
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
void createExportJob_keepsAFractionalMaxResultsAsTheIntItWasCheckedAs() {
|
||||
String jobId = insightsWith("\"MaxResults\": 1.5,").then().statusCode(200).extract().path("JobId");
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/v2/email/export-jobs/" + jobId)
|
||||
.then().statusCode(200)
|
||||
.body("ExportDataSource.MessageInsightsDataSource.MaxResults", equalTo(1));
|
||||
}
|
||||
|
||||
/** A message-insights export request carrying the given extra members. */
|
||||
private static Response insightsWith(String members) {
|
||||
return create("""
|
||||
@@ -559,7 +572,7 @@ class SesExportJobV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(19)
|
||||
@Order(20)
|
||||
void cleanUpVdmAndIdentity() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"VdmAttributes\":{\"VdmEnabled\":\"DISABLED\"}}")
|
||||
|
||||
+2
-1
@@ -154,7 +154,8 @@ class SesIdentityAttributesV2IntegrationTest {
|
||||
.put("/v2/email/identities/v2-attrs.floci.test/mail-from")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_MAP;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.LIST;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.NUMBER;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.STRING_FOR_INTEGER;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertError;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertSerializationException;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.authFor;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* The list operations read a map {@code Filter} and an integer {@code PageSize} through the
|
||||
* SesV2Json member helpers rather than the shape check, so each endpoint is covered here: a scalar
|
||||
* filter is "Expected map or null", a string page size names the Integer target and any other
|
||||
* number is narrowed to an int before the range check. Every refused case fails before anything is
|
||||
* looked up.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesListMemberTypeIntegrationTest {
|
||||
|
||||
private static final String NARROW_REGION_AUTH = authFor("ap-south-2");
|
||||
|
||||
static Stream<Arguments> scalarFilterCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("listEmailIdentities", "/v2/email/list-identities", "{\"Filter\": \"x\"}"),
|
||||
Arguments.of("listConfigurationSets", "/v2/email/list-configuration-sets", "{\"Filter\": \"x\"}"),
|
||||
Arguments.of("listTenants", "/v2/email/tenants/list", "{\"Filter\": 1}"),
|
||||
Arguments.of("listTenantResources", "/v2/email/tenants/resources/list",
|
||||
"{\"TenantName\": \"ghost\", \"Filter\": \"x\"}"));
|
||||
}
|
||||
|
||||
static Stream<Arguments> stringPageSizeCases() {
|
||||
String pageSize = "{\"PageSize\": \"1\"}";
|
||||
return Stream.of(
|
||||
Arguments.of("listEmailIdentities", "/v2/email/list-identities", pageSize),
|
||||
Arguments.of("listConfigurationSets", "/v2/email/list-configuration-sets", pageSize),
|
||||
Arguments.of("listContacts", "/v2/email/contact-lists/ghost/contacts/list", pageSize),
|
||||
Arguments.of("listImportJobs", "/v2/email/import-jobs/list", pageSize),
|
||||
Arguments.of("listExportJobs", "/v2/email/list-export-jobs", pageSize),
|
||||
Arguments.of("listEmailIdentityCertificates", "/v2/email/identity/certificates/list",
|
||||
"{\"EmailIdentity\": \"ghost.example.com\", \"PageSize\": \"1\"}"),
|
||||
Arguments.of("listTenants", "/v2/email/tenants/list", pageSize),
|
||||
Arguments.of("listTenantResources", "/v2/email/tenants/resources/list",
|
||||
"{\"TenantName\": \"ghost\", \"PageSize\": \"1\"}"),
|
||||
Arguments.of("listResourceTenants", "/v2/email/resources/tenants/list",
|
||||
"{\"ResourceArn\": \"ghost\", \"PageSize\": \"1\"}"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("scalarFilterCases")
|
||||
void scalarFilter_isExpectedMap(String caseName, String path, String body) {
|
||||
assertSerializationException("POST", path, body, EXPECTED_MAP);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("stringPageSizeCases")
|
||||
void stringPageSize_namesTheIntegerTarget(String caseName, String path, String body) {
|
||||
assertSerializationException("POST", path, body, STRING_FOR_INTEGER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonObjectBody_isASerializationException() {
|
||||
assertSerializationException("POST", "/v2/email/list-identities", "[]", LIST);
|
||||
for (String body : List.of("\"x\"", "1", "null")) {
|
||||
assertSerializationException("POST", "/v2/email/list-identities", body, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void pageSize_isNarrowedBeforeTheRangeCheck() {
|
||||
for (String identity : List.of("a@narrow.example.com", "b@narrow.example.com")) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", NARROW_REGION_AUTH)
|
||||
.body("{\"EmailIdentity\": \"" + identity + "\"}")
|
||||
.when()
|
||||
.post("/v2/email/identities")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", NARROW_REGION_AUTH)
|
||||
.body("{\"PageSize\": 1.5}")
|
||||
.when()
|
||||
.post("/v2/email/list-identities")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("EmailIdentities", hasSize(1))
|
||||
.body("NextToken", notNullValue());
|
||||
assertError("POST", "/v2/email/list-identities", "{\"PageSize\": 4294967296}", "BadRequestException",
|
||||
"Value 2147483647 for parameter PageSize is invalid. PageSize must be between 1 and 1000.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTenantResources_filterValueNamesTheStringTarget() {
|
||||
assertSerializationException("POST", "/v2/email/tenants/resources/list",
|
||||
"{\"TenantName\": \"ghost\", \"Filter\": {\"RESOURCE_TYPE\": 1}}", NUMBER);
|
||||
}
|
||||
}
|
||||
+4
@@ -9,6 +9,7 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_LIST;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_MAP;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_NULL;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.LIST;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.NUMBER;
|
||||
@@ -40,6 +41,7 @@ class SesMetricsJobsMemberTypeIntegrationTest {
|
||||
Arguments.of("stringQuery", "{\"Queries\": [\"x\"]}", EXPECTED_NULL),
|
||||
Arguments.of("numericId", "{\"Queries\": [{\"Id\": 1}]}", NUMBER),
|
||||
Arguments.of("arrayDimensions", "{\"Queries\": [{\"Dimensions\": []}]}", LIST),
|
||||
Arguments.of("stringDimensions", "{\"Queries\": [{\"Dimensions\": \"x\"}]}", EXPECTED_MAP),
|
||||
Arguments.of("numericDimensionValue", "{\"Queries\": [{\"Dimensions\": {\"ISP\": 1}}]}", NUMBER));
|
||||
}
|
||||
|
||||
@@ -62,6 +64,8 @@ class SesMetricsJobsMemberTypeIntegrationTest {
|
||||
"{\"ExportDataSource\": {\"MetricsDataSource\": {\"Metrics\": \"SEND\"}}}", EXPECTED_LIST),
|
||||
Arguments.of("arrayDimensions",
|
||||
"{\"ExportDataSource\": {\"MetricsDataSource\": {\"Dimensions\": []}}}", LIST),
|
||||
Arguments.of("stringDimensions",
|
||||
"{\"ExportDataSource\": {\"MetricsDataSource\": {\"Dimensions\": \"x\"}}}", EXPECTED_MAP),
|
||||
Arguments.of("numericDimensionValue",
|
||||
"{\"ExportDataSource\": {\"MetricsDataSource\": {\"Dimensions\": {\"ISP\": [1]}}}}", NUMBER),
|
||||
Arguments.of("objectIncludeFilter",
|
||||
|
||||
+2
-1
@@ -275,7 +275,8 @@ class SesSuppressionV2IntegrationTest {
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+17
-4
@@ -685,8 +685,24 @@ class SesTemplateV2IntegrationTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("wrongTypeSendEmailBodies")
|
||||
@MethodSource("io.github.hectorvent.floci.services.ses.SesV2SerializationErrors#nonObjectBodies")
|
||||
@Order(51)
|
||||
void sendEmail_nonObjectBody_isASerializationException(String body, String message) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body(body)
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("wrongTypeSendEmailBodies")
|
||||
@Order(52)
|
||||
void sendEmail_wrongMemberType_returnsSerializationException(String label, String body) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
@@ -701,9 +717,6 @@ class SesTemplateV2IntegrationTest {
|
||||
|
||||
static Stream<Arguments> malformedSendEmailBodies() {
|
||||
return Stream.of(
|
||||
Arguments.of("body is array", "[1,2,3]"),
|
||||
Arguments.of("body is JSON null literal", "null"),
|
||||
Arguments.of("body is JSON string", "\"hello\""),
|
||||
Arguments.of("TemplateData as invalid JSON string", """
|
||||
{
|
||||
"FromEmailAddress": "sender@example.com",
|
||||
|
||||
+3
-3
@@ -178,11 +178,11 @@ class SesTenantAssociationV2IntegrationTest {
|
||||
v2().body("{\"TenantName\":\"" + TENANT + "\",\"NextToken\":\"garbage-token\"}")
|
||||
.when().post("/v2/email/tenants/resources/list").then().statusCode(400)
|
||||
.body("message", equalTo("Invalid Next Token"));
|
||||
// An integral value outside the int range must be rejected, not silently truncated
|
||||
// (4294967296 would truncate to 0 and produce the wrong Smithy message).
|
||||
// A value outside the int range saturates, as AWS reads it, rather than truncating to 0.
|
||||
v2().body("{\"TenantName\":\"" + TENANT + "\",\"PageSize\":4294967296}")
|
||||
.when().post("/v2/email/tenants/resources/list").then().statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"));
|
||||
.body("message", equalTo("1 validation error detected: Value '2147483647' at 'pageSize' failed "
|
||||
+ "to satisfy constraint: Member must have value less than or equal to 100"));
|
||||
v2().body("{\"TenantName\":\"ghost-tenant\"}")
|
||||
.when().post("/v2/email/tenants/resources/list").then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
|
||||
+15
-1
@@ -134,11 +134,25 @@ class SesTestRenderV2IntegrationTest {
|
||||
static Stream<Arguments> malformedRenderBodies() {
|
||||
return Stream.of(
|
||||
Arguments.of("null body", null),
|
||||
Arguments.of("non-object body (array)", "[1,2,3]"),
|
||||
Arguments.of("TemplateData as object", "{\"TemplateData\": {\"name\": \"Alice\"}}")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void testRenderEmailTemplate_arrayBody_isASerializationException() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("[1,2,3]")
|
||||
.when()
|
||||
.post("/v2/email/templates/v2-render-welcome/render")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("SerializationException"))
|
||||
.body("message", equalTo("Start of list found where not expected"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void testRenderEmailTemplate_dateHeaderIsUtc() {
|
||||
|
||||
@@ -70,9 +70,14 @@ class SesV2JsonTest {
|
||||
|
||||
@Test
|
||||
void requireJsonObject_rejectsNullAndNonObjects() {
|
||||
assertEquals("Request body must be a JSON object.", assertAws("BadRequestException", 400,
|
||||
assertNull(assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.requireJsonObject(null)).getMessage());
|
||||
assertAws("BadRequestException", 400, () -> SesV2Json.requireJsonObject(json("[]")));
|
||||
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.requireJsonObject(json("[]"))).getMessage());
|
||||
for (String body : List.of("\"x\"", "1", "true", "null")) {
|
||||
assertNull(assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.requireJsonObject(json(body))).getMessage(), body);
|
||||
}
|
||||
SesV2Json.requireJsonObject(json("{}"));
|
||||
}
|
||||
|
||||
@@ -116,8 +121,10 @@ class SesV2JsonTest {
|
||||
assertTrue(SesV2Json.readOptionBody(MAPPER, " ").isObject());
|
||||
assertEquals("REQUIRE", SesV2Json.readOptionBody(MAPPER, "{\"HttpsPolicy\":\"REQUIRE\"}")
|
||||
.path("HttpsPolicy").asText());
|
||||
assertEquals("Request body must be a JSON object.", assertAws("BadRequestException", 400,
|
||||
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.readOptionBody(MAPPER, "[1]")).getMessage());
|
||||
assertNull(assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.readOptionBody(MAPPER, "null")).getMessage());
|
||||
assertAws("BadRequestException", 400, () -> SesV2Json.readOptionBody(MAPPER, "{not json"));
|
||||
}
|
||||
|
||||
@@ -172,9 +179,9 @@ class SesV2JsonTest {
|
||||
assertNull(SesV2Json.stringMapMemberOrAbsent(node, "missing"));
|
||||
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.stringMapMemberOrAbsent(node, "a")).getMessage());
|
||||
assertEquals("Expected null", assertAws("SerializationException", 400,
|
||||
assertEquals("Expected map or null", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.stringMapMemberOrAbsent(node, "s")).getMessage());
|
||||
assertEquals("Expected null", assertAws("SerializationException", 400,
|
||||
assertEquals("Expected map or null", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.stringMapMemberOrAbsent(node, "i")).getMessage());
|
||||
}
|
||||
|
||||
@@ -228,14 +235,29 @@ class SesV2JsonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void intMemberOrAbsent_rejectsNonIntegralAndOutOfRange() {
|
||||
JsonNode node = json("{\"i\":5,\"f\":1.5,\"big\":1099511627776,\"s\":\"5\",\"z\":null}");
|
||||
void intMemberOrAbsent_truncatesAFractionAndSaturatesOutOfRange() {
|
||||
JsonNode node = json("{\"i\":5,\"f\":1.5,\"big\":4294967296,\"neg\":-4294967296,\"z\":null}");
|
||||
assertEquals(5, SesV2Json.intMemberOrAbsent(node, "i"));
|
||||
assertEquals(1, SesV2Json.intMemberOrAbsent(node, "f"));
|
||||
assertEquals(Integer.MAX_VALUE, SesV2Json.intMemberOrAbsent(node, "big"));
|
||||
assertEquals(Integer.MIN_VALUE, SesV2Json.intMemberOrAbsent(node, "neg"));
|
||||
assertNull(SesV2Json.intMemberOrAbsent(node, "z"));
|
||||
assertNull(SesV2Json.intMemberOrAbsent(node, "missing"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.intMemberOrAbsent(node, "f"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.intMemberOrAbsent(node, "big"));
|
||||
assertAws("SerializationException", 400, () -> SesV2Json.intMemberOrAbsent(node, "s"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void intMemberOrAbsent_namesTheWrongJsonType() {
|
||||
JsonNode node = json("{\"s\":\"5\",\"t\":true,\"f\":false,\"o\":{},\"a\":[]}");
|
||||
assertEquals("STRING_VALUE can not be converted to an Integer", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.intMemberOrAbsent(node, "s")).getMessage());
|
||||
assertEquals("TRUE_VALUE can not be converted to an Integer", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.intMemberOrAbsent(node, "t")).getMessage());
|
||||
assertEquals("FALSE_VALUE can not be converted to an Integer", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.intMemberOrAbsent(node, "f")).getMessage());
|
||||
assertEquals("Start of structure or map found where not expected.", assertAws("SerializationException",
|
||||
400, () -> SesV2Json.intMemberOrAbsent(node, "o")).getMessage());
|
||||
assertEquals("Start of list found where not expected", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.intMemberOrAbsent(node, "a")).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -49,10 +49,11 @@ class SesV2RequestShapesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapMemberReadsLikeAStructure() {
|
||||
void mapMemberReadsLikeAStructureButExpectsAMap() {
|
||||
assertAccepted("ListTenantResources", "{\"Filter\":{\"RESOURCE_TYPE\":\"x\"}}");
|
||||
assertRejected("ListTenantResources", "{\"Filter\":[]}", LIST);
|
||||
assertRejected("ListTenantResources", "{\"Filter\":\"x\"}", "Expected null");
|
||||
assertRejected("ListTenantResources", "{\"Filter\":\"x\"}", "Expected map or null");
|
||||
assertRejected("ListTenantResources", "{\"Filter\":1}", "Expected map or null");
|
||||
assertRejected("ListTenantResources", "{\"Filter\":{\"RESOURCE_TYPE\":1}}",
|
||||
"NUMBER_VALUE can not be converted to a String");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@@ -17,10 +21,20 @@ final class SesV2SerializationErrors {
|
||||
static final String NUMBER = "NUMBER_VALUE can not be converted to a String";
|
||||
static final String EXPECTED_NULL = "Expected null";
|
||||
static final String EXPECTED_LIST = "Expected list or null";
|
||||
static final String EXPECTED_MAP = "Expected map or null";
|
||||
static final String STRING_FOR_INTEGER = "STRING_VALUE can not be converted to an Integer";
|
||||
|
||||
private SesV2SerializationErrors() {
|
||||
}
|
||||
|
||||
/** A body that is not a JSON object, with the message AWS answers it with. */
|
||||
static Stream<Arguments> nonObjectBodies() {
|
||||
return Stream.of(
|
||||
Arguments.of("[1,2,3]", LIST),
|
||||
Arguments.of("null", null),
|
||||
Arguments.of("\"hello\"", null));
|
||||
}
|
||||
|
||||
/** An Authorization header signed for {@code region}, for a test that needs its own region state. */
|
||||
static String authFor(String region) {
|
||||
return "AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/email/aws4_request";
|
||||
|
||||
Reference in new issue
Block a user