fix(ses): coerce a v2 boolean string only when it names a boolean (#4887)

SES v2 accepts a JSON string for a boolean member only when it reads,
case-insensitively, as true/yes/y/t/1 or false/no/n/f/0; any other string
is a SerializationException. Floci turned every string into true, so
UnsubscribeAll "false" stored true. Affects UnsubscribeAll, SendingEnabled
and AutoWarmupEnabled.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-02 09:47:03 -04:00
1 parent ae216f22a0
commit 5b6c53d0df
9 files changed
+73 -26

No files matched your search

@@ -193,7 +193,7 @@ class SesConfigurationSetSendingOptionsV2IntegrationTest {
@Test
@Order(13)
void putSendingOptions_stringSendingEnabled_coercesToTrue() {
// Real AWS coerces any string to true (200), matching CreateConfigurationSet. Verify the
// Real AWS coerces "yes" to true (200), matching CreateConfigurationSet. Verify the
// persisted value, not just the status — CS was disabled by @Order(12).
given()
.contentType("application/json")
@@ -458,7 +458,7 @@ class SesConfigurationSetV2IntegrationTest {
@Test
@Order(19)
void createConfigurationSet_stringSendingEnabled_coercesToTrue() {
// AWS accepts any string for SendingEnabled and stores true
// AWS accepts "yes" for SendingEnabled and stores true
// (verified against real AWS SES V2 on 2026-06-13).
given()
.contentType("application/json")
@@ -263,9 +263,9 @@ class SesContactV2IntegrationTest {
.body("__type", equalTo("BadRequestException"));
}
// Type coercion — verified against real AWS (Jackson-backed), consistent with parseSendingEnabled:
// a JSON string coerces to the Boolean UnsubscribeAll (any string -> true), but a number is a
// SerializationException; AttributesData (String) rejects non-string types the same way.
// Type coercion, verified against real AWS: a JSON string coerces to the Boolean UnsubscribeAll
// only when it names a boolean, and a number is a SerializationException; AttributesData
// (String) rejects non-string types the same way.
@Test
@Order(21)
@@ -296,13 +296,25 @@ class SesContactV2IntegrationTest {
@Test
@Order(24)
void createContact_unsubscribeAllString_coercesToTrue() {
// AWS coerces ANY JSON string to true for the Boolean field (unlike a number, which is rejected).
post(CONTACTS, "{\"EmailAddress\":\"type-d@example.com\",\"UnsubscribeAll\":\"no\"}")
void createContact_unsubscribeAllString_coercesByText() {
post(CONTACTS, "{\"EmailAddress\":\"type-d@example.com\",\"UnsubscribeAll\":\"yes\"}")
.then().statusCode(200);
given().header("Authorization", SES_AUTH)
.when().get(CONTACTS + "/type-d@example.com")
.then().statusCode(200).body("UnsubscribeAll", equalTo(true));
given().contentType("application/json").header("Authorization", SES_AUTH)
.body("{\"UnsubscribeAll\":\"no\"}")
.when().put(CONTACTS + "/type-d@example.com")
.then().statusCode(200);
given().header("Authorization", SES_AUTH)
.when().get(CONTACTS + "/type-d@example.com")
.then().statusCode(200).body("UnsubscribeAll", equalTo(false));
post(CONTACTS, "{\"EmailAddress\":\"type-e@example.com\",\"UnsubscribeAll\":\"abc\"}")
.then().statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("STRING_VALUE can not be converted to an Boolean"));
}
@Test
@@ -195,17 +195,32 @@ class SesDedicatedIpV2IntegrationTest {
@Test
@Order(15)
void putAccountAutoWarmup_stringCoercesToTrue() {
// AWS's Jackson layer coerces a JSON string to true for SES v2 booleans.
void putAccountAutoWarmup_stringCoercesByText() {
// SES v2 coerces a JSON string only when it names a boolean.
given().contentType("application/json").header("Authorization", AUTH_HEADER)
.body("{\"AutoWarmupEnabled\": \"nonsense\"}")
.body("{\"AutoWarmupEnabled\": \"no\"}")
.when().put("/v2/email/account/dedicated-ips/warmup")
.then().statusCode(200);
given().header("Authorization", AUTH_HEADER)
.when().get("/v2/email/account")
.then().statusCode(200)
.body("DedicatedIpAutoWarmupEnabled", equalTo(false));
given().contentType("application/json").header("Authorization", AUTH_HEADER)
.body("{\"AutoWarmupEnabled\": \"yes\"}")
.when().put("/v2/email/account/dedicated-ips/warmup")
.then().statusCode(200);
given().header("Authorization", AUTH_HEADER)
.when().get("/v2/email/account")
.then().statusCode(200)
.body("DedicatedIpAutoWarmupEnabled", equalTo(true));
given().contentType("application/json").header("Authorization", AUTH_HEADER)
.body("{\"AutoWarmupEnabled\": \"nonsense\"}")
.when().put("/v2/email/account/dedicated-ips/warmup")
.then().statusCode(400)
.body("__type", equalTo("SerializationException"))
.body("message", equalTo("STRING_VALUE can not be converted to an Boolean"));
}
@Test
@@ -130,13 +130,11 @@ class SesV2JsonTest {
}
@Test
void coerceBoolean_matchesAwsJacksonCoercion() {
void coerceBoolean_matchesAwsCoercion() {
JsonNode node = json(
"{\"t\":true,\"f\":false,\"s\":\"no\",\"z\":null,\"n\":0,\"a\":[],\"o\":{}}");
"{\"t\":true,\"f\":false,\"z\":null,\"n\":0,\"a\":[],\"o\":{}}");
assertTrue(SesV2Json.coerceBoolean(node.path("t")));
assertFalse(SesV2Json.coerceBoolean(node.path("f")));
// A JSON string coerces to true regardless of its text (probe-confirmed).
assertTrue(SesV2Json.coerceBoolean(node.path("s")));
assertNull(assertAws("SerializationException", 400,
() -> SesV2Json.coerceBoolean(node.path("z"))).getMessage());
assertEquals("NUMBER_VALUE can not be converted to a Boolean",
@@ -150,6 +148,22 @@ class SesV2JsonTest {
() -> SesV2Json.coerceBoolean(node.path("o"))).getMessage());
}
@Test
void coerceBoolean_coercesOnlyStringsThatNameABoolean() {
// Probe-confirmed: the match is case-insensitive and exact, so padding is not trimmed.
for (String text : List.of("true", "TRUE", "Yes", "y", "T", "1")) {
assertTrue(SesV2Json.coerceBoolean(json("\"" + text + "\"")), text);
}
for (String text : List.of("false", "FALSE", "No", "n", "F", "0")) {
assertFalse(SesV2Json.coerceBoolean(json("\"" + text + "\"")), text);
}
for (String text : List.of("abc", "", "on", "off", " true", "2")) {
assertEquals("STRING_VALUE can not be converted to an Boolean",
assertAws("SerializationException", 400,
() -> SesV2Json.coerceBoolean(json("\"" + text + "\""))).getMessage(), text);
}
}
@Test
void unexpectedStartError_distinguishesListFromStructure() {
assertEquals("Start of list found where not expected",
@@ -229,6 +243,7 @@ class SesV2JsonTest {
assertFalse(SesV2Json.parseSendingEnabled(json("{}").path("SendingEnabled")));
assertTrue(SesV2Json.parseSendingEnabled(json("true")));
assertTrue(SesV2Json.parseSendingEnabled(json("\"yes\"")));
assertFalse(SesV2Json.parseSendingEnabled(json("\"no\"")));
assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("null")));
assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("0")));
}