mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ses): align /_aws/ses inspection endpoint with LocalStack behavior (#512)
* fix(ses): store text and html body separately and return raw as RawData
The inspection endpoint (/_aws/ses) previously collapsed bodyHtml and
bodyText into a single field, making both text_part and html_part
identical. Split SentEmail.body into bodyText and bodyHtml so the
inspection response correctly distinguishes the two, with null for the
absent part — matching LocalStack 4.14.0 behavior.
Raw emails now use a dedicated rawData field and constructor. The
inspection endpoint returns RawData (the full MIME message) without
Destination, Subject, or Body fields, matching LocalStack's shape.
Tests: 4 new integration tests covering text+html separation, text-only
(html_part=null), html-only (text_part=null), and raw email (RawData
without Body/Subject/Destination).
* fix(ses): parse and store ReplyToAddresses
ReplyToAddresses was silently dropped on both SES v1 (Query) and v2
(REST JSON) send paths. Parse it from the request, store it on
SentEmail, and return it in the inspection endpoint (/_aws/ses) for
non-raw emails. The field is omitted when empty, matching LocalStack
behavior.
* fix(ses): return all regions in inspection endpoint
LocalStack's /_aws/ses returns emails from all regions regardless of
request headers, with each message carrying its own Region field.
Floci previously filtered by the default region, hiding emails sent
to other regions.
- Add region field to SentEmail, set on send.
- SesInspectionController GET now calls getAllEmails() (no region
filter) and reads region from each email.
- DELETE clears all regions.
* refactor(ses): remove unused RegionResolver and use putNull for region
SesInspectionController no longer filters by region, so the injected
RegionResolver is dead code. Remove it and align the null-region
handling with other optional fields (putNull instead of empty string).
* fix(ses): use bulk clear and add v1 ReplyToAddresses test
- clearAllEmails() now calls emailStore.clear() instead of deleting
entries one-by-one, avoiding N disk writes on persistent backends.
- New SesIntegrationTest covering the SES v1 Query path for
ReplyToAddresses: sends via SendEmail with ReplyToAddresses.member.1
and verifies round-trip through the /_aws/ses inspection endpoint.
* refactor(ses): simplify getEmails/clearEmails to region-agnostic
The inspection endpoint now returns all regions unconditionally, so
the region-scoped getEmails(region) and clearEmails(region) are dead
code. Replace them with parameter-less getEmails() and clearEmails(),
and drop the intermediate getAllEmails/clearAllEmails aliases.
* fix(ses): add backward-compat alias for legacy Body field and multi-region test
- @JsonAlias("Body") on bodyText so persisted SentEmail objects from
before the text/html split still deserialize their body into bodyText
rather than silently losing it.
- New test: send emails in two different regions (us-east-1 and
ap-northeast-1) and verify /_aws/ses returns both with correct
per-message Region values.
* refactor(ses): move region and replyToAddresses into SentEmail constructors
Both fields were set via setters immediately after construction, which
is inconsistent with the other fields that are constructor arguments.
Add them to the Simple and Raw constructors so all required state is
established at creation time.
* refactor(ses): align sendEmail parameter order with SentEmail constructor
Move region to the first parameter position so the argument order
matches the SentEmail constructor (messageId, region, source, to, cc,
bcc, replyTo, subject, bodyText, bodyHtml). No functional change.
* refactor(ses): remove unused RegionResolver and validate rawMessage
- SesService no longer uses RegionResolver (region is always passed as
a parameter from controllers). Remove the field, constructor parameter,
and import.
- sendRawEmail now rejects null/blank rawMessage with
InvalidParameterValue, preventing a stored email that would appear
as non-raw in the inspection endpoint.
* fix(ses): validate source in sendRawEmail
sendRawEmail lacked the null/blank check on source that sendEmail
already had, allowing stored messages with Source=null and a 200
response. Add the same guard for consistency.
* refactor(ses): remove unused EmulatorConfig from SesService constructor
The config parameter was injected but never referenced.
* revert: restore EmulatorConfig in SesService constructor
Removing the unused EmulatorConfig parameter caused an awscli compat
test failure (SES: verify identities deleted). The parameter likely
influences Quarkus CDI initialization ordering — StorageFactory may
depend on EmulatorConfig being resolved first. Restore with
@SuppressWarnings("unused") to document intent.
* fix(ses): omit empty CcAddresses and BccAddresses from inspection response
LocalStack omits these keys when the list is empty rather than returning
an empty array. Apply the same !isEmpty() guard already used for
ReplyToAddresses.
* fix(ses): omit empty ToAddresses and restore region parameter order
- Apply the same !isEmpty() guard to ToAddresses so it is omitted from
the inspection response when empty, consistent with CcAddresses,
BccAddresses, and ReplyToAddresses.
- Revert sendEmail parameter order: move region back to the last
position to match the convention used by all other SesService methods
(verifyEmailIdentity, deleteIdentity, listIdentities, etc.).
* refactor(ses): remove unused EmulatorConfig from SesService constructor
The config parameter was injected but never referenced. A previous
attempt to remove it (76d6c22) was reverted due to a CI failure, but
that failure may have been flaky (S3 Notifications queue filter
round-trip, a known pre-existing issue). Retrying after rebase onto
latest main.
This commit is contained in:
1 parent
0f70ff75a8
commit
4719269df4
7 files changed
+463
-63
No files matched your search
@@ -357,6 +357,34 @@ class SesIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void sendEmailV1_replyToAddressesStoredInInspection() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request")
|
||||
.formParam("Action", "SendEmail")
|
||||
.formParam("Source", "sender@example.com")
|
||||
.formParam("Destination.ToAddresses.member.1", "recipient@example.com")
|
||||
.formParam("ReplyToAddresses.member.1", "reply@example.com")
|
||||
.formParam("Message.Subject.Data", "V1 ReplyTo")
|
||||
.formParam("Message.Body.Text.Data", "body")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("<MessageId>"));
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].ReplyToAddresses", hasItem("reply@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void unsupportedAction_returns400() {
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
|
||||
@@ -617,6 +617,321 @@ class SesV2IntegrationTest {
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
// ──────────────── Inspection endpoint (/_aws/ses) ────────────────
|
||||
|
||||
@Test
|
||||
@Order(70)
|
||||
void inspectionEndpoint_textAndHtmlAreStoredSeparately() {
|
||||
// Create identity
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailIdentity": "inspect-sender@example.com"}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/identities")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Clear any previous messages
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
// Send with distinct Text and Html bodies
|
||||
String messageId = given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "Inspect Test"},
|
||||
"Body": {
|
||||
"Text": {"Data": "plain text body"},
|
||||
"Html": {"Data": "<p>html body</p>"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("MessageId");
|
||||
|
||||
// Verify via inspection endpoint
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses?id=" + messageId)
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].Body.text_part", equalTo("plain text body"))
|
||||
.body("messages[0].Body.html_part", equalTo("<p>html body</p>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(71)
|
||||
void inspectionEndpoint_textOnlyEmail() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "Text Only"},
|
||||
"Body": {
|
||||
"Text": {"Data": "only text"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].Body.text_part", equalTo("only text"))
|
||||
.body("messages[0].Body.html_part", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(72)
|
||||
void inspectionEndpoint_htmlOnlyEmail() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "Html Only"},
|
||||
"Body": {
|
||||
"Html": {"Data": "<b>only html</b>"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].Body.text_part", nullValue())
|
||||
.body("messages[0].Body.html_part", equalTo("<b>only html</b>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(73)
|
||||
void inspectionEndpoint_replyToAddressesAreStored() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"ReplyToAddresses": ["reply1@example.com", "reply2@example.com"],
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "ReplyTo Test"},
|
||||
"Body": {"Text": {"Data": "hello"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].ReplyToAddresses", hasItems("reply1@example.com", "reply2@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(74)
|
||||
void inspectionEndpoint_noReplyToOmitsField() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "No ReplyTo"},
|
||||
"Body": {"Text": {"Data": "hello"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0]", not(hasKey("ReplyToAddresses")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(75)
|
||||
void inspectionEndpoint_rawEmailReturnsRawData() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "inspect-sender@example.com",
|
||||
"Destination": {
|
||||
"ToAddresses": ["inspect-to@example.com"]
|
||||
},
|
||||
"Content": {
|
||||
"Raw": {
|
||||
"Data": "Subject: Raw\\r\\n\\r\\nRaw body"
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages[0].RawData", notNullValue())
|
||||
.body("messages[0].RawData", containsString("Raw body"))
|
||||
.body("messages[0]", not(hasKey("Destination")))
|
||||
.body("messages[0]", not(hasKey("Subject")))
|
||||
.body("messages[0]", not(hasKey("Body")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(80)
|
||||
void inspectionEndpoint_returnsEmailsFromAllRegions() {
|
||||
given().delete("/_aws/ses").then().statusCode(200);
|
||||
|
||||
// Create identity usable in both regions (domain covers all addresses)
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailIdentity": "example.com"}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/identities")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Send from us-east-1
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request")
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "multi@example.com",
|
||||
"Destination": {"ToAddresses": ["to@example.com"]},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "US East"},
|
||||
"Body": {"Text": {"Data": "from us-east-1"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Send from ap-northeast-1
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization",
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-1/ses/aws4_request")
|
||||
.body("""
|
||||
{
|
||||
"FromEmailAddress": "multi@example.com",
|
||||
"Destination": {"ToAddresses": ["to@example.com"]},
|
||||
"Content": {
|
||||
"Simple": {
|
||||
"Subject": {"Data": "AP NE"},
|
||||
"Body": {"Text": {"Data": "from ap-northeast-1"}}
|
||||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/outbound-emails")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
// Inspection returns both, each with correct Region
|
||||
given()
|
||||
.when()
|
||||
.get("/_aws/ses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("messages.size()", equalTo(2))
|
||||
.body("messages.find { it.Subject == 'US East' }.Region", equalTo("us-east-1"))
|
||||
.body("messages.find { it.Subject == 'AP NE' }.Region", equalTo("ap-northeast-1"));
|
||||
}
|
||||
|
||||
// ──────────────── GetEmailIdentity full response ────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user