Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(ses): check v2 configuration set request bodies against the service model (#5836)

Kenshin Okinaka43ad2148961a
diff --git a/docs/services/ses.md b/docs/services/ses.md
index 96e3560d0b..d6276f95db 100644
--- a/docs/services/ses.md
+++ b/docs/services/ses.md
@@ -503,7 +503,7 @@ S/MIME certificate associations are stored per region and never used: Floci does
### Request member types
-The send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`) check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does. The first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message:
+The operations whose body nests a structure in a structure, or holds a list of structures, check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does: the send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`), `CreateConfigurationSet`, `UpdateConfigurationSet`, `PutConfigurationSetSuppressionOptions`, `PutConfigurationSetVdmOptions`, `CreateConfigurationSetEventDestination` and `UpdateConfigurationSetEventDestination`. In those operations, the first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message:
| Member type | Value sent | Message |
|---|---|---|
@@ -514,6 +514,8 @@ The send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`
A JSON `null` member counts as absent. A `null` address list element passes this check and fails later, as on AWS: `SendEmail` answers `Invalid email address null.` after its content and sender checks and before the tenant lookup, and `SendBulkEmail` reports it as the `INVALID_PARAMETER` status of the entry it belongs to (of every entry for a `null` Reply-To), or as `Destination cannot be empty` when no entry of the request has a non-null recipient. The account-level sending switch is still checked first, so a paused account answers `SendingPausedException` even for a malformed body.
+The other operations check their members one at a time, and some of them still answer a wrong JSON type with `BadRequestException`.
+
The body shapes are vendored in `src/main/resources/aws/sesv2-request-shapes.json`, generated by `tools/aws/regen_sesv2_shapes.py` from the botocore release pinned in `tools/aws/requirements.txt`.
### IAM enforcement
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
index 8ed9034f7d..147ce18b9a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
@@ -40,13 +40,13 @@ import java.util.List;
import java.util.Map;
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
+import static io.github.hectorvent.floci.services.ses.SesV2Json.expectedNullError;
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseOptionString;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSuppressedReasons;
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
-import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
@@ -85,7 +85,8 @@ public class SesConfigurationSetController {
public Response createConfigurationSet(@Context HttpHeaders headers, String body) {
String region = regionResolver.resolveRegion(headers);
try {
- JsonNode request = objectMapper.readTree(body);
+ JsonNode request = readOptionBody(objectMapper, body);
+ SesV2RequestShapes.check("CreateConfigurationSet", request);
String name = request.path("ConfigurationSetName").asText(null);
SesConfigurationSetService.validateName(name);
ConfigurationSet cs = new ConfigurationSet(name);
@@ -95,9 +96,6 @@ public class SesConfigurationSetController {
}
JsonNode suppressionNode = request.path("SuppressionOptions");
if (!suppressionNode.isMissingNode() && !suppressionNode.isNull()) {
- if (!suppressionNode.isObject()) {
- throw new AwsException("SerializationException", "Expected null", 400);
- }
JsonNode reasonsNode = suppressionNode.path("SuppressedReasons");
if (reasonsNode.isMissingNode() || reasonsNode.isNull()) {
throw new AwsException("InternalFailure",
@@ -109,14 +107,10 @@ public class SesConfigurationSetController {
}
JsonNode sendingNode = request.path("SendingOptions");
if (!sendingNode.isMissingNode() && !sendingNode.isNull()) {
- if (!sendingNode.isObject()) {
- throw new AwsException("SerializationException", "Expected null", 400);
- }
cs.setSendingEnabled(coerceBooleanOrFalse(sendingNode.path("SendingEnabled")));
}
JsonNode reputationNode = request.path("ReputationOptions");
if (!reputationNode.isMissingNode() && !reputationNode.isNull()) {
- requireOptionObject(reputationNode);
cs.setReputationMetricsEnabled(
coerceBooleanOrFalse(reputationNode.path("ReputationMetricsEnabled")));
}
@@ -253,18 +247,14 @@ public class SesConfigurationSetController {
String body) {
String region = regionResolver.resolveRegion(headers);
try {
- JsonNode request = (body == null || body.isBlank())
- ? objectMapper.createObjectNode()
- : objectMapper.readTree(body);
- requireJsonObject(request);
+ JsonNode request = readOptionBody(objectMapper, body);
+ SesV2RequestShapes.check("PutConfigurationSetSuppressionOptions", request);
List<String> reasons = parseSuppressedReasons(request.path("SuppressedReasons"));
configSetService.putSuppressionOptions(name, reasons, region);
LOG.infov("SES V2 PutConfigurationSetSuppressionOptions: {0} on {1}", reasons, name);
return Response.ok(objectMapper.createObjectNode()).build();
} catch (AwsException e) {
throw remapV1Exception(e);
- } catch (JsonProcessingException e) {
- throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@@ -361,6 +351,7 @@ public class SesConfigurationSetController {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode request = readOptionBody(objectMapper, body);
+ SesV2RequestShapes.check("PutConfigurationSetVdmOptions", request);
JsonNode vdmNode = request.path("VdmOptions");
VdmOptions options = (vdmNode.isMissingNode() || vdmNode.isNull())
? null : parseVdmOptions(vdmNode);
@@ -378,7 +369,8 @@ public class SesConfigurationSetController {
String region = regionResolver.resolveRegion(headers);
try {
JsonNode request = readOptionBody(objectMapper, body);
- String name = stringMemberOrAbsent(request, "ConfigurationSetName");
+ SesV2RequestShapes.check("UpdateConfigurationSet", request);
+ String name = request.path("ConfigurationSetName").textValue();
if (name == null || name.isBlank()) {
throw new AwsException("BadRequestException", "ConfigurationSetName is required.", 400);
}
@@ -396,7 +388,7 @@ public class SesConfigurationSetController {
/** Reject a non-object option block, mirroring the AWS deserialization layer. */
private static void requireOptionObject(JsonNode node) {
if (!node.isObject()) {
- throw new AwsException("SerializationException", "Expected null", 400);
+ throw expectedNullError();
}
}
@@ -460,22 +452,15 @@ public class SesConfigurationSetController {
// empty union to DefaultScheme, lets SmimeScheme win when both members are sent, and stores a
// missing SignatureFormat as DETACHED. Returns null for "no change".
private static MessageSecurityOptions parseMessageSecurityOptions(JsonNode node) {
- requireOptionObject(node);
JsonNode schemeNode = node.path("SigningScheme");
if (schemeNode.isMissingNode() || schemeNode.isNull()) {
return null;
}
- requireOptionObject(schemeNode);
- JsonNode defaultNode = schemeNode.path("DefaultScheme");
- if (!defaultNode.isMissingNode() && !defaultNode.isNull()) {
- requireOptionObject(defaultNode);
- }
JsonNode smimeNode = schemeNode.path("SmimeScheme");
if (smimeNode.isMissingNode() || smimeNode.isNull()) {
return new MessageSecurityOptions(SigningScheme.defaultScheme());
}
- requireOptionObject(smimeNode);
- String format = stringMemberOrAbsent(smimeNode, "SignatureFormat");
+ String format = smimeNode.path("SignatureFormat").textValue();
if (format == null) {
format = SIGNATURE_FORMAT_DETACHED;
} else if (!SIGNATURE_FORMAT_DETACHED.equals(format)) {
@@ -488,12 +473,10 @@ public class SesConfigurationSetController {
}
private static VdmOptions parseVdmOptions(JsonNode node) {
- requireOptionObject(node);
VdmOptions v = new VdmOptions();
JsonNode dashboard = node.path("DashboardOptions");
if (!dashboard.isMissingNode() && !dashboard.isNull()) {
- requireOptionObject(dashboard);
- String engagementMetrics = parseOptionString(dashboard.path("EngagementMetrics"), "EngagementMetrics");
+ String engagementMetrics = dashboard.path("EngagementMetrics").textValue();
if (engagementMetrics != null) {
DashboardOptions d = new DashboardOptions();
d.setEngagementMetrics(engagementMetrics);
@@ -502,8 +485,7 @@ public class SesConfigurationSetController {
}
JsonNode guardian = node.path("GuardianOptions");
if (!guardian.isMissingNode() && !guardian.isNull()) {
- requireOptionObject(guardian);
- String optimized = parseOptionString(guardian.path("OptimizedSharedDelivery"), "OptimizedSharedDelivery");
+ String optimized = guardian.path("OptimizedSharedDelivery").textValue();
if (optimized != null) {
GuardianOptions g = new GuardianOptions();
g.setOptimizedSharedDelivery(optimized);
@@ -539,13 +521,14 @@ public class SesConfigurationSetController {
String body) {
String region = regionResolver.resolveRegion(headers);
try {
- JsonNode request = objectMapper.readTree(body);
+ JsonNode request = readOptionBody(objectMapper, body);
+ SesV2RequestShapes.check("CreateConfigurationSetEventDestination", request);
String edName = request.path("EventDestinationName").asText(null);
if (edName == null || edName.isBlank()) {
throw new AwsException("BadRequestException", "EventDestinationName is required.", 400);
}
JsonNode edNode = request.path("EventDestination");
- if (!edNode.isObject()) {
+ if (edNode.isMissingNode() || edNode.isNull()) {
throw new AwsException("BadRequestException", "EventDestination is required.", 400);
}
EventDestination dest = parseEventDestination(edNode);
@@ -587,9 +570,10 @@ public class SesConfigurationSetController {
String body) {
String region = regionResolver.resolveRegion(headers);
try {
- JsonNode request = objectMapper.readTree(body);
+ JsonNode request = readOptionBody(objectMapper, body);
+ SesV2RequestShapes.check("UpdateConfigurationSetEventDestination", request);
JsonNode edNode = request.path("EventDestination");
- if (!edNode.isObject()) {
+ if (edNode.isMissingNode() || edNode.isNull()) {
throw new AwsException("BadRequestException", "EventDestination is required.", 400);
}
EventDestination dest = parseEventDestination(edNode);
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
index 0fd9b1bc6b..a6f0491d28 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
@@ -140,11 +140,7 @@ final class SesV2Json {
if (node.isNull()) {
throw new AwsException("SerializationException", null, 400);
}
- if (node.isNumber()) {
- throw new AwsException("SerializationException",
- "NUMBER_VALUE can not be converted to a Boolean", 400);
- }
- throw unexpectedStartError(node);
+ throw scalarTypeError(node, "Boolean");
}
/**
@@ -313,36 +309,16 @@ final class SesV2Json {
}
/**
- * Parses a {@code SuppressedReasons} JSON array into a list, validating
- * structure only; reason values are validated by the service layer.
- * Structural violations reproduce the AWS deserialization-layer errors
- * (verified against real AWS SES V2 on 2026-06-13): a non-array node and
- * non-string scalar / container elements fail with
- * {@code SerializationException}, while {@code null} elements pass
- * deserialization and are rejected by the service-layer value validation,
- * exactly as AWS does. Missing / null yields an empty list for the PUT
- * path, which AWS treats as an explicit empty override.
+ * Reads a {@code SuppressedReasons} member whose type {@link SesV2RequestShapes} has already
+ * checked; reason values are validated by the service layer. A {@code null} element is kept, so
+ * that validation rejects it as AWS does (verified against real AWS SES V2 on 2026-06-13).
+ * Missing / null yields an empty list for the PUT path, which AWS treats as an explicit empty
+ * override.
*/
static List<String> parseSuppressedReasons(JsonNode reasonsNode) {
List<String> reasons = new ArrayList<>();
- if (!reasonsNode.isMissingNode() && !reasonsNode.isNull()) {
- if (!reasonsNode.isArray()) {
- throw new AwsException("SerializationException", "Expected list or null", 400);
- }
- for (JsonNode r : reasonsNode) {
- if (r.isTextual() || r.isNull()) {
- reasons.add(r.asText(null));
- } else if (r.isNumber()) {
- throw new AwsException("SerializationException",
- "NUMBER_VALUE can not be converted to a String", 400);
- } else if (r.isBoolean()) {
- throw new AwsException("SerializationException",
- (r.booleanValue() ? "TRUE_VALUE" : "FALSE_VALUE")
- + " can not be converted to a String", 400);
- } else {
- throw unexpectedStartError(r);
- }
- }
+ for (JsonNode r : reasonsNode) {
+ reasons.add(r.textValue());
}
return reasons;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java
index 12beb5a035..82ba815124 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2RequestShapes.java
@@ -14,6 +14,10 @@ import java.util.Map;
* {@code aws/sesv2-request-shapes.json}, generated from botocore's SES v2 model by
* {@code tools/aws/regen_sesv2_shapes.py}.
*
+ * <p>An operation calls this when its body nests a structure in a structure or holds a list of
+ * structures, where member-by-member checks drift apart. A flat body, a {@code Tags}-only body and
+ * a list operation's map {@code Filter} keep the {@link SesV2Json} member helpers.
+ *
* <p>AWS reads the body in order and reports the first bad member, without naming it. A JSON null
* counts as an absent member, a null list element is left to the operation's own validation, and
* a member the model does not know is ignored. A map container answers like a structure, as the
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetMemberTypeIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetMemberTypeIntegrationTest.java
new file mode 100644
index 0000000000..328b5c4216
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetMemberTypeIntegrationTest.java
@@ -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].");
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java
index 33672ce982..649adad9f7 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetV2IntegrationTest.java
@@ -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() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesSendMemberTypeIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesSendMemberTypeIntegrationTest.java
index 28acf5ce95..9fb0b8f5ee 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesSendMemberTypeIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesSendMemberTypeIntegrationTest.java
@@ -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 = "[email protected]";
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\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ConfigurationSetName\": 123,", SIMPLE),
NUMBER);
}
@Test
void v2SendEmail_numericRawData_namesTheBlobType() {
- assertSerializationException(SEND, send("\"FromEmailAddress\": \"[email protected]\",",
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\",",
"{\"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\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"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\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"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\": \"[email protected]\", "
- + "\"Destination\": \"" + TO + "\",", SIMPLE), "Expected null");
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ + "\"Destination\": \"" + TO + "\",", SIMPLE), EXPECTED_NULL);
}
@Test
void v2SendEmail_arrayDestination_returnsStartOfList() {
- assertSerializationException(SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"Destination\": [\"" + TO + "\"],", SIMPLE), LIST);
}
@Test
void v2SendEmail_nonArrayReplyTo_returnsExpectedList() {
- assertSerializationException(SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, "
+ "\"ReplyToAddresses\": \"[email protected]\",", SIMPLE), EXPECTED_LIST);
}
@Test
void v2SendEmail_nullReplyToElement_isAnInvalidAddress() {
- assertError(SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ assertError("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplyToAddresses\": [null],", SIMPLE),
"BadRequestException", "Invalid email address null.");
}
@Test
void v2SendEmail_nullAddressElementIsReportedAfterContentTypeErrors() {
- assertSerializationException(SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"ReplyToAddresses\": [null],",
"{\"Simple\": {\"Subject\": {\"Data\": 123}, \"Body\": {\"Text\": {\"Data\": \"b\"}}}}"), NUMBER);
}
@Test
void v2SendEmail_contentTypeErrorPrecedesEmailTagValidation() {
- assertSerializationException(SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ assertSerializationException("POST", SEND, send("\"FromEmailAddress\": \"[email protected]\", "
+ "\"EmailTags\": [{\"Name\": \"\", \"Value\": \"v\"}],",
"{\"Raw\": {\"Data\": 123}}"), "NUMBER_VALUE can not be converted to a Blob");
}
@Test
void v2SendBulkEmail_replyToTypeErrorPrecedesMissingSender() {
- assertSerializationException(BULK, bulkSend("\"ReplyToAddresses\": \"[email protected]\",",
+ assertSerializationException("POST", BULK, bulkSend("\"ReplyToAddresses\": \"[email protected]\",",
"{\"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\": \"[email protected]\",",
+ assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": \"[email protected]\",",
"[\"" + 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\": \"[email protected]\", "
+ assertSerializationException("POST", BULK, bulkSend("\"FromEmailAddress\": \"[email protected]\", "
+ "\"ReplyToAddresses\": [null],", "{\"ToAddresses\": [1]}"), NUMBER);
}
@Test
void v2SendBulkEmail_entryReplacementTypeErrorPrecedesMissingStoredTemplate() {
- assertSerializationException(BULK, """
+ assertSerializationException("POST", BULK, """
{
"FromEmailAddress": "[email protected]",
"DefaultContent": {"Template": {"TemplateName": "no-such-template", "TemplateData": "{}"}},
@@ -193,7 +175,7 @@ class SesSendMemberTypeIntegrationTest {
@Test
void v2SendBulkEmail_entryTypeErrorPrecedesMissingStoredTemplate() {
- assertSerializationException(BULK, """
+ assertSerializationException("POST", BULK, """
{
"FromEmailAddress": "[email protected]",
"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);
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
index b9ec876849..e3ed177a46 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2JsonTest.java
@@ -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
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2SerializationErrors.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2SerializationErrors.java
new file mode 100644
index 0000000000..f80039e2ee
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2SerializationErrors.java
@@ -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);
+ }
+}