mirror of
https://github.com/floci-io/floci.git
synced 2026-12-05 02:58:00 -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
+18
-34
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user