feat(ses): add MAIL FROM domain and identity attribute operations (#716)

* feat(ses): add MAIL FROM domain and identity attribute operations

v1 (Query):
- SetIdentityMailFromDomain / GetIdentityMailFromDomainAttributes
- SetIdentityFeedbackForwardingEnabled
- SetIdentityHeadersInNotificationsEnabled
- GetIdentityNotificationAttributes now reflects the stored
  feedbackForwardingEnabled and per-NotificationType
  headersInNotificationsEnabled flags instead of hard-coded defaults

v2 (REST JSON):
- PUT /v2/email/identities/{id}/mail-from -> PutEmailIdentityMailFromAttributes
- GetEmailIdentity response surfaces real MailFromAttributes
  (MailFromDomain / MailFromDomainStatus / BehaviorOnMxFailure) instead
  of the previously hard-coded "" / NOT_STARTED / USE_DEFAULT_VALUE
- v1 PascalCase <-> v2 SCREAMING_SNAKE BehaviorOnMxFailure values are
  translated at the controller boundary, with both ends rejecting
  unknown enum values

Identity gains mailFromDomain, behaviorOnMxFailure (v1 form),
mailFromDomainStatus, and headersInNotificationsEnabled fields. The
service layer normalizes BehaviorOnMxFailure to the canonical SESv1
enum values (UseDefaultValue / RejectMessage), so storage is
consistent regardless of which protocol wrote it.

Validation (verified against live aws-cli output):
- ForwardingEnabled / Enabled / MailFromDomain are required on the
  matching v1 setters; missing values produce InvalidParameterValue
  rather than silently being treated as false / null
- An empty-string MailFromDomain remains the documented "clear" path,
  distinct from a missing parameter; whitespace-only values are
  rejected (only "" or null clear the setting)
- BehaviorOnMxFailure / NotificationType enum violations return the
  AWS-canonical "1 validation error detected: Value at '<param>' failed
  to satisfy constraint: Member must satisfy enum value set: [...]"
  message: ValidationError on v1, BadRequestException on v2
- Unknown identity on v1 setters returns InvalidParameterValue with
  the AWS-canonical "Identity <X> does not exist." form (HTTP 400)
- v2 PutEmailIdentityMailFromAttributes follows the same wire mapping:
  unknown identity surfaces as BadRequestException (HTTP 400) via
  remapV1Exception, with the same "Identity <X> does not exist."
  message text. Schema / enum validation runs before the service call
  so an unknown enum on a missing identity still surfaces as an enum
  error rather than as the identity error
- v2 controller validates that MailFromDomain and BehaviorOnMxFailure
  are JSON strings; non-textual values produce BadRequestException
- AwsQueryController.SES_ACTIONS picks up the new v1 actions for the
  auth-less fallback dispatch

Tests: 21 v1 integration cases, 9 v2 integration cases, 4 SDK compat
cases (AWS Java SDK 2.42.24).

* fix(ses): align identity-setter missing-identity errors with live AWS

Previously setFeedbackForwardingEnabled threw NotFoundException/404 and
setHeadersInNotificationsEnabled threw a Floci-specific
"Identity <X> does not exist." message. Real AWS verified via
aws-cli returns InvalidParameterValue (HTTP 400) for both, but with
*different* operation-specific message texts:

- SetIdentityFeedbackForwardingEnabled (also v2 PUT /feedback after
  remapV1Exception):
    Identity X is invalid. Must be a verified email address or domain.
- SetIdentityHeadersInNotificationsEnabled:
    Identity X is invalid. It must be a verified email address or domain.
- SetIdentityMailFromDomain (unchanged in this commit):
    Identity <X> does not exist.

Update the service-level throws so each setter emits its operation's
exact wire shape. setFeedbackForwardingEnabled now also benefits the
pre-existing v2 PUT /feedback endpoint, which previously surfaced
NotFoundException/404 instead of BadRequestException/400.

Tests:
- v1 unknown-identity coverage for SetIdentityFeedbackForwardingEnabled
  (new) and updated message-text assertion for HeadersInNotificationsEnabled
- v2 unknown-identity coverage for PUT /feedback
- SDK compat additions: getIdentityNotificationAttributes round-trip
  exercising forwarding/header flags, and v2
  PutEmailIdentityMailFromAttributes unknown-identity throwing
  BadRequestException

* test(ses): update putFeedbackAttributes_notFound to expect BadRequest

The previous commit changed setFeedbackForwardingEnabled to throw
InvalidParameterValue (HTTP 400) for missing identities to match real
AWS, which propagates through remapV1Exception as BadRequestException
on the v2 PUT /feedback path. The pre-existing
SesV2IntegrationTest.putFeedbackAttributes_notFound still asserted the
old 404 / NotFoundException behavior, so it began failing in CI.

Update the test to expect 400 / BadRequestException, matching the
verified live AWS response.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-05 22:41:17 -05:00
1 parent aee46fe2da
commit bd3a33326c
10 files changed
+951 -11

No files matched your search

@@ -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);
}
}