Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): add MAIL FROM domain and identity attribute operations (#716)
Kenshin Okinakabd3a33326c80
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.javanew file mode 100644index 0000000000..dd9d706629--- /dev/null+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesIdentityAttributesTest.java@@ -0,0 +1,170 @@+package com.floci.test;++import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.DisplayName;+import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestMethodOrder;++import software.amazon.awssdk.awscore.exception.AwsServiceException;+import software.amazon.awssdk.services.ses.SesClient;+import software.amazon.awssdk.services.ses.model.DeleteIdentityRequest;+import software.amazon.awssdk.services.ses.model.GetIdentityMailFromDomainAttributesRequest;+import software.amazon.awssdk.services.ses.model.GetIdentityMailFromDomainAttributesResponse;+import software.amazon.awssdk.services.ses.model.GetIdentityNotificationAttributesRequest;+import software.amazon.awssdk.services.ses.model.GetIdentityNotificationAttributesResponse;+import software.amazon.awssdk.services.ses.model.IdentityMailFromDomainAttributes;+import software.amazon.awssdk.services.ses.model.IdentityNotificationAttributes;+import software.amazon.awssdk.services.ses.model.SetIdentityFeedbackForwardingEnabledRequest;+import software.amazon.awssdk.services.ses.model.SetIdentityHeadersInNotificationsEnabledRequest;+import software.amazon.awssdk.services.ses.model.SetIdentityMailFromDomainRequest;+import software.amazon.awssdk.services.ses.model.VerifyDomainIdentityRequest;++import software.amazon.awssdk.services.sesv2.SesV2Client;+import software.amazon.awssdk.services.sesv2.model.BadRequestException;+import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;+import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;+import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityRequest;+import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityResponse;+import software.amazon.awssdk.services.sesv2.model.PutEmailIdentityMailFromAttributesRequest;++import static org.assertj.core.api.Assertions.assertThat;+import static org.assertj.core.api.Assertions.assertThatThrownBy;++@DisplayName("SES Identity Attributes (MAIL FROM, DKIM, headers)")+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class SesIdentityAttributesTest {++ private static SesClient sesV1;+ private static SesV2Client sesV2;+ private static String v1Domain;+ private static String v2Domain;++ @BeforeAll+ static void setup() {+ sesV1 = TestFixtures.sesClient();+ sesV2 = TestFixtures.sesV2Client();+ String suffix = TestFixtures.uniqueName();+ v1Domain = suffix + ".v1-attrs.example.com";+ v2Domain = suffix + ".v2-attrs.example.com";+ }++ @AfterAll+ static void cleanup() {+ if (sesV1 != null) {+ try {+ sesV1.deleteIdentity(DeleteIdentityRequest.builder().identity(v1Domain).build());+ } catch (Exception ignored) {}+ sesV1.close();+ }+ if (sesV2 != null) {+ try {+ sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder()+ .emailIdentity(v2Domain).build());+ } catch (Exception ignored) {}+ sesV2.close();+ }+ }++ // ───────────────────────── V1 ─────────────────────────++ @Test+ @Order(1)+ void v1SetAndGetMailFromDomain() {+ sesV1.verifyDomainIdentity(VerifyDomainIdentityRequest.builder().domain(v1Domain).build());++ sesV1.setIdentityMailFromDomain(SetIdentityMailFromDomainRequest.builder()+ .identity(v1Domain)+ .mailFromDomain("mail." + v1Domain)+ .behaviorOnMXFailure("RejectMessage")+ .build());++ GetIdentityMailFromDomainAttributesResponse response =+ sesV1.getIdentityMailFromDomainAttributes(GetIdentityMailFromDomainAttributesRequest.builder()+ .identities(v1Domain).build());++ IdentityMailFromDomainAttributes attrs = response.mailFromDomainAttributes().get(v1Domain);+ assertThat(attrs).isNotNull();+ assertThat(attrs.mailFromDomain()).isEqualTo("mail." + v1Domain);+ assertThat(attrs.behaviorOnMXFailureAsString()).isEqualTo("RejectMessage");+ }++ @Test+ @Order(2)+ void v1SetIdentityFeedbackForwardingEnabled() {+ sesV1.setIdentityFeedbackForwardingEnabled(SetIdentityFeedbackForwardingEnabledRequest.builder()+ .identity(v1Domain)+ .forwardingEnabled(false)+ .build());+ // success = no exception+ }++ @Test+ @Order(3)+ void v1SetIdentityHeadersInNotificationsEnabled() {+ sesV1.setIdentityHeadersInNotificationsEnabled(SetIdentityHeadersInNotificationsEnabledRequest.builder()+ .identity(v1Domain)+ .notificationType("Bounce")+ .enabled(true)+ .build());+ // success = no exception+ }++ @Test+ @Order(4)+ void v1GetIdentityNotificationAttributes_reflectsForwardingAndHeaderFlags() {+ // Order(2) disabled forwarding; Order(3) enabled headers-in-Bounce.+ // The Get call should now return those values.+ GetIdentityNotificationAttributesResponse response =+ sesV1.getIdentityNotificationAttributes(GetIdentityNotificationAttributesRequest.builder()+ .identities(v1Domain).build());+ IdentityNotificationAttributes attrs = response.notificationAttributes().get(v1Domain);+ assertThat(attrs).isNotNull();+ assertThat(attrs.forwardingEnabled()).isFalse();+ assertThat(attrs.headersInBounceNotificationsEnabled()).isTrue();+ assertThat(attrs.headersInComplaintNotificationsEnabled()).isFalse();+ assertThat(attrs.headersInDeliveryNotificationsEnabled()).isFalse();+ }++ // ───────────────────────── V2 ─────────────────────────++ @Test+ @Order(10)+ void v2PutAndGetMailFromAttributes() {+ sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder()+ .emailIdentity(v2Domain).build());++ sesV2.putEmailIdentityMailFromAttributes(PutEmailIdentityMailFromAttributesRequest.builder()+ .emailIdentity(v2Domain)+ .mailFromDomain("mail." + v2Domain)+ .behaviorOnMxFailure("REJECT_MESSAGE")+ .build());++ GetEmailIdentityResponse response = sesV2.getEmailIdentity(GetEmailIdentityRequest.builder()+ .emailIdentity(v2Domain).build());++ assertThat(response.mailFromAttributes()).isNotNull();+ assertThat(response.mailFromAttributes().mailFromDomain()).isEqualTo("mail." + v2Domain);+ assertThat(response.mailFromAttributes().behaviorOnMxFailureAsString())+ .isEqualTo("REJECT_MESSAGE");+ assertThat(response.mailFromAttributes().mailFromDomainStatusAsString())+ .isEqualTo("SUCCESS");+ }++ @Test+ @Order(11)+ void v2PutEmailIdentityMailFromAttributes_unknownIdentity_throwsBadRequest() {+ String missing = "sdk-missing-" + TestFixtures.uniqueName() + ".example.com";+ assertThatThrownBy(() -> sesV2.putEmailIdentityMailFromAttributes(+ PutEmailIdentityMailFromAttributesRequest.builder()+ .emailIdentity(missing)+ .mailFromDomain("mail." + missing)+ .behaviorOnMxFailure("USE_DEFAULT_VALUE")+ .build()))+ .isInstanceOf(BadRequestException.class)+ .extracting(e -> ((AwsServiceException) e).statusCode())+ .isEqualTo(400);+ }+}diff --git a/docs/services/ses.md b/docs/services/ses.mdindex c074923f24..a8725630f3 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -32,6 +32,10 @@ Floci exposes the classic Amazon SES Query API used by `aws ses ...` commands an| `DeleteVerifiedEmailAddress` | Delete a verified email identity || `SetIdentityNotificationTopic` | Store SNS notification topic ARNs for an identity || `GetIdentityNotificationAttributes` | Read stored notification topic settings |+| `SetIdentityFeedbackForwardingEnabled` | Toggle feedback forwarding for an identity |+| `SetIdentityHeadersInNotificationsEnabled` | Toggle headers-in-notifications per notification type |+| `SetIdentityMailFromDomain` | Set or clear the MAIL FROM domain for an identity |+| `GetIdentityMailFromDomainAttributes` | Read MAIL FROM domain settings || `GetIdentityDkimAttributes` | Return DKIM status for identities || `CreateConfigurationSet` | Create a configuration set || `DescribeConfigurationSet` | Read a configuration set |@@ -176,6 +180,7 @@ Alongside the classic Query API, Floci implements a subset of the SES v2 REST JS| `DELETE` | `/v2/email/identities/{emailIdentity}` | `DeleteEmailIdentity` || `PUT` | `/v2/email/identities/{emailIdentity}/dkim` | `PutEmailIdentityDkimAttributes` || `PUT` | `/v2/email/identities/{emailIdentity}/feedback` | `PutEmailIdentityFeedbackAttributes` |+| `PUT` | `/v2/email/identities/{emailIdentity}/mail-from` | `PutEmailIdentityMailFromAttributes` || `POST` | `/v2/email/outbound-emails` | `SendEmail` (simple / raw / templated) || `POST` | `/v2/email/outbound-bulk-emails` | `SendBulkEmail` (templated, multiple destinations) || `GET` | `/v2/email/account` | `GetAccount` |diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.javaindex 741fa679a1..187ea46f8e 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java@@ -299,6 +299,9 @@ public class AwsQueryController {"SendEmail", "SendRawEmail", "GetSendQuota", "GetSendStatistics","GetAccountSendingEnabled", "ListVerifiedEmailAddresses", "DeleteVerifiedEmailAddress","SetIdentityNotificationTopic", "GetIdentityNotificationAttributes",+ "SetIdentityFeedbackForwardingEnabled",+ "SetIdentityHeadersInNotificationsEnabled",+ "SetIdentityMailFromDomain", "GetIdentityMailFromDomainAttributes","GetIdentityDkimAttributes","CreateTemplate", "UpdateTemplate", "GetTemplate", "DeleteTemplate","ListTemplates", "SendTemplatedEmail", "SendBulkTemplatedEmail",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 731618141e..06de04f392 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@@ -156,6 +156,51 @@ public class SesController {}}+ // ────────────────── Identity MAIL FROM ──────────────────────────++ @PUT+ @Path("/identities/{emailIdentity}/mail-from")+ public Response putEmailIdentityMailFromAttributes(@Context HttpHeaders headers,+ @PathParam("emailIdentity") String emailIdentity,+ String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ if (body == null || body.isBlank()) {+ throw new AwsException("BadRequestException", "Request body is required.", 400);+ }+ JsonNode request = objectMapper.readTree(body);+ requireJsonObject(request);+ JsonNode mailFromDomainNode = request.path("MailFromDomain");+ if (mailFromDomainNode.isMissingNode()) {+ throw new AwsException("BadRequestException",+ "MailFromDomain is required (use an empty string to clear the existing setting).", 400);+ }+ if (!mailFromDomainNode.isNull() && !mailFromDomainNode.isTextual()) {+ throw new AwsException("BadRequestException",+ "MailFromDomain must be a JSON string (or null).", 400);+ }+ String mailFromDomain = mailFromDomainNode.isNull()+ ? ""+ : mailFromDomainNode.asText("");+ JsonNode behaviorNode = request.path("BehaviorOnMxFailure");+ String behaviorV2 = null;+ if (!behaviorNode.isMissingNode() && !behaviorNode.isNull()) {+ if (!behaviorNode.isTextual()) {+ throw new AwsException("BadRequestException",+ "BehaviorOnMxFailure must be a JSON string.", 400);+ }+ behaviorV2 = behaviorNode.asText(null);+ }+ String behaviorV1 = v2BehaviorToV1(behaviorV2);+ sesService.setMailFromDomain(emailIdentity, mailFromDomain, behaviorV1, region);+ 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);+ }+ }+// ──────────────────── Identity Feedback ─────────────────────────@PUT@@ -650,9 +695,12 @@ public class SesController {result.set("DkimAttributes", buildDkimAttributes(identity));ObjectNode mailFromAttributes = result.putObject("MailFromAttributes");- mailFromAttributes.put("MailFromDomain", "");- mailFromAttributes.put("MailFromDomainStatus", "NOT_STARTED");- mailFromAttributes.put("BehaviorOnMxFailure", "USE_DEFAULT_VALUE");+ String mailFromDomain = identity.getMailFromDomain();+ mailFromAttributes.put("MailFromDomain", mailFromDomain == null ? "" : mailFromDomain);+ mailFromAttributes.put("MailFromDomainStatus",+ mailFromDomain == null ? "NOT_STARTED" : toV2Status(identity.getMailFromDomainStatus()));+ mailFromAttributes.put("BehaviorOnMxFailure",+ v1BehaviorToV2(identity.getBehaviorOnMxFailure()));result.putObject("Policies");result.putArray("Tags");@@ -660,6 +708,28 @@ public class SesController {return result;}+ private static String v1BehaviorToV2(String v1) {+ if ("RejectMessage".equals(v1)) {+ return "REJECT_MESSAGE";+ }+ return "USE_DEFAULT_VALUE";+ }++ private static String v2BehaviorToV1(String v2) {+ if (v2 == null) {+ return null;+ }+ if ("REJECT_MESSAGE".equals(v2)) {+ return "RejectMessage";+ }+ if ("USE_DEFAULT_VALUE".equals(v2)) {+ return "UseDefaultValue";+ }+ throw new AwsException("BadRequestException",+ "1 validation error detected: Value at 'behaviorOnMxFailure' failed to satisfy "+ + "constraint: Member must satisfy enum value set: [REJECT_MESSAGE, USE_DEFAULT_VALUE]", 400);+ }+private ObjectNode buildDkimAttributes(Identity identity) {ObjectNode dkim = objectMapper.createObjectNode();dkim.put("SigningEnabled", identity.isDkimEnabled());diff --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 eebbb4996d..53691e6448 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@@ -58,6 +58,10 @@ public class SesQueryHandler {case "DeleteVerifiedEmailAddress" -> handleDeleteVerifiedEmailAddress(params, region);case "SetIdentityNotificationTopic" -> handleSetIdentityNotificationTopic(params, region);case "GetIdentityNotificationAttributes" -> handleGetIdentityNotificationAttributes(params, region);+ case "SetIdentityFeedbackForwardingEnabled" -> handleSetIdentityFeedbackForwardingEnabled(params, region);+ case "SetIdentityHeadersInNotificationsEnabled" -> handleSetIdentityHeadersInNotificationsEnabled(params, region);+ case "SetIdentityMailFromDomain" -> handleSetIdentityMailFromDomain(params, region);+ case "GetIdentityMailFromDomainAttributes" -> handleGetIdentityMailFromDomainAttributes(params, region);case "GetIdentityDkimAttributes" -> handleGetIdentityDkimAttributes(params, region);case "CreateTemplate" -> handleCreateTemplate(params, region);case "UpdateTemplate" -> handleUpdateTemplate(params, region);@@ -243,10 +247,13 @@ public class SesQueryHandler {xml.elem("BounceTopic", identity.getNotificationAttributes().getOrDefault("BounceTopic", ""));xml.elem("ComplaintTopic", identity.getNotificationAttributes().getOrDefault("ComplaintTopic", ""));xml.elem("DeliveryTopic", identity.getNotificationAttributes().getOrDefault("DeliveryTopic", ""));- xml.elem("ForwardingEnabled", "true");- xml.elem("HeadersInBounceNotificationsEnabled", "false");- xml.elem("HeadersInComplaintNotificationsEnabled", "false");- xml.elem("HeadersInDeliveryNotificationsEnabled", "false");+ xml.elem("ForwardingEnabled", String.valueOf(identity.isFeedbackForwardingEnabled()));+ xml.elem("HeadersInBounceNotificationsEnabled",+ String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Bounce", false)));+ xml.elem("HeadersInComplaintNotificationsEnabled",+ String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Complaint", false)));+ xml.elem("HeadersInDeliveryNotificationsEnabled",+ String.valueOf(identity.getHeadersInNotificationsEnabled().getOrDefault("Delivery", false)));}xml.end("value");xml.end("entry");@@ -274,6 +281,66 @@ public class SesQueryHandler {return Response.ok(AwsQueryResponse.envelope("GetIdentityDkimAttributes", AwsNamespaces.SES, xml.build())).build();}+ private Response handleSetIdentityFeedbackForwardingEnabled(MultivaluedMap<String, String> params, String region) {+ String identityValue = getParam(params, "Identity");+ boolean enabled = parseRequiredBoolean(params, "ForwardingEnabled");+ sesService.setFeedbackForwardingEnabled(identityValue, enabled, region);+ return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityFeedbackForwardingEnabled", AwsNamespaces.SES)).build();+ }++ private Response handleSetIdentityHeadersInNotificationsEnabled(MultivaluedMap<String, String> params, String region) {+ String identityValue = getParam(params, "Identity");+ String notificationType = getParam(params, "NotificationType");+ boolean enabled = parseRequiredBoolean(params, "Enabled");+ sesService.setHeadersInNotificationsEnabled(identityValue, notificationType, enabled, region);+ return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityHeadersInNotificationsEnabled", AwsNamespaces.SES)).build();+ }++ private Response handleSetIdentityMailFromDomain(MultivaluedMap<String, String> params, String region) {+ String identityValue = getParam(params, "Identity");+ String mailFromDomain = getParam(params, "MailFromDomain");+ if (mailFromDomain == null) {+ throw new AwsException("InvalidParameterValue",+ "MailFromDomain is required (use an empty string to clear the existing setting).", 400);+ }+ String behaviorOnMxFailure = getParam(params, "BehaviorOnMXFailure");+ sesService.setMailFromDomain(identityValue, mailFromDomain, behaviorOnMxFailure, region);+ return Response.ok(AwsQueryResponse.envelopeEmptyResult("SetIdentityMailFromDomain", AwsNamespaces.SES)).build();+ }++ private static boolean parseRequiredBoolean(MultivaluedMap<String, String> params, String name) {+ String raw = params.getFirst(name);+ if (raw == null) {+ throw new AwsException("InvalidParameterValue", name + " is required.", 400);+ }+ if (!"true".equalsIgnoreCase(raw) && !"false".equalsIgnoreCase(raw)) {+ throw new AwsException("InvalidParameterValue",+ name + " must be \"true\" or \"false\".", 400);+ }+ return Boolean.parseBoolean(raw);+ }++ private Response handleGetIdentityMailFromDomainAttributes(MultivaluedMap<String, String> params, String region) {+ List<String> identities = extractMembers(params, "Identities");+ var xml = new XmlBuilder().start("MailFromDomainAttributes");+ for (String identityValue : identities) {+ Identity identity = sesService.getMailFromAttributes(identityValue, region);+ xml.start("entry");+ xml.elem("key", identityValue);+ xml.start("value");+ xml.elem("MailFromDomain", identity != null && identity.getMailFromDomain() != null+ ? identity.getMailFromDomain() : "");+ xml.elem("MailFromDomainStatus", identity != null+ ? identity.getMailFromDomainStatus() : "Pending");+ xml.elem("BehaviorOnMXFailure", identity != null+ ? identity.getBehaviorOnMxFailure() : "UseDefaultValue");+ xml.end("value");+ xml.end("entry");+ }+ xml.end("MailFromDomainAttributes");+ return Response.ok(AwsQueryResponse.envelope("GetIdentityMailFromDomainAttributes", AwsNamespaces.SES, xml.build())).build();+ }+// --- Templates ---private Response handleCreateTemplate(MultivaluedMap<String, String> params, String region) {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 af23f448cc..7fdc830161 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@@ -238,13 +238,76 @@ public class SesService {public void setFeedbackForwardingEnabled(String identityValue, boolean enabled, String region) {String key = identityKey(region, identityValue);Identity identity = identityStore.get(key)- .orElseThrow(() -> new AwsException("NotFoundException",- "Identity does not exist: " + identityValue, 404));+ .orElseThrow(() -> new AwsException("InvalidParameterValue",+ "Identity " + identityValue+ + " is invalid. Must be a verified email address or domain.", 400));identity.setFeedbackForwardingEnabled(enabled);identityStore.put(key, identity);LOG.infov("Updated feedback forwarding for {0}: enabled={1}", identityValue, enabled);}+ public void setMailFromDomain(String identityValue, String mailFromDomain,+ String behaviorOnMxFailure, String region) {+ String normalizedBehavior = null;+ if (behaviorOnMxFailure != null) {+ if (!"UseDefaultValue".equals(behaviorOnMxFailure)+ && !"RejectMessage".equals(behaviorOnMxFailure)) {+ throw new AwsException("ValidationError",+ "1 validation error detected: Value at 'behaviorOnMXFailure' failed to satisfy "+ + "constraint: Member must satisfy enum value set: [RejectMessage, UseDefaultValue]", 400);+ }+ normalizedBehavior = behaviorOnMxFailure;+ }+ boolean clearing = mailFromDomain == null || mailFromDomain.isEmpty();+ if (!clearing && mailFromDomain.isBlank()) {+ throw new AwsException("InvalidParameterValue",+ "MailFromDomain must be a domain or an empty string to clear; whitespace is not accepted.", 400);+ }+ String key = identityKey(region, identityValue);+ Identity identity = identityStore.get(key)+ .orElseThrow(() -> new AwsException("InvalidParameterValue",+ "Identity <" + identityValue + "> does not exist.", 400));+ identity.setMailFromDomain(clearing ? null : mailFromDomain);+ identity.setMailFromDomainStatus(clearing ? "Pending" : "Success");+ if (normalizedBehavior != null) {+ identity.setBehaviorOnMxFailure(normalizedBehavior);+ }+ identityStore.put(key, identity);+ LOG.infov("Updated MAIL FROM domain for {0}: domain={1}, behavior={2}",+ identityValue, mailFromDomain, normalizedBehavior);+ }++ public Identity getMailFromAttributes(String identityValue, String region) {+ String key = identityKey(region, identityValue);+ return identityStore.get(key).orElse(null);+ }++ private static final java.util.List<String> NOTIFICATION_TYPES =+ java.util.List.of("Bounce", "Complaint", "Delivery");++ public void setHeadersInNotificationsEnabled(String identityValue, String notificationType,+ boolean enabled, String region) {+ if (notificationType == null || notificationType.isBlank()) {+ throw new AwsException("InvalidParameterValue",+ "NotificationType is required.", 400);+ }+ if (!NOTIFICATION_TYPES.contains(notificationType)) {+ throw new AwsException("ValidationError",+ "1 validation error detected: Value at 'notificationType' failed to satisfy "+ + "constraint: Member must satisfy enum value set: "+ + NOTIFICATION_TYPES, 400);+ }+ String key = identityKey(region, identityValue);+ Identity identity = identityStore.get(key)+ .orElseThrow(() -> new AwsException("InvalidParameterValue",+ "Identity " + identityValue+ + " is invalid. It must be a verified email address or domain.", 400));+ identity.getHeadersInNotificationsEnabled().put(notificationType, enabled);+ identityStore.put(key, identity);+ LOG.infov("Updated headers-in-notifications for {0}: {1}={2}",+ identityValue, notificationType, enabled);+ }+public List<String> getVerifiedEmailAddresses(String region) {String prefix = "identity::" + region + "::";List<Identity> all = identityStore.scan(k -> k.startsWith(prefix));diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/Identity.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/Identity.javaindex 0aadf25ee4..3852122509 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/model/Identity.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/Identity.java@@ -36,6 +36,18 @@ public class Identity {@JsonProperty("FeedbackForwardingEnabled")private boolean feedbackForwardingEnabled = true;+ @JsonProperty("MailFromDomain")+ private String mailFromDomain;++ @JsonProperty("BehaviorOnMxFailure")+ private String behaviorOnMxFailure = "UseDefaultValue";++ @JsonProperty("MailFromDomainStatus")+ private String mailFromDomainStatus = "Pending";++ @JsonProperty("HeadersInNotificationsEnabled")+ private Map<String, Boolean> headersInNotificationsEnabled = new HashMap<>();+@JsonProperty("CreatedAt")private Instant createdAt;@@ -75,6 +87,18 @@ public class Identity {public boolean isFeedbackForwardingEnabled() { return feedbackForwardingEnabled; }public void setFeedbackForwardingEnabled(boolean feedbackForwardingEnabled) { this.feedbackForwardingEnabled = feedbackForwardingEnabled; }+ public String getMailFromDomain() { return mailFromDomain; }+ public void setMailFromDomain(String mailFromDomain) { this.mailFromDomain = mailFromDomain; }++ public String getBehaviorOnMxFailure() { return behaviorOnMxFailure; }+ public void setBehaviorOnMxFailure(String behaviorOnMxFailure) { this.behaviorOnMxFailure = behaviorOnMxFailure; }++ public String getMailFromDomainStatus() { return mailFromDomainStatus; }+ public void setMailFromDomainStatus(String mailFromDomainStatus) { this.mailFromDomainStatus = mailFromDomainStatus; }++ public Map<String, Boolean> getHeadersInNotificationsEnabled() { return headersInNotificationsEnabled; }+ public void setHeadersInNotificationsEnabled(Map<String, Boolean> headersInNotificationsEnabled) { this.headersInNotificationsEnabled = headersInNotificationsEnabled; }+public Instant getCreatedAt() { return createdAt; }public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.javanew file mode 100644index 0000000000..9c711cc80a--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV1IntegrationTest.java@@ -0,0 +1,330 @@+package io.github.hectorvent.floci.services.ses;++import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestMethodOrder;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.containsString;++@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class SesIdentityAttributesV1IntegrationTest {++ private static final String AUTH =+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";++ @Test+ @Order(1)+ void verifyDomainIdentity_setsUpDomain() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "VerifyDomainIdentity")+ .formParam("Domain", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("VerifyDomainIdentityResponse"));+ }++ @Test+ @Order(2)+ void setIdentityMailFromDomain_setsAttributes() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("MailFromDomain", "mail.v1-attrs.floci.test")+ .formParam("BehaviorOnMXFailure", "RejectMessage")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("SetIdentityMailFromDomainResponse"));+ }++ @Test+ @Order(3)+ void getIdentityMailFromDomainAttributes_returnsValues() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "GetIdentityMailFromDomainAttributes")+ .formParam("Identities.member.1", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<MailFromDomain>mail.v1-attrs.floci.test</MailFromDomain>"))+ .body(containsString("<MailFromDomainStatus>Success</MailFromDomainStatus>"))+ .body(containsString("<BehaviorOnMXFailure>RejectMessage</BehaviorOnMXFailure>"));+ }++ @Test+ @Order(4)+ void setIdentityMailFromDomain_emptyDomain_clears() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("MailFromDomain", "")+ .when()+ .post("/")+ .then()+ .statusCode(200);++ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "GetIdentityMailFromDomainAttributes")+ .formParam("Identities.member.1", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<MailFromDomain></MailFromDomain>"))+ .body(containsString("<MailFromDomainStatus>Pending</MailFromDomainStatus>"));+ }++ @Test+ @Order(5)+ void setIdentityFeedbackForwardingEnabled_togglesFlag() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityFeedbackForwardingEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("ForwardingEnabled", "false")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("SetIdentityFeedbackForwardingEnabledResponse"));+ }++ @Test+ @Order(6)+ void setIdentityHeadersInNotificationsEnabled_setsFlag() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityHeadersInNotificationsEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("NotificationType", "Bounce")+ .formParam("Enabled", "true")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("SetIdentityHeadersInNotificationsEnabledResponse"));+ }++ @Test+ @Order(10)+ void setIdentityMailFromDomain_unknownIdentity_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "ghost.floci.test")+ .formParam("MailFromDomain", "mail.ghost.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>InvalidParameterValue</Code>"))+ .body(containsString("Identity <ghost.floci.test> does not exist."));+ }++ @Test+ @Order(11)+ void setIdentityMailFromDomain_missingMailFromDomain_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }++ @Test+ @Order(12)+ void setIdentityFeedbackForwardingEnabled_missingForwardingEnabled_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityFeedbackForwardingEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }++ @Test+ @Order(13)+ void setIdentityHeadersInNotificationsEnabled_missingEnabled_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityHeadersInNotificationsEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("NotificationType", "Bounce")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }++ @Test+ @Order(14)+ void setIdentityFeedbackForwardingEnabled_invalidBoolean_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityFeedbackForwardingEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("ForwardingEnabled", "yes")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }++ @Test+ @Order(15)+ void setIdentityMailFromDomain_unknownBehaviorOnMxFailure_returnsValidationError() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("MailFromDomain", "mail.v1-attrs.floci.test")+ .formParam("BehaviorOnMXFailure", "BogusValue")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>ValidationError</Code>"))+ .body(containsString("Member must satisfy enum value set: [RejectMessage, UseDefaultValue]"));+ }++ @Test+ @Order(20)+ void setIdentityMailFromDomain_whitespaceMailFromDomain_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("MailFromDomain", " ")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("InvalidParameterValue"));+ }++ @Test+ @Order(19)+ void setIdentityMailFromDomain_emptyBehaviorOnMxFailure_returnsValidationError() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityMailFromDomain")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("MailFromDomain", "mail.v1-attrs.floci.test")+ .formParam("BehaviorOnMXFailure", "")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>ValidationError</Code>"));+ }++ @Test+ @Order(18)+ void setIdentityHeadersInNotificationsEnabled_unknownNotificationType_returnsValidationError() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityHeadersInNotificationsEnabled")+ .formParam("Identity", "v1-attrs.floci.test")+ .formParam("NotificationType", "bounce")+ .formParam("Enabled", "true")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>ValidationError</Code>"))+ .body(containsString("Member must satisfy enum value set"));+ }++ @Test+ @Order(16)+ void setIdentityHeadersInNotificationsEnabled_unknownIdentity_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityHeadersInNotificationsEnabled")+ .formParam("Identity", "ghost-headers.floci.test")+ .formParam("NotificationType", "Bounce")+ .formParam("Enabled", "true")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>InvalidParameterValue</Code>"))+ .body(containsString("Identity ghost-headers.floci.test is invalid. It must be a verified email address or domain."));+ }++ @Test+ @Order(21)+ void setIdentityFeedbackForwardingEnabled_unknownIdentity_returnsInvalidParameterValue() {+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "SetIdentityFeedbackForwardingEnabled")+ .formParam("Identity", "ghost-feedback.floci.test")+ .formParam("ForwardingEnabled", "true")+ .when()+ .post("/")+ .then()+ .statusCode(400)+ .body(containsString("<Code>InvalidParameterValue</Code>"))+ .body(containsString("Identity ghost-feedback.floci.test is invalid. Must be a verified email address or domain."));+ }++ @Test+ @Order(17)+ void getIdentityNotificationAttributes_reflectsForwardingAndHeaderFlags() {+ // Order(5) disabled forwarding, Order(6) enabled headers-in-Bounce.+ // The Get call should now report those, not hard-coded defaults.+ given()+ .contentType("application/x-www-form-urlencoded")+ .header("Authorization", AUTH)+ .formParam("Action", "GetIdentityNotificationAttributes")+ .formParam("Identities.member.1", "v1-attrs.floci.test")+ .when()+ .post("/")+ .then()+ .statusCode(200)+ .body(containsString("<ForwardingEnabled>false</ForwardingEnabled>"))+ .body(containsString("<HeadersInBounceNotificationsEnabled>true</HeadersInBounceNotificationsEnabled>"))+ .body(containsString("<HeadersInComplaintNotificationsEnabled>false</HeadersInComplaintNotificationsEnabled>"))+ .body(containsString("<HeadersInDeliveryNotificationsEnabled>false</HeadersInDeliveryNotificationsEnabled>"));+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.javanew file mode 100644index 0000000000..7cd5a63a8e--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesIdentityAttributesV2IntegrationTest.java@@ -0,0 +1,204 @@+package io.github.hectorvent.floci.services.ses;++import io.quarkus.test.junit.QuarkusTest;+import org.junit.jupiter.api.MethodOrderer;+import org.junit.jupiter.api.Order;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestMethodOrder;++import static io.restassured.RestAssured.given;+import static org.hamcrest.Matchers.equalTo;++@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class SesIdentityAttributesV2IntegrationTest {++ private static final String AUTH_HEADER =+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";++ @Test+ @Order(1)+ void createEmailIdentity_setsUpDomain() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"EmailIdentity": "v2-attrs.floci.test"}+ """)+ .when()+ .post("/v2/email/identities")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(2)+ void putEmailIdentityMailFromAttributes_setsDomain() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "MailFromDomain": "mail.v2-attrs.floci.test",+ "BehaviorOnMxFailure": "REJECT_MESSAGE"+ }+ """)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(3)+ void getEmailIdentity_includesMailFromAttributes() {+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/v2/email/identities/v2-attrs.floci.test")+ .then()+ .statusCode(200)+ .body("MailFromAttributes.MailFromDomain", equalTo("mail.v2-attrs.floci.test"))+ .body("MailFromAttributes.MailFromDomainStatus", equalTo("SUCCESS"))+ .body("MailFromAttributes.BehaviorOnMxFailure", equalTo("REJECT_MESSAGE"));+ }++ @Test+ @Order(4)+ void putEmailIdentityMailFromAttributes_emptyDomain_clears() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"MailFromDomain": ""}+ """)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/v2/email/identities/v2-attrs.floci.test")+ .then()+ .statusCode(200)+ .body("MailFromAttributes.MailFromDomain", equalTo(""))+ .body("MailFromAttributes.MailFromDomainStatus", equalTo("NOT_STARTED"));+ }++ @Test+ @Order(5)+ void putEmailIdentityMailFromAttributes_unknownIdentity_returnsBadRequest() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"MailFromDomain": "mail.ghost.floci.test"}+ """)+ .when()+ .put("/v2/email/identities/ghost.floci.test/mail-from")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo("Identity <ghost.floci.test> does not exist."));+ }++ @Test+ @Order(11)+ void putEmailIdentityFeedbackAttributes_unknownIdentity_returnsBadRequest() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"EmailForwardingEnabled": true}+ """)+ .when()+ .put("/v2/email/identities/ghost-feedback.floci.test/feedback")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo(+ "Identity ghost-feedback.floci.test is invalid. Must be a verified email address or domain."));+ }++ @Test+ @Order(6)+ void putEmailIdentityMailFromAttributes_invalidJson_returns400() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("[1,2,3]")+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));+ }++ @Test+ @Order(7)+ void putEmailIdentityMailFromAttributes_missingBody_returns400() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));+ }++ @Test+ @Order(8)+ void putEmailIdentityMailFromAttributes_missingMailFromDomainField_returns400() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"BehaviorOnMxFailure": "USE_DEFAULT_VALUE"}+ """)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));+ }++ @Test+ @Order(9)+ void putEmailIdentityMailFromAttributes_mailFromDomainAsObject_returns400() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"MailFromDomain": {"foo": "bar"}}+ """)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));+ }++ @Test+ @Order(10)+ void putEmailIdentityMailFromAttributes_unknownBehavior_returns400() {+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "MailFromDomain": "mail.v2-attrs.floci.test",+ "BehaviorOnMxFailure": "BOGUS_VALUE"+ }+ """)+ .when()+ .put("/v2/email/identities/v2-attrs.floci.test/mail-from")+ .then()+ .body("message", org.hamcrest.Matchers.containsString(+ "Member must satisfy enum value set: [REJECT_MESSAGE, USE_DEFAULT_VALUE]"))+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));+ }+}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.javaindex 928a6ca3c1..f6ee84e882 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesV2IntegrationTest.java@@ -464,6 +464,10 @@ class SesV2IntegrationTest {@Test@Order(42)void putFeedbackAttributes_notFound() {+ // Real SES v2 returns BadRequestException (HTTP 400) for an unknown+ // identity on this endpoint, with the "Identity X is invalid..."+ // message inherited from the v1 SetIdentityFeedbackForwardingEnabled+ // wire shape via remapV1Exception.given().contentType("application/json").header("Authorization", AUTH_HEADER)@@ -473,8 +477,8 @@ class SesV2IntegrationTest {.when().put("/v2/email/identities/[email protected]/feedback").then()- .statusCode(404)- .body("__type", equalTo("NotFoundException"));+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"));}// ──────────────── Account Sending ────────────────