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,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 &lt;ghost.floci.test&gt; 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>"));
}
}
@@ -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"));
}
}
@@ -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/nonexistent@example.com/feedback")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"));
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
// ──────────────── Account Sending ────────────────