mirror of
https://github.com/floci-io/floci.git
synced 2026-12-05 11:07:59 -05:00
fix(ses): check v2 configuration set request bodies against the service model (#5836)
* fix(ses): check v2 configuration set request bodies against the service model
CreateConfigurationSet, UpdateConfigurationSet,
PutConfigurationSetSuppressionOptions, PutConfigurationSetVdmOptions and
Create/UpdateConfigurationSetEventDestination now check their body against
the vendored SES v2 shapes before any other validation, as the send
operations do. A member of the wrong JSON type, nested ones included, is a
SerializationException with the deserializer's message, ahead of the name
validation and the configuration set lookup.
The type checks the walk makes unreachable are removed from the option
parsers and parseSuppressedReasons. requireOptionObject and coerceBoolean
build their messages through the SesV2Json helpers. A non-object event
destination is now a SerializationException instead of "EventDestination is
required.", and these operations answer a non-object body with "Request
body must be a JSON object." while a blank body still reads as {}.
* fix(ses): read the suppression-options body like the other checked operations
PutConfigurationSetSuppressionOptions inlined the blank-body, parse and
requireJsonObject steps that readOptionBody already performs, which made
its order look different from the other checked operations. It now calls
readOptionBody, so all six read the body the same way before the shape
check. Behaviour is unchanged.
* test(ses): share the SES v2 member-type test helpers
The configuration set member-type test copied the send test's request
assertion and deserializer message constants. Both now use
SesV2SerializationErrors, which takes the HTTP method, so the Contact and
metrics/import/export PRs can reuse it.
This commit is contained in:
1 parent
6aac097c82
commit
43ad214896
9 files changed
+307
-146
No files matched your search
+203
@@ -0,0 +1,203 @@
|
||||
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.stream.Stream;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_LIST;
|
||||
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;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.STRUCTURE;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertError;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertSerializationException;
|
||||
|
||||
/**
|
||||
* The configuration set operations whose body nests a structure check it against the SES v2
|
||||
* shapes, so a member of the wrong JSON type is a SerializationException ahead of the name
|
||||
* validation and the configuration set lookup. The messages per JSON type are covered by
|
||||
* SesV2RequestShapesTest; these cases show each operation runs the check, nested members included.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesConfigurationSetMemberTypeIntegrationTest {
|
||||
|
||||
private static final String MISSING_CS = "v2-cs-member-type-missing";
|
||||
private static final String CREATE = "/v2/email/configuration-sets";
|
||||
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(
|
||||
Arguments.of("numericName", "\"ConfigurationSetName\": 123", NUMBER),
|
||||
Arguments.of("stringTagsBeforeNameValidation",
|
||||
"\"ConfigurationSetName\": \"\", \"Tags\": \"not-an-array\"", EXPECTED_LIST),
|
||||
Arguments.of("stringTagElement", "\"Tags\": [\"env\"]", EXPECTED_NULL),
|
||||
Arguments.of("numericTagKey", "\"Tags\": [{\"Key\": 1, \"Value\": \"v\"}]", NUMBER),
|
||||
Arguments.of("arrayTrackingOptions", "\"TrackingOptions\": []", LIST),
|
||||
Arguments.of("booleanTlsPolicy", "\"DeliveryOptions\": {\"TlsPolicy\": true}",
|
||||
"TRUE_VALUE can not be converted to a String"),
|
||||
Arguments.of("stringSuppressionOptions", "\"SuppressionOptions\": \"BOUNCE\"", EXPECTED_NULL),
|
||||
Arguments.of("stringSuppressedReasons",
|
||||
"\"SuppressionOptions\": {\"SuppressedReasons\": \"BOUNCE\"}", EXPECTED_LIST),
|
||||
Arguments.of("stringConditionThreshold", "\"SuppressionOptions\": {\"SuppressedReasons\": [], "
|
||||
+ "\"ValidationOptions\": {\"ConditionThreshold\": \"x\"}}", EXPECTED_NULL),
|
||||
Arguments.of("stringSendingOptions", "\"SendingOptions\": \"x\"", EXPECTED_NULL),
|
||||
Arguments.of("arrayReputationOptions", "\"ReputationOptions\": []", LIST),
|
||||
Arguments.of("arrayDashboardOptions", "\"VdmOptions\": {\"DashboardOptions\": []}", LIST),
|
||||
Arguments.of("numericArchiveArn", "\"ArchivingOptions\": {\"ArchiveArn\": 1}", NUMBER),
|
||||
Arguments.of("stringSmimeScheme",
|
||||
"\"MessageSecurityOptions\": {\"SigningScheme\": {\"SmimeScheme\": \"x\"}}", EXPECTED_NULL));
|
||||
}
|
||||
|
||||
static Stream<Arguments> eventDestinationCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("stringEventDestination", "\"EventDestination\": \"x\"", EXPECTED_NULL),
|
||||
Arguments.of("arrayEventDestination", "\"EventDestination\": []", LIST),
|
||||
Arguments.of("stringMatchingEventTypes", destination("\"MatchingEventTypes\": \"SEND\""),
|
||||
EXPECTED_LIST),
|
||||
Arguments.of("numericEventType", destination("\"MatchingEventTypes\": [1]"), NUMBER),
|
||||
Arguments.of("stringFirehoseDestination", destination("\"KinesisFirehoseDestination\": \"x\""),
|
||||
EXPECTED_NULL),
|
||||
Arguments.of("objectDimensionConfigurations",
|
||||
destination("\"CloudWatchDestination\": {\"DimensionConfigurations\": {}}"), STRUCTURE),
|
||||
Arguments.of("stringDimensionConfiguration",
|
||||
destination("\"CloudWatchDestination\": {\"DimensionConfigurations\": [\"x\"]}"),
|
||||
EXPECTED_NULL),
|
||||
Arguments.of("numericTopicArn", destination("\"SnsDestination\": {\"TopicArn\": 1}"), NUMBER),
|
||||
Arguments.of("booleanEventBusArn", destination("\"EventBridgeDestination\": {\"EventBusArn\": false}"),
|
||||
"FALSE_VALUE can not be converted to a String"),
|
||||
Arguments.of("arrayPinpointDestination", destination("\"PinpointDestination\": []"), LIST));
|
||||
}
|
||||
|
||||
static Stream<Arguments> putSuppressionOptionsCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("stringSuppressedReasons", "\"SuppressedReasons\": \"BOUNCE\"", EXPECTED_LIST),
|
||||
Arguments.of("numericReason", "\"SuppressedReasons\": [1]", NUMBER),
|
||||
Arguments.of("objectReason", "\"SuppressedReasons\": [{}]", STRUCTURE),
|
||||
Arguments.of("stringConditionThreshold",
|
||||
"\"ValidationOptions\": {\"ConditionThreshold\": \"x\"}", EXPECTED_NULL));
|
||||
}
|
||||
|
||||
static Stream<Arguments> putVdmOptionsCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("stringVdmOptions", "\"VdmOptions\": \"x\"", EXPECTED_NULL),
|
||||
Arguments.of("arrayGuardianOptions", "\"VdmOptions\": {\"GuardianOptions\": []}", LIST),
|
||||
Arguments.of("numericEngagementMetrics",
|
||||
"\"VdmOptions\": {\"DashboardOptions\": {\"EngagementMetrics\": 1}}", NUMBER));
|
||||
}
|
||||
|
||||
static Stream<Arguments> updateConfigurationSetCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("numericName", "\"ConfigurationSetName\": 123", NUMBER),
|
||||
Arguments.of("stringSigningScheme", "\"ConfigurationSetName\": \"" + MISSING_CS + "\", "
|
||||
+ "\"MessageSecurityOptions\": {\"SigningScheme\": \"x\"}", EXPECTED_NULL),
|
||||
Arguments.of("arrayDefaultScheme", "\"ConfigurationSetName\": \"" + MISSING_CS + "\", "
|
||||
+ "\"MessageSecurityOptions\": {\"SigningScheme\": {\"DefaultScheme\": []}}", LIST),
|
||||
Arguments.of("numericSignatureFormat", "\"ConfigurationSetName\": \"" + MISSING_CS + "\", "
|
||||
+ "\"MessageSecurityOptions\": {\"SigningScheme\": "
|
||||
+ "{\"SmimeScheme\": {\"SignatureFormat\": 1}}}", NUMBER));
|
||||
}
|
||||
|
||||
static Stream<Arguments> nonObjectBodyEndpoints() {
|
||||
return Stream.of(
|
||||
Arguments.of("POST", CREATE),
|
||||
Arguments.of("POST", DESTINATIONS),
|
||||
Arguments.of("PUT", DESTINATIONS + "/ed-missing"),
|
||||
Arguments.of("PUT", MISSING_CS_PATH + "/suppression-options"),
|
||||
Arguments.of("PUT", MISSING_CS_PATH + "/vdm-options"),
|
||||
Arguments.of("POST", UPDATE));
|
||||
}
|
||||
|
||||
static Stream<Arguments> blankBodyEndpoints() {
|
||||
return Stream.of(
|
||||
Arguments.of("POST", CREATE, "The configuration set name must be specified."),
|
||||
Arguments.of("POST", DESTINATIONS, "EventDestinationName is required."),
|
||||
Arguments.of("PUT", DESTINATIONS + "/ed-missing", "EventDestination is required."),
|
||||
Arguments.of("POST", UPDATE, "ConfigurationSetName is required."));
|
||||
}
|
||||
|
||||
private static String destination(String members) {
|
||||
return "\"EventDestination\": {" + members + "}";
|
||||
}
|
||||
|
||||
private static void assertMembersRejected(String method, String path, String members, String message) {
|
||||
assertSerializationException(method, path, "{" + members + "}", message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("createConfigurationSetCases")
|
||||
void createConfigurationSet_wrongMemberType(String caseName, String members, String message) {
|
||||
assertMembersRejected("POST", CREATE, members, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("eventDestinationCases")
|
||||
void createConfigurationSetEventDestination_wrongMemberTypeBeforeLookup(String caseName, String members,
|
||||
String message) {
|
||||
assertMembersRejected("POST", DESTINATIONS,
|
||||
"\"EventDestinationName\": \"ed-" + caseName + "\", " + members, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("eventDestinationCases")
|
||||
void updateConfigurationSetEventDestination_wrongMemberTypeBeforeLookup(String caseName, String members,
|
||||
String message) {
|
||||
assertMembersRejected("PUT", DESTINATIONS + "/ed-missing", members, message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createConfigurationSetEventDestination_numericNameBeforeLookup() {
|
||||
assertMembersRejected("POST", DESTINATIONS,
|
||||
"\"EventDestinationName\": 123, " + destination("\"Enabled\": true"), NUMBER);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("putSuppressionOptionsCases")
|
||||
void putConfigurationSetSuppressionOptions_wrongMemberTypeBeforeLookup(String caseName, String members,
|
||||
String message) {
|
||||
assertMembersRejected("PUT", MISSING_CS_PATH + "/suppression-options", members, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("putVdmOptionsCases")
|
||||
void putConfigurationSetVdmOptions_wrongMemberTypeBeforeLookup(String caseName, String members,
|
||||
String message) {
|
||||
assertMembersRejected("PUT", MISSING_CS_PATH + "/vdm-options", members, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("updateConfigurationSetCases")
|
||||
void updateConfigurationSet_wrongMemberTypeBeforeLookup(String caseName, String members, String message) {
|
||||
assertMembersRejected("POST", UPDATE, members, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("nonObjectBodyEndpoints")
|
||||
void nonObjectBody_isRejectedBeforeTheShapeCheck(String method, String path) {
|
||||
assertError(method, path, "[]", "BadRequestException", NOT_AN_OBJECT);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0} {1}")
|
||||
@MethodSource("blankBodyEndpoints")
|
||||
void blankBody_isReadAsAnEmptyObject(String method, String path, String message) {
|
||||
assertError(method, path, "", "BadRequestException", message);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createConfigurationSet_nullTagElement_isLeftToTheTagParser() {
|
||||
assertError("POST", CREATE, "{\"ConfigurationSetName\": \"v2-cs-member-type-null-tag\", \"Tags\": [null]}",
|
||||
"SerializationException", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void putConfigurationSetSuppressionOptions_nullReason_isAnInvalidReason() {
|
||||
assertError("PUT", MISSING_CS_PATH + "/suppression-options", "{\"SuppressedReasons\": [null]}",
|
||||
"BadRequestException", "Reason null is invalid, must be one of [BOUNCE, COMPLAINT].");
|
||||
}
|
||||
}
|
||||
-19
@@ -56,25 +56,6 @@ class SesConfigurationSetV2IntegrationTest {
|
||||
.body("__type", equalTo("AlreadyExistsException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createConfigurationSet_tagsNotArray() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"ConfigurationSetName": "v2-cs-bad-tags",
|
||||
"Tags": "not-an-array"
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void createConfigurationSet_missingName() {
|
||||
|
||||
+30
-48
@@ -6,8 +6,13 @@ import org.junit.jupiter.api.Test;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_LIST;
|
||||
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;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.STRUCTURE;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertError;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertSerializationException;
|
||||
|
||||
/**
|
||||
* A v2 send member of the wrong JSON type fails deserialization on AWS with a
|
||||
@@ -18,8 +23,6 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
@QuarkusTest
|
||||
class SesSendMemberTypeIntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
|
||||
private static final String TO = "success@simulator.amazonses.com";
|
||||
private static final String SEND = "/v2/email/outbound-emails";
|
||||
private static final String BULK = "/v2/email/outbound-bulk-emails";
|
||||
@@ -28,27 +31,6 @@ class SesSendMemberTypeIntegrationTest {
|
||||
"{\"Simple\": {\"Subject\": {\"Data\": \"s\"}, \"Body\": {\"Text\": {\"Data\": \"b\"}}}}";
|
||||
private static final String INLINE_TEMPLATE =
|
||||
"{\"Template\": {\"TemplateContent\": {\"Subject\": \"s\", \"Text\": \"b\"}, \"TemplateData\": \"{}\"}}";
|
||||
private static final String STRUCTURE = "Start of structure or map found where not expected.";
|
||||
private static final String LIST = "Start of list found where not expected";
|
||||
private static final String NUMBER = "NUMBER_VALUE can not be converted to a String";
|
||||
private static final String EXPECTED_LIST = "Expected list or null";
|
||||
|
||||
private static void assertError(String path, String body, String type, String message) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH)
|
||||
.body(body)
|
||||
.when()
|
||||
.post(path)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo(type))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
|
||||
private static void assertSerializationException(String path, String body, String message) {
|
||||
assertError(path, body, "SerializationException", message);
|
||||
}
|
||||
|
||||
private static String send(String members, String content) {
|
||||
return "{" + members + "\"Content\": " + content + "}";
|
||||
@@ -66,39 +48,39 @@ class SesSendMemberTypeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void v2SendEmail_objectFromEmailAddress_isNotReadAsAbsent() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": {},",
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": {},",
|
||||
"{\"Raw\": {\"Data\": \"" + rawData() + "\"}}"), STRUCTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_numericConfigurationSetName_returnsSerializationException() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ConfigurationSetName\": 123,", SIMPLE),
|
||||
NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_numericRawData_namesTheBlobType() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\",",
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\",",
|
||||
"{\"Raw\": {\"Data\": 123}}"), "NUMBER_VALUE can not be converted to a Blob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_simpleContentTypeErrorPrecedesMissingSender() {
|
||||
assertSerializationException(SEND, send("\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
assertSerializationException("POST", SEND, send("\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
"{\"Simple\": {\"Subject\": {\"Data\": 123}, \"Body\": {\"Text\": {\"Data\": \"b\"}}}}"), NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_stringSubject_returnsExpectedNull() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
"{\"Simple\": {\"Subject\": \"s\", \"Body\": {\"Text\": {\"Data\": \"b\"}}}}"), "Expected null");
|
||||
"{\"Simple\": {\"Subject\": \"s\", \"Body\": {\"Text\": {\"Data\": \"b\"}}}}"), EXPECTED_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_stringHeaders_returnsExpectedList() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
"{\"Simple\": {\"Subject\": {\"Data\": \"s\"}, \"Body\": {\"Text\": {\"Data\": \"b\"}}, "
|
||||
+ "\"Headers\": \"X-A: b\"}}"), EXPECTED_LIST);
|
||||
@@ -106,83 +88,83 @@ class SesSendMemberTypeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void v2SendEmail_templateNameTypeErrorPrecedesMissingSender() {
|
||||
assertSerializationException(SEND, send("\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
assertSerializationException("POST", SEND, send("\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]},",
|
||||
"{\"Template\": {\"TemplateName\": 123, \"TemplateData\": \"{}\"}}"), NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_stringDestination_returnsExpectedNull() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": \"" + TO + "\",", SIMPLE), "Expected null");
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": \"" + TO + "\",", SIMPLE), EXPECTED_NULL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_arrayDestination_returnsStartOfList() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": [\"" + TO + "\"],", SIMPLE), LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_nonArrayReplyTo_returnsExpectedList() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, "
|
||||
+ "\"ReplyToAddresses\": \"reply@example.com\",", SIMPLE), EXPECTED_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_nullReplyToElement_isAnInvalidAddress() {
|
||||
assertError(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertError("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplyToAddresses\": [null],", SIMPLE),
|
||||
"BadRequestException", "Invalid email address null.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_nullAddressElementIsReportedAfterContentTypeErrors() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplyToAddresses\": [null],",
|
||||
"{\"Simple\": {\"Subject\": {\"Data\": 123}, \"Body\": {\"Text\": {\"Data\": \"b\"}}}}"), NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendEmail_contentTypeErrorPrecedesEmailTagValidation() {
|
||||
assertSerializationException(SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"EmailTags\": [{\"Name\": \"\", \"Value\": \"v\"}],",
|
||||
"{\"Raw\": {\"Data\": 123}}"), "NUMBER_VALUE can not be converted to a Blob");
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_replyToTypeErrorPrecedesMissingSender() {
|
||||
assertSerializationException(BULK, bulkSend("\"ReplyToAddresses\": \"reply@example.com\",",
|
||||
assertSerializationException("POST", BULK, bulkSend("\"ReplyToAddresses\": \"reply@example.com\",",
|
||||
"{\"ToAddresses\": [\"" + TO + "\"]}"), EXPECTED_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_entryDestinationTypeErrorPrecedesMalformedSender() {
|
||||
assertSerializationException(BULK, bulkSend("\"FromEmailAddress\": \"sender@\",",
|
||||
assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": \"sender@\",",
|
||||
"{\"ToAddresses\": [\"" + TO + "\"], \"CcAddresses\": \"bad-shape\"}"), EXPECTED_LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_arrayEntryDestination_returnsStartOfList() {
|
||||
assertSerializationException(BULK, bulkSend("\"FromEmailAddress\": \"sender@example.com\",",
|
||||
assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": \"sender@example.com\",",
|
||||
"[\"" + TO + "\"]"), LIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_numericFromEmailAddress_returnsSerializationException() {
|
||||
assertSerializationException(BULK, bulkSend("\"FromEmailAddress\": 123,",
|
||||
assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": 123,",
|
||||
"{\"ToAddresses\": [\"" + TO + "\"]}"), NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_nullReplyToElementIsReportedAfterEntryTypeErrors() {
|
||||
assertSerializationException(BULK, bulkSend("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": \"sender@example.com\", "
|
||||
+ "\"ReplyToAddresses\": [null],", "{\"ToAddresses\": [1]}"), NUMBER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_entryReplacementTypeErrorPrecedesMissingStoredTemplate() {
|
||||
assertSerializationException(BULK, """
|
||||
assertSerializationException("POST", BULK, """
|
||||
{
|
||||
"FromEmailAddress": "sender@example.com",
|
||||
"DefaultContent": {"Template": {"TemplateName": "no-such-template", "TemplateData": "{}"}},
|
||||
@@ -193,7 +175,7 @@ class SesSendMemberTypeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void v2SendBulkEmail_entryTypeErrorPrecedesMissingStoredTemplate() {
|
||||
assertSerializationException(BULK, """
|
||||
assertSerializationException("POST", BULK, """
|
||||
{
|
||||
"FromEmailAddress": "sender@example.com",
|
||||
"DefaultContent": {"Template": {"TemplateName": "no-such-template", "TemplateData": "{}"}},
|
||||
@@ -204,6 +186,6 @@ class SesSendMemberTypeIntegrationTest {
|
||||
|
||||
@Test
|
||||
void v2SendCustomVerificationEmail_numericEmailAddress_returnsSerializationException() {
|
||||
assertSerializationException(VERIFY, "{\"EmailAddress\": 123, \"TemplateName\": \"t\"}", NUMBER);
|
||||
assertSerializationException("POST", VERIFY, "{\"EmailAddress\": 123, \"TemplateName\": \"t\"}", NUMBER);
|
||||
}
|
||||
}
|
||||
@@ -249,7 +249,7 @@ class SesV2JsonTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseSuppressedReasons_absentIsEmpty_elementsFollowAwsCoercion() {
|
||||
void parseSuppressedReasons_absentIsEmpty_keepsNullElements() {
|
||||
assertEquals(List.of(),
|
||||
SesV2Json.parseSuppressedReasons(json("{}").path("SuppressedReasons")));
|
||||
assertEquals(List.of(), SesV2Json.parseSuppressedReasons(json("null")));
|
||||
@@ -258,17 +258,6 @@ class SesV2JsonTest {
|
||||
// A null element passes deserialization and is left to the service-layer value check.
|
||||
assertEquals(Arrays.asList("BOUNCE", null),
|
||||
SesV2Json.parseSuppressedReasons(json("[\"BOUNCE\",null]")));
|
||||
assertEquals("Expected list or null", assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.parseSuppressedReasons(json("\"BOUNCE\""))).getMessage());
|
||||
assertEquals("NUMBER_VALUE can not be converted to a String",
|
||||
assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.parseSuppressedReasons(json("[1]"))).getMessage());
|
||||
assertEquals("TRUE_VALUE can not be converted to a String",
|
||||
assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.parseSuppressedReasons(json("[true]"))).getMessage());
|
||||
assertEquals("Start of structure or map found where not expected.",
|
||||
assertAws("SerializationException", 400,
|
||||
() -> SesV2Json.parseSuppressedReasons(json("[{}]"))).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* The deserializer messages SES v2 answers for a body member of the wrong JSON type, and the
|
||||
* request assertion the member-type integration tests share. The messages per JSON type are
|
||||
* covered by SesV2RequestShapesTest; the integration tests use these to show an endpoint runs the
|
||||
* shape check.
|
||||
*/
|
||||
final class SesV2SerializationErrors {
|
||||
|
||||
static final String AUTH = "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
|
||||
static final String STRUCTURE = "Start of structure or map found where not expected.";
|
||||
static final String LIST = "Start of list found where not expected";
|
||||
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";
|
||||
|
||||
private SesV2SerializationErrors() {
|
||||
}
|
||||
|
||||
static void assertError(String method, String path, String body, String type, String message) {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH)
|
||||
.body(body)
|
||||
.when()
|
||||
.request(method, path)
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo(type))
|
||||
.body("message", equalTo(message));
|
||||
}
|
||||
|
||||
static void assertSerializationException(String method, String path, String body, String message) {
|
||||
assertError(method, path, body, "SerializationException", message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user