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:
Kenshin Okinaka authored and GitHub committed 2026-05-12 19:44:31 -05:00
1 parent 7516acb5f9
commit 944f82a6a4
7 files changed
+681

No files matched your search

@@ -0,0 +1,117 @@
package com.floci.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
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 software.amazon.awssdk.services.sesv2.SesV2Client;
import software.amazon.awssdk.services.sesv2.model.DeleteSuppressedDestinationRequest;
import software.amazon.awssdk.services.sesv2.model.GetSuppressedDestinationRequest;
import software.amazon.awssdk.services.sesv2.model.GetSuppressedDestinationResponse;
import software.amazon.awssdk.services.sesv2.model.ListSuppressedDestinationsRequest;
import software.amazon.awssdk.services.sesv2.model.ListSuppressedDestinationsResponse;
import software.amazon.awssdk.services.sesv2.model.NotFoundException;
import software.amazon.awssdk.services.sesv2.model.PutSuppressedDestinationRequest;
import software.amazon.awssdk.services.sesv2.model.SuppressionListReason;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("SES V2 Suppression list")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesSuppressionListTest {
private static SesV2Client sesV2;
private static String bounceEmail;
private static String complaintEmail;
@BeforeAll
static void setup() {
sesV2 = TestFixtures.sesV2Client();
String suffix = TestFixtures.uniqueName();
bounceEmail = "sdk-bounce-" + suffix + "@example.com";
complaintEmail = "sdk-complaint-" + suffix + "@example.com";
}
@AfterAll
static void cleanup() {
if (sesV2 != null) {
try {
sesV2.deleteSuppressedDestination(DeleteSuppressedDestinationRequest.builder()
.emailAddress(bounceEmail).build());
} catch (Exception ignored) {}
try {
sesV2.deleteSuppressedDestination(DeleteSuppressedDestinationRequest.builder()
.emailAddress(complaintEmail).build());
} catch (Exception ignored) {}
sesV2.close();
}
}
@Test
@Order(1)
void putAndGet_bounceRoundTrips() {
sesV2.putSuppressedDestination(PutSuppressedDestinationRequest.builder()
.emailAddress(bounceEmail)
.reason(SuppressionListReason.BOUNCE)
.build());
GetSuppressedDestinationResponse got = sesV2.getSuppressedDestination(
GetSuppressedDestinationRequest.builder()
.emailAddress(bounceEmail).build());
assertThat(got.suppressedDestination().emailAddress()).isEqualTo(bounceEmail);
assertThat(got.suppressedDestination().reason()).isEqualTo(SuppressionListReason.BOUNCE);
assertThat(got.suppressedDestination().lastUpdateTime()).isNotNull();
}
@Test
@Order(2)
void putAndGet_complaintRoundTrips() {
sesV2.putSuppressedDestination(PutSuppressedDestinationRequest.builder()
.emailAddress(complaintEmail)
.reason(SuppressionListReason.COMPLAINT)
.build());
GetSuppressedDestinationResponse got = sesV2.getSuppressedDestination(
GetSuppressedDestinationRequest.builder()
.emailAddress(complaintEmail).build());
assertThat(got.suppressedDestination().reason()).isEqualTo(SuppressionListReason.COMPLAINT);
}
@Test
@Order(3)
void list_includesBothEntries() {
ListSuppressedDestinationsResponse listed = sesV2.listSuppressedDestinations(
ListSuppressedDestinationsRequest.builder().build());
assertThat(listed.suppressedDestinationSummaries())
.extracting(s -> s.emailAddress())
.contains(bounceEmail, complaintEmail);
}
@Test
@Order(4)
void list_filteredByReason() {
ListSuppressedDestinationsResponse listed = sesV2.listSuppressedDestinations(
ListSuppressedDestinationsRequest.builder()
.reasons(SuppressionListReason.BOUNCE)
.build());
assertThat(listed.suppressedDestinationSummaries())
.allMatch(s -> s.reason() == SuppressionListReason.BOUNCE);
}
@Test
@Order(5)
void delete_removesEntry_subsequentGetThrowsNotFound() {
sesV2.deleteSuppressedDestination(DeleteSuppressedDestinationRequest.builder()
.emailAddress(bounceEmail).build());
assertThatThrownBy(() -> sesV2.getSuppressedDestination(
GetSuppressedDestinationRequest.builder()
.emailAddress(bounceEmail).build()))
.isInstanceOf(NotFoundException.class);
}
}