fix(ses): persist inline options on v2 CreateConfigurationSet (#1307)

* fix(ses): persist inline options on v2 CreateConfigurationSet

CreateConfigurationSet parsed only ConfigurationSetName and Tags,
silently dropping the SendingOptions and SuppressionOptions blocks of
the request. GetConfigurationSet then fabricated a default
SendingOptions ("SendingEnabled": true via the null-means-enabled
effective getter), so a set created with SendingEnabled: false read
back as true, and SuppressedReasons vanished entirely. Real AWS echoes
both blocks verbatim (verified live 2026-06-12).

The controller now parses both blocks onto the ConfigurationSet before
the single store write, with the same structural validation as the
dedicated PUT endpoints (non-object blocks, non-boolean SendingEnabled
and non-string reasons are rejected with BadRequestException). The
service validates suppression reason values at create alongside the
existing tag validation, so an invalid reason rejects the request
without leaving a half-created set behind. The SuppressedReasons
structural parsing is shared with PutConfigurationSetSuppressionOptions
via a common helper.

The remaining five inline option groups (Tracking / Delivery /
Reputation / Vdm / Archiving) have no model fields or endpoints yet
and stay out of scope.

* fix(ses): match AWS error layers on v2 CreateConfigurationSet options

Live verification against real AWS SES V2 (2026-06-13) showed the
endpoint validates inline options in two layers that the previous
commit conflated into BadRequestException:

- Type violations fail in the deserialization layer with
  SerializationException: non-object option blocks ("Expected null"),
  a non-array SuppressedReasons ("Expected list or null"), and
  non-string reason elements / non-boolean scalars for SendingEnabled
  (token-style messages such as "NUMBER_VALUE can not be converted to
  a String").
- Value violations fail in the validation layer with
  BadRequestException using the constraint-style message ("1 validation
  error detected: ..."), which differs from the natural-language
  sentence the PUT endpoint uses for the same check.

SendingEnabled itself follows AWS deserialization semantics: a missing
member inside a present SendingOptions block defaults to false, any
string coerces to true, and an explicit null fails with a null-message
SerializationException. SuppressionOptions without SuppressedReasons
reproduces the 500 InternalFailure AWS itself returns, so code
developed against Floci fails the same way it would in production.

* fix(ses): align null suppressed-reason handling with AWS on v2 create

Live verification (2026-06-13) shows AWS lets a null element pass the
SuppressedReasons deserialization ("Expected list or null") and rejects
it in value validation with the same natural-language sentence the PUT
endpoint uses, not the constraint-style message reported for invalid
non-null values. CreateConfigurationSet now branches accordingly, the
parsing helper's javadoc documents the intentional null pass-through,
and the FALSE_VALUE token message is covered by a test now that it is
verified rather than inferred.

* fix(ses): make null suppressed-reason branch explicit on v2 create

The null check relied on validateConfigSetSuppressionReason always
throwing, which would silently fall through to the constraint-style
message if that method ever changed. The branch now throws directly,
with the sentence shared through a message helper. Also locks the
verbatim AWS "Expected null" response for non-object option blocks
into a test so the surprising message does not get "fixed" later.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-06-13 01:48:13 -05:00
1 parent ceb4d84431
commit 161a6ba7e0
3 files changed
+469 -18

No files matched your search

@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.MessageHeader;
import io.github.hectorvent.floci.services.ses.model.MessageTag;
import io.github.hectorvent.floci.services.ses.model.SuppressedDestination;
import io.github.hectorvent.floci.services.ses.model.SuppressionOptions;
import io.github.hectorvent.floci.services.ses.model.Tag;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -609,6 +610,27 @@ public class SesController {
if (parsedTags != null) {
cs.setTags(parsedTags);
}
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",
"An internal failure has occurred.", 500);
}
SuppressionOptions options = new SuppressionOptions();
options.setSuppressedReasons(parseSuppressedReasons(reasonsNode));
cs.setSuppressionOptions(options);
}
JsonNode sendingNode = request.path("SendingOptions");
if (!sendingNode.isMissingNode() && !sendingNode.isNull()) {
if (!sendingNode.isObject()) {
throw new AwsException("SerializationException", "Expected null", 400);
}
cs.setSendingEnabled(parseSendingEnabled(sendingNode.path("SendingEnabled")));
}
sesService.createConfigurationSet(cs, region);
LOG.infov("SES V2 CreateConfigurationSet: {0}", name);
return Response.ok(objectMapper.createObjectNode()).build();
@@ -674,21 +696,7 @@ public class SesController {
? objectMapper.createObjectNode()
: objectMapper.readTree(body);
requireJsonObject(request);
JsonNode reasonsNode = request.path("SuppressedReasons");
List<String> reasons = new ArrayList<>();
if (!reasonsNode.isMissingNode() && !reasonsNode.isNull()) {
if (!reasonsNode.isArray()) {
throw new AwsException("BadRequestException",
"SuppressedReasons must be an array.", 400);
}
for (JsonNode r : reasonsNode) {
if (r.isNull() || !r.isTextual()) {
throw new AwsException("BadRequestException",
"SuppressedReasons entries must be strings.", 400);
}
reasons.add(r.asText());
}
}
List<String> reasons = parseSuppressedReasons(request.path("SuppressedReasons"));
sesService.putConfigurationSetSuppressionOptions(name, reasons, region);
LOG.infov("SES V2 PutConfigurationSetSuppressionOptions: {0} on {1}", reasons, name);
return Response.ok(objectMapper.createObjectNode()).build();
@@ -1267,6 +1275,77 @@ public class SesController {
return out;
}
/**
* 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.
*/
private 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);
}
}
}
return reasons;
}
/**
* Reproduces the AWS deserialization behavior for {@code SendingEnabled}
* (verified against real AWS SES V2 on 2026-06-13): a missing member
* defaults to {@code false}, any string coerces to {@code true}, and
* explicit {@code null} or non-boolean scalars fail with
* {@code SerializationException}.
*/
private static boolean parseSendingEnabled(JsonNode enabledNode) {
if (enabledNode.isMissingNode()) {
return false;
}
if (enabledNode.isBoolean()) {
return enabledNode.booleanValue();
}
if (enabledNode.isTextual()) {
return true;
}
if (enabledNode.isNull()) {
throw new AwsException("SerializationException", null, 400);
}
if (enabledNode.isNumber()) {
throw new AwsException("SerializationException",
"NUMBER_VALUE can not be converted to a Boolean", 400);
}
throw unexpectedStartError(enabledNode);
}
private static AwsException unexpectedStartError(JsonNode node) {
if (node.isArray()) {
return new AwsException("SerializationException",
"Start of list found where not expected", 400);
}
return new AwsException("SerializationException",
"Start of structure or map found where not expected.", 400);
}
/**
* Parse a V2 SES {@code Content.Simple.Headers} / {@code Content.Template.Headers} array
* (additional message headers, elements use {@code Name}/{@code Value}). Returns an empty
@@ -626,6 +626,23 @@ public class SesService {
validateTag(tag);
}
}
if (configSet.getSuppressionOptions() != null
&& configSet.getSuppressionOptions().getSuppressedReasons() != null) {
for (String reason : configSet.getSuppressionOptions().getSuppressedReasons()) {
if (reason == null) {
throw new AwsException("BadRequestException",
invalidSuppressionReasonMessage(null), 400);
}
if (!isValidConfigSetSuppressionReason(reason)) {
throw new AwsException("BadRequestException",
"1 validation error detected: Value at "
+ "'suppressionOptions.suppressedReasons' failed to satisfy "
+ "constraint: Member must satisfy constraint: "
+ "[Member must satisfy enum value set: [BOUNCE, COMPLAINT]]",
400);
}
}
}
if (configSetStore.get(key).isPresent()) {
throw new AwsException("ConfigurationSetAlreadyExists",
"Configuration set " + configSet.getName() + " already exists.", 400);
@@ -1336,15 +1353,26 @@ public class SesService {
* V2 SES uses a different, simpler natural-language sentence on this
* endpoint than on the three older suppression APIs above:
* "Reason <X> is invalid, must be one of [BOUNCE, COMPLAINT]."
* (Verified against real AWS V2 SES on 2026-06-03.)
* (Verified against real AWS V2 SES on 2026-06-03.) CreateConfigurationSet
* reports the constraint-style validation message for invalid non-null
* values but falls back to this sentence for null elements, matching AWS
* (verified 2026-06-13); see {@link #createConfigurationSet}.
*/
private static void validateConfigSetSuppressionReason(String reason) {
if (reason == null || (!"BOUNCE".equals(reason) && !"COMPLAINT".equals(reason))) {
if (!isValidConfigSetSuppressionReason(reason)) {
throw new AwsException("BadRequestException",
"Reason " + reason + " is invalid, must be one of [BOUNCE, COMPLAINT].", 400);
invalidSuppressionReasonMessage(reason), 400);
}
}
private static boolean isValidConfigSetSuppressionReason(String reason) {
return "BOUNCE".equals(reason) || "COMPLAINT".equals(reason);
}
private static String invalidSuppressionReasonMessage(String reason) {
return "Reason " + reason + " is invalid, must be one of [BOUNCE, COMPLAINT].";
}
static void validateTag(Tag tag) {
if (tag == null) {
throw new AwsException("InvalidParameterValue", "Tag must not be null.", 400);