feat(ses): apply suppression list during send with per-CS SuppressionOptions override (#1109)

When SendEmail / SendRawEmail is called with a recipient on the
account-level suppression list whose reason matches the effective
SuppressedReasons (the configuration set's SuppressionOptions
override if present, else the account-level reasons), Floci now:

1. Emits a synthetic Bounce or Complaint event (per the suppression
   reason) through the configured event destinations alongside the
   always-emitted Send event.
2. Drops the suppressed recipient from the SMTP relay step, while
   still delivering the message to non-suppressed recipients on the
   same send.

The SendEmail API response (200 + MessageId), the stored SentEmail
(used by the LocalStack-compatible /_aws/ses inspection endpoint),
and the published event's mail.destination all continue to reflect
the original recipient list — matching how AWS reports the message
at the API and event layers.

This PR bundles two related pieces:
- The per-configuration-set SuppressionOptions block (Put endpoint +
  GetConfigurationSet response shape + getEffectiveSuppressedReasons
  helper). Mirrors AWS V2 PutConfigurationSetSuppressionOptions:
  empty list = explicit "no suppression filtering" for this CS,
  unset block = fall back to account-level reasons. The validation
  message for the new endpoint matches the AWS V2 natural-language
  form ("Reason <X> is invalid, must be one of [BOUNCE, COMPLAINT].")
  which is distinct from the V1-style nested message returned by the
  three older suppression endpoints; both forms were verified
  against live AWS on 2026-06-03.
- The send-time filter + synthetic-event partitioning, plumbed
  through getEffectiveSuppressedReasons so the override takes effect
  per-send. collectSuppressedReasons and resolveSuppressionReason
  now both take configurationSetName, hitting the per-CS override
  when present and falling back to the account-level reasons
  otherwise.

Per-recipient: when only some recipients are suppressed, the
non-suppressed ones still reach smtpRelay.relay() / relayRaw().
The relay is skipped entirely only when every recipient is
suppressed.

- Recipient suppressed with reason BOUNCE (and BOUNCE in the
  effective reasons) -> synthetic Bounce event; not relayed.
- Recipient suppressed with reason COMPLAINT (and COMPLAINT in the
  effective reasons) -> synthetic Complaint event; not relayed.
- Reason mismatch or address not on the list -> Send only; relayed
  normally.
- Simulator-address recipients and suppression-listed recipients
  are unioned into the same event's recipient list, deduplicated.

Tests
- SesConfigurationSetSuppressionOptionsV2IntegrationTest (16 cases)
  for the CRUD + helper.
- SesConfigurationSetTest SDK compat (6 V2 cases) using
  SesV2Client.PutConfigurationSetSuppressionOptions and the typed
  SuppressionListReason enum (+ the WithStrings escape hatch for
  the server-side validation path).
- SesServiceSmtpTest grows four cases pinning the send-time
  override behaviour: empty list on the CS disables filtering and
  the relay receives the address; BOUNCE-only override leaves
  COMPLAINT-suppressed addresses unfiltered; a CS without an
  override falls back to account-level (parity with no-CS sends);
  raw-send mirrors the JSON-send path.
- SesEventPayload / SesEventPublishingV2IntegrationTest / further
  send-path coverage from the original suppression PR is preserved.
- All 452 SES tests pass.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-06-03 21:57:20 -05:00
1 parent 2a14f35c2d
commit 19b0432b8c
13 files changed
+1136 -34

No files matched your search

@@ -21,6 +21,8 @@ import software.amazon.awssdk.services.ses.model.ListConfigurationSetsResponse;
import software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.GetConfigurationSetRequest;
import software.amazon.awssdk.services.sesv2.model.GetConfigurationSetResponse;
import software.amazon.awssdk.services.sesv2.model.PutConfigurationSetSuppressionOptionsRequest;
import software.amazon.awssdk.services.sesv2.model.SuppressionListReason;
import software.amazon.awssdk.services.sesv2.model.Tag;
import static org.assertj.core.api.Assertions.assertThat;
@@ -38,6 +40,7 @@ class SesConfigurationSetTest {
private static SesV2Client sesV2;
private static String v1Name;
private static String v2Name;
private static String suppressionCsName;
@BeforeAll
static void setup() {
@@ -46,6 +49,7 @@ class SesConfigurationSetTest {
String suffix = TestFixtures.uniqueName();
v1Name = "sdk-v1-cs-" + suffix;
v2Name = "sdk-v2-cs-" + suffix;
suppressionCsName = "sdk-v2-cs-supp-" + suffix;
}
@AfterAll
@@ -56,6 +60,7 @@ class SesConfigurationSetTest {
}
if (sesV2 != null) {
safelyDeleteV2(v2Name);
safelyDeleteV2(suppressionCsName);
sesV2.close();
}
}
@@ -208,6 +213,99 @@ class SesConfigurationSetTest {
.isEqualTo(400);
}
// ─────────────────── V2 SuppressionOptions (per-CS) ───────────────────
@Test
@Order(30)
void v2SuppressionOptions_setup_createsSuppressionConfigurationSet() {
sesV2.createConfigurationSet(software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetRequest.builder()
.configurationSetName(suppressionCsName)
.build());
// Before any PutSuppressionOptions, the response has no SuppressionOptions block.
GetConfigurationSetResponse before = sesV2.getConfigurationSet(GetConfigurationSetRequest.builder()
.configurationSetName(suppressionCsName)
.build());
assertThat(before.suppressionOptions()).isNull();
}
@Test
@Order(31)
void v2PutSuppressionOptions_bounceOnly_visibleOnGet() {
sesV2.putConfigurationSetSuppressionOptions(PutConfigurationSetSuppressionOptionsRequest.builder()
.configurationSetName(suppressionCsName)
.suppressedReasons(SuppressionListReason.BOUNCE)
.build());
GetConfigurationSetResponse after = sesV2.getConfigurationSet(GetConfigurationSetRequest.builder()
.configurationSetName(suppressionCsName)
.build());
assertThat(after.suppressionOptions()).isNotNull();
assertThat(after.suppressionOptions().suppressedReasons())
.containsExactly(SuppressionListReason.BOUNCE);
}
@Test
@Order(32)
void v2PutSuppressionOptions_bothReasons() {
sesV2.putConfigurationSetSuppressionOptions(PutConfigurationSetSuppressionOptionsRequest.builder()
.configurationSetName(suppressionCsName)
.suppressedReasons(SuppressionListReason.BOUNCE, SuppressionListReason.COMPLAINT)
.build());
GetConfigurationSetResponse after = sesV2.getConfigurationSet(GetConfigurationSetRequest.builder()
.configurationSetName(suppressionCsName)
.build());
assertThat(after.suppressionOptions().suppressedReasons())
.containsExactlyInAnyOrder(SuppressionListReason.BOUNCE, SuppressionListReason.COMPLAINT);
}
@Test
@Order(33)
void v2PutSuppressionOptions_emptyList_explicitlyDisablesFiltering() {
// Per the AWS V2 contract, an empty SuppressedReasons list is the documented way
// to disable suppression filtering for a configuration set.
sesV2.putConfigurationSetSuppressionOptions(PutConfigurationSetSuppressionOptionsRequest.builder()
.configurationSetName(suppressionCsName)
.suppressedReasons(java.util.Collections.emptyList())
.build());
GetConfigurationSetResponse after = sesV2.getConfigurationSet(GetConfigurationSetRequest.builder()
.configurationSetName(suppressionCsName)
.build());
assertThat(after.suppressionOptions()).isNotNull();
assertThat(after.suppressionOptions().suppressedReasons()).isEmpty();
}
@Test
@Order(34)
void v2PutSuppressionOptions_invalidReason_rejectedAt400() {
// The typed enum (SuppressionListReason) prevents passing an unknown value through
// the SDK, so use the WithStrings variant to round-trip the literal "INVALID" to
// the wire and exercise server-side validation.
assertThatThrownBy(() -> sesV2.putConfigurationSetSuppressionOptions(
PutConfigurationSetSuppressionOptionsRequest.builder()
.configurationSetName(suppressionCsName)
.suppressedReasonsWithStrings("BOUNCE", "INVALID")
.build()))
.isInstanceOf(AwsServiceException.class)
.extracting(e -> ((AwsServiceException) e).statusCode())
.isEqualTo(400);
}
@Test
@Order(35)
void v2PutSuppressionOptions_unknownConfigurationSet_rejectedAt404() {
assertThatThrownBy(() -> sesV2.putConfigurationSetSuppressionOptions(
PutConfigurationSetSuppressionOptionsRequest.builder()
.configurationSetName(suppressionCsName + "-does-not-exist")
.suppressedReasons(SuppressionListReason.BOUNCE)
.build()))
.isInstanceOf(AwsServiceException.class)
.extracting(e -> ((AwsServiceException) e).statusCode())
.isEqualTo(404);
}
// ─────────────────────────── Helpers ───────────────────────────
private static void safelyDeleteV1(String name) {