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

@@ -320,4 +320,348 @@ class SesConfigurationSetV2IntegrationTest {
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"))
.body("Tags.find { it.Key == 'env' }.Value", equalTo("stg"));
}
@Test
@Order(17)
void createConfigurationSet_inlineOptions_echoedOnGet() {
// AWS echoes inline options set at create time verbatim
// (verified against real AWS SES V2 on 2026-06-12).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-inline-options",
"SendingOptions": {"SendingEnabled": false},
"SuppressionOptions": {"SuppressedReasons": ["BOUNCE"]}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-inline-options")
.then()
.statusCode(200)
.body("SendingOptions.SendingEnabled", equalTo(false))
.body("SuppressionOptions.SuppressedReasons", hasSize(1))
.body("SuppressionOptions.SuppressedReasons", hasItem("BOUNCE"));
}
@Test
@Order(18)
void createConfigurationSet_invalidSuppressionReason_rejectedWithoutCreating() {
// Unlike PutConfigurationSetSuppressionOptions, AWS reports the
// constraint-style validation message on this endpoint, even for
// multiple invalid values (verified against real AWS SES V2 on
// 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-bad-reason",
"SuppressionOptions": {"SuppressedReasons": ["INVALID"]}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("1 validation error detected: Value at "
+ "'suppressionOptions.suppressedReasons' failed to satisfy constraint: "
+ "Member must satisfy constraint: "
+ "[Member must satisfy enum value set: [BOUNCE, COMPLAINT]]"));
// Validation happens before the store write, so the set must not exist.
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-bad-reason")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"));
}
@Test
@Order(19)
void createConfigurationSet_stringSendingEnabled_coercesToTrue() {
// AWS accepts any string for SendingEnabled and stores true
// (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-string-sending",
"SendingOptions": {"SendingEnabled": "yes"}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-string-sending")
.then()
.statusCode(200)
.body("SendingOptions.SendingEnabled", equalTo(true));
}
@Test
@Order(20)
void createConfigurationSet_emptySendingOptions_defaultsToFalse() {
// AWS treats a missing SendingEnabled member inside a present
// SendingOptions block as false, unlike a fully absent block which
// defaults to true (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-empty-sending",
"SendingOptions": {}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-empty-sending")
.then()
.statusCode(200)
.body("SendingOptions.SendingEnabled", equalTo(false));
}
@Test
@Order(21)
void createConfigurationSet_nullSendingEnabled_serializationError() {
// Explicit null fails AWS deserialization with a null message and the
// set is not created (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-null-sending",
"SendingOptions": {"SendingEnabled": null}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-null-sending")
.then()
.statusCode(404);
}
@Test
@Order(22)
void createConfigurationSet_numberSendingEnabled_serializationError() {
// Verified against real AWS SES V2 on 2026-06-13.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-number-sending",
"SendingOptions": {"SendingEnabled": 1}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("NUMBER_VALUE can not be converted to a Boolean"));
}
@Test
@Order(23)
void createConfigurationSet_missingSuppressedReasons_internalFailure() {
// AWS itself returns 500 InternalFailure when SuppressionOptions is
// present without SuppressedReasons, and the set is not created;
// reproduced faithfully (verified against real AWS SES V2 on
// 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-empty-suppression",
"SuppressionOptions": {}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(500)
.body("__type", equalTo("InternalFailure"))
.body("message", equalTo("An internal failure has occurred."));
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-empty-suppression")
.then()
.statusCode(404);
}
@Test
@Order(24)
void createConfigurationSet_nonArraySuppressedReasons_serializationError() {
// Verified against real AWS SES V2 on 2026-06-13.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-string-reasons",
"SuppressionOptions": {"SuppressedReasons": "BOUNCE"}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("Expected list or null"));
}
@Test
@Order(25)
void createConfigurationSet_emptySuppressedReasonsList_echoedOnGet() {
// An explicit empty list is stored and echoed as-is
// (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-empty-reasons",
"SuppressionOptions": {"SuppressedReasons": []}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-empty-reasons")
.then()
.statusCode(200)
.body("SuppressionOptions.SuppressedReasons", hasSize(0));
}
@Test
@Order(26)
void createConfigurationSet_nullSuppressedReason_rejectedWithPutStyleMessage() {
// A null element passes AWS deserialization ("Expected list or null")
// and fails value validation with the natural-language sentence, not
// the constraint-style message used for invalid non-null values
// (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-null-reason",
"SuppressionOptions": {"SuppressedReasons": ["BOUNCE", null]}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("Reason null is invalid, must be one of [BOUNCE, COMPLAINT]."));
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-null-reason")
.then()
.statusCode(404);
}
@Test
@Order(27)
void createConfigurationSet_booleanSuppressedReason_serializationError() {
// Verified against real AWS SES V2 on 2026-06-13.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-boolean-reason",
"SuppressionOptions": {"SuppressedReasons": [false]}
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("FALSE_VALUE can not be converted to a String"));
}
@Test
@Order(28)
void createConfigurationSet_nonObjectOptionBlocks_serializationError() {
// "Expected null" looks odd but is the verbatim AWS response for a
// non-object option block (verified against real AWS SES V2 on
// 2026-06-13).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-string-suppression",
"SuppressionOptions": "nope"
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("Expected null"));
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"ConfigurationSetName": "v2-cs-string-options",
"SendingOptions": "nope"
}
""")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("Expected null"));
}
}