fix(ses): order the send checks and read v1 bulk destinations like SES (#6490)

* fix(ses): verify the sender before the stored template and tenant associations

A tenant-scoped SES v2 send refused an unassociated resource with the
403 before anything else, and SendEmail and SendBulkEmail looked a
stored template up before checking the sender. AWS reports a missing
configuration set, then an unverified sender or return path, then a
missing stored template, and the tenant association 403 last. The
tenant lookup and the DISABLED refusal stay early; the template lookup
and the association check now run inside the send, after sender
verification.

SendBulkEmail and SendBulkTemplatedEmail now verify the sender and
return path once for the whole call, unless no entry has a recipient.

* fix(ses): run the tenant gate inside the send and order v1 bulk like v2

The first half of the tenant gate (lookup and DISABLED refusal) moves
from the v2 controller into the send paths, so the association check
reuses the tenant it found, and a raw message is read for its
X-SES-CONFIGURATION-SET header only when the tenant is DISABLED.

v1 SendBulkTemplatedEmail passes its stored template to the send, which
looks it up after sender verification as v2 SendBulkEmail does.

* fix(ses): read every v1 bulk destination entry like AWS

SendBulkTemplatedEmail stopped reading Destinations.member.N at the first
entry with no addresses, replacement data or tags. An empty ToAddresses
list, which boto3 sends as a bare empty-valued key, ended the list there,
so later entries were dropped and a lone empty entry was answered "At
least one destination is required." instead of reaching the send.

The handler now reads up to the highest member index. A missing Template
(with no TemplateArn), missing Destinations, and an entry without a
Destination or a skipped index are model violations, answered together as
one 400 ValidationError ahead of the address syntax, the template selector
and the destination count. In the send, an entry with no recipient beside
entries with one fails alone with "Missing required header 'To'." on v1
and v2 alike, while a request in which no entry names a recipient still
answers every entry "Destination cannot be empty", ahead of sender
verification and the template lookup. All of it was probed.

* refactor(ses): build the value-less not-null violation in SmithyValidationErrors

Some operations answer a missing member as "Value at '<path>' failed to
satisfy constraint: Member must not be null", without the null that
SmithyValidationErrors.notNull puts after "Value". SesQueryHandler,
SesExportJobService and SesReceiptRuleService each built that text
themselves. SmithyValidationErrors.notNullWithoutValue now builds it
beside notNull, and the three use it.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-25 10:27:24 -04:00
1 parent 00e6b0d905
commit ba82e0aeaa
18 files changed
+1063 -242

No files matched your search

@@ -50,6 +50,15 @@ class SmithyValidationErrorsTest {
void noViolations_isAProgrammingError() {
assertThrows(IllegalArgumentException.class, () -> SmithyValidationErrors.message(List.of()));
}
@Test
void notNull_hasTwoForms() {
assertEquals("Value null at 'a.b' failed to satisfy constraint: Member must not be null",
SmithyValidationErrors.notNull("a.b"));
assertEquals("Value at 'a.b' failed to satisfy constraint: Member must not be null",
SmithyValidationErrors.notNullWithoutValue("a.b"));
}
@Test
void lengthBoundsPreserveValuesAndIncludeEndpoints() {
assertEquals("Value '' at 'name' failed to satisfy constraint: "
@@ -11,7 +11,9 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
@@ -19,6 +21,7 @@ import java.util.stream.Stream;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -32,12 +35,29 @@ class SesBulkV1IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
// A sender of its own: an identity under example.com would outlive this class and reach the
// other SES classes that share the application.
private static final String SENDER = "bulk-v1@floci.test";
private static final String MISSING_DESTINATION_2 = "1 validation error detected: Value at "
+ "'destinations.2.member.destination' failed to satisfy constraint: Member must not be null";
private static final Pattern MESSAGE_ID_PATTERN =
Pattern.compile("<MessageId>([^<]+)</MessageId>");
@Test
@Order(1)
void createTemplate() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "VerifyEmailIdentity")
.formParam("EmailAddress", SENDER)
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
@@ -59,7 +79,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"team\":\"floci\"}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
@@ -111,7 +131,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "ghost")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.when()
@@ -128,13 +148,15 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at 'destinations' "
+ "failed to satisfy constraint: Member must not be null"));
}
@Test
@@ -144,38 +166,37 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo("1 validation error detected: Value at 'template' "
+ "failed to satisfy constraint: Member must not be null"));
}
@Test
@Order(6)
void sendBulkTemplatedEmail_perEntryMissingDestination_mapsToInvalidParameterValue() {
// An entry with only ReplacementTemplateData (no recipient) reaches the per-entry send,
// which throws AwsException("InvalidParameterValue", ...). Expected per-entry
// Status string in v1 is "InvalidParameterValue", not "Failed" or "InvalidParameter".
// DefaultTemplateData supplies team so rendering succeeds before the recipient check.
String body = given()
void sendBulkTemplatedEmail_entryWithoutDestination_isAValidationError() {
// An entry with only ReplacementTemplateData has a null Destination, which the model
// validation refuses for the whole request (probe-confirmed).
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"team\":\"floci\"}")
.formParam("Destinations.member.1.ReplacementTemplateData", "{\"name\":\"Ghost\"}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.formParam("Destinations.member.2.ReplacementTemplateData", "{\"name\":\"Ghost\"}")
.when()
.post("/")
.then()
.statusCode(200)
.extract().body().asString();
assertEquals(1L, body.split("<Status>InvalidParameterValue</Status>", -1).length - 1L,
"expected per-entry Status=InvalidParameterValue");
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo(MISSING_DESTINATION_2));
}
@Test
@@ -196,7 +217,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.when()
@@ -223,7 +244,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "ghost"), 51)
.when()
.post("/")
@@ -244,7 +265,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"team\":\"floci\"}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
@@ -268,7 +289,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", defaultTemplateData)
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com");
@@ -297,7 +318,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome");
for (int i = 1; i <= 51; i++) {
spec = spec.formParam(
@@ -319,7 +340,7 @@ class SesBulkV1IntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"name\":\"X\",\"team\":\"floci\"}"), 50)
.when()
@@ -331,6 +352,133 @@ class SesBulkV1IntegrationTest {
assertEquals(50L, body.split("<Status>Success</Status>", -1).length - 1L);
}
@Test
@Order(14)
void sendBulkTemplatedEmail_emptyToAddresses_answersTheEntryBeforeSenderAndTemplate() {
// boto3 serializes ToAddresses=[] as a bare empty-valued key. AWS answers the entry even
// for an unverified Source and a missing template (probe-confirmed).
String body = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk-v1-unverified@floci.test")
.formParam("Template", "ghost")
.formParam("DefaultTemplateData", "{}")
.formParam("Destinations.member.1.Destination.ToAddresses", "")
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<Status>InvalidParameterValue</Status>"))
.body(containsString("<Error>Destination cannot be empty</Error>"))
.body(not(containsString("<MessageId>")))
.extract().body().asString();
assertEquals(1L, body.split("<member>", -1).length - 1L);
}
@Test
@Order(15)
void sendBulkTemplatedEmail_skippedIndex_isAValidationError() {
// boto3 sends nothing for Destination={}, which leaves a gap in the member indexes.
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"name\":\"X\",\"team\":\"floci\"}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.formParam("Destinations.member.3.Destination.ToAddresses.member.1", "bob@example.com")
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo(MISSING_DESTINATION_2));
}
@Test
@Order(16)
void sendBulkTemplatedEmail_emptyEntryBesideRecipients_failsOnlyThatEntry() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", SENDER)
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"name\":\"X\",\"team\":\"floci\"}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com")
.formParam("Destinations.member.2.Destination.ToAddresses", "")
.formParam("Destinations.member.3.Destination.ToAddresses.member.1", "bob@example.com")
.when()
.post("/")
.then()
.statusCode(200)
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member.size()", equalTo(3))
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[0].Status",
equalTo("Success"))
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[1].Status",
equalTo("InvalidParameterValue"))
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[1].Error",
equalTo("Missing required header 'To'."))
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[1].MessageId.size()",
equalTo(0))
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[2].Status",
equalTo("Success"));
}
// The model validation answers ahead of the address syntax, the template selector and the
// destination count (probed 2026-10-25).
@ParameterizedTest(name = "{0}")
@MethodSource("modelViolationParams")
@Order(17)
void sendBulkTemplatedEmail_modelValidationPrecedesOtherChecks(String label, Map<String, String> params,
String message) {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParams(params)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("ValidationError"))
.body("ErrorResponse.Error.Message", equalTo(message));
}
static Stream<Arguments> modelViolationParams() {
Map<String, String> withoutDestination2 = Map.of(
"Destinations.member.1.Destination.ToAddresses.member.1", "alice@example.com",
"Destinations.member.2.ReplacementTemplateData", "{}");
Map<String, String> gapAt2 = new HashMap<>();
for (int i = 1; i <= 51; i++) {
if (i != 2) {
gapAt2.put("Destinations.member." + i + ".Destination.ToAddresses.member.1",
"user" + i + "@example.com");
}
}
return Stream.of(
Arguments.of("malformed Source",
with(withoutDestination2, "Source", "not-an-address", "Template", "v1-bulk-welcome"),
MISSING_DESTINATION_2),
Arguments.of("no Template", with(withoutDestination2, "Source", SENDER),
"2 validation errors detected: Value at 'template' failed to satisfy constraint: "
+ "Member must not be null; Value at 'destinations.2.member.destination' "
+ "failed to satisfy constraint: Member must not be null"),
Arguments.of("51 indexes with a gap", with(gapAt2, "Source", SENDER, "Template", "v1-bulk-welcome"),
MISSING_DESTINATION_2));
}
private static Map<String, String> with(Map<String, String> params, String... namesAndValues) {
Map<String, String> merged = new HashMap<>(params);
for (int i = 0; i < namesAndValues.length; i += 2) {
merged.put(namesAndValues[i], namesAndValues[i + 1]);
}
return merged;
}
private static RequestSpecification destinations(RequestSpecification spec, int count) {
for (int i = 1; i <= count; i++) {
spec = spec.formParam("Destinations.member." + i + ".Destination.ToAddresses.member.1",
@@ -9,6 +9,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.List;
import java.util.stream.Stream;
import static io.restassured.RestAssured.given;
@@ -26,6 +27,10 @@ class SesBulkV2IntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
// Senders of their own: an identity under example.com would outlive this class and reach the
// other SES classes that share the application.
private static final List<String> SENDERS =
List.of("bulk-v2@floci.test", "bulk-v2-second@floci.test", "bulk-v2-inline@floci.test");
private static final String DESTINATION_COUNT_MESSAGE =
"You must specify at least 1 destination, and no more than 50 destinations";
@@ -33,6 +38,16 @@ class SesBulkV2IntegrationTest {
@Test
@Order(1)
void createTemplate() {
for (String sender : SENDERS) {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{\"EmailIdentity\": \"" + sender + "\"}")
.when()
.post("/v2/email/identities")
.then()
.statusCode(200);
}
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
@@ -60,7 +75,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {
"TemplateName": "v2-bulk-welcome",
@@ -103,7 +118,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk2@example.com",
"FromEmailAddress": "bulk-v2-second@floci.test",
"DefaultContent": {
"Template": {
"TemplateName": "v2-bulk-welcome",
@@ -156,7 +171,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "inline@example.com",
"FromEmailAddress": "bulk-v2-inline@floci.test",
"DefaultContent": {
"Template": {
"TemplateContent": {
@@ -203,7 +218,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "ghost"}
},
@@ -227,7 +242,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome"}
},
@@ -250,7 +265,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {},
"BulkEmailEntries": [
{"Destination": {"ToAddresses": ["alice@example.com"]}}
@@ -272,7 +287,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome"}
},
@@ -295,7 +310,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome", "TemplateData": "{\\"team\\":\\"floci\\"}"}
},
@@ -368,14 +383,14 @@ class SesBulkV2IntegrationTest {
return Stream.of(
Arguments.of("BulkEmailEntries element is null", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": [null]
}
""".formatted(validDefaultTemplate)),
Arguments.of("DefaultTemplateData as invalid JSON string", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome", "TemplateData": "{not json"}
},
@@ -390,21 +405,21 @@ class SesBulkV2IntegrationTest {
return Stream.of(
Arguments.of("BulkEmailEntries element is string", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": ["bad"]
}
""".formatted(validDefaultTemplate)),
Arguments.of("Destination as string", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": [{"Destination": "bad"}]
}
""".formatted(validDefaultTemplate)),
Arguments.of("DefaultTemplateData as object", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome", "TemplateData": {"team": "floci"}}
},
@@ -413,7 +428,7 @@ class SesBulkV2IntegrationTest {
"""),
Arguments.of("per-entry ReplacementTemplateData as object", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": [
{
@@ -427,7 +442,7 @@ class SesBulkV2IntegrationTest {
""".formatted(validDefaultTemplate)),
Arguments.of("ReplacementEmailContent as string", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": [
{
@@ -439,7 +454,7 @@ class SesBulkV2IntegrationTest {
""".formatted(validDefaultTemplate)),
Arguments.of("ReplacementEmailContent as array", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
%s,
"BulkEmailEntries": [
{
@@ -451,7 +466,7 @@ class SesBulkV2IntegrationTest {
""".formatted(validDefaultTemplate)),
Arguments.of("ReplacementTemplate as array", """
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome", "TemplateData": "{\\"team\\":\\"floci\\"}"}
},
@@ -479,7 +494,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome"}
},
@@ -503,7 +518,7 @@ class SesBulkV2IntegrationTest {
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"FromEmailAddress": "bulk-v2@floci.test",
"DefaultContent": {
"Template": {
"TemplateName": "v2-bulk-welcome",
@@ -627,6 +642,33 @@ class SesBulkV2IntegrationTest {
""".formatted(entries(51)), "Template must have at least a subject, text, or html part."));
}
// An entry with no recipient beside one with a recipient fails on its own (probed 2026-10-25).
@Test
@Order(18)
void sendBulkEmail_emptyEntryBesideRecipients_failsOnlyThatEntry() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk-v2-inline@floci.test",
"DefaultContent": {"Template": {"TemplateContent": {"Subject": "s", "Text": "t"}}},
"BulkEmailEntries": [
{"Destination": {"ToAddresses": ["alice@example.com"]}},
{"Destination": {"ToAddresses": []}}
]
}
""")
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(200)
.body("BulkEmailEntryResults", hasSize(2))
.body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS"))
.body("BulkEmailEntryResults[1].Status", equalTo("INVALID_PARAMETER"))
.body("BulkEmailEntryResults[1].Error", equalTo("Missing required header 'To'."));
}
private static String entries(int count) {
StringBuilder entries = new StringBuilder();
for (int i = 1; i <= count; i++) {
@@ -116,12 +116,13 @@ class SesSendAddressSyntaxIntegrationTest {
@Test
void v2SendBulkEmail_malformedEntryRecipient_failsOnlyThatEntry() {
verifySender();
given()
.contentType("application/json")
.header("Authorization", AUTH)
.body("""
{
"FromEmailAddress": "sender@example.com",
"FromEmailAddress": "%2$s",
"DefaultContent": {"Template": {
"TemplateContent": {"Subject": "s", "Text": "b"},
"TemplateData": "{}"}},
@@ -131,7 +132,7 @@ class SesSendAddressSyntaxIntegrationTest {
{"Destination": {"ToAddresses": ["%1$s"], "CcAddresses": ["やまだ@example.com"]}}
]
}
""".formatted(TO))
""".formatted(TO, VERIFIED_SENDER))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
@@ -146,6 +147,7 @@ class SesSendAddressSyntaxIntegrationTest {
@Test
void v1SendBulkTemplatedEmail_malformedEntryRecipient_failsOnlyThatEntry() {
verifySender();
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
@@ -162,7 +164,7 @@ class SesSendAddressSyntaxIntegrationTest {
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "sender@example.com")
.formParam("Source", VERIFIED_SENDER)
.formParam("Template", "address-syntax-bulk")
.formParam("DefaultTemplateData", "{}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "success@")
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
@@ -18,7 +19,9 @@ class SesSendNullAddressIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
private static final String SENDER = "sender@example.com";
// A verified sender of its own: an identity under example.com would outlive this class and
// reach the other SES classes that share the application.
private static final String SENDER = "null-address-sender@floci.test";
private static final String TO = "success@simulator.amazonses.com";
private static final String SIMPLE =
"{\"Simple\": {\"Subject\": {\"Data\": \"s\"}, \"Body\": {\"Text\": {\"Data\": \"b\"}}}}";
@@ -50,6 +53,19 @@ class SesSendNullAddressIntegrationTest {
return "{\"Destination\": " + destination + "}";
}
@BeforeEach
void verifySender() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "VerifyEmailIdentity")
.formParam("EmailAddress", SENDER)
.when()
.post("/")
.then()
.statusCode(200);
}
@Test
void sendEmail_nullToAddress_isAnInvalidAddress() {
send("{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": {\"ToAddresses\": [null]}, "
@@ -0,0 +1,265 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.nullValue;
/**
* Without a tenant, the v2 sends look a stored template up last: an unknown configuration set is
* reported first, then an unverified sender or feedback forwarding address, and only then an
* unknown template (probe-confirmed). A SendBulkEmail in which no entry names a recipient answers
* every entry before any of them. The v1 SendTemplatedEmail and SendBulkTemplatedEmail follow the
* same order with Source and ReturnPath, and the bulk send counts its destinations first
* (probe-confirmed).
*/
@QuarkusTest
class SesSendTemplateLookupOrderIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String AUTH_V1 =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
private static final String UNVERIFIED = "sender@unverified-template-order.floci.test";
private static final String VERIFIED = "sender@template-order.floci.test";
private static final String TO = "success@simulator.amazonses.com";
private static final String GHOST_CONFIG_SET = "template-order-ghost-config-set";
private static final String GHOST_TEMPLATE =
"{\"Template\": {\"TemplateName\": \"template-order-ghost\", \"TemplateData\": \"{}\"}}";
private static final String INLINE_TEMPLATE =
"{\"Template\": {\"TemplateContent\": {\"Subject\": \"s\", \"Text\": \"b\"}, \"TemplateData\": \"{}\"}}";
private static final String VALID_ENTRY = "{\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}}";
private static final String NOT_VERIFIED_MESSAGE =
"Email address is not verified. The following identities failed the check in region US-EAST-1: ";
private static final String V1_GHOST_TEMPLATE = "template-order-v1-ghost";
// Not @BeforeAll: the Quarkus test port is only bound once the first test starts.
@BeforeEach
void verifySender() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH_V1)
.formParam("Action", "VerifyEmailIdentity")
.formParam("EmailAddress", VERIFIED)
.when()
.post("/")
.then()
.statusCode(200);
}
private static ValidatableResponse post(String path, String body) {
return given()
.contentType("application/json")
.header("Authorization", AUTH)
.body(body)
.when()
.post(path)
.then();
}
private static ValidatableResponse bulk(String sender, String content, String members, String entries) {
return post("/v2/email/outbound-bulk-emails", "{\"FromEmailAddress\": \"" + sender + "\", " + members
+ "\"DefaultContent\": " + content + ", \"BulkEmailEntries\": [" + entries + "]}");
}
private static ValidatableResponse send(String sender, String members) {
return post("/v2/email/outbound-emails", "{\"FromEmailAddress\": \"" + sender + "\", " + members
+ "\"Destination\": {\"ToAddresses\": [\"" + TO + "\"]}, \"Content\": " + GHOST_TEMPLATE + "}");
}
private static ValidatableResponse templated(String source, String... params) {
return v1(given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH_V1)
.formParam("Action", "SendTemplatedEmail")
.formParam("Source", source)
.formParam("Destination.ToAddresses.member.1", TO)
.formParam("Template", V1_GHOST_TEMPLATE)
.formParam("TemplateData", "{}"), params);
}
private static ValidatableResponse bulkTemplated(String source, int destinations, String... params) {
RequestSpecification spec = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH_V1)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", source)
.formParam("Template", V1_GHOST_TEMPLATE)
.formParam("DefaultTemplateData", "{}");
for (int i = 1; i <= destinations; i++) {
spec = spec.formParam("Destinations.member." + i + ".Destination.ToAddresses.member.1", TO);
}
return v1(spec, params);
}
private static ValidatableResponse v1(RequestSpecification spec, String... params) {
for (int i = 0; i < params.length; i += 2) {
spec = spec.formParam(params[i], params[i + 1]);
}
return spec.when().post("/").then();
}
private static void assertV1Error(ValidatableResponse response, String code, String message) {
response
.statusCode(400)
.body(containsString("<Code>" + code + "</Code>"))
.body(containsString("<Message>" + message + "</Message>"));
}
private static void assertNotVerified(ValidatableResponse response, String unverified) {
response
.statusCode(400)
.body("__type", equalTo("MessageRejected"))
.body("message", equalTo(NOT_VERIFIED_MESSAGE + unverified));
}
private static void assertConfigSetNotFound(ValidatableResponse response) {
response
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("Configuration set <" + GHOST_CONFIG_SET + "> does not exist."));
}
private static void assertTemplateNotFound(ValidatableResponse response) {
response
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("Template template-order-ghost does not exist."));
}
@Test
void sendBulkEmail_unverifiedSenderPrecedesUnknownTemplate() {
assertNotVerified(bulk(UNVERIFIED, GHOST_TEMPLATE, "", VALID_ENTRY), UNVERIFIED);
}
@Test
void sendBulkEmail_unverifiedSenderPrecedesUnknownTemplateArn() {
assertNotVerified(bulk(UNVERIFIED, "{\"Template\": {\"TemplateArn\": "
+ "\"arn:aws:ses:us-east-1:000000000000:template/template-order-ghost\", \"TemplateData\": \"{}\"}}",
"", VALID_ENTRY), UNVERIFIED);
}
@Test
void sendBulkEmail_unknownConfigurationSetPrecedesUnverifiedSender() {
assertConfigSetNotFound(bulk(UNVERIFIED, INLINE_TEMPLATE,
"\"ConfigurationSetName\": \"" + GHOST_CONFIG_SET + "\", ", VALID_ENTRY));
}
@Test
void sendBulkEmail_verifiedSender_unknownTemplate() {
assertTemplateNotFound(bulk(VERIFIED, GHOST_TEMPLATE, "", VALID_ENTRY));
}
@Test
void sendBulkEmail_unknownConfigurationSetPrecedesUnknownTemplate() {
assertConfigSetNotFound(bulk(VERIFIED, GHOST_TEMPLATE,
"\"ConfigurationSetName\": \"" + GHOST_CONFIG_SET + "\", ", VALID_ENTRY));
}
@Test
void sendBulkEmail_unverifiedFeedbackForwardingAddressPrecedesUnknownTemplate() {
assertNotVerified(bulk(VERIFIED, GHOST_TEMPLATE,
"\"FeedbackForwardingEmailAddress\": \"" + UNVERIFIED + "\", ", VALID_ENTRY), UNVERIFIED);
}
@Test
void sendBulkEmail_unknownTemplatePrecedesMalformedEntryAndReplyTo() {
assertTemplateNotFound(bulk(VERIFIED, GHOST_TEMPLATE, "",
"{\"Destination\": {\"ToAddresses\": [\"bad\"]}}"));
assertTemplateNotFound(bulk(VERIFIED, GHOST_TEMPLATE, "\"ReplyToAddresses\": [\"bad\"], ", VALID_ENTRY));
}
@Test
void sendBulkEmail_noEntryWithARecipient_answersEveryEntryBeforeSenderAndTemplate() {
for (String sender : new String[] {UNVERIFIED, VERIFIED}) {
bulk(sender, GHOST_TEMPLATE, "", "{\"Destination\": {}}, {\"Destination\": {\"ToAddresses\": []}}")
.statusCode(200)
.body("BulkEmailEntryResults", hasSize(2))
.body("BulkEmailEntryResults[0].Status", equalTo("INVALID_PARAMETER"))
.body("BulkEmailEntryResults[0].Error", equalTo("Destination cannot be empty"))
.body("BulkEmailEntryResults[0].MessageId", nullValue())
.body("BulkEmailEntryResults[1].Status", equalTo("INVALID_PARAMETER"))
.body("BulkEmailEntryResults[1].Error", equalTo("Destination cannot be empty"));
}
}
@Test
void sendEmail_unverifiedSenderPrecedesUnknownTemplate() {
assertNotVerified(send(UNVERIFIED, ""), UNVERIFIED);
}
@Test
void sendEmail_unknownConfigurationSetPrecedesUnverifiedSender() {
assertConfigSetNotFound(send(UNVERIFIED, "\"ConfigurationSetName\": \"" + GHOST_CONFIG_SET + "\", "));
}
@Test
void sendEmail_unverifiedFeedbackForwardingAddressPrecedesUnknownTemplate() {
assertNotVerified(send(VERIFIED, "\"FeedbackForwardingEmailAddress\": \"" + UNVERIFIED + "\", "),
UNVERIFIED);
}
@Test
void sendEmail_verifiedSender_unknownTemplate() {
assertTemplateNotFound(send(VERIFIED, ""));
}
@Test
void sendTemplatedEmail_unverifiedSourcePrecedesUnknownTemplate() {
assertV1Error(templated(UNVERIFIED), "MessageRejected", NOT_VERIFIED_MESSAGE + UNVERIFIED);
}
@Test
void sendTemplatedEmail_unverifiedReturnPathPrecedesUnknownTemplate() {
assertV1Error(templated(VERIFIED, "ReturnPath", UNVERIFIED), "MessageRejected",
NOT_VERIFIED_MESSAGE + UNVERIFIED);
}
@Test
void sendTemplatedEmail_unknownConfigurationSetPrecedesUnverifiedSource() {
assertV1Error(templated(UNVERIFIED, "ConfigurationSetName", GHOST_CONFIG_SET),
"ConfigurationSetDoesNotExist", "Configuration set &lt;" + GHOST_CONFIG_SET + "&gt; does not exist.");
}
@Test
void sendTemplatedEmail_verifiedSource_unknownTemplate() {
assertV1Error(templated(VERIFIED), "TemplateDoesNotExist",
"Template " + V1_GHOST_TEMPLATE + " does not exist.");
}
@Test
void sendBulkTemplatedEmail_unverifiedSourcePrecedesUnknownTemplate() {
assertV1Error(bulkTemplated(UNVERIFIED, 1), "MessageRejected", NOT_VERIFIED_MESSAGE + UNVERIFIED);
}
@Test
void sendBulkTemplatedEmail_unverifiedReturnPathPrecedesUnknownTemplate() {
assertV1Error(bulkTemplated(VERIFIED, 1, "ReturnPath", UNVERIFIED), "MessageRejected",
NOT_VERIFIED_MESSAGE + UNVERIFIED);
}
@Test
void sendBulkTemplatedEmail_unknownConfigurationSetPrecedesUnverifiedSource() {
assertV1Error(bulkTemplated(UNVERIFIED, 1, "ConfigurationSetName", GHOST_CONFIG_SET),
"ConfigurationSetDoesNotExist", "Configuration set &lt;" + GHOST_CONFIG_SET + "&gt; does not exist.");
}
@Test
void sendBulkTemplatedEmail_verifiedSource_unknownTemplate() {
assertV1Error(bulkTemplated(VERIFIED, 1), "TemplateDoesNotExist",
"Template " + V1_GHOST_TEMPLATE + " does not exist.");
}
@Test
void sendBulkTemplatedEmail_destinationCountPrecedesUnverifiedSource() {
assertV1Error(bulkTemplated(UNVERIFIED, 51), "InvalidParameterValue",
"You must specify at least 1 destination, and no more than 50 destinations");
}
}
@@ -557,4 +557,123 @@ class SesSendVerifiedSenderIntegrationTest {
""".formatted(OWNER_IDENTITY_ARN, rawMessage(OWNER_ADDRESS,
"X-SES-SOURCE-ARN: " + DELEGATE_IDENTITY_ARN, "X-SES-FROM-ARN: " + DELEGATE_IDENTITY_ARN))));
}
private static RequestSpecification sendBulkTemplatedEmail(String authorization, String source) {
return query(authorization, "SendBulkTemplatedEmail")
.formParam("Source", source)
.formParam("Template", TEMPLATE)
.formParam("DefaultTemplateData", "{}")
.formParam("Destinations.member.1.Destination.ToAddresses.member.1", "to@example.com");
}
private static String bulkBody(String from, String extraMembers, String entries) {
return """
{
"FromEmailAddress": "%s",
%s
"DefaultContent": {"Template": {"TemplateContent": {"Subject": "s", "Text": "b"}}},
"BulkEmailEntries": %s
}
""".formatted(from, extraMembers, entries);
}
private static String bulkBody(String from) {
return bulkBody(from, "", "[{\"Destination\": {\"ToAddresses\": [\"to@example.com\"]}}]");
}
private static void assertBulkMessageRejectedV2(RequestSpecification request, String unverified) {
request
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("MessageRejected"))
.body("message", equalTo(NOT_VERIFIED_MESSAGE + unverified));
}
@Test
void v2SendBulkEmail_unverifiedFrom_rejectsTheWholeCall() {
assertBulkMessageRejectedV2(v2Request(AUTH_V2, bulkBody(UNVERIFIED)), UNVERIFIED);
assertNothingCapturedFrom(UNVERIFIED);
}
@Test
void v2SendBulkEmail_unverifiedFeedbackForwardingAddress_rejectsTheWholeCall() {
String source = "bulk-rp-" + VERIFIED;
String feedback = "bulk-bounces@unverified-sender.floci.test";
verifyEmailIdentity(source);
assertBulkMessageRejectedV2(v2Request(AUTH_V2, bulkBody(source,
"\"FeedbackForwardingEmailAddress\": \"" + feedback + "\",",
"[{\"Destination\": {\"ToAddresses\": [\"to@example.com\"]}}]")), feedback);
assertNothingCapturedFrom(source);
}
@Test
void v2SendBulkEmail_noEntryHasARecipient_senderIsNotChecked() {
// AWS fails each entry on its missing destination and never reaches the sender check.
v2Request(AUTH_V2, bulkBody(UNVERIFIED, "", "[{\"Destination\": {}}]"))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(200)
.body("BulkEmailEntryResults[0].Status", equalTo("INVALID_PARAMETER"));
}
@Test
void v2SendBulkEmail_verifiedFrom_succeeds() {
String source = "bulk-" + VERIFIED;
verifyEmailIdentity(source);
v2Request(AUTH_V2, bulkBody(source))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(200)
.body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS"));
}
@Test
void v2SendBulkEmail_fromAndFeedbackForwardingIdentityArnsOfAnotherAccount_succeeds() {
verifyOwnerAddress();
v2Request(DELEGATE_AUTH_V2, bulkBody(OWNER_ADDRESS,
"\"FromEmailAddressIdentityArn\": \"" + OWNER_IDENTITY_ARN + "\","
+ "\"FeedbackForwardingEmailAddress\": \"" + OWNER_ADDRESS + "\","
+ "\"FeedbackForwardingEmailAddressIdentityArn\": \"" + OWNER_IDENTITY_ARN + "\",",
"[{\"Destination\": {\"ToAddresses\": [\"to@example.com\"]}}]"))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(200)
.body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS"));
}
@Test
void v1SendBulkTemplatedEmail_unverifiedSource_returnsMessageRejected() {
createTemplate(AUTH_V1);
assertMessageRejected(sendBulkTemplatedEmail(AUTH_V1, UNVERIFIED), UNVERIFIED);
assertNothingCapturedFrom(UNVERIFIED);
}
@Test
void v1SendBulkTemplatedEmail_sourceAndReturnPathArnsOfAnotherAccount_succeeds() {
verifyOwnerAddress();
createTemplate(DELEGATE_AUTH_V1);
sendBulkTemplatedEmail(DELEGATE_AUTH_V1, OWNER_ADDRESS)
.formParam("SourceArn", OWNER_IDENTITY_ARN)
.formParam("ReturnPath", OWNER_ADDRESS)
.formParam("ReturnPathArn", OWNER_IDENTITY_ARN)
.when()
.post("/")
.then()
.statusCode(200)
.body("SendBulkTemplatedEmailResponse.SendBulkTemplatedEmailResult.Status.member[0].Status",
equalTo("Success"));
}
}
@@ -0,0 +1,184 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
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.nio.charset.StandardCharsets;
import java.util.Base64;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/**
* Where the tenant association 403 sits among the other errors of a tenant send. It is the last
* check: AWS reports an unverified sender or return path, a missing configuration set and a missing
* stored template first (probe-confirmed with an ENABLED tenant, on SendEmail Simple, Template and
* Raw, and on SendBulkEmail).
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesTenantSendOrderV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String TENANT = "floci-order-tenant";
private static final String DOMAIN = "floci-order.example.com";
private static final String FROM = "sender@" + DOMAIN;
private static final String UNVERIFIED = "sender@floci-order-unverified.example.com";
private static final String CONFIG_SET = "floci-order-cs";
private static final String TEMPLATE = "floci-order-tpl";
private static final String ARN_PREFIX = "arn:aws:ses:us-east-1:000000000000:";
private static final String NOT_VERIFIED =
"Email address is not verified. The following identities failed the check in region US-EAST-1: ";
private static final String DESTINATION =
"\"Destination\":{\"ToAddresses\":[\"success@simulator.amazonses.com\"]},";
private static final String SIMPLE =
"\"Content\":{\"Simple\":{\"Subject\":{\"Data\":\"s\"},\"Body\":{\"Text\":{\"Data\":\"t\"}}}}";
private static RequestSpecification v2() {
return given().contentType("application/json").header("Authorization", AUTH);
}
private static String member(String name, String value) {
return "\"" + name + "\":\"" + value + "\",";
}
private static ValidatableResponse send(String members, String content) {
return v2().body("{" + member("TenantName", TENANT) + DESTINATION + members + content + "}")
.when().post("/v2/email/outbound-emails").then();
}
private static ValidatableResponse bulk(String members) {
return v2().body("{" + member("TenantName", TENANT) + members
+ "\"DefaultContent\":{\"Template\":{\"TemplateContent\":{\"Subject\":\"s\",\"Text\":\"t\"}}},"
+ "\"BulkEmailEntries\":[{\"Destination\":{\"ToAddresses\":"
+ "[\"success@simulator.amazonses.com\"]}}]}")
.when().post("/v2/email/outbound-bulk-emails").then();
}
private static String raw(String from) {
return raw(from, "");
}
private static String raw(String from, String extraHeaders) {
String mime = "From: " + from + "\r\nTo: success@simulator.amazonses.com\r\n" + extraHeaders
+ "Subject: s\r\n\r\nt";
return "\"Content\":{\"Raw\":{\"Data\":\""
+ Base64.getEncoder().encodeToString(mime.getBytes(StandardCharsets.UTF_8)) + "\"}}";
}
private static String storedTemplate(String name) {
return "\"Content\":{\"Template\":{\"TemplateName\":\"" + name + "\",\"TemplateData\":\"{}\"}}";
}
private static void assertNotVerified(ValidatableResponse response, String address) {
response.statusCode(400)
.body("__type", equalTo("MessageRejected"))
.body("message", equalTo(NOT_VERIFIED + address));
}
private static void assertNotAssociated(ValidatableResponse response, String resource) {
response.statusCode(403)
.body("__type", equalTo("AccessDeniedException"))
.body("message", equalTo("Tenant not associated with resources [" + ARN_PREFIX + resource + "]."));
}
@Test
@Order(1)
void setup_tenantAndResources() {
v2().body("{\"TenantName\":\"" + TENANT + "\"}")
.when().post("/v2/email/tenants").then().statusCode(200);
SesDomainIdentityTestHelper.createVerified(DOMAIN, AUTH);
v2().body("{\"ConfigurationSetName\":\"" + CONFIG_SET + "\"}")
.when().post("/v2/email/configuration-sets").then().statusCode(200);
v2().body("{\"TemplateName\":\"" + TEMPLATE + "\",\"TemplateContent\":{\"Subject\":\"s\",\"Text\":\"t\"}}")
.when().post("/v2/email/templates").then().statusCode(200);
}
@Test
@Order(2)
void unverifiedSender_isReportedBeforeTheUnassociatedIdentity() {
assertNotVerified(send(member("FromEmailAddress", UNVERIFIED), SIMPLE), UNVERIFIED);
assertNotVerified(send(member("FromEmailAddress", UNVERIFIED), raw(UNVERIFIED)), UNVERIFIED);
assertNotVerified(send("", raw(UNVERIFIED)), UNVERIFIED);
assertNotVerified(bulk(member("FromEmailAddress", UNVERIFIED)), UNVERIFIED);
}
@Test
@Order(3)
void unverifiedReturnPath_isReportedBeforeTheUnassociatedIdentity() {
String members = member("FromEmailAddress", FROM) + member("FeedbackForwardingEmailAddress", UNVERIFIED);
assertNotVerified(send(members, SIMPLE), UNVERIFIED);
assertNotVerified(bulk(members), UNVERIFIED);
}
@Test
@Order(4)
void missingConfigurationSet_isReportedBeforeTheAssociationAndTheSender() {
String ghost = member("ConfigurationSetName", "floci-order-ghost-cs");
send(member("FromEmailAddress", FROM) + ghost, SIMPLE).statusCode(404)
.body("message", equalTo("Configuration set <floci-order-ghost-cs> does not exist."));
send(member("FromEmailAddress", UNVERIFIED) + ghost, SIMPLE).statusCode(404)
.body("message", equalTo("Configuration set <floci-order-ghost-cs> does not exist."));
bulk(member("FromEmailAddress", FROM) + ghost).statusCode(404)
.body("message", equalTo("Configuration set <floci-order-ghost-cs> does not exist."));
}
@Test
@Order(5)
void missingStoredTemplate_isReportedBeforeTheAssociation() {
send(member("FromEmailAddress", FROM), storedTemplate("floci-order-ghost-tpl")).statusCode(404)
.body("__type", equalTo("NotFoundException"));
}
@Test
@Order(6)
void verifiedSender_unassociatedIdentity_is403() {
assertNotAssociated(send(member("FromEmailAddress", FROM), SIMPLE), "identity/" + DOMAIN);
assertNotAssociated(send(member("FromEmailAddress", FROM), raw(FROM)), "identity/" + DOMAIN);
assertNotAssociated(bulk(member("FromEmailAddress", FROM)), "identity/" + DOMAIN);
}
@Test
@Order(7)
void associatedIdentity_unassociatedConfigurationSetOrTemplate_is403UnlessTheReturnPathIsUnverified() {
v2().body("{\"TenantName\":\"" + TENANT + "\",\"ResourceArn\":\"" + ARN_PREFIX + "identity/" + DOMAIN + "\"}")
.when().post("/v2/email/tenants/resources").then().statusCode(200);
String withConfigSet = member("FromEmailAddress", FROM) + member("ConfigurationSetName", CONFIG_SET);
assertNotAssociated(send(withConfigSet, SIMPLE), "configuration-set/" + CONFIG_SET);
assertNotAssociated(bulk(withConfigSet), "configuration-set/" + CONFIG_SET);
assertNotAssociated(send(member("FromEmailAddress", FROM), storedTemplate(TEMPLATE)), "template/" + TEMPLATE);
send(member("FromEmailAddress", FROM), storedTemplate("floci-order-ghost-tpl")).statusCode(404);
String unverifiedReturnPath = withConfigSet + member("FeedbackForwardingEmailAddress", UNVERIFIED);
assertNotVerified(send(unverifiedReturnPath, SIMPLE), UNVERIFIED);
assertNotVerified(bulk(unverifiedReturnPath), UNVERIFIED);
}
// The configuration set a raw message names only in its X-SES-CONFIGURATION-SET header is the one
// the send uses, so it must be associated too.
@Test
@Order(8)
void associatedIdentity_rawHeaderConfigurationSet_is403() {
assertNotAssociated(send(member("FromEmailAddress", FROM),
raw(FROM, "X-SES-CONFIGURATION-SET: " + CONFIG_SET + "\r\n")), "configuration-set/" + CONFIG_SET);
}
@Test
@Order(9)
void cleanup() {
v2().body("{\"TenantName\":\"" + TENANT + "\"}")
.when().post("/v2/email/tenants/delete").then().statusCode(200);
v2().when().delete("/v2/email/templates/" + TEMPLATE).then().statusCode(200);
v2().when().delete("/v2/email/configuration-sets/" + CONFIG_SET).then().statusCode(200);
v2().when().delete("/v2/email/identities/" + DOMAIN).then().statusCode(200);
}
}
@@ -185,8 +185,8 @@ class SesTenantSendV2IntegrationTest {
@Test
@Order(8)
void rawSend_gatesTheMimeDerivedSender() {
v2().body("{\"EmailIdentity\":\"floci-raw.example.com\"}")
.when().post("/v2/email/identities").then().statusCode(200);
// Verified, so the 403 is what stops the send: an unverified sender is reported first.
SesDomainIdentityTestHelper.createVerified("floci-raw.example.com", AUTH);
String mime = "From: probe@floci-raw.example.com\r\nTo: success@simulator.amazonses.com\r\n"
+ "Subject: s\r\n\r\nbody";
String data = java.util.Base64.getEncoder().encodeToString(mime.getBytes(java.nio.charset.StandardCharsets.UTF_8));