feat(ses): add v2 PutAccountSuppressionAttributes (#853)

Implements PUT /v2/email/account/suppression so callers can change the
account-level suppression list reasons (BOUNCE / COMPLAINT). Entries
are persisted per region in ses-account-suppression.json via a new
AccountSuppressionAttributes model.

GetAccount's response is extended with a SuppressionAttributes object
that carries the stored SuppressedReasons. The setting itself is
metadata-only — floci does not synthesise bounce/complaint events so
no auto-suppression is triggered; the configuration round-trips for
SDK users and tooling that introspects account-level settings.

Behaviour aligned with real-AWS verification:

- SuppressedReasons accepts BOUNCE / COMPLAINT, validated against the
  AWS-canonical nested "Member must satisfy constraint:
  [Member must satisfy enum value set: [BOUNCE, COMPLAINT]]" wording
  (verbatim match against real AWS).
- SuppressedReasons may be omitted (treated as empty list) or supplied
  as an empty array (clears the reasons) — both return 200.
- Non-textual array members (JSON null, numeric, etc.) are rejected
  with BadRequestException.
- Fresh regions report the AWS-default [BOUNCE, COMPLAINT] via
  GetAccount; an explicit PUT (including an empty list) overrides it.
- The optional ValidationAttributes body field is accepted but not
  parsed (Tier S scope).

Tests:
- SesV2IntegrationTest gains nine cases covering store-and-list,
  clear-with-empty-array, missing field defaulting to empty, invalid
  Reason (with the AWS-canonical nested message asserted), non-array
  SuppressedReasons, JSON null array member, numeric array member,
  optional ValidationAttributes, and the default-on-fresh-region
  assertion in the existing getAccount case.
- SesAccountSuppressionTest exercises the Java SDK round trip and an
  explicit empty list through SesV2Client; @BeforeAll captures the
  caller's existing SuppressedReasons and @AfterAll restores it with
  failures surfaced so a real-AWS run cannot silently leave the
  account with auto-suppression disabled.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-15 22:59:14 -05:00
1 parent 6d36f66e5f
commit 010bbd15cd
8 files changed
+362 -2

No files matched your search

@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
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;
@@ -36,6 +37,7 @@ class SesServiceSmtpTest {
new InMemoryStorage<String, EmailTemplate>(),
new InMemoryStorage<String, ConfigurationSet>(),
new InMemoryStorage<String, SuppressedDestination>(),
new InMemoryStorage<String, AccountSuppressionAttributes>(),
smtpRelay,
new ObjectMapper());
}
@@ -220,6 +220,9 @@ class SesV2IntegrationTest {
@Test
@Order(11)
void getAccount() {
// SuppressionAttributes defaults to BOUNCE + COMPLAINT on a fresh region,
// matching real SES account behaviour. Later @Order(58+) tests overwrite
// the stored value, so this assertion only holds before those run.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
@@ -231,7 +234,9 @@ class SesV2IntegrationTest {
.body("ProductionAccessEnabled", equalTo(true))
.body("SendQuota.Max24HourSend", notNullValue())
.body("SendQuota.MaxSendRate", notNullValue())
.body("SendQuota.SentLast24Hours", notNullValue());
.body("SendQuota.SentLast24Hours", notNullValue())
.body("SuppressionAttributes.SuppressedReasons",
containsInAnyOrder("BOUNCE", "COMPLAINT"));
}
@Test
@@ -572,6 +577,175 @@ class SesV2IntegrationTest {
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(58)
void putAccountSuppressionAttributes_storesReasons_visibleViaGetAccount() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": ["BOUNCE", "COMPLAINT"]}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/account")
.then()
.statusCode(200)
.body("SuppressionAttributes.SuppressedReasons", containsInAnyOrder("BOUNCE", "COMPLAINT"));
}
@Test
@Order(59)
void putAccountSuppressionAttributes_emptyArray_clearsReasons() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": []}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/account")
.then()
.statusCode(200)
.body("SuppressionAttributes.SuppressedReasons", hasSize(0));
}
@Test
@Order(61)
void putAccountSuppressionAttributes_missingField_succeedsWithEmptyList() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{}")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/account")
.then()
.statusCode(200)
.body("SuppressionAttributes.SuppressedReasons", hasSize(0));
}
@Test
@Order(62)
void putAccountSuppressionAttributes_invalidReason_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": ["BOUNCE", "OTHER"]}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", containsString(
"1 validation error detected: Value at 'suppressedReasons' failed to satisfy constraint: "
+ "Member must satisfy constraint: [Member must satisfy enum value set: [BOUNCE, COMPLAINT]]"));
}
@Test
@Order(63)
void putAccountSuppressionAttributes_reasonsNotArray_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": "BOUNCE"}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(64)
void putAccountSuppressionAttributes_nullMember_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": [null]}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(65)
void putAccountSuppressionAttributes_numericMember_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"SuppressedReasons": [1, 2]}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(66)
void putAccountSuppressionAttributes_acceptsValidationAttributes() {
// The optional ValidationAttributes object is accepted but not parsed —
// verifying the request shape does not regress to a 400.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"SuppressedReasons": ["BOUNCE"],
"ValidationAttributes": {
"ConditionThreshold": {
"ConditionThresholdEnabled": "ENABLED",
"OverallConfidenceThreshold": {
"ConfidenceVerdictThreshold": "HIGH"
}
}
}
}
""")
.when()
.put("/v2/email/account/suppression")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/account")
.then()
.statusCode(200)
.body("SuppressionAttributes.SuppressedReasons", contains("BOUNCE"));
}
@Test
@Order(57)
void sendEmail_ccOnly_noToAddresses() {