mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): add v2 suppression list endpoints (#813)
* feat(ses): add v2 suppression list endpoints
Implements the v2 SES suppression list management plane at
/v2/email/suppression/addresses:
- PUT /v2/email/suppression/addresses PutSuppressedDestination
- GET /v2/email/suppression/addresses/{EmailAddress} GetSuppressedDestination
- DELETE /v2/email/suppression/addresses/{EmailAddress} DeleteSuppressedDestination
- GET /v2/email/suppression/addresses ListSuppressedDestinations
(repeated Reason filter)
Entries are persisted per region in ses-suppression.json. A repeat Put for
the same EmailAddress updates the existing entry's Reason and LastUpdateTime.
List responses are sorted by LastUpdateTime then EmailAddress for stable
output across runs.
Behaviour aligned with real AWS responses:
- EmailAddress is silently trimmed of leading/trailing whitespace on Put
/ Get / Delete; whitespace-only is rejected with BadRequestException.
- Reason validation errors use the AWS-canonical "1 validation error
detected: Value at '<field>' failed to satisfy constraint: Member must
satisfy enum value set: [BOUNCE, COMPLAINT]" wording, with the nested
"Member must satisfy constraint: [...]" wrapping AWS emits for the
list-typed reasons filter.
- ListSuppressedDestinations accepts a repeated Reason query param (the
Java SDK's .reasons(...) varargs serialise this way) and applies
OR-semantics across the supplied values.
- GetSuppressedDestination and DeleteSuppressedDestination return
NotFoundException with "Email address <X> does not exist on your
suppression list." for unknown addresses — Delete is not idempotent
on AWS so floci matches.
SendEmail integration is intentionally out of scope: suppressed addresses
are still delivered locally so that existing send tests remain unaffected.
A follow-up PR can wire suppression checks into the send path along with
the PutAccount/ConfigurationSetSuppressionOptions configuration endpoints.
Tests:
- SesSuppressionV2IntegrationTest covers Put/Get/Delete lifecycle, List
sort order, single- and multi-Reason filter (with OR semantics), Put
updates, trim-on-Put, idempotent-Get-on-known, and validation errors.
- SesSuppressionListTest exercises the same surface through the Java SDK
v2 SesV2Client.
* fix(ses): reject null and non-object bodies on PutSuppressedDestination
Jackson's NullNode.asText("default") returns the literal string "null"
rather than the default, so a body like
{"EmailAddress": null, "Reason": "BOUNCE"}
silently stored an entry under the email address "null". Validate the
body is a JSON object via requireJsonObject and require both
EmailAddress and Reason to be present and textual via a new
readRequiredStringField helper.
SesSuppressionV2IntegrationTest gains three cases covering null
EmailAddress, null Reason, and a non-object root body.
This commit is contained in:
1 parent
7516acb5f9
commit
944f82a6a4
7 files changed
+681
No files matched your search
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
|
||||
import io.github.hectorvent.floci.services.ses.model.EmailTemplate;
|
||||
import io.github.hectorvent.floci.services.ses.model.Identity;
|
||||
import io.github.hectorvent.floci.services.ses.model.SentEmail;
|
||||
import io.github.hectorvent.floci.services.ses.model.SuppressedDestination;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -34,6 +35,7 @@ class SesServiceSmtpTest {
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
new InMemoryStorage<String, EmailTemplate>(),
|
||||
new InMemoryStorage<String, ConfigurationSet>(),
|
||||
new InMemoryStorage<String, SuppressedDestination>(),
|
||||
smtpRelay,
|
||||
new ObjectMapper());
|
||||
}
|
||||
|
||||
+339
@@ -0,0 +1,339 @@
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* Integration tests for SES v2 suppression list endpoints at /v2/email/suppression/addresses.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSuppressionV2IntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void putSuppressedDestination_bounce() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "bounce-1@example.com", "Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void putSuppressedDestination_complaint() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "complaint-1@example.com", "Reason": "COMPLAINT"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void getSuppressedDestination_returnsStoredEntry() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses/bounce-1@example.com")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestination.EmailAddress", equalTo("bounce-1@example.com"))
|
||||
.body("SuppressedDestination.Reason", equalTo("BOUNCE"))
|
||||
.body("SuppressedDestination.LastUpdateTime", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void getSuppressedDestination_unknown_returns404() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses/missing@example.com")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void putSuppressedDestination_updatesExistingReason() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "bounce-1@example.com", "Reason": "COMPLAINT"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses/bounce-1@example.com")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestination.Reason", equalTo("COMPLAINT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void listSuppressedDestinations_returnsAll() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestinationSummaries", hasSize(greaterThanOrEqualTo(2)))
|
||||
.body("SuppressedDestinationSummaries.EmailAddress",
|
||||
hasItems("bounce-1@example.com", "complaint-1@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void listSuppressedDestinations_filteredByReason() {
|
||||
// Seed a BOUNCE entry so the filter has something to exclude — without it
|
||||
// every existing entry is already COMPLAINT (bounce-1 was flipped at @Order(5))
|
||||
// and the assertion would pass even if the server ignored the filter.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "filter-bounce@example.com", "Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("Reason", "COMPLAINT")
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestinationSummaries.Reason.unique()", contains("COMPLAINT"))
|
||||
.body("SuppressedDestinationSummaries.EmailAddress",
|
||||
not(hasItem("filter-bounce@example.com")));
|
||||
|
||||
// Clean up so the BOUNCE seed does not leak into later assertions
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/v2/email/suppression/addresses/filter-bounce@example.com")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void deleteSuppressedDestination_removesEntry() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/v2/email/suppression/addresses/bounce-1@example.com")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses/bounce-1@example.com")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void deleteSuppressedDestination_unknown_returns404() {
|
||||
// AWS DeleteSuppressedDestination is not idempotent — an unknown email
|
||||
// surfaces as NotFoundException with the same wording as GetSuppressedDestination.
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.delete("/v2/email/suppression/addresses/already-gone@example.com")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"))
|
||||
.body("message", containsString("does not exist on your suppression list"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void putSuppressedDestination_invalidReason_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "bad@example.com", "Reason": "OTHER"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void putSuppressedDestination_missingEmailAddress_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void putSuppressedDestination_missingBody_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void putSuppressedDestination_nullEmailAddress_returns400() {
|
||||
// JSON null for EmailAddress must not coerce into the literal string "null".
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": null, "Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void putSuppressedDestination_nullReason_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "null-reason@example.com", "Reason": null}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void putSuppressedDestination_nonObjectBody_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("[\"not\", \"an\", \"object\"]")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void putSuppressedDestination_trimsWhitespaceFromEmailAddress() {
|
||||
// AWS silently trims leading/trailing whitespace from EmailAddress on Put.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": " padded@example.com ", "Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses/padded@example.com")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestination.EmailAddress", equalTo("padded@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void listSuppressedDestinations_unknownReasonFilter_returns400() {
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("Reason", "OTHER")
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
void listSuppressedDestinations_multipleReasonFilters_appliesOrSemantics() {
|
||||
// Seed a BOUNCE entry alongside the surviving complaint-1 COMPLAINT entry
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"EmailAddress": "multi-bounce@example.com", "Reason": "BOUNCE"}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("Reason", "BOUNCE")
|
||||
.queryParam("Reason", "COMPLAINT")
|
||||
.when()
|
||||
.get("/v2/email/suppression/addresses")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("SuppressedDestinationSummaries.EmailAddress",
|
||||
hasItems("multi-bounce@example.com", "complaint-1@example.com"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user