mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): add the v2 reputation entity operations (#6407)
* feat(ses): add the v2 reputation entity operations Implement ListReputationEntities, GetReputationEntity, UpdateReputationEntityPolicy and UpdateReputationEntityCustomerManagedStatus. Every tenant is a reputation entity referenced by its full ARN. The policy and the customer-managed status live on the tenant record, and the status is the tenant's aggregate SendingStatus. A tenant whose status is DISABLED is now refused on SendEmail and SendBulkEmail with MessageRejected. Shapes, messages and validation order follow probes against real SES. * test(ses): surface unexpected tenant cleanup failures in the reputation compat test
This commit is contained in:
1 parent
84727e3f2f
commit
5a9f9cbbd6
22 files changed
+1371
-62
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.EXPECTED_MAP;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.LIST;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.NUMBER;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.STRUCTURE;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2SerializationErrors.assertSerializationException;
|
||||
|
||||
/**
|
||||
* The reputation entity operations check their body against the SES v2 shapes, so a member of the
|
||||
* wrong JSON type is a SerializationException ahead of every other check. The updates name an
|
||||
* entity type and a reference that would both be refused, to show the body is read first.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesReputationEntityMemberTypeIntegrationTest {
|
||||
|
||||
private static final String LIST_PATH = "/v2/email/reputation/entities";
|
||||
private static final String ENTITY_PATH = "/v2/email/reputation/entities/FOO/hello";
|
||||
|
||||
static Stream<Arguments> listReputationEntitiesCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("stringFilter", "{\"Filter\": \"x\"}", EXPECTED_MAP),
|
||||
Arguments.of("arrayFilter", "{\"Filter\": []}", LIST),
|
||||
Arguments.of("numericFilterValue", "{\"Filter\": {\"SENDING_STATUS\": 1}}", NUMBER),
|
||||
Arguments.of("objectNextToken", "{\"NextToken\": {}}", STRUCTURE),
|
||||
Arguments.of("arrayNextToken", "{\"NextToken\": []}", LIST));
|
||||
}
|
||||
|
||||
static Stream<Arguments> updateReputationEntityPolicyCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("numericPolicy", "{\"ReputationEntityPolicy\": 1}", NUMBER),
|
||||
Arguments.of("objectPolicy", "{\"ReputationEntityPolicy\": {}}", STRUCTURE),
|
||||
Arguments.of("arrayPolicy", "{\"ReputationEntityPolicy\": []}", LIST));
|
||||
}
|
||||
|
||||
static Stream<Arguments> updateReputationEntityCustomerManagedStatusCases() {
|
||||
return Stream.of(
|
||||
Arguments.of("booleanStatus", "{\"SendingStatus\": true}", "TRUE_VALUE can not be converted to a String"),
|
||||
Arguments.of("objectStatus", "{\"SendingStatus\": {}}", STRUCTURE),
|
||||
Arguments.of("arrayStatus", "{\"SendingStatus\": []}", LIST));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("listReputationEntitiesCases")
|
||||
void listReputationEntities_wrongMemberType(String caseName, String body, String message) {
|
||||
assertSerializationException("POST", LIST_PATH, body, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("updateReputationEntityPolicyCases")
|
||||
void updateReputationEntityPolicy_wrongMemberType(String caseName, String body, String message) {
|
||||
assertSerializationException("PUT", ENTITY_PATH + "/policy", body, message);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("updateReputationEntityCustomerManagedStatusCases")
|
||||
void updateReputationEntityCustomerManagedStatus_wrongMemberType(String caseName, String body, String message) {
|
||||
assertSerializationException("PUT", ENTITY_PATH + "/customer-managed-status", body, message);
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.services.ses.SesReputationEntityService.ReputationEntity;
|
||||
import io.github.hectorvent.floci.services.ses.model.Tenant;
|
||||
import io.github.hectorvent.floci.testing.MutableClock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class SesReputationEntityServiceTest {
|
||||
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
|
||||
private MutableClock clock;
|
||||
private SesTenantService tenants;
|
||||
private SesReputationEntityService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
clock = new MutableClock();
|
||||
tenants = new SesTenantService(new InMemoryStorage<>(), new InMemoryStorage<>(), clock, new SecureRandom());
|
||||
service = new SesReputationEntityService(tenants, clock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void get_defaultPolicyFollowsTheRegionsPartition() {
|
||||
Tenant cn = tenants.createTenant("acme", List.of(), ACCOUNT, "cn-north-1");
|
||||
|
||||
ReputationEntity entity = service.get("RESOURCE", cn.tenantArn(), "cn-north-1");
|
||||
|
||||
assertEquals("arn:aws-cn:ses:cn-north-1:aws:reputation-policy/standard", entity.policy());
|
||||
assertNull(entity.customerManagedStatus());
|
||||
assertEquals("ENABLED", entity.sendingStatusAggregate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void get_isRegionScoped() {
|
||||
Tenant tenant = tenants.createTenant("acme", List.of(), ACCOUNT, REGION);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.get("RESOURCE", tenant.tenantArn(), "us-west-2"));
|
||||
|
||||
assertEquals("BadRequestException", e.getErrorCode());
|
||||
assertEquals(400, e.getHttpStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatePolicy_checksOnlyTheAccountAndTheResource() {
|
||||
Tenant tenant = tenants.createTenant("acme", List.of(), ACCOUNT, REGION);
|
||||
|
||||
for (String policy : List.of("arn:aws-cn:ses:cn-north-1:aws:reputation-policy/none",
|
||||
"arn:aws-nope:ses:mars-1:aws:reputation-policy/strict",
|
||||
"arn:aws:ses::aws:reputation-policy/standard")) {
|
||||
service.updatePolicy("RESOURCE", tenant.tenantArn(), policy, REGION);
|
||||
assertEquals(policy, service.get("RESOURCE", tenant.tenantArn(), REGION).policy());
|
||||
}
|
||||
for (String policy : List.of("arn:aws:sqs:us-east-1:aws:reputation-policy/none",
|
||||
"arn:aws:ses:us-east-1:aws:reputation-policy/",
|
||||
"arn:aws:ses:us-east-1:aws:reputation-policy/strict/x",
|
||||
"arn:aws:ses:us-east-1:aws:policy/none")) {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.updatePolicy("RESOURCE", tenant.tenantArn(), policy, REGION));
|
||||
assertEquals("Provided resource identifier is invalid", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateStatus_stampsEveryCallAndKeepsTheOtherTenantState() {
|
||||
Tenant tenant = tenants.createTenant("acme", List.of(), ACCOUNT, REGION);
|
||||
service.updatePolicy("RESOURCE", tenant.tenantArn(), "arn:aws:ses:us-east-1:aws:reputation-policy/strict",
|
||||
REGION);
|
||||
|
||||
service.updateCustomerManagedStatus("RESOURCE", tenant.tenantArn(), "DISABLED", REGION);
|
||||
Instant first = service.get("RESOURCE", tenant.tenantArn(), REGION).customerManagedStatus()
|
||||
.lastUpdatedTimestamp();
|
||||
clock.advance(Duration.ofMinutes(5));
|
||||
service.updateCustomerManagedStatus("RESOURCE", tenant.tenantArn(), "DISABLED", REGION);
|
||||
|
||||
ReputationEntity entity = service.get("RESOURCE", tenant.tenantArn(), REGION);
|
||||
assertTrue(entity.customerManagedStatus().lastUpdatedTimestamp().isAfter(first.plus(Duration.ofMinutes(5))));
|
||||
assertEquals("DISABLED", entity.sendingStatusAggregate());
|
||||
assertEquals("arn:aws:ses:us-east-1:aws:reputation-policy/strict", entity.policy());
|
||||
assertEquals("DISABLED", tenants.getTenant("acme", REGION).sendingStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_byReference_prefixIsCaseSensitive() {
|
||||
Tenant b = tenants.createTenant("beta", List.of(), ACCOUNT, REGION);
|
||||
Tenant a = tenants.createTenant("alpha", List.of(), ACCOUNT, REGION);
|
||||
|
||||
assertEquals(List.of(a.tenantArn(), b.tenantArn()),
|
||||
service.list(Map.of(), null, null, REGION).items().stream().map(ReputationEntity::reference).toList());
|
||||
assertTrue(service.list(Map.of("ENTITY_REFERENCE_PREFIX", a.tenantArn().toUpperCase(Locale.ROOT)),
|
||||
null, null, REGION).items().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void list_tokenFromAnotherRegion_isUnreadableNotBoundElsewhere() {
|
||||
tenants.createTenant("alpha", List.of(), ACCOUNT, "us-west-2");
|
||||
tenants.createTenant("beta", List.of(), ACCOUNT, "us-west-2");
|
||||
PaginatedResult<ReputationEntity> page = service.list(Map.of(), 1, null, "us-west-2");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.list(Map.of(), 1, page.nextToken(), REGION));
|
||||
|
||||
assertEquals("Failed to deserialize token. ", e.getMessage());
|
||||
}
|
||||
}
|
||||
+298
@@ -0,0 +1,298 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
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 java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
/**
|
||||
* Integration tests for the SES v2 reputation entity operations. Every tenant is an entity
|
||||
* referenced by its full ARN; shapes, messages and precedence follow the 2026-10-23 probes.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesReputationEntityV2IntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
|
||||
private static final String PREFIX = "arn:aws:ses:us-east-1:000000000000:tenant/floci-rep-it-";
|
||||
private static final String POLICY_PREFIX = "arn:aws:ses:us-east-1:aws:reputation-policy/";
|
||||
private static final String INVALID_IDENTIFIER = "Provided resource identifier is invalid";
|
||||
|
||||
private static String arnA;
|
||||
private static String arnB;
|
||||
|
||||
// The reference is sent percent-encoded as the SDKs send it, so RestAssured must not encode it again.
|
||||
private static RequestSpecification v2() {
|
||||
return given().urlEncodingEnabled(false).contentType("application/json").header("Authorization", AUTH);
|
||||
}
|
||||
|
||||
private static String entityPath(String type, String reference) {
|
||||
return "/v2/email/reputation/entities/" + type + "/" + URLEncoder.encode(reference, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String createTenant(String name) {
|
||||
return v2().body("{\"TenantName\":\"" + name + "\"}")
|
||||
.when().post("/v2/email/tenants").then().statusCode(200)
|
||||
.extract().path("TenantArn");
|
||||
}
|
||||
|
||||
private static String prefixFilter(String extra) {
|
||||
return "{\"Filter\":{\"ENTITY_REFERENCE_PREFIX\":\"" + PREFIX + "\"}" + extra + "}";
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void setup_tenants() {
|
||||
arnA = createTenant("floci-rep-it-a");
|
||||
arnB = createTenant("floci-rep-it-b");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void list_everyTenantIsAnEntityWithEveryMemberRendered() {
|
||||
v2().body(prefixFilter(""))
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("$", hasKey("NextToken"))
|
||||
.body("NextToken", nullValue())
|
||||
.body("ReputationEntities.ReputationEntityReference", contains(arnA, arnB))
|
||||
.body("ReputationEntities[0]", hasKey("AwsSesManagedStatus"))
|
||||
.body("ReputationEntities[0].AwsSesManagedStatus", nullValue())
|
||||
.body("ReputationEntities[0]", hasKey("CustomerManagedStatus"))
|
||||
.body("ReputationEntities[0].CustomerManagedStatus", nullValue())
|
||||
.body("ReputationEntities[0].ReputationEntityType", equalTo("RESOURCE"))
|
||||
.body("ReputationEntities[0].ReputationImpact", equalTo("NONE"))
|
||||
.body("ReputationEntities[0].ReputationManagementPolicy", equalTo(POLICY_PREFIX + "standard"))
|
||||
.body("ReputationEntities[0].SendingStatusAggregate", equalTo("ENABLED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void get_matchesOnlyTheFullArn() {
|
||||
v2().when().get(entityPath("RESOURCE", arnA)).then().statusCode(200)
|
||||
.body("ReputationEntity.ReputationEntityReference", equalTo(arnA))
|
||||
.body("ReputationEntity.SendingStatusAggregate", equalTo("ENABLED"));
|
||||
|
||||
String tenantId = arnA.substring(arnA.lastIndexOf('/') + 1);
|
||||
for (String other : new String[] {
|
||||
"arn:aws:ses:us-east-1:000000000000:tenant/" + tenantId,
|
||||
PREFIX + "a",
|
||||
PREFIX + "wrong/" + tenantId,
|
||||
arnA.replace("us-east-1", "us-west-2"),
|
||||
"arn:aws:ses:us-east-1:000000000000:identity/example.com"}) {
|
||||
v2().when().get(entityPath("RESOURCE", other)).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("ReputationEntity <" + other + "> does not exist"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void literalSlashesInTheReference_reachNoRoute() {
|
||||
v2().when().get("/v2/email/reputation/entities/RESOURCE/" + arnA).then().statusCode(404);
|
||||
v2().body("{\"SendingStatus\":\"DISABLED\"}")
|
||||
.when().put("/v2/email/reputation/entities/RESOURCE/" + arnA + "/customer-managed-status")
|
||||
.then().statusCode(404);
|
||||
v2().body("{\"TenantName\":\"floci-rep-it-a\"}")
|
||||
.when().post("/v2/email/tenants/get").then().statusCode(200)
|
||||
.body("Tenant.SendingStatus", equalTo("ENABLED"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void get_typeThenReferenceFormat() {
|
||||
v2().when().get(entityPath("FOO", "hello")).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("1 validation error detected: Value at 'reputationEntityType' failed "
|
||||
+ "to satisfy constraint: Member must satisfy enum value set: [RESOURCE]"));
|
||||
v2().when().get(entityPath("RESOURCE", "hello")).then().statusCode(400)
|
||||
.body("message", equalTo(INVALID_IDENTIFIER));
|
||||
v2().when().get(entityPath("RESOURCE", "arn:aws:sqs:us-east-1:000000000000:q")).then().statusCode(400)
|
||||
.body("message", equalTo(INVALID_IDENTIFIER));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updatePolicy_storesTheGivenArn() {
|
||||
v2().body("{\"ReputationEntityPolicy\":\"" + POLICY_PREFIX + "strict\"}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/policy").then().statusCode(200);
|
||||
v2().when().get(entityPath("RESOURCE", arnA)).then().statusCode(200)
|
||||
.body("ReputationEntity.ReputationManagementPolicy", equalTo(POLICY_PREFIX + "strict"));
|
||||
|
||||
String otherRegion = "arn:aws:ses:us-west-2:aws:reputation-policy/none";
|
||||
v2().body("{\"ReputationEntityPolicy\":\"" + otherRegion + "\"}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/policy").then().statusCode(200);
|
||||
v2().when().get(entityPath("RESOURCE", arnA)).then().statusCode(200)
|
||||
.body("ReputationEntity.ReputationManagementPolicy", equalTo(otherRegion));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void updatePolicy_checksThePolicyFirst() {
|
||||
for (String body : new String[] {
|
||||
"{}",
|
||||
"{\"ReputationEntityPolicy\":\"standard\"}",
|
||||
"{\"ReputationEntityPolicy\":\"" + POLICY_PREFIX + "lax\"}",
|
||||
"{\"ReputationEntityPolicy\":\"" + POLICY_PREFIX + "STANDARD\"}",
|
||||
"{\"ReputationEntityPolicy\":\"arn:aws:ses:us-east-1:000000000000:reputation-policy/standard\"}"}) {
|
||||
v2().body(body).when().put(entityPath("RESOURCE", arnA) + "/policy").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo(INVALID_IDENTIFIER));
|
||||
}
|
||||
// Even a bad entity type loses to a bad policy.
|
||||
v2().body("{\"ReputationEntityPolicy\":\"x\"}")
|
||||
.when().put(entityPath("FOO", PREFIX + "ghost/tn-0") + "/policy").then().statusCode(400)
|
||||
.body("message", equalTo(INVALID_IDENTIFIER));
|
||||
v2().body("{\"ReputationEntityPolicy\":\"" + POLICY_PREFIX + "standard\"}")
|
||||
.when().put(entityPath("RESOURCE", PREFIX + "ghost/tn-0") + "/policy").then().statusCode(400)
|
||||
.body("message", equalTo("ReputationEntity <" + PREFIX + "ghost/tn-0> does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void updateStatus_disabledIsTheAggregateEverywhere() {
|
||||
v2().body("{\"SendingStatus\":\"DISABLED\"}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/customer-managed-status").then().statusCode(200);
|
||||
|
||||
v2().when().get(entityPath("RESOURCE", arnA)).then().statusCode(200)
|
||||
.body("ReputationEntity.CustomerManagedStatus.Status", equalTo("DISABLED"))
|
||||
.body("ReputationEntity.CustomerManagedStatus.Cause", equalTo("Status manually updated."))
|
||||
.body("ReputationEntity.CustomerManagedStatus.LastUpdatedTimestamp", notNullValue())
|
||||
.body("ReputationEntity.AwsSesManagedStatus", nullValue())
|
||||
.body("ReputationEntity.SendingStatusAggregate", equalTo("DISABLED"));
|
||||
v2().body("{\"TenantName\":\"floci-rep-it-a\"}")
|
||||
.when().post("/v2/email/tenants/get").then().statusCode(200)
|
||||
.body("Tenant.SendingStatus", equalTo("DISABLED"));
|
||||
v2().body("{\"Filter\":{\"SENDING_STATUS\":\"DISABLED\",\"TENANT_NAME_CONTAINS\":\"floci-rep-it-\"}}")
|
||||
.when().post("/v2/email/tenants/list").then().statusCode(200)
|
||||
.body("Tenants.TenantArn", contains(arnA));
|
||||
// The entity filter takes one key, so other classes' tenants may show up here as well.
|
||||
v2().body("{\"Filter\":{\"SENDING_STATUS\":\"DISABLED\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("ReputationEntities.ReputationEntityReference", hasItem(arnA))
|
||||
.body("ReputationEntities.ReputationEntityReference", not(hasItem(arnB)));
|
||||
|
||||
// The same status again is accepted, not a conflict.
|
||||
v2().body("{\"SendingStatus\":\"DISABLED\"}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/customer-managed-status").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void updateStatus_referenceThenStatusThenExistence() {
|
||||
v2().body("{}")
|
||||
.when().put(entityPath("RESOURCE", "hello") + "/customer-managed-status").then().statusCode(400)
|
||||
.body("message", equalTo(INVALID_IDENTIFIER));
|
||||
v2().body("{}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/customer-managed-status").then().statusCode(400)
|
||||
.body("message", equalTo("1 validation error detected: Value at 'sendingStatus' failed to "
|
||||
+ "satisfy constraint: Member must not be null"));
|
||||
v2().body("{\"SendingStatus\":\"PAUSED\"}")
|
||||
.when().put(entityPath("RESOURCE", PREFIX + "ghost/tn-0") + "/customer-managed-status")
|
||||
.then().statusCode(400)
|
||||
.body("message", equalTo("1 validation error detected: Value at 'sendingStatus' failed to "
|
||||
+ "satisfy constraint: Member must satisfy enum value set: [ENABLED, REINSTATED, DISABLED]"));
|
||||
v2().body("{\"SendingStatus\":\"ENABLED\"}")
|
||||
.when().put(entityPath("RESOURCE", PREFIX + "ghost/tn-0") + "/customer-managed-status")
|
||||
.then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("ReputationEntity <" + PREFIX + "ghost/tn-0> does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void list_filterValues() {
|
||||
v2().body("{\"Filter\":{\"SENDING_STATUS\":\"ENABLED\",\"ENTITY_TYPE\":\"RESOURCE\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("Too many filters provided."));
|
||||
for (String[] bad : new String[][] {
|
||||
{"SENDING_STATUS", "disabled"}, {"ENTITY_TYPE", "resource"}, {"REPUTATION_IMPACT", "none"}}) {
|
||||
v2().body("{\"Filter\":{\"" + bad[0] + "\":\"" + bad[1] + "\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid reputation entity " + bad[0] + " specified"));
|
||||
}
|
||||
v2().body("{\"Filter\":{\"REPUTATION_IMPACT\":\"MEDIUM\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("ReputationEntities", empty());
|
||||
v2().body("{\"Filter\":{\"FOO\":\"x\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "
|
||||
+ "constraint: Map keys must satisfy constraint: [Member must satisfy enum value set: "
|
||||
+ "[ENTITY_REFERENCE_PREFIX, REPUTATION_IMPACT, ENTITY_TYPE, SENDING_STATUS]]"));
|
||||
v2().body("{\"Filter\":{\"SENDING_STATUS\":\"\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("1 validation error detected: Value at 'filter' failed to satisfy "
|
||||
+ "constraint: Map value must satisfy constraint: [Member must have length less than "
|
||||
+ "or equal to 512, Member must have length greater than or equal to 1]"));
|
||||
v2().body("{\"Filter\":{\"ENTITY_REFERENCE_PREFIX\":\"" + PREFIX.replace("floci-rep-it-", "FLOCI-REP-IT-") + "\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("ReputationEntities", empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void list_paging() {
|
||||
String token = v2().body(prefixFilter(",\"PageSize\":1"))
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("ReputationEntities.ReputationEntityReference", contains(arnA))
|
||||
.extract().path("NextToken");
|
||||
v2().body(prefixFilter(",\"PageSize\":1,\"NextToken\":\"" + token + "\""))
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(200)
|
||||
.body("ReputationEntities.ReputationEntityReference", contains(arnB))
|
||||
.body("NextToken", nullValue());
|
||||
v2().body("{\"PageSize\":1,\"NextToken\":\"" + token + "\"}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("Pagination token is bound to a different set of filtering parameters"));
|
||||
for (String bad : new String[] {"garbage", ""}) {
|
||||
v2().body("{\"NextToken\":\"" + bad + "\"}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("Failed to deserialize token. "));
|
||||
}
|
||||
// The page size is checked before the filter and the token.
|
||||
v2().body("{\"PageSize\":0,\"NextToken\":\"garbage\",\"Filter\":{\"SENDING_STATUS\":\"X\"}}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
v2().body("{\"PageSize\":1001}")
|
||||
.when().post("/v2/email/reputation/entities").then().statusCode(400)
|
||||
.body("message", equalTo("The page size must be between 1 and 1000"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void updateStatus_reinstatedAndEnabledBecomeTheAggregate() {
|
||||
for (String status : new String[] {"REINSTATED", "ENABLED"}) {
|
||||
v2().body("{\"SendingStatus\":\"" + status + "\"}")
|
||||
.when().put(entityPath("RESOURCE", arnA) + "/customer-managed-status").then().statusCode(200);
|
||||
v2().when().get(entityPath("RESOURCE", arnA)).then().statusCode(200)
|
||||
.body("ReputationEntity.CustomerManagedStatus.Status", equalTo(status))
|
||||
.body("ReputationEntity.SendingStatusAggregate", equalTo(status));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void deleteTenant_removesTheEntity() {
|
||||
v2().body("{\"TenantName\":\"floci-rep-it-b\"}")
|
||||
.when().post("/v2/email/tenants/delete").then().statusCode(200);
|
||||
v2().when().get(entityPath("RESOURCE", arnB)).then().statusCode(400)
|
||||
.body("message", equalTo("ReputationEntity <" + arnB + "> does not exist"));
|
||||
v2().body("{\"TenantName\":\"floci-rep-it-a\"}")
|
||||
.when().post("/v2/email/tenants/delete").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
+10
@@ -86,6 +86,16 @@ class SesSendNullAddressIntegrationTest {
|
||||
.body("message", equalTo(NULL_ADDRESS));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkEmail_onlyEmptyDestinationsInTheRequest_answerEmptyDestination() {
|
||||
bulk("", entry("{}") + ", " + entry("{\"ToAddresses\": [], \"CcAddresses\": [null]}"))
|
||||
.statusCode(200)
|
||||
.body("BulkEmailEntryResults[0].Status", equalTo("INVALID_PARAMETER"))
|
||||
.body("BulkEmailEntryResults[0].Error", equalTo(EMPTY_DESTINATION))
|
||||
.body("BulkEmailEntryResults[1].Status", equalTo("INVALID_PARAMETER"))
|
||||
.body("BulkEmailEntryResults[1].Error", equalTo(EMPTY_DESTINATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendBulkEmail_onlyNullRecipientsInTheRequest_answerEmptyDestination() {
|
||||
bulk("", entry("{\"ToAddresses\": [null]}") + ", " + entry("{\"ToAddresses\": [null]}"))
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ class SesTenantListFilterServiceTest {
|
||||
service.createTenant(name, List.of(), ACCOUNT, REGION);
|
||||
}
|
||||
tenantStore.put("tenant::" + REGION + "::other-FILTER-gamma", new Tenant("other-FILTER-gamma",
|
||||
"tn-gamma", "arn", Instant.now(), List.of(), "DISABLED", null));
|
||||
"tn-gamma", "arn", Instant.now(), List.of(), "DISABLED", null, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+110
-2
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
@@ -20,8 +21,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
* the From identity (exact-address precedence included) and the configuration set; the
|
||||
* stored-template gate is inferred from the association model, not observed. The send-path
|
||||
* tenant-not-found wording differs from the management operations (no angle brackets, account id
|
||||
* included, probe-confirmed). The tenant's SendingStatus is not checked — nothing can move it off
|
||||
* ENABLED in the emulator.
|
||||
* included, probe-confirmed). A tenant whose customer-managed status is DISABLED is refused with a
|
||||
* 400 {@code MessageRejected} (probe-confirmed for the simple, templated, raw and bulk sends).
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
@@ -266,6 +267,23 @@ class SesTenantSendV2IntegrationTest {
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(404)
|
||||
.body("message", equalTo(
|
||||
"Tenant ghost-tenant for AwsAccountId 000000000000 not found."));
|
||||
// The tenant is looked up before the stored template...
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"ghost-tenant\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"ghost-template\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":"
|
||||
+ "[\"success@simulator.amazonses.com\"]}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(404)
|
||||
.body("message", equalTo(
|
||||
"Tenant ghost-tenant for AwsAccountId 000000000000 not found."));
|
||||
// ...but not at all when no entry names a recipient: each entry is answered instead.
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"ghost-tenant\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"" + TEMPLATE + "\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(200)
|
||||
.body("BulkEmailEntryResults[0].Status", equalTo("INVALID_PARAMETER"))
|
||||
.body("BulkEmailEntryResults[0].Error", equalTo("Destination cannot be empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,6 +300,96 @@ class SesTenantSendV2IntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void send_disabledTenant_isRejectedBeforeAssociationAndVerification() {
|
||||
String tenantArn = v2().body("{\"TenantName\":\"" + TENANT + "\"}")
|
||||
.when().post("/v2/email/tenants/get").then().statusCode(200)
|
||||
.extract().path("Tenant.TenantArn");
|
||||
String disabled = "Sending disabled for <" + tenantArn
|
||||
+ ">. For more information, please check the resource configuration and status.";
|
||||
setStatus(tenantArn, "DISABLED");
|
||||
|
||||
v2().body(simpleSend(TENANT, ""))
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", equalTo(disabled));
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"" + TENANT + "\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"" + TEMPLATE + "\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":"
|
||||
+ "[\"success@simulator.amazonses.com\"]}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", equalTo(disabled));
|
||||
// A malformed address and a send with no recipient are reported ahead of the refusal...
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"" + TENANT + "\","
|
||||
+ "\"Content\":{\"Simple\":{\"Subject\":{\"Data\":\"s\"},"
|
||||
+ "\"Body\":{\"Text\":{\"Data\":\"t\"}}}}}")
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("At least one destination address is required."));
|
||||
v2().body(simpleSend(TENANT, "").replace(FROM, "not an address"))
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Local address contains control or whitespace"));
|
||||
// ...while a raw message with no recipient anywhere is refused before its missing To header...
|
||||
String noRecipients = Base64.getEncoder().encodeToString(
|
||||
("From: " + FROM + "\r\nSubject: s\r\n\r\nbody\r\n").getBytes(StandardCharsets.UTF_8));
|
||||
v2().body("{\"TenantName\":\"" + TENANT + "\",\"Content\":{\"Raw\":{\"Data\":\"" + noRecipients + "\"}}}")
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", equalTo(disabled));
|
||||
// ...and an unverified sender and an unassociated identity both lose to the refusal...
|
||||
v2().body(simpleSend(TENANT, "").replace(FROM, "someone@unverified.example.com"))
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"));
|
||||
// ...while an unknown configuration set still wins over it, except on a bulk send.
|
||||
v2().body(simpleSend(TENANT, "\"ConfigurationSetName\":\"ghost-cs\","))
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"))
|
||||
.body("message", equalTo("Configuration set <ghost-cs> does not exist."));
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"" + TENANT + "\","
|
||||
+ "\"ConfigurationSetName\":\"ghost-cs\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"" + TEMPLATE + "\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":"
|
||||
+ "[\"success@simulator.amazonses.com\"]}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", equalTo(disabled));
|
||||
// A bulk send meets the refusal before an unknown stored template, and skips it when no
|
||||
// entry names a recipient.
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"" + TENANT + "\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"ghost-template\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":"
|
||||
+ "[\"success@simulator.amazonses.com\"]}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(400)
|
||||
.body("__type", equalTo("MessageRejected"))
|
||||
.body("message", equalTo(disabled));
|
||||
v2().body("{\"FromEmailAddress\":\"" + FROM + "\",\"TenantName\":\"" + TENANT + "\","
|
||||
+ "\"DefaultContent\":{\"Template\":{\"TemplateName\":\"" + TEMPLATE + "\","
|
||||
+ "\"TemplateData\":\"{}\"}},"
|
||||
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":[]}}]}")
|
||||
.when().post("/v2/email/outbound-bulk-emails").then().statusCode(200)
|
||||
.body("BulkEmailEntryResults[0].Status", equalTo("INVALID_PARAMETER"))
|
||||
.body("BulkEmailEntryResults[0].Error", equalTo("Destination cannot be empty"));
|
||||
|
||||
setStatus(tenantArn, "REINSTATED");
|
||||
v2().body(simpleSend(TENANT, ""))
|
||||
.when().post("/v2/email/outbound-emails").then().statusCode(200)
|
||||
.body("MessageId", notNullValue());
|
||||
setStatus(tenantArn, "ENABLED");
|
||||
}
|
||||
|
||||
private static void setStatus(String tenantArn, String status) {
|
||||
v2().urlEncodingEnabled(false).body("{\"SendingStatus\":\"" + status + "\"}")
|
||||
.when().put("/v2/email/reputation/entities/RESOURCE/"
|
||||
+ URLEncoder.encode(tenantArn, StandardCharsets.UTF_8) + "/customer-managed-status")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void cleanup_cascadeAndResources() {
|
||||
v2().body("{\"TenantName\":\"" + TENANT + "\"}")
|
||||
.when().post("/v2/email/tenants/delete").then().statusCode(200);
|
||||
|
||||
+5
-1
@@ -25,6 +25,7 @@ import static org.hamcrest.Matchers.notNullValue;
|
||||
class SesV2BodyReadIntegrationTest {
|
||||
|
||||
private static final String IDENTITY = "/v2/email/identities/body-read-ghost.example.com";
|
||||
private static final String REPUTATION_ENTITY = "/v2/email/reputation/entities/RESOURCE/body-read-ghost";
|
||||
|
||||
private static final List<Arguments> ENDPOINTS = List.of(
|
||||
Arguments.of("POST", "/v2/email/tenants/list"),
|
||||
@@ -44,7 +45,10 @@ class SesV2BodyReadIntegrationTest {
|
||||
Arguments.of("POST", "/v2/email/outbound-emails"),
|
||||
Arguments.of("POST", "/v2/email/dedicated-ip-pools"),
|
||||
Arguments.of("PUT", "/v2/email/suppression/addresses"),
|
||||
Arguments.of("POST", "/v2/email/tags"));
|
||||
Arguments.of("POST", "/v2/email/tags"),
|
||||
Arguments.of("POST", "/v2/email/reputation/entities"),
|
||||
Arguments.of("PUT", REPUTATION_ENTITY + "/policy"),
|
||||
Arguments.of("PUT", REPUTATION_ENTITY + "/customer-managed-status"));
|
||||
|
||||
static Stream<Arguments> malformedBodyCases() {
|
||||
return ENDPOINTS.stream().flatMap(endpoint -> Stream.of("{", "{\"a\":}", "{} x", "{}{}")
|
||||
|
||||
Reference in new issue
Block a user