Light, fluffy, and always free - The AWS Local Emulator alternative
refactor(ses): split the account endpoints into SesAccountController (#3782)
Kenshin Okinaka3f10acdb9563
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.javaindex b961ea53aa..281c1b6a51 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java@@ -33,6 +33,7 @@ import io.github.hectorvent.floci.services.oam.OamController;import io.github.hectorvent.floci.services.cloudfront.CloudFrontController;import io.github.hectorvent.floci.services.cloudfront.CloudFrontServingController;import io.github.hectorvent.floci.services.route53.Route53Controller;+import io.github.hectorvent.floci.services.ses.SesAccountController;import io.github.hectorvent.floci.services.ses.SesContactController;import io.github.hectorvent.floci.services.ses.SesController;import io.github.hectorvent.floci.services.ses.SesCvetController;@@ -290,9 +291,9 @@ public class ResolvedServiceCatalog {"ses", config.storage().mode(), 5000L, AwsNamespaces.SES, ServiceProtocol.REST_JSON,protocols(ServiceProtocol.REST_JSON, ServiceProtocol.QUERY),Set.of(), Set.of("email", "ses", "sesv2"), Set.of(),- Set.of(SesController.class, SesContactController.class,- SesCvetController.class, SesDedicatedIpController.class,- SesTemplateController.class)),+ Set.of(SesController.class, SesAccountController.class,+ SesContactController.class, SesCvetController.class,+ SesDedicatedIpController.class, SesTemplateController.class)),descriptor("es", "opensearch", config.services().opensearch().enabled(), true,"opensearch", storageMode(config.storage().services().opensearch().mode(), config.storage().mode()),config.storage().services().opensearch().flushIntervalMs(), null, ServiceProtocol.REST_JSON,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.javanew file mode 100644index 0000000000..2f98a05210--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java@@ -0,0 +1,323 @@+package io.github.hectorvent.floci.services.ses;++import com.fasterxml.jackson.core.JsonProcessingException;+import com.fasterxml.jackson.databind.JsonNode;+import com.fasterxml.jackson.databind.ObjectMapper;+import com.fasterxml.jackson.databind.node.ArrayNode;+import com.fasterxml.jackson.databind.node.ObjectNode;+import io.github.hectorvent.floci.core.common.AwsException;+import io.github.hectorvent.floci.core.common.RegionResolver;+import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;+import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;+import jakarta.inject.Inject;+import jakarta.ws.rs.Consumes;+import jakarta.ws.rs.GET;+import jakarta.ws.rs.POST;+import jakarta.ws.rs.PUT;+import jakarta.ws.rs.Path;+import jakarta.ws.rs.Produces;+import jakarta.ws.rs.core.Context;+import jakarta.ws.rs.core.HttpHeaders;+import jakarta.ws.rs.core.MediaType;+import jakarta.ws.rs.core.Response;+import org.jboss.logging.Logger;++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.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;+import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;++/**+ * SES V2 account-level endpoints ({@code /v2/email/account}), split out of {@link SesController}.+ * The settings live in {@link SesAccountService}; {@code GetAccount} also reads the account+ * suppression attributes from {@link SesSuppressionService} and the sent-mail count from+ * {@link SesSentEmailService}, a read-only composition that needs no facade orchestration, so this+ * controller does not depend on {@link SesService}.+ */+@Path("/v2/email")+@Produces(MediaType.APPLICATION_JSON)+@Consumes(MediaType.APPLICATION_JSON)+public class SesAccountController {++ private static final Logger LOG = Logger.getLogger(SesAccountController.class);++ private final SesAccountService accountService;+ private final SesSuppressionService suppressionService;+ private final SesSentEmailService sentEmailService;+ private final RegionResolver regionResolver;+ private final ObjectMapper objectMapper;++ @Inject+ public SesAccountController(SesAccountService accountService,+ SesSuppressionService suppressionService,+ SesSentEmailService sentEmailService,+ RegionResolver regionResolver, ObjectMapper objectMapper) {+ this.accountService = accountService;+ this.suppressionService = suppressionService;+ this.sentEmailService = sentEmailService;+ this.regionResolver = regionResolver;+ this.objectMapper = objectMapper;+ }++ @GET+ @Path("/account")+ public Response getAccount(@Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ long sentCount = sentEmailService.countInRegion(region);+ boolean sendingEnabled = accountService.isAccountSendingEnabled(region);+ AccountSuppressionAttributes suppression =+ suppressionService.getAccountSuppressionAttributes(region);++ ObjectNode result = objectMapper.createObjectNode();+ result.put("DedicatedIpAutoWarmupEnabled",+ accountService.isDedicatedIpAutoWarmupEnabled(region));+ result.put("EnforcementStatus", "HEALTHY");+ result.put("ProductionAccessEnabled", true);+ result.put("SendingEnabled", sendingEnabled);++ ObjectNode sendQuota = result.putObject("SendQuota");+ sendQuota.put("Max24HourSend", 200.0);+ sendQuota.put("MaxSendRate", 1.0);+ sendQuota.put("SentLast24Hours", (double) sentCount);++ ObjectNode suppressionAttrs = result.putObject("SuppressionAttributes");+ ArrayNode reasons = suppressionAttrs.putArray("SuppressedReasons");+ for (String r : suppression.getSuppressedReasons()) {+ reasons.add(r);+ }++ // AWS only surfaces VdmAttributes once VDM has been configured for the region (an untouched+ // region omits the key entirely), and only adds the Dashboard/Guardian sub-attributes while+ // VdmEnabled is ENABLED.+ accountService.findAccountVdmAttributes(region).ifPresent(vdm -> {+ ObjectNode vdmAttrs = result.putObject("VdmAttributes");+ vdmAttrs.put("VdmEnabled", featureStatus(vdm.vdmEnabled()));+ if (vdm.vdmEnabled()) {+ vdmAttrs.putObject("DashboardAttributes")+ .put("EngagementMetrics", featureStatus(vdm.engagementMetrics()));+ vdmAttrs.putObject("GuardianAttributes")+ .put("OptimizedSharedDelivery", featureStatus(vdm.optimizedSharedDelivery()));+ }+ });++ // Like VdmAttributes, AWS omits Details until PutAccountDetails has run for the region.+ accountService.findAccountDetails(region).ifPresent(details -> {+ ObjectNode d = result.putObject("Details");+ d.put("MailType", details.mailType());+ d.put("WebsiteURL", details.websiteUrl());+ if (details.contactLanguage() != null) {+ d.put("ContactLanguage", details.contactLanguage());+ }+ if (details.useCaseDescription() != null) {+ d.put("UseCaseDescription", details.useCaseDescription());+ }+ if (details.additionalContactEmailAddresses() != null+ && !details.additionalContactEmailAddresses().isEmpty()) {+ ArrayNode addrs = d.putArray("AdditionalContactEmailAddresses");+ details.additionalContactEmailAddresses().forEach(addrs::add);+ }+ ObjectNode review = d.putObject("ReviewDetails");+ review.put("Status", details.reviewStatus());+ review.put("CaseId", details.caseId());+ });++ return Response.ok(result).build();+ }++ @PUT+ @Path("/account/vdm")+ public Response putAccountVdmAttributes(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode request = (body == null || body.isBlank())+ ? objectMapper.createObjectNode()+ : objectMapper.readTree(body);+ requireJsonObject(request);+ JsonNode vdm = request.path("VdmAttributes");+ if (!vdm.isObject()) {+ throw new AwsException("BadRequestException", "VdmAttributes is required.", 400);+ }+ boolean vdmEnabled = parseFeatureStatus(vdm, "VdmEnabled",+ "vdmAttributes.vdmEnabled", true);+ boolean engagement = parseFeatureStatus(+ requireObjectOrAbsent(vdm, "DashboardAttributes"), "EngagementMetrics",+ "vdmAttributes.dashboardAttributes.engagementMetrics", false);+ boolean osd = parseFeatureStatus(+ requireObjectOrAbsent(vdm, "GuardianAttributes"), "OptimizedSharedDelivery",+ "vdmAttributes.guardianAttributes.optimizedSharedDelivery", false);+ accountService.putAccountVdmAttributes(region,+ new AccountVdmAttributes(vdmEnabled, engagement, osd));+ LOG.infov("SES V2 PutAccountVdmAttributes: enabled={0}, engagement={1}, osd={2}",+ vdmEnabled, engagement, osd);+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ } catch (JsonProcessingException e) {+ throw new AwsException("BadRequestException", e.getMessage(), 400);+ }+ }++ @POST+ @Path("/account/details")+ public Response putAccountDetails(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode request = (body == null || body.isBlank())+ ? objectMapper.createObjectNode()+ : objectMapper.readTree(body);+ requireJsonObject(request);++ // Parse every member first (rejecting wrong JSON types as a serialization error, the way+ // AWS does before validation), then validate the parsed values together so all constraint+ // violations are aggregated into one response.+ String mailType = stringMemberOrAbsent(request, "MailType");+ String websiteUrl = stringMemberOrAbsent(request, "WebsiteURL");+ String contactLanguage = stringMemberOrAbsent(request, "ContactLanguage");+ String useCaseDescription = stringMemberOrAbsent(request, "UseCaseDescription");++ List<String> additionalContacts = null;+ JsonNode contacts = request.path("AdditionalContactEmailAddresses");+ if (!contacts.isMissingNode() && !contacts.isNull()) {+ // A typed list member: reject a non-array, and reject non-string elements, rather than+ // coercing (asText would turn 123 into "123"), matching how AWS rejects type mismatches.+ if (!contacts.isArray()) {+ throw new AwsException("SerializationException", null, 400);+ }+ additionalContacts = new ArrayList<>();+ for (JsonNode node : contacts) {+ if (!node.isTextual()) {+ throw new AwsException("SerializationException", null, 400);+ }+ additionalContacts.add(node.textValue());+ }+ }+ JsonNode productionAccess = request.path("ProductionAccessEnabled");+ if (!productionAccess.isMissingNode() && !productionAccess.isNull() && !productionAccess.isBoolean()) {+ throw new AwsException("SerializationException", null, 400);+ }+ boolean productionAccessEnabled = productionAccess.asBoolean(false);++ // 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.+ accountService.putAccountDetails(region, mailType, websiteUrl, contactLanguage,+ useCaseDescription, additionalContacts, productionAccessEnabled);+ LOG.infov("SES V2 PutAccountDetails: region={0}, mailType={1}", region, mailType);+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ } catch (JsonProcessingException e) {+ // AWS reports a malformed JSON body as a SerializationException, the same error type used+ // for wrong-typed members above.+ throw new AwsException("SerializationException", null, 400);+ }+ }++ @PUT+ @Path("/account/dedicated-ips/warmup")+ public Response putAccountDedicatedIpWarmupAttributes(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode request = readOptionBody(objectMapper, body);+ 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).+ boolean enabled = enabledNode.isMissingNode() ? false : coerceBoolean(enabledNode);+ accountService.setDedicatedIpAutoWarmup(region, enabled);+ LOG.infov("SES V2 PutAccountDedicatedIpWarmupAttributes: {0}", enabled);+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ }+ }++ @PUT+ @Path("/account/suppression")+ public Response putAccountSuppressionAttributes(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode request = (body == null || body.isBlank())+ ? 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());+ }+ }+ suppressionService.putAccountSuppressionAttributes(region, reasons);+ LOG.infov("SES V2 PutAccountSuppressionAttributes: {0}", reasons);+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ } catch (JsonProcessingException e) {+ throw new AwsException("BadRequestException", e.getMessage(), 400);+ }+ }++ @PUT+ @Path("/account/sending")+ 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());+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ } catch (Exception e) {+ throw new AwsException("BadRequestException", e.getMessage(), 400);+ }+ }++ private static String featureStatus(boolean enabled) {+ return enabled ? "ENABLED" : "DISABLED";+ }++ // Parse an AWS FeatureStatus (ENABLED/DISABLED) field. A required member that is absent, or any+ // value outside the enum, is a Smithy BadRequestException the way AWS returns it; an absent+ // optional member defaults to DISABLED (false).+ private static boolean parseFeatureStatus(JsonNode parent, String field, String path, boolean required) {+ JsonNode node = parent.path(field);+ if (node.isMissingNode() || node.isNull()) {+ if (required) {+ throw new AwsException("BadRequestException",+ "1 validation error detected: Value null at '" + path+ + "' failed to satisfy constraint: Member must not be null", 400);+ }+ return false;+ }+ if (node.isTextual()) {+ String value = node.asText();+ if ("ENABLED".equals(value)) {+ return true;+ }+ if ("DISABLED".equals(value)) {+ return false;+ }+ }+ throw new AwsException("BadRequestException",+ "1 validation error detected: Value at '" + path+ + "' failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]",+ 400);+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.javaindex a9a6fa7639..2f41748d0f 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java@@ -2,8 +2,6 @@ package io.github.hectorvent.floci.services.ses;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RegionResolver;-import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;-import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;import io.github.hectorvent.floci.services.ses.model.DashboardOptions;import io.github.hectorvent.floci.services.ses.model.GuardianOptions;@@ -49,9 +47,10 @@ import java.util.Collections;import java.util.List;import java.util.Map;-import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBoolean;import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;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;import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;@@ -60,7 +59,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObjecimport static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringArrayOrAbsent;import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;-import static io.github.hectorvent.floci.services.ses.SesV2Json.unexpectedStartError;/*** REST JSON controller for the AWS SES V2 API.@@ -82,14 +80,18 @@ public class SesController {private final SesService sesService;// The bulk send resolves a stored template's content before handing the entries to the facade.private final SesTemplateService templateService;+ // The send endpoints read the account-level sending switch before building the message.+ private final SesAccountService accountService;private final RegionResolver regionResolver;private final ObjectMapper objectMapper;@Injectpublic SesController(SesService sesService, SesTemplateService templateService,- RegionResolver regionResolver, ObjectMapper objectMapper) {+ SesAccountService accountService, RegionResolver regionResolver,+ ObjectMapper objectMapper) {this.sesService = sesService;this.templateService = templateService;+ this.accountService = accountService;this.regionResolver = regionResolver;this.objectMapper = objectMapper;}@@ -471,7 +473,7 @@ public class SesController {public Response sendEmail(@Context HttpHeaders headers, String body) {String region = regionResolver.resolveRegion(headers);try {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("SendingPausedException","Account sending is disabled.", 400);}@@ -605,7 +607,7 @@ public class SesController {public Response sendBulkEmail(@Context HttpHeaders headers, String body) {String region = regionResolver.resolveRegion(headers);try {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("SendingPausedException","Account sending is disabled.", 400);}@@ -742,7 +744,7 @@ public class SesController {String region = regionResolver.resolveRegion(headers);String templateName = null;try {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("SendingPausedException","Account sending is disabled.", 400);}@@ -1507,263 +1509,6 @@ public class SesController {}}- // ──────────────────────────── Account ────────────────────────────-- @GET- @Path("/account")- public Response getAccount(@Context HttpHeaders headers) {- String region = regionResolver.resolveRegion(headers);- long sentCount = sesService.getSentEmailCount(region);- boolean sendingEnabled = sesService.isAccountSendingEnabled(region);- AccountSuppressionAttributes suppression = sesService.getAccountSuppressionAttributes(region);-- ObjectNode result = objectMapper.createObjectNode();- result.put("DedicatedIpAutoWarmupEnabled", sesService.isAccountDedicatedIpAutoWarmupEnabled(region));- result.put("EnforcementStatus", "HEALTHY");- result.put("ProductionAccessEnabled", true);- result.put("SendingEnabled", sendingEnabled);-- ObjectNode sendQuota = result.putObject("SendQuota");- sendQuota.put("Max24HourSend", 200.0);- sendQuota.put("MaxSendRate", 1.0);- sendQuota.put("SentLast24Hours", (double) sentCount);-- ObjectNode suppressionAttrs = result.putObject("SuppressionAttributes");- ArrayNode reasons = suppressionAttrs.putArray("SuppressedReasons");- for (String r : suppression.getSuppressedReasons()) {- reasons.add(r);- }-- // AWS only surfaces VdmAttributes once VDM has been configured for the region (an untouched- // region omits the key entirely), and only adds the Dashboard/Guardian sub-attributes while- // VdmEnabled is ENABLED.- sesService.findAccountVdmAttributes(region).ifPresent(vdm -> {- ObjectNode vdmAttrs = result.putObject("VdmAttributes");- vdmAttrs.put("VdmEnabled", featureStatus(vdm.vdmEnabled()));- if (vdm.vdmEnabled()) {- vdmAttrs.putObject("DashboardAttributes")- .put("EngagementMetrics", featureStatus(vdm.engagementMetrics()));- vdmAttrs.putObject("GuardianAttributes")- .put("OptimizedSharedDelivery", featureStatus(vdm.optimizedSharedDelivery()));- }- });-- // Like VdmAttributes, AWS omits Details until PutAccountDetails has run for the region.- sesService.findAccountDetails(region).ifPresent(details -> {- ObjectNode d = result.putObject("Details");- d.put("MailType", details.mailType());- d.put("WebsiteURL", details.websiteUrl());- if (details.contactLanguage() != null) {- d.put("ContactLanguage", details.contactLanguage());- }- if (details.useCaseDescription() != null) {- d.put("UseCaseDescription", details.useCaseDescription());- }- if (details.additionalContactEmailAddresses() != null- && !details.additionalContactEmailAddresses().isEmpty()) {- ArrayNode addrs = d.putArray("AdditionalContactEmailAddresses");- details.additionalContactEmailAddresses().forEach(addrs::add);- }- ObjectNode review = d.putObject("ReviewDetails");- review.put("Status", details.reviewStatus());- review.put("CaseId", details.caseId());- });-- return Response.ok(result).build();- }-- private static String featureStatus(boolean enabled) {- return enabled ? "ENABLED" : "DISABLED";- }-- @PUT- @Path("/account/vdm")- public Response putAccountVdmAttributes(@Context HttpHeaders headers, String body) {- String region = regionResolver.resolveRegion(headers);- try {- JsonNode request = (body == null || body.isBlank())- ? objectMapper.createObjectNode()- : objectMapper.readTree(body);- requireJsonObject(request);- JsonNode vdm = request.path("VdmAttributes");- if (!vdm.isObject()) {- throw new AwsException("BadRequestException", "VdmAttributes is required.", 400);- }- boolean vdmEnabled = parseFeatureStatus(vdm, "VdmEnabled",- "vdmAttributes.vdmEnabled", true);- boolean engagement = parseFeatureStatus(- requireObjectOrAbsent(vdm, "DashboardAttributes"), "EngagementMetrics",- "vdmAttributes.dashboardAttributes.engagementMetrics", false);- boolean osd = parseFeatureStatus(- requireObjectOrAbsent(vdm, "GuardianAttributes"), "OptimizedSharedDelivery",- "vdmAttributes.guardianAttributes.optimizedSharedDelivery", false);- sesService.putAccountVdmAttributes(region,- new AccountVdmAttributes(vdmEnabled, engagement, osd));- LOG.infov("SES V2 PutAccountVdmAttributes: enabled={0}, engagement={1}, osd={2}",- vdmEnabled, engagement, osd);- return Response.ok(objectMapper.createObjectNode()).build();- } catch (AwsException e) {- throw remapV1Exception(e);- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {- throw new AwsException("BadRequestException", e.getMessage(), 400);- }- }-- @POST- @Path("/account/details")- public Response putAccountDetails(@Context HttpHeaders headers, String body) {- String region = regionResolver.resolveRegion(headers);- try {- JsonNode request = (body == null || body.isBlank())- ? objectMapper.createObjectNode()- : objectMapper.readTree(body);- requireJsonObject(request);-- // Parse every member first (rejecting wrong JSON types as a serialization error, the way- // AWS does before validation), then validate the parsed values together so all constraint- // violations are aggregated into one response.- String mailType = stringMemberOrAbsent(request, "MailType");- String websiteUrl = stringMemberOrAbsent(request, "WebsiteURL");- String contactLanguage = stringMemberOrAbsent(request, "ContactLanguage");- String useCaseDescription = stringMemberOrAbsent(request, "UseCaseDescription");-- List<String> additionalContacts = null;- JsonNode contacts = request.path("AdditionalContactEmailAddresses");- if (!contacts.isMissingNode() && !contacts.isNull()) {- // A typed list member: reject a non-array, and reject non-string elements, rather than- // coercing (asText would turn 123 into "123"), matching how AWS rejects type mismatches.- if (!contacts.isArray()) {- throw new AwsException("SerializationException", null, 400);- }- additionalContacts = new ArrayList<>();- for (JsonNode node : contacts) {- if (!node.isTextual()) {- throw new AwsException("SerializationException", null, 400);- }- additionalContacts.add(node.textValue());- }- }- JsonNode productionAccess = request.path("ProductionAccessEnabled");- if (!productionAccess.isMissingNode() && !productionAccess.isNull() && !productionAccess.isBoolean()) {- throw new AwsException("SerializationException", null, 400);- }- boolean productionAccessEnabled = productionAccess.asBoolean(false);-- // 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.- sesService.putAccountDetails(region, mailType, websiteUrl, contactLanguage,- useCaseDescription, additionalContacts, productionAccessEnabled);- LOG.infov("SES V2 PutAccountDetails: region={0}, mailType={1}", region, mailType);- return Response.ok(objectMapper.createObjectNode()).build();- } catch (AwsException e) {- throw remapV1Exception(e);- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {- // AWS reports a malformed JSON body as a SerializationException, the same error type used- // for wrong-typed members above.- throw new AwsException("SerializationException", null, 400);- }- }-- // Parse an AWS FeatureStatus (ENABLED/DISABLED) field. A required member that is absent, or any- // value outside the enum, is a Smithy BadRequestException the way AWS returns it; an absent- // optional member defaults to DISABLED (false).- private static boolean parseFeatureStatus(JsonNode parent, String field, String path, boolean required) {- JsonNode node = parent.path(field);- if (node.isMissingNode() || node.isNull()) {- if (required) {- throw new AwsException("BadRequestException",- "1 validation error detected: Value null at '" + path- + "' failed to satisfy constraint: Member must not be null", 400);- }- return false;- }- if (node.isTextual()) {- String value = node.asText();- if ("ENABLED".equals(value)) {- return true;- }- if ("DISABLED".equals(value)) {- return false;- }- }- throw new AwsException("BadRequestException",- "1 validation error detected: Value at '" + path- + "' failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]",- 400);- }-- @PUT- @Path("/account/dedicated-ips/warmup")- public Response putAccountDedicatedIpWarmupAttributes(@Context HttpHeaders headers, String body) {- String region = regionResolver.resolveRegion(headers);- try {- JsonNode request = readOptionBody(objectMapper, body);- 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).- boolean enabled = enabledNode.isMissingNode() ? false : coerceBoolean(enabledNode);- sesService.setAccountDedicatedIpAutoWarmup(region, enabled);- LOG.infov("SES V2 PutAccountDedicatedIpWarmupAttributes: {0}", enabled);- return Response.ok(objectMapper.createObjectNode()).build();- } catch (AwsException e) {- throw remapV1Exception(e);- }- }-- @PUT- @Path("/account/suppression")- public Response putAccountSuppressionAttributes(@Context HttpHeaders headers, String body) {- String region = regionResolver.resolveRegion(headers);- try {- JsonNode request = (body == null || body.isBlank())- ? 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());- }- }- sesService.putAccountSuppressionAttributes(region, reasons);- LOG.infov("SES V2 PutAccountSuppressionAttributes: {0}", reasons);- return Response.ok(objectMapper.createObjectNode()).build();- } catch (AwsException e) {- throw remapV1Exception(e);- } catch (com.fasterxml.jackson.core.JsonProcessingException e) {- throw new AwsException("BadRequestException", e.getMessage(), 400);- }- }-- @PUT- @Path("/account/sending")- 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);- }- sesService.setAccountSendingEnabled(region, sendingEnabledNode.booleanValue());- return Response.ok(objectMapper.createObjectNode()).build();- } catch (AwsException e) {- throw remapV1Exception(e);- } catch (Exception e) {- throw new AwsException("BadRequestException", e.getMessage(), 400);- }- }-// ──────────────────── Suppression list ───────────────────────────@PUT@@ -2071,55 +1816,6 @@ public class SesController {return node;}- /**- * 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;- }- return coerceBoolean(enabledNode);- }-/*** Parse a V2 SES {@code Content.Simple.Headers} / {@code Content.Template.Headers} array* (additional message headers, elements use {@code Name}/{@code Value}). Returns an emptydiff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.javaindex 7d8f8d7935..8bf3926c87 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java@@ -49,17 +49,22 @@ public class SesQueryHandler {private final SesIdentityService identityService;private final SesTemplateService templateService;private final SesCvetService cvetService;+ private final SesAccountService accountService;+ private final SesSentEmailService sentEmailService;private final ObjectMapper objectMapper;@Injectpublic SesQueryHandler(SesService sesService, SesReceiptRuleService receiptRuleService,SesIdentityService identityService, SesTemplateService templateService,- SesCvetService cvetService, ObjectMapper objectMapper) {+ SesCvetService cvetService, SesAccountService accountService,+ SesSentEmailService sentEmailService, ObjectMapper objectMapper) {this.sesService = sesService;this.receiptRuleService = receiptRuleService;this.identityService = identityService;this.templateService = templateService;this.cvetService = cvetService;+ this.accountService = accountService;+ this.sentEmailService = sentEmailService;this.objectMapper = objectMapper;}@@ -223,7 +228,7 @@ public class SesQueryHandler {}private Response handleSendEmail(MultivaluedMap<String, String> params, String region) {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("AccountSendingPausedException","Account sending is disabled.", 400);}@@ -249,7 +254,7 @@ public class SesQueryHandler {}private Response handleSendRawEmail(MultivaluedMap<String, String> params, String region) {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("AccountSendingPausedException","Account sending is disabled.", 400);}@@ -270,12 +275,13 @@ public class SesQueryHandler {var xml = new XmlBuilder().elem("Max24HourSend", "200.0").elem("MaxSendRate", "1.0")- .elem("SentLast24Hours", String.valueOf((double) sesService.getSentEmailCount(region)));+ .elem("SentLast24Hours",+ String.valueOf((double) sentEmailService.countInRegion(region)));return Response.ok(AwsQueryResponse.envelope("GetSendQuota", AwsNamespaces.SES, xml.build())).build();}private Response handleGetSendStatistics(String region) {- long sentCount = sesService.getSentEmailCount(region);+ long sentCount = sentEmailService.countInRegion(region);var xml = new XmlBuilder().start("SendDataPoints");if (sentCount > 0) {xml.start("member")@@ -291,14 +297,14 @@ public class SesQueryHandler {}private Response handleGetAccountSendingEnabled(String region) {- boolean enabled = sesService.isAccountSendingEnabled(region);+ boolean enabled = accountService.isAccountSendingEnabled(region);String result = new XmlBuilder().elem("Enabled", String.valueOf(enabled)).build();return Response.ok(AwsQueryResponse.envelope("GetAccountSendingEnabled", AwsNamespaces.SES, result)).build();}private Response handleUpdateAccountSendingEnabled(MultivaluedMap<String, String> params, String region) {boolean enabled = parseXsdBoolean(params, "Enabled");- sesService.setAccountSendingEnabled(region, enabled);+ accountService.setAccountSendingEnabled(region, enabled);return Response.ok(AwsQueryResponse.envelopeEmptyResult("UpdateAccountSendingEnabled", AwsNamespaces.SES)).build();}@@ -561,7 +567,7 @@ public class SesQueryHandler {}private Response handleSendTemplatedEmail(MultivaluedMap<String, String> params, String region) {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("AccountSendingPausedException","Account sending is disabled.", 400);}@@ -663,7 +669,7 @@ public class SesQueryHandler {}private Response handleSendCustomVerificationEmail(MultivaluedMap<String, String> params, String region) {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("AccountSendingPausedException","Account sending is disabled.", 400);}@@ -689,7 +695,7 @@ public class SesQueryHandler {}private Response handleSendBulkTemplatedEmail(MultivaluedMap<String, String> params, String region) {- if (!sesService.isAccountSendingEnabled(region)) {+ if (!accountService.isAccountSendingEnabled(region)) {throw new AwsException("AccountSendingPausedException","Account sending is disabled.", 400);}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.javaindex 92b5d6a1c4..bb44a39c07 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java@@ -4,9 +4,6 @@ import io.github.hectorvent.floci.config.EmulatorConfig;import io.github.hectorvent.floci.core.common.AwsArnUtils;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.common.RegionResolver;-import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;-import io.github.hectorvent.floci.services.ses.model.AccountDetails;-import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult;@@ -48,7 +45,6 @@ import java.util.LinkedHashMap;import java.util.List;import java.util.Locale;import java.util.Map;-import java.util.Optional;import java.util.Set;import java.util.UUID;@@ -64,10 +60,9 @@ public class SesService {// flows and send-path reads, reaching the store through its find/save.private final SesIdentityService identityService;// Sent-email records extracted to SesSentEmailService. The send path records finished emails via- // it; send-statistics and inspection read back through it.+ // it; the account and v1 statistics reads go to the service directly, inspection still reads+ // back through the facade.private final SesSentEmailService sentEmailService;- // Account-level settings, extracted to its own service. The facade delegates.- private final SesAccountService accountService;// Email templates extracted to SesTemplateService. The facade delegates; the templated-send path// reads via it, and ARN-dispatched tagging reads/writes via its find/save.private final SesTemplateService templateService;@@ -106,8 +101,7 @@ public class SesService {private final RegionResolver regionResolver;@Inject- public SesService(SesIdentityService identityService, SesAccountService accountService,- SesCvetService cvetService,+ public SesService(SesIdentityService identityService, SesCvetService cvetService,SesPolicyService policyService, SesContactService contactService,SesSuppressionService suppressionService, SesDedicatedIpService dedicatedIpService,SesTemplateService templateService, SesSentEmailService sentEmailService,@@ -117,7 +111,6 @@ public class SesService {RegionResolver regionResolver) {this.identityService = identityService;this.sentEmailService = sentEmailService;- this.accountService = accountService;this.templateService = templateService;this.configSetService = configSetService;this.suppressionService = suppressionService;@@ -135,7 +128,6 @@ public class SesService {SesService(SesIdentityService identityService,SesSentEmailService sentEmailService,- SesAccountService accountService,SesTemplateService templateService,SesConfigurationSetService configSetService,SesSuppressionService suppressionService,@@ -147,7 +139,6 @@ public class SesService {SmtpRelay smtpRelay) {this.identityService = identityService;this.sentEmailService = sentEmailService;- this.accountService = accountService;this.templateService = templateService;this.configSetService = configSetService;this.suppressionService = suppressionService;@@ -546,10 +537,6 @@ public class SesService {return events;}- public long getSentEmailCount(String region) {- return sentEmailService.countInRegion(region);- }-public void setIdentityNotificationTopic(String identityValue, String notificationType,String snsTopic, String region) {identityService.setIdentityNotificationTopic(identityValue, notificationType, snsTopic, region);@@ -674,33 +661,6 @@ public class SesService {sentEmailService.clear();}- public boolean isAccountSendingEnabled(String region) {- return accountService.isAccountSendingEnabled(region);- }-- public void setAccountSendingEnabled(String region, boolean enabled) {- accountService.setAccountSendingEnabled(region, enabled);- }-- public Optional<AccountDetails> findAccountDetails(String region) {- return accountService.findAccountDetails(region);- }-- public AccountDetails putAccountDetails(String region, String mailType, String websiteUrl,- String contactLanguage, String useCaseDescription,- List<String> additionalContacts, boolean productionAccessEnabled) {- return accountService.putAccountDetails(region, mailType, websiteUrl, contactLanguage,- useCaseDescription, additionalContacts, productionAccessEnabled);- }-- public Optional<AccountVdmAttributes> findAccountVdmAttributes(String region) {- return accountService.findAccountVdmAttributes(region);- }-- public void putAccountVdmAttributes(String region, AccountVdmAttributes vdm) {- accountService.putAccountVdmAttributes(region, vdm);- }-public void setConfigurationSetSendingEnabled(String configSetName, boolean enabled, String region) {configSetService.setSendingEnabled(configSetName, enabled, region);}@@ -1178,17 +1138,6 @@ public class SesService {}}-- // Dedicated-IP auto-warmup is an account-level setting owned by SesAccountService.-- public boolean isAccountDedicatedIpAutoWarmupEnabled(String region) {- return accountService.isDedicatedIpAutoWarmupEnabled(region);- }-- public void setAccountDedicatedIpAutoWarmup(String region, boolean enabled) {- accountService.setDedicatedIpAutoWarmup(region, enabled);- }-public void createConfigurationSetEventDestination(String configSetName, String eventDestinationName,EventDestination dest, String region) {configSetService.createEventDestination(configSetName, eventDestinationName, dest, region);@@ -1231,7 +1180,8 @@ public class SesService {return List.copyOf(options.getSuppressedReasons());}}- return List.copyOf(getAccountSuppressionAttributes(region).getSuppressedReasons());+ return List.copyOf(+ suppressionService.getAccountSuppressionAttributes(region).getSuppressedReasons());}@@ -1354,17 +1304,10 @@ public class SesService {}// ──────────────────── Suppression (account attributes + list) ────────────────────- // Storage lives in SesSuppressionService; the facade forwards, and its send+ // Storage lives in SesSuppressionService; the account attributes are read and written by the v2+ // controller directly, the list operations below keep the tenant routing here, and the send// filters (collectSuppressedReasons / resolveSuppressionReason) read entries back through it.- public AccountSuppressionAttributes getAccountSuppressionAttributes(String region) {- return suppressionService.getAccountSuppressionAttributes(region);- }-- public void putAccountSuppressionAttributes(String region, List<String> suppressedReasons) {- suppressionService.putAccountSuppressionAttributes(region, suppressedReasons);- }-// A TenantName routes each suppression-list operation to that tenant's own list (fully separate// from the account list on AWS); the reason/address validation still runs first, matching the// probed precedence where request validation precedes tenant existence.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.javaindex eb2e538c21..2de633cd37 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@@ -200,4 +200,53 @@ final class SesV2Json {}return node.asText();}++ /**+ * 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.+ */+ 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}.+ */+ static boolean parseSendingEnabled(JsonNode enabledNode) {+ if (enabledNode.isMissingNode()) {+ return false;+ }+ return coerceBoolean(enabledNode);+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.javaindex 71dcb6cf2e..6c0900bcc3 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetSuppressionOptionsV2IntegrationTest.java@@ -37,6 +37,9 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {@InjectSesService sesService;+ @Inject+ SesSuppressionService suppressionService;+@Test@Order(1)void createConfigurationSet() {@@ -213,7 +216,9 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {List<String> effective = sesService.getEffectiveSuppressedReasons(csNoOverride, REGION);// Account defaults to [BOUNCE, COMPLAINT]; matches account state when no per-CS override.- assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);+ assertEquals(+ suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),+ effective);}@Test@@ -261,14 +266,18 @@ class SesConfigurationSetSuppressionOptionsV2IntegrationTest {@Order(23)void effectiveReasons_nullConfigSetName_returnsAccountLevel() {List<String> effective = sesService.getEffectiveSuppressedReasons(null, REGION);- assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);+ assertEquals(+ suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),+ effective);}@Test@Order(24)void effectiveReasons_blankConfigSetName_returnsAccountLevel() {List<String> effective = sesService.getEffectiveSuppressedReasons(" ", REGION);- assertEquals(sesService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(), effective);+ assertEquals(+ suppressionService.getAccountSuppressionAttributes(REGION).getSuppressedReasons(),+ effective);}@Testdiff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionReasonTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionReasonTest.javaindex 672d307407..26e8172be7 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionReasonTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceSuppressionReasonTest.java@@ -25,6 +25,7 @@ class SesServiceSuppressionReasonTest {private static final String REGION = "us-east-1";private SesService service;+ private SesSuppressionService suppression;private InMemoryStorage<String, SuppressedDestination> suppressionStore;private InMemoryStorage<String, AccountSuppressionAttributes> accountSuppressionStore;@@ -34,6 +35,7 @@ class SesServiceSuppressionReasonTest {suppressionStore = builder.suppressionStore();accountSuppressionStore = builder.accountSuppressionStore();service = builder.build();+ suppression = builder.suppressionService();}@Test@@ -54,7 +56,7 @@ class SesServiceSuppressionReasonTest {void onListButReasonNotInAccountSettings_returnsNull() {service.putSuppressedDestination(REGION, "[email protected]", "COMPLAINT");// Narrow the account settings to BOUNCE only.- service.putAccountSuppressionAttributes(REGION, List.of("BOUNCE"));+ suppression.putAccountSuppressionAttributes(REGION, List.of("BOUNCE"));assertNull(service.resolveSuppressionReason("[email protected]", null, REGION));}@@ -62,7 +64,7 @@ class SesServiceSuppressionReasonTest {void accountSettingsEmpty_returnsNull() {service.putSuppressedDestination(REGION, "[email protected]", "BOUNCE");// Disable account-level suppression by passing an empty list.- service.putAccountSuppressionAttributes(REGION, new ArrayList<>());+ suppression.putAccountSuppressionAttributes(REGION, new ArrayList<>());assertNull(service.resolveSuppressionReason("[email protected]", null, REGION));}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.javaindex 423027a14b..7525ff889b 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java@@ -2,9 +2,7 @@ package io.github.hectorvent.floci.services.ses;import com.fasterxml.jackson.databind.ObjectMapper;import io.github.hectorvent.floci.core.storage.InMemoryStorage;-import io.github.hectorvent.floci.services.ses.model.AccountDetails;import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;-import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;import io.github.hectorvent.floci.services.ses.model.Contact;import io.github.hectorvent.floci.services.ses.model.ContactList;@@ -34,9 +32,6 @@ final class SesServiceTestBuilder {private final InMemoryStorage<String, Identity> identityStore = new InMemoryStorage<>();private final InMemoryStorage<String, SentEmail> emailStore = new InMemoryStorage<>();- private final InMemoryStorage<String, Boolean> accountSettingsStore = new InMemoryStorage<>();- private final InMemoryStorage<String, AccountVdmAttributes> accountVdmStore = new InMemoryStorage<>();- private final InMemoryStorage<String, AccountDetails> accountDetailsStore = new InMemoryStorage<>();private final InMemoryStorage<String, EmailTemplate> templateStore = new InMemoryStorage<>();private final InMemoryStorage<String, ConfigurationSet> configSetStore = new InMemoryStorage<>();private final InMemoryStorage<String, SuppressedDestination> suppressionStore = new InMemoryStorage<>();@@ -57,9 +52,10 @@ final class SesServiceTestBuilder {private Route53Service route53Service = null;private ObjectMapper objectMapper = new ObjectMapper();private Clock clock = Clock.systemUTC();- // Built by build(); exposed so tests can seed contacts through the domain service now that the- // facade no longer forwards the contact CRUD.+ // Built by build(); exposed so tests can seed contacts and account suppression through the domain+ // services now that the facade no longer forwards those operations.private SesContactService contactService;+ private SesSuppressionService suppressionService;static SesServiceTestBuilder create() {return new SesServiceTestBuilder();@@ -122,15 +118,23 @@ final class SesServiceTestBuilder {return contactService;}+ SesSuppressionService suppressionService() {+ if (suppressionService == null) {+ throw new IllegalStateException("call build() first");+ }+ return suppressionService;+ }+SesService build() {contactService = new SesContactService(contactListStore, contactStore, clock);+ suppressionService = new SesSuppressionService(suppressionStore, accountSuppressionStore,+ new InMemoryStorage<>());return new SesService(new SesIdentityService(identityStore, route53Service, clock),new SesSentEmailService(emailStore),- new SesAccountService(accountSettingsStore, accountVdmStore, accountDetailsStore),new SesTemplateService(templateStore, objectMapper, new SecureRandom()),new SesConfigurationSetService(configSetStore),- new SesSuppressionService(suppressionStore, accountSuppressionStore, new InMemoryStorage<>()),+ suppressionService,new SesDedicatedIpService(dedicatedIpPoolStore),contactService,new SesPolicyService(policyStore, objectMapper),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.javaindex 569e9e549f..db6d6c6853 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@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.services.ses.model.Tag;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.function.Executable;+import java.util.Arrays;import java.util.List;import static org.junit.jupiter.api.Assertions.assertEquals;@@ -197,4 +198,36 @@ class SesV2JsonTest {() -> SesV2Json.readRequiredStringField(node, field)).getMessage());}}++ @Test+ void parseSuppressedReasons_absentIsEmpty_elementsFollowAwsCoercion() {+ assertEquals(List.of(),+ SesV2Json.parseSuppressedReasons(json("{}").path("SuppressedReasons")));+ assertEquals(List.of(), SesV2Json.parseSuppressedReasons(json("null")));+ assertEquals(List.of("BOUNCE", "COMPLAINT"),+ SesV2Json.parseSuppressedReasons(json("[\"BOUNCE\",\"COMPLAINT\"]")));+ // A null element passes deserialization and is left to the service-layer value check.+ assertEquals(Arrays.asList("BOUNCE", null),+ SesV2Json.parseSuppressedReasons(json("[\"BOUNCE\",null]")));+ assertEquals("Expected list or null", assertAws("SerializationException", 400,+ () -> SesV2Json.parseSuppressedReasons(json("\"BOUNCE\""))).getMessage());+ assertEquals("NUMBER_VALUE can not be converted to a String",+ assertAws("SerializationException", 400,+ () -> SesV2Json.parseSuppressedReasons(json("[1]"))).getMessage());+ assertEquals("TRUE_VALUE can not be converted to a String",+ assertAws("SerializationException", 400,+ () -> SesV2Json.parseSuppressedReasons(json("[true]"))).getMessage());+ assertEquals("Start of structure or map found where not expected.",+ assertAws("SerializationException", 400,+ () -> SesV2Json.parseSuppressedReasons(json("[{}]"))).getMessage());+ }++ @Test+ void parseSendingEnabled_missingIsFalse_otherwiseCoerces() {+ assertFalse(SesV2Json.parseSendingEnabled(json("{}").path("SendingEnabled")));+ assertTrue(SesV2Json.parseSendingEnabled(json("true")));+ assertTrue(SesV2Json.parseSendingEnabled(json("\"yes\"")));+ assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("null")));+ assertAws("SerializationException", 400, () -> SesV2Json.parseSendingEnabled(json("0")));+ }}