Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): support v2 tenant suppression attributes and tenant-scoped suppression list (#2743)
Kenshin Okinakafc3c28323ac9
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTenantTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTenantTest.javaindex 73c6e87d9a..9a5098bb8f 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTenantTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTenantTest.java@@ -19,16 +19,19 @@ import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetRequestimport software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;import software.amazon.awssdk.services.sesv2.model.DeleteTenantRequest;import software.amazon.awssdk.services.sesv2.model.DeleteTenantResourceAssociationRequest;+import software.amazon.awssdk.services.sesv2.model.GetSuppressedDestinationResponse;import software.amazon.awssdk.services.sesv2.model.GetTenantRequest;import software.amazon.awssdk.services.sesv2.model.GetTenantResponse;import software.amazon.awssdk.services.sesv2.model.ListResourceTenantsRequest;import software.amazon.awssdk.services.sesv2.model.ListResourceTenantsResponse;+import software.amazon.awssdk.services.sesv2.model.ListSuppressedDestinationsResponse;import software.amazon.awssdk.services.sesv2.model.ListTenantResourcesFilterKey;import software.amazon.awssdk.services.sesv2.model.ListTenantResourcesRequest;import software.amazon.awssdk.services.sesv2.model.ListTenantResourcesResponse;import software.amazon.awssdk.services.sesv2.model.ListTenantsRequest;import software.amazon.awssdk.services.sesv2.model.ListTenantsResponse;import software.amazon.awssdk.services.sesv2.model.NotFoundException;+import software.amazon.awssdk.services.sesv2.model.SuppressionListReason;import software.amazon.awssdk.services.sesv2.model.Tag;import java.util.Map;@@ -37,15 +40,19 @@ import static org.assertj.core.api.Assertions.assertThat;import static org.assertj.core.api.Assertions.assertThatThrownBy;/**- * SDK compatibility test for the SES v2 tenant APIs: the CRUD (CreateTenant / GetTenant /- * ListTenants / DeleteTenant) and the resource associations (CreateTenantResourceAssociation /- * DeleteTenantResourceAssociation / ListTenantResources / ListResourceTenants), one ordered flow- * against a live Floci instance. One AWS quirk drives the association assertions: the service's wire- * values for ResourceType — in responses and as the RESOURCE_TYPE filter value — are the ARN- * segments (identity / configuration-set / template), not the SDK's EMAIL_IDENTITY-style enum- * constants. Real AWS rejects the enum spelling as a filter and returns values the SDK maps to- * UNKNOWN_TO_SDK_VERSION, so the test asserts resourceTypeAsString. Tenants are reversible- * (create + delete), so cleanup restores the account.+ * SDK compatibility test for the SES v2 tenant APIs, one ordered flow against a live Floci+ * instance: the CRUD (CreateTenant / GetTenant / ListTenants / DeleteTenant), the resource+ * associations (CreateTenantResourceAssociation / DeleteTenantResourceAssociation /+ * ListTenantResources / ListResourceTenants), and tenant suppression (PutTenantSuppressionAttributes+ * plus the TenantName-scoped suppression-list operations). One AWS quirk drives the association+ * assertions: the service's wire values for ResourceType — in responses and as the RESOURCE_TYPE+ * filter value — are the ARN segments (identity / configuration-set / template), not the SDK's+ * EMAIL_IDENTITY-style enum constants. Real AWS rejects the enum spelling as a filter and returns+ * values the SDK maps to UNKNOWN_TO_SDK_VERSION, so the test asserts resourceTypeAsString. The+ * suppression block asserts the all-or-nothing attribute pair (a bare TenantName clears it), the+ * per-tenant list fully separate from the account list, the non-idempotent tenant-scoped delete,+ * and the DeleteTenant cascade. Tenants are reversible (create + delete), so cleanup restores the+ * account.*/@DisplayName("SES v2 Tenants")@TestMethodOrder(MethodOrderer.OrderAnnotation.class)@@ -54,6 +61,8 @@ class SesTenantTest {private static final String TENANT = "compat-tenant-alpha";private static final String IDENTITY = "compat-assoc.example.com";private static final String CONFIG_SET = "compat-assoc-cs";+ private static final String TENANT_ADDR = "[email protected]";+ private static final String ACCOUNT_ADDR = "[email protected]";private static SesV2Client sesV2;private static String identityArn;@@ -65,6 +74,8 @@ class SesTenantTest {sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(IDENTITY).build());sesV2.createConfigurationSet(CreateConfigurationSetRequest.builder().configurationSetName(CONFIG_SET).build());+ sesV2.putSuppressedDestination(r -> r.emailAddress(ACCOUNT_ADDR)+ .reason(SuppressionListReason.BOUNCE));}@AfterAll@@ -79,6 +90,7 @@ class SesTenantTest {sesV2.deleteConfigurationSet(DeleteConfigurationSetRequest.builder().configurationSetName(CONFIG_SET).build());sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(IDENTITY).build());+ sesV2.deleteSuppressedDestination(r -> r.emailAddress(ACCOUNT_ADDR));sesV2.close();}}@@ -238,17 +250,97 @@ class SesTenantTest {@Test@Order(15)- void deleteTenant_cascadesRemainingAssociations_thenGetIsNotFound() {+ void putTenantSuppressionAttributes_setsPair_getTenantReturnsThem() {+ sesV2.putTenantSuppressionAttributes(r -> r.tenantName(TENANT)+ .suppressedReasonsWithStrings("BOUNCE", "COMPLAINT")+ .suppressionScope("TENANT"));+ GetTenantResponse resp = sesV2.getTenant(GetTenantRequest.builder().tenantName(TENANT).build());+ assertThat(resp.tenant().suppressionAttributes().suppressedReasonsAsStrings())+ .containsExactly("BOUNCE", "COMPLAINT");+ assertThat(resp.tenant().suppressionAttributes().suppressionScopeAsString()).isEqualTo("TENANT");+ }++ @Test+ @Order(16)+ void putTenantSuppressionAttributes_halfPair_throwsBadRequest() {+ assertThatThrownBy(() -> sesV2.putTenantSuppressionAttributes(r -> r.tenantName(TENANT)+ .suppressedReasonsWithStrings("BOUNCE")))+ .isInstanceOf(BadRequestException.class)+ .hasMessageContaining("SuppressedReasons cannot be specified without SuppressionScope.");+ }++ @Test+ @Order(17)+ void putTenantSuppressionAttributes_bareTenantName_clearsTheBlock() {+ sesV2.putTenantSuppressionAttributes(r -> r.tenantName(TENANT));+ GetTenantResponse resp = sesV2.getTenant(GetTenantRequest.builder().tenantName(TENANT).build());+ assertThat(resp.tenant().suppressionAttributes()).isNull();+ }++ @Test+ @Order(18)+ void tenantSuppressionList_isSeparateFromAccountList() {+ sesV2.putSuppressedDestination(r -> r.emailAddress(TENANT_ADDR)+ .reason(SuppressionListReason.BOUNCE).tenantName(TENANT));++ GetSuppressedDestinationResponse got = sesV2.getSuppressedDestination(+ r -> r.emailAddress(TENANT_ADDR).tenantName(TENANT));+ assertThat(got.suppressedDestination().tenantName()).isEqualTo(TENANT);++ assertThatThrownBy(() -> sesV2.getSuppressedDestination(r -> r.emailAddress(TENANT_ADDR)))+ .isInstanceOf(NotFoundException.class)+ .hasMessageContaining("on your suppression list");+ assertThatThrownBy(() -> sesV2.getSuppressedDestination(+ r -> r.emailAddress(ACCOUNT_ADDR).tenantName(TENANT)))+ .isInstanceOf(NotFoundException.class)+ .hasMessageContaining("on your tenant suppression list");+ }++ @Test+ @Order(19)+ void tenantSuppressionList_listsOnlyTenantEntries() {+ ListSuppressedDestinationsResponse resp =+ sesV2.listSuppressedDestinations(r -> r.tenantName(TENANT));+ assertThat(resp.suppressedDestinationSummaries()).hasSize(1);+ assertThat(resp.suppressedDestinationSummaries().get(0).emailAddress()).isEqualTo(TENANT_ADDR);+ }++ @Test+ @Order(20)+ void tenantSuppressionOps_missingTenant_throwNotFound() {+ assertThatThrownBy(() -> sesV2.putSuppressedDestination(r -> r.emailAddress(TENANT_ADDR)+ .reason(SuppressionListReason.BOUNCE).tenantName("compat-sup-ghost")))+ .isInstanceOf(NotFoundException.class)+ .hasMessageContaining("The requested tenant <compat-sup-ghost> does not exist.");+ }++ @Test+ @Order(21)+ void tenantSuppressionDelete_isNotIdempotent() {+ sesV2.deleteSuppressedDestination(r -> r.emailAddress(TENANT_ADDR).tenantName(TENANT));+ // Unlike the resource associations, a second tenant-scoped delete is a NotFound.+ assertThatThrownBy(() -> sesV2.deleteSuppressedDestination(+ r -> r.emailAddress(TENANT_ADDR).tenantName(TENANT)))+ .isInstanceOf(NotFoundException.class);+ }++ @Test+ @Order(22)+ void deleteTenant_cascadesAssociationsAndSuppressionEntries_thenGetIsNotFound() {+ sesV2.putSuppressedDestination(r -> r.emailAddress(TENANT_ADDR)+ .reason(SuppressionListReason.COMPLAINT).tenantName(TENANT));sesV2.deleteTenant(DeleteTenantRequest.builder().tenantName(TENANT).build());ListResourceTenantsResponse resp = sesV2.listResourceTenants(ListResourceTenantsRequest.builder().resourceArn(identityArn).build());assertThat(resp.resourceTenants()).isEmpty();+ assertThatThrownBy(() -> sesV2.listSuppressedDestinations(r -> r.tenantName(TENANT)))+ .isInstanceOf(NotFoundException.class);assertThatThrownBy(() -> sesV2.getTenant(GetTenantRequest.builder().tenantName(TENANT).build())).isInstanceOf(NotFoundException.class);}@Test- @Order(16)+ @Order(23)void deleteTenant_missing_throwsNotFound() {assertThatThrownBy(() -> sesV2.deleteTenant(DeleteTenantRequest.builder().tenantName("compat-tenant-does-not-exist").build()))diff --git a/docs/services/ses.md b/docs/services/ses.mdindex 6c205c74b3..53a2314212 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -218,6 +218,7 @@ Alongside the classic Query API, Floci implements a subset of the SES v2 REST JS| `POST` | `/v2/email/tenants/resources/delete` | `DeleteTenantResourceAssociation` || `POST` | `/v2/email/tenants/resources/list` | `ListTenantResources` || `POST` | `/v2/email/resources/tenants/list` | `ListResourceTenants` |+| `POST` | `/v2/email/tenant/suppression` | `PutTenantSuppressionAttributes` || `POST` | `/v2/email/templates` | `CreateEmailTemplate` || `GET` | `/v2/email/templates` | `ListEmailTemplates` || `GET` | `/v2/email/templates/{templateName}` | `GetEmailTemplate` |@@ -290,7 +291,9 @@ Account provisioning details are stored per region. `PutAccountDetails` sets `MaTenants (multi-tenancy) are stored per region. `CreateTenant` requires a `TenantName` (1–64 chars, `[A-Za-z0-9_-]`) and accepts optional `Tags`; it returns the tenant with a generated `TenantId` (`tn-` + 30 hex), a `TenantArn` (`arn:aws:ses:<region>:<account>:tenant/<name>/<id>`), a `CreatedTimestamp`, and `SendingStatus` `ENABLED`. The operations use RPC-style POST subpaths (`/tenants/get`, `/tenants/list`, `/tenants/delete`); `ListTenants` returns the `TenantInfo` subset (no `Tags`/`SendingStatus`) and currently returns every tenant in a single page — `PageSize`/`NextToken` pagination is not yet implemented. A duplicate name is `AlreadyExistsException`; an unknown tenant on get/delete is `NotFoundException`.-Tenant resource associations link a tenant to email identities, configuration sets, and email templates. Matching real AWS, the wire values for `ResourceType` — in responses and as the `Filter` `RESOURCE_TYPE` value — are the ARN segments `identity` / `configuration-set` / `template`; the SDK's `EMAIL_IDENTITY`-style enum constants are rejected, as AWS itself does. The resource must exist in the same account and region; a duplicate association is `AlreadyExistsException`, and deleting a missing one succeeds silently. Deleting a resource that still has associations is rejected, while `DeleteTenant` cascades its associations away. The list operations return a single page (no `PageSize`/`NextToken` pagination yet, like `ListTenants`); tenant suppression and tenant-scoped sending are not yet implemented.+Tenant resource associations link a tenant to email identities, configuration sets, and email templates. Matching real AWS, the wire values for `ResourceType` — in responses and as the `Filter` `RESOURCE_TYPE` value — are the ARN segments `identity` / `configuration-set` / `template`; the SDK's `EMAIL_IDENTITY`-style enum constants are rejected, as AWS itself does. The resource must exist in the same account and region; a duplicate association is `AlreadyExistsException`, and deleting a missing one succeeds silently. Deleting a resource that still has associations is rejected, while `DeleteTenant` cascades its associations away. The list operations return a single page (no `PageSize`/`NextToken` pagination yet, like `ListTenants`); tenant-scoped sending is not yet implemented.++`PutTenantSuppressionAttributes` sets a tenant's `SuppressedReasons`/`SuppressionScope` pair on AWS's own singular `/v2/email/tenant/suppression` route. The pair is all-or-nothing: both members set the block (an empty reason list is valid), half a pair is rejected, and a bare `TenantName` clears it. A `TenantName` on the suppression-list operations (body member on put, query parameter on get/delete/list) routes them to the tenant's own list — separate from the account list, independent of `SuppressionScope`, cascaded away by `DeleteTenant`, and with a non-idempotent delete.Suppression list entries are stored per region with `Reason` ∈ {`BOUNCE`, `COMPLAINT`}. At send time, a recipient is suppressed when it appears on the suppression list AND its stored `Reason` is contained in the **effective** `SuppressedReasons` for the send. The effective list is the configuration set's `SuppressionOptions.SuppressedReasons` (set via `PutConfigurationSetSuppressionOptions`) when present — an **empty list is preserved as an explicit "no suppression filtering for this configuration set"** — otherwise it falls back to the account-level `AccountSuppressionAttributes.SuppressedReasons` (set via `PutAccountSuppressionAttributes`, default `[BOUNCE, COMPLAINT]`). Following the AWS V2 contract, there is no dedicated `GetConfigurationSetSuppressionOptions` action; once set, the block is read back through `GetConfigurationSet`'s response (the field is omitted when the configuration set has no override).diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.javaindex 461c42069c..55fceafb2a 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java@@ -867,8 +867,19 @@ public class SesController {requireJsonObject(request);String tenantName = stringMemberOrAbsent(request, "TenantName");List<Tag> tags = parseTagsArray(request.path("Tags"));+ List<String> suppressedReasons = null;+ String suppressionScope = null;+ JsonNode attrs = request.path("SuppressionAttributes");+ if (!attrs.isMissingNode() && !attrs.isNull()) {+ if (!attrs.isObject()) {+ throw new AwsException("SerializationException", null, 400);+ }+ suppressedReasons = stringArrayOrAbsent(attrs, "SuppressedReasons");+ suppressionScope = stringMemberOrAbsent(attrs, "SuppressionScope");+ }String accountId = regionResolver.getAccountId();- Tenant tenant = sesService.createTenant(tenantName, tags, accountId, region);+ Tenant tenant = sesService.createTenant(tenantName, tags, suppressedReasons,+ suppressionScope, accountId, region);return Response.ok(tenantJson(tenant)).build();} catch (AwsException e) {throw remapV1Exception(e);@@ -1066,6 +1077,30 @@ public class SesController {}}+ // Phase 3: PutTenantSuppressionAttributes. The route really is the singular "tenant", unlike+ // every other tenant route (verified against real AWS and the SDK marshaller).+ @POST+ @Path("/tenant/suppression")+ public Response putTenantSuppressionAttributes(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ try {+ JsonNode request = (body == null || body.isBlank())+ ? objectMapper.createObjectNode()+ : objectMapper.readTree(body);+ requireJsonObject(request);+ String tenantName = stringMemberOrAbsent(request, "TenantName");+ List<String> suppressedReasons = stringArrayOrAbsent(request, "SuppressedReasons");+ String suppressionScope = stringMemberOrAbsent(request, "SuppressionScope");+ sesService.putTenantSuppressionAttributes(tenantName, suppressedReasons,+ suppressionScope, region);+ return Response.ok(objectMapper.createObjectNode()).build();+ } catch (AwsException e) {+ throw remapV1Exception(e);+ } catch (com.fasterxml.jackson.core.JsonProcessingException e) {+ throw new AwsException("SerializationException", null, 400);+ }+ }+// Read a typed string member: absent/null returns null, but a present value of the wrong JSON type// is rejected rather than coerced (asText would turn 123 into "123"), matching AWS.private static String stringMemberOrAbsent(JsonNode parent, String field) {@@ -1096,9 +1131,41 @@ public class SesController {}}node.put("SendingStatus", tenant.sendingStatus());+ // AWS renders the block as an explicit null when the tenant has none.+ if (tenant.suppressionAttributes() == null) {+ node.putNull("SuppressionAttributes");+ } else {+ ObjectNode attrs = node.putObject("SuppressionAttributes");+ ArrayNode reasons = attrs.putArray("SuppressedReasons");+ for (String reason : tenant.suppressionAttributes().suppressedReasons()) {+ reasons.add(reason);+ }+ attrs.put("SuppressionScope", tenant.suppressionAttributes().suppressionScope());+ }return node;}+ // Parse an optional array of strings: absent/null returns null, an empty array stays an empty+ // list (the distinction matters for the suppression-attributes pair rules), and a non-string+ // element is rejected rather than coerced.+ private static List<String> stringArrayOrAbsent(JsonNode parent, String field) {+ JsonNode n = parent.path(field);+ if (n.isMissingNode() || n.isNull()) {+ return null;+ }+ if (!n.isArray()) {+ throw new AwsException("SerializationException", null, 400);+ }+ List<String> values = new ArrayList<>();+ for (JsonNode item : n) {+ if (!item.isTextual()) {+ throw new AwsException("SerializationException", null, 400);+ }+ values.add(item.textValue());+ }+ return values;+ }+@POST@Path("/templates")public Response createEmailTemplate(@Context HttpHeaders headers, String body) {@@ -2371,7 +2438,8 @@ public class SesController {requireJsonObject(request);String emailAddress = readRequiredStringField(request, "EmailAddress");String reason = readRequiredStringField(request, "Reason");- sesService.putSuppressedDestination(region, emailAddress, reason);+ String tenantName = stringMemberOrAbsent(request, "TenantName");+ sesService.putSuppressedDestination(region, emailAddress, reason, tenantName);LOG.infov("SES V2 PutSuppressedDestination: {0} ({1})", emailAddress, reason);return Response.ok(objectMapper.createObjectNode()).build();} catch (AwsException e) {@@ -2392,10 +2460,12 @@ public class SesController {@GET@Path("/suppression/addresses/{emailAddress}")public Response getSuppressedDestination(@Context HttpHeaders headers,- @PathParam("emailAddress") String emailAddress) {+ @PathParam("emailAddress") String emailAddress,+ @QueryParam("TenantName") String tenantName) {String region = regionResolver.resolveRegion(headers);try {- SuppressedDestination suppressed = sesService.getSuppressedDestination(region, emailAddress);+ SuppressedDestination suppressed =+ sesService.getSuppressedDestination(region, emailAddress, tenantName);ObjectNode result = objectMapper.createObjectNode();ObjectNode entry = result.putObject("SuppressedDestination");entry.put("EmailAddress", suppressed.getEmailAddress());@@ -2403,6 +2473,8 @@ public class SesController {if (suppressed.getLastUpdateTime() != null) {entry.put("LastUpdateTime", suppressed.getLastUpdateTime().getEpochSecond());}+ // AWS renders TenantName on every entry — an explicit null for account-level ones.+ entry.put("TenantName", suppressed.getTenantName());return Response.ok(result).build();} catch (AwsException e) {throw remapV1Exception(e);@@ -2412,10 +2484,11 @@ public class SesController {@DELETE@Path("/suppression/addresses/{emailAddress}")public Response deleteSuppressedDestination(@Context HttpHeaders headers,- @PathParam("emailAddress") String emailAddress) {+ @PathParam("emailAddress") String emailAddress,+ @QueryParam("TenantName") String tenantName) {String region = regionResolver.resolveRegion(headers);try {- sesService.deleteSuppressedDestination(region, emailAddress);+ sesService.deleteSuppressedDestination(region, emailAddress, tenantName);LOG.infov("SES V2 DeleteSuppressedDestination: {0}", emailAddress);return Response.ok(objectMapper.createObjectNode()).build();} catch (AwsException e) {@@ -2426,11 +2499,12 @@ public class SesController {@GET@Path("/suppression/addresses")public Response listSuppressedDestinations(@Context HttpHeaders headers,- @QueryParam("Reason") List<String> reasons) {+ @QueryParam("Reason") List<String> reasons,+ @QueryParam("TenantName") String tenantName) {String region = regionResolver.resolveRegion(headers);List<SuppressedDestination> entries;try {- entries = sesService.listSuppressedDestinations(region, reasons);+ entries = sesService.listSuppressedDestinations(region, reasons, tenantName);} catch (AwsException e) {throw remapV1Exception(e);}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.javaindex 79097e72f1..94fbaa8460 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java@@ -1658,8 +1658,15 @@ public class SesService {// ──────────────────────── Tenants (multi-tenancy) ────────────────────────// Tenants live in SesTenantService; the facade forwards.- public Tenant createTenant(String tenantName, List<Tag> tags, String accountId, String region) {- return tenantService.createTenant(tenantName, tags, accountId, region);+ public Tenant createTenant(String tenantName, List<Tag> tags, List<String> suppressedReasons,+ String suppressionScope, String accountId, String region) {+ return tenantService.createTenant(tenantName, tags, suppressedReasons, suppressionScope,+ accountId, region);+ }++ public void putTenantSuppressionAttributes(String tenantName, List<String> suppressedReasons,+ String suppressionScope, String region) {+ tenantService.putSuppressionAttributes(tenantName, suppressedReasons, suppressionScope, region);}public Tenant getTenant(String tenantName, String region) {@@ -1671,7 +1678,10 @@ public class SesService {}public void deleteTenant(String tenantName, String region) {- tenantService.deleteTenant(tenantName, region);+ // The tenant-scoped suppression entries live in the suppression domain; the callback runs+ // their cascade inside the tenant lock, before the associations and the tenant record.+ tenantService.deleteTenant(tenantName, region,+ tenant -> suppressionService.deleteAllForTenant(region, tenant.tenantId()));}// The association operations validate resource existence here in the facade — the tenant domain@@ -2372,20 +2382,78 @@ public class SesService {suppressionService.putAccountSuppressionAttributes(region, suppressedReasons);}+ // A TenantName routes each suppression-list operation to that tenant's own list (fully separate+ // from the account list on AWS); the reason/address validation still runs first, matching the+ // probed precedence where request validation precedes tenant existence.+public void putSuppressedDestination(String region, String emailAddress, String reason) {- suppressionService.putSuppressedDestination(region, emailAddress, reason);+ putSuppressedDestination(region, emailAddress, reason, null);}public SuppressedDestination getSuppressedDestination(String region, String emailAddress) {- return suppressionService.getSuppressedDestination(region, emailAddress);+ return getSuppressedDestination(region, emailAddress, null);}public void deleteSuppressedDestination(String region, String emailAddress) {- suppressionService.deleteSuppressedDestination(region, emailAddress);+ deleteSuppressedDestination(region, emailAddress, null);+ }++ public List<SuppressedDestination> listSuppressedDestinations(String region,+ List<String> reasonFilters) {+ return listSuppressedDestinations(region, reasonFilters, null);+ }++ public void putSuppressedDestination(String region, String emailAddress, String reason,+ String tenantName) {+ if (tenantName == null) {+ suppressionService.putSuppressedDestination(region, emailAddress, reason);+ return;+ }+ // The address and reason are validated before the tenant is resolved, keeping request+ // validation ahead of tenant existence for every member, as on the attribute operations.+ SesSuppressionService.normalizeSuppressionEmail(emailAddress);+ SesSuppressionService.validateSuppressionReason(reason, "reason", false);+ tenantService.runWithTenant(tenantName, region, tenant -> {+ suppressionService.putTenantSuppressedDestination(region, tenant.tenantId(),+ tenantName, emailAddress, reason);+ return null;+ });}- public List<SuppressedDestination> listSuppressedDestinations(String region, List<String> reasonFilters) {- return suppressionService.listSuppressedDestinations(region, reasonFilters);+ public SuppressedDestination getSuppressedDestination(String region, String emailAddress,+ String tenantName) {+ if (tenantName == null) {+ return suppressionService.getSuppressedDestination(region, emailAddress);+ }+ SesSuppressionService.normalizeSuppressionEmail(emailAddress);+ return tenantService.runWithTenant(tenantName, region, tenant ->+ suppressionService.getTenantSuppressedDestination(region, tenant.tenantId(),+ emailAddress));+ }++ public void deleteSuppressedDestination(String region, String emailAddress, String tenantName) {+ if (tenantName == null) {+ suppressionService.deleteSuppressedDestination(region, emailAddress);+ return;+ }+ SesSuppressionService.normalizeSuppressionEmail(emailAddress);+ tenantService.runWithTenant(tenantName, region, tenant -> {+ suppressionService.deleteTenantSuppressedDestination(region, tenant.tenantId(),+ emailAddress);+ return null;+ });+ }++ public List<SuppressedDestination> listSuppressedDestinations(String region,+ List<String> reasonFilters,+ String tenantName) {+ if (tenantName == null) {+ return suppressionService.listSuppressedDestinations(region, reasonFilters);+ }+ SesSuppressionService.validateReasonFilters(reasonFilters);+ return tenantService.runWithTenant(tenantName, region, tenant ->+ suppressionService.listTenantSuppressedDestinations(region, tenant.tenantId(),+ reasonFilters));}/**diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.javaindex 143a32ca4e..f88278562e 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java@@ -39,19 +39,24 @@ public class SesSuppressionService {private final StorageBackend<String, SuppressedDestination> suppressionStore;private final StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore;+ private final StorageBackend<String, SuppressedDestination> tenantSuppressionStore;@Injectpublic SesSuppressionService(StorageFactory storageFactory) {- this.suppressionStore = storageFactory.create("ses", "ses-suppression.json",- new TypeReference<Map<String, SuppressedDestination>>() {});- this.accountSuppressionStore = storageFactory.create("ses", "ses-account-suppression.json",- new TypeReference<Map<String, AccountSuppressionAttributes>>() {});+ this(storageFactory.create("ses", "ses-suppression.json",+ new TypeReference<Map<String, SuppressedDestination>>() {}),+ storageFactory.create("ses", "ses-account-suppression.json",+ new TypeReference<Map<String, AccountSuppressionAttributes>>() {}),+ storageFactory.create("ses", "ses-tenant-suppression.json",+ new TypeReference<Map<String, SuppressedDestination>>() {}));}SesSuppressionService(StorageBackend<String, SuppressedDestination> suppressionStore,- StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore) {+ StorageBackend<String, AccountSuppressionAttributes> accountSuppressionStore,+ StorageBackend<String, SuppressedDestination> tenantSuppressionStore) {this.suppressionStore = suppressionStore;this.accountSuppressionStore = accountSuppressionStore;+ this.tenantSuppressionStore = tenantSuppressionStore;}// ──────────────────── Account-level suppression attributes ────────────────────@@ -168,15 +173,7 @@ public class SesSuppressionService {}public List<SuppressedDestination> listSuppressedDestinations(String region, List<String> reasonFilters) {- Set<String> filters = new HashSet<>();- if (reasonFilters != null) {- for (String r : reasonFilters) {- if (r != null && !r.isBlank()) {- validateSuppressionReason(r, "reasons", true);- filters.add(r);- }- }- }+ Set<String> filters = validateReasonFilters(reasonFilters);String prefix = "suppression::" + region + "::";List<SuppressedDestination> all = new ArrayList<>(suppressionStore.scan(k -> k.startsWith(prefix)));all.sort(Comparator.comparing(SuppressedDestination::getLastUpdateTime,@@ -195,7 +192,101 @@ public class SesSuppressionService {return "suppression::" + region + "::" + emailAddress;}- private static String normalizeSuppressionEmail(String emailAddress) {+ // ──────────────────── Tenant-scoped suppression list (Phase 3) ────────────────────+ // Probe-confirmed 2026-08-30: each tenant's list is fully separate from the account list (they+ // are mutually invisible), the tenant's SuppressionScope does not gate these operations, and the+ // not-found message says "tenant suppression list". Keys carry the TenantId, so a recreated+ // same-name tenant starts with an empty list; DeleteTenant cascades via deleteAllForTenant.+ // Callers pass through SesTenantService.runWithTenant, which resolves the tenant (404) and+ // serializes against the DeleteTenant cascade.++ public void putTenantSuppressedDestination(String region, String tenantId, String tenantName,+ String emailAddress, String reason) {+ String normalized = normalizeSuppressionEmail(emailAddress);+ validateSuppressionReason(reason, "reason", false);+ SuppressedDestination entry = new SuppressedDestination(normalized, reason);+ entry.setTenantName(tenantName);+ tenantSuppressionStore.put(tenantSuppressionKey(region, tenantId, normalized), entry);+ LOG.infov("Suppressed destination {0} for tenant {1} in region {2} (reason={3})",+ normalized, tenantName, region, reason);+ }++ public SuppressedDestination getTenantSuppressedDestination(String region, String tenantId,+ String emailAddress) {+ String normalized = normalizeSuppressionEmail(emailAddress);+ return tenantSuppressionStore.get(tenantSuppressionKey(region, tenantId, normalized))+ .orElseThrow(() -> tenantEntryNotFound(normalized));+ }++ /** Unlike the tenant resource associations, this delete is not idempotent on AWS: a second+ * delete of the same address is a NotFound. */+ public void deleteTenantSuppressedDestination(String region, String tenantId, String emailAddress) {+ String normalized = normalizeSuppressionEmail(emailAddress);+ String key = tenantSuppressionKey(region, tenantId, normalized);+ if (tenantSuppressionStore.get(key).isEmpty()) {+ throw tenantEntryNotFound(normalized);+ }+ tenantSuppressionStore.delete(key);+ LOG.infov("Removed tenant suppression entry for {0} in region {1}", normalized, region);+ }++ public List<SuppressedDestination> listTenantSuppressedDestinations(String region, String tenantId,+ List<String> reasonFilters) {+ Set<String> filters = validateReasonFilters(reasonFilters);+ String prefix = tenantSuppressionKeyPrefix(region, tenantId);+ List<SuppressedDestination> all =+ new ArrayList<>(tenantSuppressionStore.scan(k -> k.startsWith(prefix)));+ all.sort(Comparator.comparing(SuppressedDestination::getLastUpdateTime,+ Comparator.nullsLast(Comparator.naturalOrder()))+ .thenComparing(SuppressedDestination::getEmailAddress,+ Comparator.nullsLast(Comparator.naturalOrder())));+ if (filters.isEmpty()) {+ return all;+ }+ return all.stream()+ .filter(s -> filters.contains(s.getReason()))+ .toList();+ }++ /** DeleteTenant's cascade for this domain, run from inside the tenant lock. */+ public void deleteAllForTenant(String region, String tenantId) {+ String prefix = tenantSuppressionKeyPrefix(region, tenantId);+ for (String key : tenantSuppressionStore.keys().stream()+ .filter(k -> k.startsWith(prefix)).toList()) {+ tenantSuppressionStore.delete(key);+ }+ }++ private static AwsException tenantEntryNotFound(String normalizedEmail) {+ return new AwsException("NotFoundException",+ "Email address " + normalizedEmail + " does not exist on your tenant suppression list.",+ 404);+ }++ private static String tenantSuppressionKey(String region, String tenantId, String emailAddress) {+ return tenantSuppressionKeyPrefix(region, tenantId) + emailAddress;+ }++ private static String tenantSuppressionKeyPrefix(String region, String tenantId) {+ return "tenantSuppression::" + region + "::" + tenantId + "::";+ }++ /** Validates a Reasons filter list, returning the non-blank values; shared by the account and+ * tenant list paths, and by the facade to keep request validation ahead of tenant existence. */+ static Set<String> validateReasonFilters(List<String> reasonFilters) {+ Set<String> filters = new HashSet<>();+ if (reasonFilters != null) {+ for (String r : reasonFilters) {+ if (r != null && !r.isBlank()) {+ validateSuppressionReason(r, "reasons", true);+ filters.add(r);+ }+ }+ }+ return filters;+ }++ static String normalizeSuppressionEmail(String emailAddress) {if (emailAddress == null || emailAddress.isBlank()) {throw new AwsException("BadRequestException", "EmailAddress is required.", 400);}@@ -223,7 +314,7 @@ public class SesSuppressionService {* (single Reason field) returns the unwrapped form; the two list-bearing APIs return the wrapped* form. Shared by the two sub-domains above, which is why they were extracted together.*/- private static void validateSuppressionReason(String reason, String fieldName, boolean nested) {+ static void validateSuppressionReason(String reason, String fieldName, boolean nested) {if (reason == null || (!"BOUNCE".equals(reason) && !"COMPLAINT".equals(reason))) {String constraint = nested? "Member must satisfy constraint: [Member must satisfy enum value set: [BOUNCE, COMPLAINT]]"diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.javaindex 2f81c04aa6..bc6361c9f9 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.storage.StorageFactory;import io.github.hectorvent.floci.services.ses.model.Tag;import io.github.hectorvent.floci.services.ses.model.Tenant;import io.github.hectorvent.floci.services.ses.model.TenantResourceAssociation;+import io.github.hectorvent.floci.services.ses.model.TenantSuppressionAttributes;import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import org.jboss.logging.Logger;@@ -16,8 +17,12 @@ import java.time.Clock;import java.time.Instant;import java.util.Comparator;import java.util.List;+import java.util.HashSet;import java.util.Map;import java.util.Optional;+import java.util.Set;+import java.util.function.Consumer;+import java.util.function.Function;import java.util.regex.Pattern;/**@@ -30,8 +35,10 @@ import java.util.regex.Pattern;* AlreadyExists message), not the key.** <p>Phase 2 adds tenant→resource associations, owned here as well ({@code associationStore}); the- * facade validates that the referenced resource exists before delegating. Tenant suppression and- * tenant-scoped sending are separate follow-ups.+ * facade validates that the referenced resource exists before delegating. Phase 3 adds the tenant+ * suppression attributes (stored on the tenant record) — the tenant-scoped suppression list itself+ * lives in {@code SesSuppressionService} with the account list, and cascades through the+ * {@code DeleteTenant} callback. Tenant-scoped sending is a separate follow-up.*/@ApplicationScopedpublic class SesTenantService {@@ -87,12 +94,20 @@ public class SesTenantService {}public Tenant createTenant(String tenantName, List<Tag> tags, String accountId, String region) {- validateTenantName(tenantName);+ return createTenant(tenantName, tags, null, null, accountId, region);+ }++ public Tenant createTenant(String tenantName, List<Tag> tags, List<String> suppressedReasons,+ String suppressionScope, String accountId, String region) {+ validateTenantName(tenantName, true);SesTags.validate(tags);+ TenantSuppressionAttributes attrs =+ validateSuppressionAttributesPair(suppressedReasons, suppressionScope);String key = tenantKey(region, tenantName);String tenantId = generateTenantId();String tenantArn = "arn:aws:ses:" + region + ":" + accountId + ":tenant/" + tenantName + "/" + tenantId;- Tenant tenant = new Tenant(tenantName, tenantId, tenantArn, Instant.now(clock), tags, "ENABLED");+ Tenant tenant = new Tenant(tenantName, tenantId, tenantArn, Instant.now(clock), tags,+ "ENABLED", attrs);// Only the check-then-put needs to be atomic, so two concurrent creates for the same name can't// both observe the key as absent; the id/ARN/record are built outside the lock.synchronized (tenantMutationLock) {@@ -110,7 +125,7 @@ public class SesTenantService {public Tenant getTenant(String tenantName, String region) {// TenantName is a required, min-length-1 member, so a malformed name is a BadRequest, not a// lookup miss.- validateTenantName(tenantName);+ validateTenantName(tenantName, false);return tenantStore.get(tenantKey(region, tenantName)).orElseThrow(() -> tenantNotFound(tenantName));}@@ -125,15 +140,25 @@ public class SesTenantService {}public void deleteTenant(String tenantName, String region) {- validateTenantName(tenantName);+ deleteTenant(tenantName, region, tenant -> { });+ }++ /**+ * Deletes the tenant. {@code dependentCascade} runs inside the lock with the resolved tenant so+ * the facade can cascade state held by other domains (the tenant suppression list); like the+ * associations, it runs before the tenant record is removed — persistent/wal backends apply each+ * deletion durably, so a crash mid-cascade must leave the tenant record (a retryable+ * DeleteTenant) rather than orphans no API call can remove.+ */+ public void deleteTenant(String tenantName, String region, Consumer<Tenant> dependentCascade) {+ validateTenantName(tenantName, false);String key = tenantKey(region, tenantName);synchronized (tenantMutationLock) {Tenant tenant = tenantStore.get(key).orElseThrow(() -> tenantNotFound(tenantName));+ dependentCascade.accept(tenant);// AWS cascades: deleting a tenant silently removes its resource associations// (probe-confirmed 2026-08-28). Keys carry the TenantId, so a recreated same-name tenant- // never sees the old associations. The associations go first — persistent/wal backends- // apply each deletion durably, so a crash mid-cascade must leave the tenant record (a- // retryable DeleteTenant) rather than orphan associations no API call can remove.+ // never sees the old associations.String assocPrefix = associationKeyPrefix(region, tenant.tenantId());for (String assocKey : associationStore.keys().stream().filter(k -> k.startsWith(assocPrefix)).toList()) {@@ -159,12 +184,9 @@ public class SesTenantService {* service-level message instead of the Smithy one.*/public Tenant tenantForAssociation(String tenantName, String region) {- if (tenantName == null) {- throw new AwsException("BadRequestException",- "1 validation error detected: Value at 'tenantName' failed to satisfy constraint: "- + "Member must not be null", 400);- }- if (tenantName.isBlank()) {+ // Absent and empty both get the service-level message here (probe-confirmed 2026-08-30) —+ // the Smithy not-null variant exists only on CreateTenant.+ if (tenantName == null || tenantName.isBlank()) {throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);}return tenantStore.get(tenantKey(region, tenantName))@@ -344,19 +366,116 @@ public class SesTenantService {return "tenantAssoc::" + region + "::" + tenantId + "::";}- // Validation order and messages verified against real AWS (2026-08-22): an empty string is the- // Smithy min-length violation, a whitespace-only value is "cannot be empty", then length, then the- // character-set rule.- private static void validateTenantName(String name) {- if (name == null) {+ // ──────────────────────── Suppression attributes (Phase 3) ────────────────────────+ // Behavior and messages probe-confirmed against real AWS us-east-1, 2026-08-30.++ /**+ * {@code PutTenantSuppressionAttributes}: both members set the block (an empty reason list is a+ * valid state), neither member clears it. Observed precedence: empty TenantName, then the Smithy+ * enum checks, then duplicates, then the pair rules, then tenant existence — a put on a missing+ * tenant still gets its request validated first.+ */+ public void putSuppressionAttributes(String tenantName, List<String> suppressedReasons,+ String suppressionScope, String region) {+ // Unlike CreateTenant, an absent TenantName gets the same service-level message as an empty+ // one here (probe-confirmed 2026-08-30) — no Smithy not-null variant on this operation.+ if (tenantName == null || tenantName.isBlank()) {+ throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);+ }+ TenantSuppressionAttributes attrs =+ validateSuppressionAttributesPair(suppressedReasons, suppressionScope);+ String key = tenantKey(region, tenantName);+ synchronized (tenantMutationLock) {+ Tenant tenant = tenantStore.get(key).orElseThrow(() -> tenantNotFound(tenantName));+ tenantStore.put(key, tenant.withSuppressionAttributes(attrs));+ }+ LOG.infov("Updated suppression attributes of SES tenant {0} in region {1}: {2}",+ tenantName, region, attrs);+ }++ /**+ * Resolves the tenant and runs {@code action} under the shared lock — the tenant-scoped+ * suppression-list operations go through this so a concurrent {@code DeleteTenant} cascade+ * cannot interleave and leave entries for a deleted tenant.+ */+ public <T> T runWithTenant(String tenantName, String region, Function<Tenant, T> action) {+ // Same service-level message for null and blank: on the operations served here the probed+ // AWS behavior collapses an absent TenantName to "cannot be empty" (only CreateTenant has+ // the Smithy not-null variant).+ if (tenantName == null || tenantName.isBlank()) {+ throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);+ }+ synchronized (tenantMutationLock) {+ Tenant tenant = tenantStore.get(tenantKey(region, tenantName))+ .orElseThrow(() -> tenantNotFound(tenantName));+ return action.apply(tenant);+ }+ }++ /**+ * Validates the SuppressedReasons/SuppressionScope pair (shared by CreateTenant and+ * PutTenantSuppressionAttributes) and returns the block to store — {@code null} when neither+ * member was given. AWS rejects half a pair with member-specific messages, and an empty reason+ * list without a scope gets its own third wording.+ */+ private static TenantSuppressionAttributes validateSuppressionAttributesPair(+ List<String> suppressedReasons, String suppressionScope) {+ if (suppressedReasons != null) {+ for (String reason : suppressedReasons) {+ SesSuppressionService.validateSuppressionReason(reason, "suppressedReasons", true);+ }+ }+ if (suppressionScope != null && !"TENANT".equals(suppressionScope)+ && !"ACCOUNT".equals(suppressionScope)) {throw new AwsException("BadRequestException",- "1 validation error detected: Value at 'tenantName' failed to satisfy constraint: "- + "Member must not be null", 400);+ "1 validation error detected: Value at 'suppressionScope' failed to satisfy "+ + "constraint: Member must satisfy enum value set: [TENANT, ACCOUNT]", 400);}- if (name.isEmpty()) {+ if (suppressedReasons != null) {+ Set<String> seen = new HashSet<>();+ for (String reason : suppressedReasons) {+ if (!seen.add(reason)) {+ throw new AwsException("BadRequestException",+ "Each suppressed reason can only be specified at most once", 400);+ }+ }+ }+ if (suppressedReasons != null && suppressionScope == null) {+ throw new AwsException("BadRequestException", suppressedReasons.isEmpty()+ ? "SuppressionScope is required when SuppressedReasons are provided. "+ + "Valid values are: TENANT, ACCOUNT"+ : "SuppressedReasons cannot be specified without SuppressionScope.", 400);+ }+ if (suppressedReasons == null && suppressionScope != null) {throw new AwsException("BadRequestException",- "1 validation error detected: Value at 'tenantName' failed to satisfy constraint: "- + "Member must have length greater than or equal to 1", 400);+ "SuppressionScope cannot be specified without SuppressedReasons.", 400);+ }+ if (suppressedReasons == null) {+ return null;+ }+ return new TenantSuppressionAttributes(List.copyOf(suppressedReasons), suppressionScope);+ }++ // Validation order and messages verified against real AWS (2026-08-22 and 2026-08-30): the two+ // Smithy wordings (not-null for an absent name, min-length for an empty one) exist ONLY on+ // CreateTenant; every other tenant operation collapses both to "TenantName cannot be empty".+ // Then a whitespace-only value is "cannot be empty", then length, then the character-set rule.+ private static void validateTenantName(String name, boolean createTenantSmithyVariants) {+ if (name == null) {+ if (createTenantSmithyVariants) {+ throw new AwsException("BadRequestException",+ "1 validation error detected: Value at 'tenantName' failed to satisfy "+ + "constraint: Member must not be null", 400);+ }+ throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);+ }+ if (name.isEmpty()) {+ if (createTenantSmithyVariants) {+ throw new AwsException("BadRequestException",+ "1 validation error detected: Value at 'tenantName' failed to satisfy "+ + "constraint: Member must have length greater than or equal to 1", 400);+ }+ throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);}if (name.isBlank()) {throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/SuppressedDestination.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/SuppressedDestination.javaindex c6001bdeae..17f767b943 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/model/SuppressedDestination.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/SuppressedDestination.java@@ -19,6 +19,10 @@ public class SuppressedDestination {@JsonProperty("LastUpdateTime")private Instant lastUpdateTime;+ // Set only on tenant-scoped entries; account-level entries keep it null (AWS renders the null).+ @JsonProperty("TenantName")+ private String tenantName;+public SuppressedDestination() {}public SuppressedDestination(String emailAddress, String reason) {@@ -35,4 +39,7 @@ public class SuppressedDestination {public Instant getLastUpdateTime() { return lastUpdateTime; }public void setLastUpdateTime(Instant lastUpdateTime) { this.lastUpdateTime = lastUpdateTime; }++ public String getTenantName() { return tenantName; }+ public void setTenantName(String tenantName) { this.tenantName = tenantName; }}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/Tenant.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/Tenant.javaindex 6530ecc4da..74067ebdb1 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/model/Tenant.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/Tenant.java@@ -16,5 +16,11 @@ public record Tenant(String tenantName,String tenantArn,Instant createdTimestamp,List<Tag> tags,- String sendingStatus) {+ String sendingStatus,+ TenantSuppressionAttributes suppressionAttributes) {++ /** Copy with different suppression attributes (records are immutable; the store is replace-only). */+ public Tenant withSuppressionAttributes(TenantSuppressionAttributes attrs) {+ return new Tenant(tenantName, tenantId, tenantArn, createdTimestamp, tags, sendingStatus, attrs);+ }}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/TenantSuppressionAttributes.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/TenantSuppressionAttributes.javanew file mode 100644index 0000000000..a1b5e93128--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/TenantSuppressionAttributes.java@@ -0,0 +1,14 @@+package io.github.hectorvent.floci.services.ses.model;++import io.quarkus.runtime.annotations.RegisterForReflection;++import java.util.List;++/**+ * A SES v2 tenant's suppression attributes, set by {@code PutTenantSuppressionAttributes} (or on+ * {@code CreateTenant}). AWS treats the pair as all-or-nothing: both members are set together (an+ * empty reason list is a valid state) and the whole block is cleared by a put with neither member.+ */+@RegisterForReflection+public record TenantSuppressionAttributes(List<String> suppressedReasons, String suppressionScope) {+}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.javaindex b757237a01..56d5f90e8e 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesServiceTestBuilder.java@@ -121,7 +121,7 @@ final class SesServiceTestBuilder {new SesAccountService(accountSettingsStore, accountVdmStore, accountDetailsStore),new SesTemplateService(templateStore),configSetStore,- new SesSuppressionService(suppressionStore, accountSuppressionStore),+ new SesSuppressionService(suppressionStore, accountSuppressionStore, new InMemoryStorage<>()),new SesDedicatedIpService(dedicatedIpPoolStore),new SesContactService(contactListStore, contactStore, clock),new SesPolicyService(policyStore, objectMapper),diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionServiceTest.javaindex 00286b3abe..cacb1d283b 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesSuppressionServiceTest.java@@ -15,8 +15,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;/*** Unit test for the extracted suppression domain. New facet: this closes the* shared-helper deferral from the account step — account suppression and the suppression list both- * live here and share the (now private) reason validation, exercised by both paths below. Two stores,- * one service.+ * live here and share the reason validation, exercised by both paths below. Phase 3 adds the+ * tenant-scoped suppression list as a third store: fully separate from the account list, keyed by+ * TenantId, cascaded by DeleteTenant through {@code deleteAllForTenant}.*/class SesSuppressionServiceTest {@@ -25,7 +26,7 @@ class SesSuppressionServiceTest {@BeforeEachvoid setUp() {- service = new SesSuppressionService(new InMemoryStorage<>(), new InMemoryStorage<>());+ service = new SesSuppressionService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());}@Test@@ -64,4 +65,68 @@ class SesSuppressionServiceTest {// Domain is canonicalized to lower case, so a differently-cased domain resolves the entry.assertTrue(service.findSuppressedDestination(REGION, "[email protected]").isPresent());}++ // ──────────────────── Tenant-scoped suppression list (Phase 3) ────────────────────++ private static final String TENANT_ID = "tn-000000000000000000000000000001";++ @Test+ void tenantList_isSeparateFromAccountList_bothWays() {+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "BOUNCE");+ service.putSuppressedDestination(REGION, "[email protected]", "BOUNCE");++ SuppressedDestination tenantEntry =+ service.getTenantSuppressedDestination(REGION, TENANT_ID, "[email protected]");+ assertEquals("acme", tenantEntry.getTenantName());++ AwsException accountMiss = assertThrows(AwsException.class,+ () -> service.getSuppressedDestination(REGION, "[email protected]"));+ assertEquals("Email address [email protected] does not exist on your suppression list.",+ accountMiss.getMessage());+ AwsException tenantMiss = assertThrows(AwsException.class,+ () -> service.getTenantSuppressedDestination(REGION, TENANT_ID, "[email protected]"));+ assertEquals("Email address [email protected] does not exist on your tenant suppression list.",+ tenantMiss.getMessage());+ }++ @Test+ void tenantDelete_isNotIdempotent() {+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "BOUNCE");+ service.deleteTenantSuppressedDestination(REGION, TENANT_ID, "[email protected]");+ AwsException e = assertThrows(AwsException.class,+ () -> service.deleteTenantSuppressedDestination(REGION, TENANT_ID, "[email protected]"));+ assertEquals("NotFoundException", e.getErrorCode());+ }++ @Test+ void tenantList_filtersByReason_andIsPerTenant() {+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "BOUNCE");+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "COMPLAINT");+ service.putTenantSuppressedDestination(REGION, "tn-other", "beta", "[email protected]", "BOUNCE");++ assertEquals(2, service.listTenantSuppressedDestinations(REGION, TENANT_ID, null).size());+ List<SuppressedDestination> bounces =+ service.listTenantSuppressedDestinations(REGION, TENANT_ID, List.of("BOUNCE"));+ assertEquals(1, bounces.size());+ assertEquals("[email protected]", bounces.get(0).getEmailAddress());+ }++ @Test+ void deleteAllForTenant_removesOnlyThatTenant() {+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "BOUNCE");+ service.putTenantSuppressedDestination(REGION, "tn-other", "beta", "[email protected]", "BOUNCE");+ service.deleteAllForTenant(REGION, TENANT_ID);+ assertEquals(0, service.listTenantSuppressedDestinations(REGION, TENANT_ID, null).size());+ assertEquals(1, service.listTenantSuppressedDestinations(REGION, "tn-other", null).size());+ }++ @Test+ void tenantPut_sharesNormalizationAndReasonValidation() {+ service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "[email protected]", "BOUNCE");+ assertEquals("[email protected]",+ service.getTenantSuppressedDestination(REGION, TENANT_ID, "[email protected]")+ .getEmailAddress());+ assertThrows(AwsException.class, () -> service.putTenantSuppressedDestination(+ REGION, TENANT_ID, "acme", "[email protected]", "NONSENSE"));+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantAssociationV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantAssociationV2IntegrationTest.javaindex 26de515f4a..4cfa19db8f 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantAssociationV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantAssociationV2IntegrationTest.java@@ -130,6 +130,10 @@ class SesTenantAssociationV2IntegrationTest {v2().body("{\"TenantName\":\"\",\"ResourceArn\":\"" + IDENTITY_ARN + "\"}").when().post("/v2/email/tenants/resources").then().statusCode(400).body("message", equalTo("TenantName cannot be empty"));+ // An absent TenantName gets the same message (probe-confirmed) — no Smithy not-null here.+ v2().body("{\"ResourceArn\":\"" + IDENTITY_ARN + "\"}")+ .when().post("/v2/email/tenants/resources").then().statusCode(400)+ .body("message", equalTo("TenantName cannot be empty"));v2().body("{\"TenantName\":\"" + TENANT + "\"}").when().post("/v2/email/tenants/resources").then().statusCode(400).body("message", equalTo("1 validation error detected: Value at 'resourceArn' failed "diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantServiceTest.javaindex ef13216645..928c3d5d46 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantServiceTest.java@@ -127,11 +127,16 @@ class SesTenantServiceTest {@Testvoid getAndDelete_rejectMalformedName() {- // A required, min-length-1 member: a blank name is a BadRequest, not a NotFound.- AwsException g = assertThrows(AwsException.class, () -> service.getTenant("", REGION));- assertEquals("BadRequestException", g.getErrorCode());- AwsException d = assertThrows(AwsException.class, () -> service.deleteTenant(" ", REGION));- assertEquals("BadRequestException", d.getErrorCode());+ // Unlike CreateTenant, both an absent and an empty name collapse to the service-level+ // message here (probe-confirmed 2026-08-30) — the Smithy wordings are CreateTenant-only.+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.getTenant("", REGION)).getMessage());+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.deleteTenant(" ", REGION)).getMessage());+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.getTenant(null, REGION)).getMessage());+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.deleteTenant(null, REGION)).getMessage());}// ──────────────────────── Resource associations (Phase 2) ────────────────────────@@ -305,14 +310,132 @@ class SesTenantServiceTest {AwsException empty = assertThrows(AwsException.class,() -> service.tenantForAssociation("", REGION));assertEquals("TenantName cannot be empty", empty.getMessage());+ // An absent TenantName gets the same message (probe-confirmed) — the Smithy not-null+ // variant exists only on CreateTenant.AwsException absent = assertThrows(AwsException.class,() -> service.tenantForAssociation(null, REGION));- assertTrue(absent.getMessage().contains("'tenantName'"));+ assertEquals("TenantName cannot be empty", absent.getMessage());AwsException missing = assertThrows(AwsException.class,() -> service.tenantForAssociation("ghost", REGION));assertEquals("NotFoundException", missing.getErrorCode());}+ // ──────────────────────── Suppression attributes (Phase 3) ────────────────────────++ @Test+ void putSuppressionAttributes_setsAndClears() {+ service.createTenant("acme", List.of(), ACCOUNT, REGION);+ service.putSuppressionAttributes("acme", List.of("BOUNCE", "COMPLAINT"), "TENANT", REGION);+ var attrs = service.getTenant("acme", REGION).suppressionAttributes();+ assertEquals(List.of("BOUNCE", "COMPLAINT"), attrs.suppressedReasons());+ assertEquals("TENANT", attrs.suppressionScope());++ // A put with neither member is AWS's clear mechanism.+ service.putSuppressionAttributes("acme", null, null, REGION);+ assertEquals(null, service.getTenant("acme", REGION).suppressionAttributes());+ }++ @Test+ void putSuppressionAttributes_emptyReasonListWithScope_isValidState() {+ service.createTenant("acme", List.of(), ACCOUNT, REGION);+ service.putSuppressionAttributes("acme", List.of(), "TENANT", REGION);+ var attrs = service.getTenant("acme", REGION).suppressionAttributes();+ assertEquals(List.of(), attrs.suppressedReasons());+ assertEquals("TENANT", attrs.suppressionScope());+ }++ @Test+ void putSuppressionAttributes_pairRules_threeMessages() {+ service.createTenant("acme", List.of(), ACCOUNT, REGION);+ assertEquals("SuppressedReasons cannot be specified without SuppressionScope.",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", List.of("BOUNCE"), null, REGION)).getMessage());+ assertEquals("SuppressionScope cannot be specified without SuppressedReasons.",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", null, "ACCOUNT", REGION)).getMessage());+ // An empty list without a scope gets AWS's third wording.+ assertEquals("SuppressionScope is required when SuppressedReasons are provided. "+ + "Valid values are: TENANT, ACCOUNT",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", List.of(), null, REGION)).getMessage());+ }++ @Test+ void putSuppressionAttributes_enumAndDuplicateMessages() {+ service.createTenant("acme", List.of(), ACCOUNT, REGION);+ assertEquals("1 validation error detected: Value at 'suppressedReasons' failed to satisfy "+ + "constraint: Member must satisfy constraint: [Member must satisfy enum value "+ + "set: [BOUNCE, COMPLAINT]]",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", List.of("NOPE"), null, REGION)).getMessage());+ assertEquals("1 validation error detected: Value at 'suppressionScope' failed to satisfy "+ + "constraint: Member must satisfy enum value set: [TENANT, ACCOUNT]",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", null, "NOPE", REGION)).getMessage());+ assertEquals("Each suppressed reason can only be specified at most once",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "acme", List.of("BOUNCE", "BOUNCE"), "ACCOUNT", REGION)).getMessage());+ }++ @Test+ void putSuppressionAttributes_precedenceMatchesAws() {+ // Empty TenantName wins over the enum check; request validation wins over existence. An+ // absent TenantName gets the same message — no Smithy not-null variant on this operation.+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "", List.of("NOPE"), "TENANT", REGION)).getMessage());+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ null, List.of("BOUNCE"), "TENANT", REGION)).getMessage());+ assertEquals("SuppressedReasons cannot be specified without SuppressionScope.",+ assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "ghost", List.of("BOUNCE"), null, REGION)).getMessage());+ AwsException ghost = assertThrows(AwsException.class, () -> service.putSuppressionAttributes(+ "ghost", List.of("BOUNCE"), "TENANT", REGION));+ assertEquals("NotFoundException", ghost.getErrorCode());+ assertEquals("The requested tenant <ghost> does not exist.", ghost.getMessage());+ }++ @Test+ void createTenant_withSuppressionAttributes_validatedAndStored() {+ Tenant tenant = service.createTenant("acme", List.of(), List.of("BOUNCE"), "TENANT",+ ACCOUNT, REGION);+ assertEquals("TENANT", tenant.suppressionAttributes().suppressionScope());+ assertThrows(AwsException.class, () -> service.createTenant("beta", List.of(),+ List.of("BOUNCE"), null, ACCOUNT, REGION));+ }++ @Test+ void runWithTenant_resolvesUnderLock_orThrows() {+ Tenant tenant = service.createTenant("acme", List.of(), ACCOUNT, REGION);+ String[] seenTenantId = new String[1];+ service.runWithTenant("acme", REGION, t -> seenTenantId[0] = t.tenantId());+ assertEquals(tenant.tenantId(), seenTenantId[0]);+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class,+ () -> service.runWithTenant(" ", REGION, t -> null)).getMessage());+ // An absent TenantName collapses to the same service-level message (probe-confirmed) —+ // the Smithy not-null variant exists only on CreateTenant.+ assertEquals("TenantName cannot be empty",+ assertThrows(AwsException.class,+ () -> service.runWithTenant(null, REGION, t -> null)).getMessage());+ assertEquals("NotFoundException",+ assertThrows(AwsException.class,+ () -> service.runWithTenant("ghost", REGION, t -> null)).getErrorCode());+ }++ @Test+ void deleteTenant_runsDependentCascadeInsideLock_beforeRecordRemoval() {+ Tenant tenant = service.createTenant("acme", List.of(), ACCOUNT, REGION);+ boolean[] sawTenantStillPresent = new boolean[1];+ service.deleteTenant("acme", REGION, t -> {+ assertEquals(tenant.tenantId(), t.tenantId());+ sawTenantStillPresent[0] = service.find("acme", REGION).isPresent();+ });+ assertTrue(sawTenantStillPresent[0]);+ assertTrue(service.find("acme", REGION).isEmpty());+ }+@Testvoid validateFilterAndPaging_matchAwsMessages() {assertEquals("Invalid resource type NOPE specified.",diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantSuppressionV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantSuppressionV2IntegrationTest.javanew file mode 100644index 0000000000..39d0320991--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTenantSuppressionV2IntegrationTest.java@@ -0,0 +1,215 @@+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.contains;+import static org.hamcrest.Matchers.equalTo;+import static org.hamcrest.Matchers.hasSize;+import static org.hamcrest.Matchers.notNullValue;+import static org.hamcrest.Matchers.nullValue;++/**+ * Integration tests for SES v2 tenant suppression (Phase 3): {@code PutTenantSuppressionAttributes}+ * on its singular {@code /v2/email/tenant/suppression} route, and the {@code TenantName}-scoped+ * variants of the suppression-list operations. Probe-confirmed behavior: the attribute pair is+ * all-or-nothing (a bare TenantName clears it), each tenant's list is fully separate from the+ * account list, the tenant-scoped delete is not idempotent, and {@code DeleteTenant} cascades the+ * entries.+ */+@QuarkusTest+@TestMethodOrder(MethodOrderer.OrderAnnotation.class)+class SesTenantSuppressionV2IntegrationTest {++ private static final String AUTH =+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";+ private static final String TENANT = "floci-sup-tenant";+ private static final String TENANT_ADDR = "[email protected]";+ private static final String ACCOUNT_ADDR = "[email protected]";++ private static io.restassured.specification.RequestSpecification v2() {+ return given().contentType("application/json").header("Authorization", AUTH);+ }++ @Test+ @Order(1)+ void createTenant_withSuppressionAttributes_rendersThem() {+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressionAttributes\":"+ + "{\"SuppressedReasons\":[\"BOUNCE\"],\"SuppressionScope\":\"TENANT\"}}")+ .when().post("/v2/email/tenants").then().statusCode(200)+ .body("SuppressionAttributes.SuppressedReasons", contains("BOUNCE"))+ .body("SuppressionAttributes.SuppressionScope", equalTo("TENANT"));+ }++ @Test+ @Order(2)+ void putSuppressionAttributes_replacesAndClears() {+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":"+ + "[\"BOUNCE\",\"COMPLAINT\"],\"SuppressionScope\":\"ACCOUNT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(200)+ .body("isEmpty()", equalTo(true));+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants/get").then().statusCode(200)+ .body("Tenant.SuppressionAttributes.SuppressedReasons", contains("BOUNCE", "COMPLAINT"))+ .body("Tenant.SuppressionAttributes.SuppressionScope", equalTo("ACCOUNT"));++ // An empty reason list with a scope is a valid state.+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":[],"+ + "\"SuppressionScope\":\"TENANT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(200);+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants/get").then().statusCode(200)+ .body("Tenant.SuppressionAttributes.SuppressedReasons", hasSize(0))+ .body("Tenant.SuppressionAttributes.SuppressionScope", equalTo("TENANT"));++ // A put with neither member clears the block; GetTenant renders the explicit null.+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(200);+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants/get").then().statusCode(200)+ .body("Tenant.SuppressionAttributes", nullValue());+ }++ @Test+ @Order(3)+ void putSuppressionAttributes_errorMatrix() {+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":[\"BOUNCE\"]}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("SuppressedReasons cannot be specified without SuppressionScope."));+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressionScope\":\"ACCOUNT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("SuppressionScope cannot be specified without SuppressedReasons."));+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":[]}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("SuppressionScope is required when SuppressedReasons are "+ + "provided. Valid values are: TENANT, ACCOUNT"));+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":[\"NOPE\"]}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("1 validation error detected: Value at 'suppressedReasons' "+ + "failed to satisfy constraint: Member must satisfy constraint: [Member must "+ + "satisfy enum value set: [BOUNCE, COMPLAINT]]"));+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressionScope\":\"NOPE\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("1 validation error detected: Value at 'suppressionScope' "+ + "failed to satisfy constraint: Member must satisfy enum value set: "+ + "[TENANT, ACCOUNT]"));+ v2().body("{\"TenantName\":\"" + TENANT + "\",\"SuppressedReasons\":"+ + "[\"BOUNCE\",\"BOUNCE\"],\"SuppressionScope\":\"ACCOUNT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("Each suppressed reason can only be specified at most once"));++ // Precedence: empty TenantName wins over enum errors; validation wins over existence. An+ // absent TenantName collapses to the same message (no Smithy not-null on this operation).+ v2().body("{\"TenantName\":\"\",\"SuppressedReasons\":[\"NOPE\"],\"SuppressionScope\":\"TENANT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("TenantName cannot be empty"));+ v2().body("{\"SuppressedReasons\":[\"BOUNCE\"],\"SuppressionScope\":\"TENANT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("TenantName cannot be empty"));+ v2().body("{\"TenantName\":\"ghost-tenant\",\"SuppressedReasons\":[\"BOUNCE\"]}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(400)+ .body("message", equalTo("SuppressedReasons cannot be specified without SuppressionScope."));+ v2().body("{\"TenantName\":\"ghost-tenant\",\"SuppressedReasons\":[\"BOUNCE\"],"+ + "\"SuppressionScope\":\"TENANT\"}")+ .when().post("/v2/email/tenant/suppression").then().statusCode(404)+ .body("__type", equalTo("NotFoundException"))+ .body("message", equalTo("The requested tenant <ghost-tenant> does not exist."));+ }++ @Test+ @Order(4)+ void tenantSuppressionList_isSeparateFromAccountList() {+ v2().body("{\"EmailAddress\":\"[email protected]\",\"Reason\":\"BOUNCE\"}")+ .when().put("/v2/email/suppression/addresses").then().statusCode(200);+ v2().body("{\"EmailAddress\":\"[email protected]\",\"Reason\":\"BOUNCE\","+ + "\"TenantName\":\"" + TENANT + "\"}")+ .when().put("/v2/email/suppression/addresses").then().statusCode(200);++ v2().when().get("/v2/email/suppression/addresses/" + TENANT_ADDR + "?TenantName=" + TENANT)+ .then().statusCode(200)+ .body("SuppressedDestination.EmailAddress", equalTo("[email protected]"))+ .body("SuppressedDestination.TenantName", equalTo(TENANT))+ .body("SuppressedDestination.LastUpdateTime", notNullValue());+ // The account entry renders an explicit TenantName null.+ v2().when().get("/v2/email/suppression/addresses/" + ACCOUNT_ADDR).then().statusCode(200)+ .body("SuppressedDestination.TenantName", nullValue());++ v2().when().get("/v2/email/suppression/addresses/" + TENANT_ADDR).then().statusCode(404)+ .body("message", equalTo("Email address [email protected] does not exist "+ + "on your suppression list."));+ v2().when().get("/v2/email/suppression/addresses/" + ACCOUNT_ADDR + "?TenantName=" + TENANT)+ .then().statusCode(404)+ .body("message", equalTo("Email address [email protected] does not exist "+ + "on your tenant suppression list."));+ }++ @Test+ @Order(5)+ void tenantSuppressionList_listAndFilter() {+ v2().when().get("/v2/email/suppression/addresses?TenantName=" + TENANT).then().statusCode(200)+ .body("SuppressedDestinationSummaries", hasSize(1))+ .body("SuppressedDestinationSummaries[0].EmailAddress",+ equalTo("[email protected]"));+ v2().when().get("/v2/email/suppression/addresses?TenantName=" + TENANT + "&Reason=COMPLAINT")+ .then().statusCode(200)+ .body("SuppressedDestinationSummaries", hasSize(0));+ v2().when().get("/v2/email/suppression/addresses?TenantName=ghost-tenant").then().statusCode(404)+ .body("message", equalTo("The requested tenant <ghost-tenant> does not exist."));+ }++ @Test+ @Order(6)+ void tenantSuppressionList_ghostTenantOnPut_andDeleteNotIdempotent() {+ v2().body("{\"EmailAddress\":\"[email protected]\",\"Reason\":\"BOUNCE\","+ + "\"TenantName\":\"ghost-tenant\"}")+ .when().put("/v2/email/suppression/addresses").then().statusCode(404)+ .body("message", equalTo("The requested tenant <ghost-tenant> does not exist."));++ // Request validation precedes tenant existence: a bad member wins over the ghost tenant.+ v2().body("{\"EmailAddress\":\"\",\"Reason\":\"BOUNCE\",\"TenantName\":\"ghost-tenant\"}")+ .when().put("/v2/email/suppression/addresses").then().statusCode(400)+ .body("message", equalTo("EmailAddress is required."));+ v2().when().get("/v2/email/suppression/addresses?TenantName=ghost-tenant&Reason=NOPE")+ .then().statusCode(400)+ .body("message", equalTo("1 validation error detected: Value at 'reasons' failed to "+ + "satisfy constraint: Member must satisfy constraint: [Member must satisfy "+ + "enum value set: [BOUNCE, COMPLAINT]]"));++ v2().when().delete("/v2/email/suppression/addresses/" + TENANT_ADDR + "?TenantName=" + TENANT)+ .then().statusCode(200);+ // Unlike the resource associations, this delete is not idempotent on AWS.+ v2().when().delete("/v2/email/suppression/addresses/" + TENANT_ADDR + "?TenantName=" + TENANT)+ .then().statusCode(404)+ .body("message", equalTo("Email address [email protected] does not exist "+ + "on your tenant suppression list."));+ }++ @Test+ @Order(7)+ void deleteTenant_cascadesSuppressionEntries_recreationStartsClean() {+ v2().body("{\"EmailAddress\":\"[email protected]\",\"Reason\":\"COMPLAINT\","+ + "\"TenantName\":\"" + TENANT + "\"}")+ .when().put("/v2/email/suppression/addresses").then().statusCode(200);+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants/delete").then().statusCode(200);++ v2().when().get("/v2/email/suppression/addresses/" + TENANT_ADDR + "?TenantName=" + TENANT)+ .then().statusCode(404)+ .body("message", equalTo("The requested tenant <" + TENANT + "> does not exist."));++ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants").then().statusCode(200)+ .body("SuppressionAttributes", nullValue());+ v2().when().get("/v2/email/suppression/addresses?TenantName=" + TENANT).then().statusCode(200)+ .body("SuppressedDestinationSummaries", hasSize(0));++ // Cleanup: the account entry and the tenant.+ v2().when().delete("/v2/email/suppression/addresses/" + ACCOUNT_ADDR).then().statusCode(200);+ v2().body("{\"TenantName\":\"" + TENANT + "\"}")+ .when().post("/v2/email/tenants/delete").then().statusCode(200);+ }+}