Skip to content

armgit / floci

Public Imported from GitHub
0

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

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

Kenshin Okinaka5b6c53d0dfd3
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
index 827bf50bdd..b64542c9ce 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
@@ -226,7 +226,7 @@ public class SesAccountController {
JsonNode enabledNode = request.path("AutoWarmupEnabled");
// AutoWarmupEnabled has a default of false: the SDK omits it when false, so a missing
// member is treated as false rather than rejected. A present value goes through the
- // shared SES v2 boolean coercion (string→true, null/number/container→SerializationException).
+ // shared SES v2 boolean coercion.
boolean enabled = enabledNode.isMissingNode() ? false : coerceBoolean(enabledNode);
accountService.setDedicatedIpAutoWarmup(region, enabled);
LOG.infov("SES V2 PutAccountDedicatedIpWarmupAttributes: {0}", enabled);
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 5844fd8364..69b1ac287d 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
@@ -238,8 +238,8 @@ public class SesConfigurationSetController {
String region = regionResolver.resolveRegion(headers);
try {
// Reuse the AWS-aligned SendingEnabled deserialization shared with CreateConfigurationSet:
- // absent -> false, string -> true, null/number -> SerializationException. An empty body
- // / {} therefore disables sending (200). Verified against real AWS.
+ // absent -> false, otherwise SesV2Json.coerceBoolean. An empty body / {} therefore
+ // disables sending (200). Verified against real AWS.
boolean enabled = parseSendingEnabled(
readOptionBody(objectMapper, body).path("SendingEnabled"));
configSetService.setSendingEnabled(name, enabled, region);
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java
index 58bf01479b..5cbbc8c873 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactController.java
@@ -315,8 +315,7 @@ public class SesContactController {
}
// UnsubscribeAll is a Boolean; AWS coerces it the same way as any other SES v2 boolean
- // (see parseSendingEnabled): a JSON string coerces to true, a number/null/array/object is a
- // SerializationException. Absent leaves it unset.
+ // (see coerceBoolean). Absent leaves it unset.
private static Boolean parseUnsubscribeAll(JsonNode request) {
if (!request.has("UnsubscribeAll")) {
return null;
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 c776fb55ee..90d3122bfe 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
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.ses.model.Tag;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
/**
* Helpers shared by the SES v2 REST JSON controllers: body and member shape checks that answer
@@ -119,14 +120,20 @@ final class SesV2Json {
return node.asText();
}
- // AWS-verified Jackson coercion for a SES v2 boolean field: a JSON string coerces to true,
- // while a number/null/array/object is a SerializationException.
+ // AWS-verified coercion for a SES v2 boolean field: a JSON string coerces only when it names a
+ // boolean (case-insensitive, untrimmed); any other string, a number, null, an array or an object
+ // is a SerializationException.
static boolean coerceBoolean(JsonNode node) {
if (node.isBoolean()) {
return node.booleanValue();
}
if (node.isTextual()) {
- return true;
+ return switch (node.textValue().toLowerCase(Locale.ROOT)) {
+ case "true", "yes", "y", "t", "1" -> true;
+ case "false", "no", "n", "f", "0" -> false;
+ default -> throw new AwsException("SerializationException",
+ "STRING_VALUE can not be converted to an Boolean", 400);
+ };
}
if (node.isNull()) {
throw new AwsException("SerializationException", null, 400);
@@ -241,9 +248,8 @@ final class SesV2Json {
/**
* 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}.
+ * defaults to {@code false}, and a present value goes through
+ * {@link #coerceBoolean(JsonNode)}.
*/
static boolean parseSendingEnabled(JsonNode enabledNode) {
if (enabledNode.isMissingNode()) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSendingOptionsV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSendingOptionsV2IntegrationTest.java
index 316e7aed08..80805c3a79 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSendingOptionsV2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSendingOptionsV2IntegrationTest.java
@@ -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")
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 ff12bc0f7f..09a24fdd83 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
@@ -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")
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java
index 90bf9efd54..9c70ce7272 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesContactV2IntegrationTest.java
@@ -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\":\"[email protected]\",\"UnsubscribeAll\":\"no\"}")
+ void createContact_unsubscribeAllString_coercesByText() {
+ post(CONTACTS, "{\"EmailAddress\":\"[email protected]\",\"UnsubscribeAll\":\"yes\"}")
.then().statusCode(200);
given().header("Authorization", SES_AUTH)
.when().get(CONTACTS + "/[email protected]")
.then().statusCode(200).body("UnsubscribeAll", equalTo(true));
+
+ given().contentType("application/json").header("Authorization", SES_AUTH)
+ .body("{\"UnsubscribeAll\":\"no\"}")
+ .when().put(CONTACTS + "/[email protected]")
+ .then().statusCode(200);
+ given().header("Authorization", SES_AUTH)
+ .when().get(CONTACTS + "/[email protected]")
+ .then().statusCode(200).body("UnsubscribeAll", equalTo(false));
+
+ post(CONTACTS, "{\"EmailAddress\":\"[email protected]\",\"UnsubscribeAll\":\"abc\"}")
+ .then().statusCode(400)
+ .body("__type", equalTo("SerializationException"))
+ .body("message", equalTo("STRING_VALUE can not be converted to an Boolean"));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpV2IntegrationTest.java
index 330944faaa..8da832c898 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpV2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpV2IntegrationTest.java
@@ -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
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 fc86fe17c9..d3843a65c1 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
@@ -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")));
}