mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): support v2 tenant suppression attributes and tenant-scoped suppression list (#2743)
* feat(ses): support v2 tenant suppression attributes and tenant-scoped suppression list * fix(ses): guard runWithTenant against a null TenantName * fix(ses): collapse an absent TenantName to the service-level message on tenant suppression ops * fix(ses): collapse an absent TenantName to the service-level message on the remaining tenant ops * fix(ses): collapse an empty TenantName to the service-level message on GetTenant/DeleteTenant
This commit is contained in:
1 parent
12a6feb0c9
commit
fc3c28323a
14 files changed
+961
-80
No files matched your search
@@ -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),
|
||||
|
||||
+68
-3
@@ -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 {
|
||||
|
||||
@BeforeEach
|
||||
void 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, "User@example.com").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", "t@example.com", "BOUNCE");
|
||||
service.putSuppressedDestination(REGION, "a@example.com", "BOUNCE");
|
||||
|
||||
SuppressedDestination tenantEntry =
|
||||
service.getTenantSuppressedDestination(REGION, TENANT_ID, "t@example.com");
|
||||
assertEquals("acme", tenantEntry.getTenantName());
|
||||
|
||||
AwsException accountMiss = assertThrows(AwsException.class,
|
||||
() -> service.getSuppressedDestination(REGION, "t@example.com"));
|
||||
assertEquals("Email address t@example.com does not exist on your suppression list.",
|
||||
accountMiss.getMessage());
|
||||
AwsException tenantMiss = assertThrows(AwsException.class,
|
||||
() -> service.getTenantSuppressedDestination(REGION, TENANT_ID, "a@example.com"));
|
||||
assertEquals("Email address a@example.com does not exist on your tenant suppression list.",
|
||||
tenantMiss.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tenantDelete_isNotIdempotent() {
|
||||
service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "t@example.com", "BOUNCE");
|
||||
service.deleteTenantSuppressedDestination(REGION, TENANT_ID, "t@example.com");
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.deleteTenantSuppressedDestination(REGION, TENANT_ID, "t@example.com"));
|
||||
assertEquals("NotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tenantList_filtersByReason_andIsPerTenant() {
|
||||
service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "a@example.com", "BOUNCE");
|
||||
service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "b@example.com", "COMPLAINT");
|
||||
service.putTenantSuppressedDestination(REGION, "tn-other", "beta", "c@example.com", "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("a@example.com", bounces.get(0).getEmailAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAllForTenant_removesOnlyThatTenant() {
|
||||
service.putTenantSuppressedDestination(REGION, TENANT_ID, "acme", "a@example.com", "BOUNCE");
|
||||
service.putTenantSuppressedDestination(REGION, "tn-other", "beta", "b@example.com", "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", "User@Example.COM", "BOUNCE");
|
||||
assertEquals("User@example.com",
|
||||
service.getTenantSuppressedDestination(REGION, TENANT_ID, "User@example.com")
|
||||
.getEmailAddress());
|
||||
assertThrows(AwsException.class, () -> service.putTenantSuppressedDestination(
|
||||
REGION, TENANT_ID, "acme", "x@example.com", "NONSENSE"));
|
||||
}
|
||||
}
|
||||
+4
@@ -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 "
|
||||
|
||||
@@ -127,11 +127,16 @@ class SesTenantServiceTest {
|
||||
|
||||
@Test
|
||||
void 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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateFilterAndPaging_matchAwsMessages() {
|
||||
assertEquals("Invalid resource type NOPE specified.",
|
||||
|
||||
+215
@@ -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 = "floci-sup-tenant@example.com";
|
||||
private static final String ACCOUNT_ADDR = "floci-sup-acct@example.com";
|
||||
|
||||
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\":\"floci-sup-acct@example.com\",\"Reason\":\"BOUNCE\"}")
|
||||
.when().put("/v2/email/suppression/addresses").then().statusCode(200);
|
||||
v2().body("{\"EmailAddress\":\"floci-sup-tenant@example.com\",\"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("floci-sup-tenant@example.com"))
|
||||
.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 floci-sup-tenant@example.com 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 floci-sup-acct@example.com 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("floci-sup-tenant@example.com"));
|
||||
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\":\"x@example.com\",\"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 floci-sup-tenant@example.com does not exist "
|
||||
+ "on your tenant suppression list."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void deleteTenant_cascadesSuppressionEntries_recreationStartsClean() {
|
||||
v2().body("{\"EmailAddress\":\"floci-sup-tenant@example.com\",\"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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user