mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ses): apply the v2 boolean coercion to the remaining boolean members (#4944)
* fix(ses): apply the v2 boolean coercion to the remaining boolean members SigningEnabled, EmailForwardingEnabled, ReputationMetricsEnabled, an event destination's Enabled, the account SendingEnabled and ProductionAccessEnabled now coerce a JSON string the way SES v2 does instead of rejecting it with an error of Floci's own. SigningEnabled, EmailForwardingEnabled and the account SendingEnabled also accept a missing member as false, as SES v2 does, where Floci required it. * test(ses): create the event destination with "yes" so the create path is checked * fix(ses): default a create-time ReputationMetricsEnabled to false when ReputationOptions omits it
This commit is contained in:
1 parent
02b0a3f536
commit
3597afda07
8 files changed
+227
-104
No files matched your search
@@ -26,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBoolean;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
|
||||
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;
|
||||
@@ -197,10 +198,8 @@ public class SesAccountController {
|
||||
}
|
||||
}
|
||||
JsonNode productionAccess = request.path("ProductionAccessEnabled");
|
||||
if (!productionAccess.isMissingNode() && !productionAccess.isNull() && !productionAccess.isBoolean()) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
boolean productionAccessEnabled = productionAccess.asBoolean(false);
|
||||
boolean productionAccessEnabled = !productionAccess.isMissingNode() && !productionAccess.isNull()
|
||||
&& coerceBoolean(productionAccess);
|
||||
|
||||
// The service owns validation and the synthetic review/case so they can't be bypassed; the
|
||||
// controller only parses the REST JSON and rejects wrong JSON types.
|
||||
@@ -227,7 +226,7 @@ public class SesAccountController {
|
||||
// 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.
|
||||
boolean enabled = enabledNode.isMissingNode() ? false : coerceBoolean(enabledNode);
|
||||
boolean enabled = coerceBooleanOrFalse(enabledNode);
|
||||
accountService.setDedicatedIpAutoWarmup(region, enabled);
|
||||
LOG.infov("SES V2 PutAccountDedicatedIpWarmupAttributes: {0}", enabled);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
@@ -274,13 +273,9 @@ public class SesAccountController {
|
||||
public Response putAccountSendingAttributes(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode sendingEnabledNode = request.get("SendingEnabled");
|
||||
if (sendingEnabledNode == null || !sendingEnabledNode.isBoolean()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SendingEnabled must be present and must be a boolean", 400);
|
||||
}
|
||||
accountService.setAccountSendingEnabled(region, sendingEnabledNode.booleanValue());
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
accountService.setAccountSendingEnabled(region,
|
||||
coerceBooleanOrFalse(request.path("SendingEnabled")));
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
|
||||
+18
-22
@@ -36,8 +36,8 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseOptionString;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseSendingEnabled;
|
||||
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;
|
||||
@@ -107,15 +107,13 @@ public class SesConfigurationSetController {
|
||||
if (!sendingNode.isObject()) {
|
||||
throw new AwsException("SerializationException", "Expected null", 400);
|
||||
}
|
||||
cs.setSendingEnabled(parseSendingEnabled(sendingNode.path("SendingEnabled")));
|
||||
cs.setSendingEnabled(coerceBooleanOrFalse(sendingNode.path("SendingEnabled")));
|
||||
}
|
||||
JsonNode reputationNode = request.path("ReputationOptions");
|
||||
if (!reputationNode.isMissingNode() && !reputationNode.isNull()) {
|
||||
requireOptionObject(reputationNode);
|
||||
Boolean rme = parseReputationMetricsEnabled(reputationNode.path("ReputationMetricsEnabled"));
|
||||
if (rme != null) {
|
||||
cs.setReputationMetricsEnabled(rme);
|
||||
}
|
||||
cs.setReputationMetricsEnabled(
|
||||
coerceBooleanOrFalse(reputationNode.path("ReputationMetricsEnabled")));
|
||||
}
|
||||
JsonNode trackingNode = request.path("TrackingOptions");
|
||||
if (!trackingNode.isMissingNode() && !trackingNode.isNull()) {
|
||||
@@ -240,7 +238,7 @@ public class SesConfigurationSetController {
|
||||
// Reuse the AWS-aligned SendingEnabled deserialization shared with CreateConfigurationSet:
|
||||
// absent -> false, otherwise SesV2Json.coerceBoolean. An empty body / {} therefore
|
||||
// disables sending (200). Verified against real AWS.
|
||||
boolean enabled = parseSendingEnabled(
|
||||
boolean enabled = coerceBooleanOrFalse(
|
||||
readOptionBody(objectMapper, body).path("SendingEnabled"));
|
||||
configSetService.setSendingEnabled(name, enabled, region);
|
||||
LOG.infov("SES V2 PutConfigurationSetSendingOptions: {0} on {1}", enabled, name);
|
||||
@@ -258,10 +256,9 @@ public class SesConfigurationSetController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
Boolean enabled = parseReputationMetricsEnabled(request.path("ReputationMetricsEnabled"));
|
||||
boolean effectiveEnabled = enabled != null && enabled;
|
||||
configSetService.setReputationMetricsEnabled(name, effectiveEnabled, region);
|
||||
LOG.infov("SES V2 PutConfigurationSetReputationOptions: {0} on {1}", effectiveEnabled, name);
|
||||
boolean enabled = coerceBooleanOrFalse(request.path("ReputationMetricsEnabled"));
|
||||
configSetService.setReputationMetricsEnabled(name, enabled, region);
|
||||
LOG.infov("SES V2 PutConfigurationSetReputationOptions: {0} on {1}", enabled, name);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
@@ -342,15 +339,14 @@ public class SesConfigurationSetController {
|
||||
}
|
||||
}
|
||||
|
||||
private static Boolean parseReputationMetricsEnabled(JsonNode node) {
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
return null;
|
||||
}
|
||||
if (!node.isBoolean()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"ReputationMetricsEnabled must be a boolean.", 400);
|
||||
}
|
||||
return node.booleanValue();
|
||||
// Enabled takes the shared SES v2 boolean coercion, which Jackson's own binding does not match.
|
||||
private EventDestination parseEventDestination(JsonNode edNode) throws JsonProcessingException {
|
||||
boolean enabled = coerceBooleanOrFalse(edNode.path("Enabled"));
|
||||
ObjectNode withoutEnabled = edNode.deepCopy();
|
||||
withoutEnabled.remove("Enabled");
|
||||
EventDestination dest = objectMapper.treeToValue(withoutEnabled, EventDestination.class);
|
||||
dest.setEnabled(enabled);
|
||||
return dest;
|
||||
}
|
||||
|
||||
private static TrackingOptions parseTrackingOptions(JsonNode node) {
|
||||
@@ -460,7 +456,7 @@ public class SesConfigurationSetController {
|
||||
if (!edNode.isObject()) {
|
||||
throw new AwsException("BadRequestException", "EventDestination is required.", 400);
|
||||
}
|
||||
EventDestination dest = objectMapper.treeToValue(edNode, EventDestination.class);
|
||||
EventDestination dest = parseEventDestination(edNode);
|
||||
configSetService.createEventDestination(configurationSetName, edName, dest,
|
||||
regionResolver.getAccountId(), region);
|
||||
LOG.infov("SES V2 CreateConfigurationSetEventDestination: {0} on {1}", edName, configurationSetName);
|
||||
@@ -504,7 +500,7 @@ public class SesConfigurationSetController {
|
||||
if (!edNode.isObject()) {
|
||||
throw new AwsException("BadRequestException", "EventDestination is required.", 400);
|
||||
}
|
||||
EventDestination dest = objectMapper.treeToValue(edNode, EventDestination.class);
|
||||
EventDestination dest = parseEventDestination(edNode);
|
||||
configSetService.updateEventDestination(configurationSetName, eventDestinationName,
|
||||
dest, regionResolver.getAccountId(), region);
|
||||
LOG.infov("SES V2 UpdateConfigurationSetEventDestination: {0} on {1}",
|
||||
|
||||
@@ -29,8 +29,10 @@ import org.jboss.logging.Logger;
|
||||
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.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
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.requireObjectOrAbsent;
|
||||
@@ -266,13 +268,8 @@ public class SesIdentityController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode signingEnabledNode = request.get("SigningEnabled");
|
||||
if (signingEnabledNode == null || !signingEnabledNode.isBoolean()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"SigningEnabled must be present and must be a boolean", 400);
|
||||
}
|
||||
boolean signingEnabled = signingEnabledNode.booleanValue();
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
boolean signingEnabled = coerceBooleanOrFalse(request.path("SigningEnabled"));
|
||||
identityService.setDkimAttributes(emailIdentity, signingEnabled, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -376,13 +373,8 @@ public class SesIdentityController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode emailForwardingEnabledNode = request.get("EmailForwardingEnabled");
|
||||
if (emailForwardingEnabledNode == null || !emailForwardingEnabledNode.isBoolean()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"EmailForwardingEnabled must be present and must be a boolean", 400);
|
||||
}
|
||||
boolean emailForwardingEnabled = emailForwardingEnabledNode.booleanValue();
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
boolean emailForwardingEnabled = coerceBooleanOrFalse(request.path("EmailForwardingEnabled"));
|
||||
identityService.setFeedbackForwardingEnabled(emailIdentity, emailForwardingEnabled,
|
||||
region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
|
||||
@@ -246,12 +246,13 @@ 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}, and a present value goes through
|
||||
* {@link #coerceBoolean(JsonNode)}.
|
||||
* An optional SES v2 boolean member whose absence means {@code false}: a missing member is
|
||||
* {@code false}, and a present value, {@code null} included, goes through
|
||||
* {@link #coerceBoolean(JsonNode)}. AWS-verified for the account's and a configuration set's
|
||||
* SendingEnabled, SigningEnabled, EmailForwardingEnabled, ReputationMetricsEnabled and an event
|
||||
* destination's Enabled.
|
||||
*/
|
||||
static boolean parseSendingEnabled(JsonNode enabledNode) {
|
||||
static boolean coerceBooleanOrFalse(JsonNode enabledNode) {
|
||||
if (enabledNode.isMissingNode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user