fix(ses): check the TemplateArn of a v1 templated send as SES does (#9131)

SendTemplatedEmail and SendBulkTemplatedEmail now check TemplateArn with the
parser the v2 sends use: partition, service, region and resource type each
answer their own "Invalid template ARN" message, a value without "arn:" and an
empty template name are rejected, and the account is not checked. The v1-only
parser that looked for ":template/" is removed, and the name/ARN alignment
check moves into SesTemplateService for both protocols; the v2 controller's
remap keeps its BadRequestException.

Both v1 sends require Template whatever TemplateArn holds, as the model does,
and answer "Template cannot be empty" ahead of the ARN checks;
SendBulkTemplatedEmail treats a whitespace-only Template as empty. The Java and
Python compatibility tests build the template ARN in the client's partition and
region.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-11-21 09:37:57 -04:00
1 parent 9b19f17fe7
commit 2b9ed9cd55
9 files changed
+288 -57

No files matched your search

@@ -240,7 +240,7 @@ class SesTemplateTest {
.build())
.content(EmailContent.builder()
.template(Template.builder()
.templateArn("arn:aws:ses:us-east-1:000000000000:template/" + name)
.templateArn(TestFixtures.arn("ses", "000000000000", "template/" + name))
.templateData("{\"name\":\"Alice\"}")
.build())
.build())
@@ -446,7 +446,7 @@ class SesTemplateTest {
.source(v1Sender)
.destination(d -> d.toAddresses("recipient@example.com"))
.template(name)
.templateArn("arn:aws:ses:us-east-1:000000000000:template/" + name)
.templateArn(TestFixtures.arn("ses", "000000000000", "template/" + name))
.templateData("{\"name\":\"Alice\"}")
.build());
assertThat(response.messageId()).isNotBlank();
@@ -207,7 +207,8 @@ class TestSesV2SendTemplatedEmail:
):
template_name = f"pytest-arn-tpl-{unique_name}"
sender = f"pytest-arn-sender-{unique_name}@example.com"
arn = f"arn:aws:ses:us-east-1:000000000000:template/{template_name}"
meta = sesv2_client.meta
arn = f"arn:{meta.partition}:ses:{meta.region_name}:000000000000:template/{template_name}"
try:
sesv2_client.create_email_identity(EmailIdentity=sender)
sesv2_client.create_email_template(
@@ -406,7 +407,8 @@ class TestSesV1SendTemplatedEmail:
accepts both and resolves via the name."""
template_name = f"pytest-v1-arn-tpl-{unique_name}"
sender = f"pytest-v1-arn-sender-{unique_name}@example.com"
arn = f"arn:aws:ses:us-east-1:000000000000:template/{template_name}"
meta = ses_client.meta
arn = f"arn:{meta.partition}:ses:{meta.region_name}:000000000000:template/{template_name}"
try:
ses_client.verify_email_identity(EmailAddress=sender)
ses_client.create_template(
+2 -1
View File
@@ -304,7 +304,8 @@ curl $AWS_ENDPOINT_URL/_aws/ses
- An email address identity is verified as soon as it is created; no inbox verification flow is required. A domain identity stays `Pending` until its DKIM CNAME records exist in a Route 53 hosted zone in Floci, then becomes `Success`.
- `SendEmail`, `SendRawEmail`, `SendTemplatedEmail` and `SendBulkTemplatedEmail`, and v2 `SendEmail` and `SendBulkEmail`, require verified senders, as on AWS ([SendEmail](https://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html), [Email sending errors](https://docs.aws.amazon.com/ses/latest/dg/troubleshoot-error-messages.html)): each address used as a "From", "Source", "Sender" or "Return-Path" address must be a verified email address identity or an address in a verified domain identity or one of its subdomains. That is the `Source` or `FromEmailAddress` and the `ReturnPath` or `FeedbackForwardingEmailAddress`, plus, on a raw message, every mailbox of its `From` header, its `Sender` and its `Return-Path` header. A v2 raw send reads the `From` header only in place of a missing `FromEmailAddress` and accepts any `From` header when one is given (probe-confirmed), so the header is checked only then. Every other address present is checked; whether AWS still checks a `Return-Path` header that the request's return path overrides has not been probed. One `MessageRejected` lists every unverified address ("Email address is not verified. The following identities failed the check in region US-EAST-1: a@example.com, b@example.com") and nothing is captured or relayed. An address covered by a sending-authorization ARN of another account (`SourceArn`, `FromArn`, `ReturnPathArn`, their `X-SES-*-ARN` headers, or v2 `FromEmailAddressIdentityArn` and `FeedbackForwardingEmailAddressIdentityArn`) is not checked, since it is the owner's identity; on a raw send the source ARN also covers the `From` and return-path addresses that have no ARN of their own. A bulk send checks its sender and return path once and rejects the whole call; when no entry has a recipient it checks neither and every entry fails on its own (probe-confirmed on v2 `SendBulkEmail` and v1 `SendBulkTemplatedEmail`). On v2 `SendEmail` and `SendBulkEmail`, and v1 `SendTemplatedEmail` and `SendBulkTemplatedEmail`, an unknown configuration set is reported before the check and an unknown stored template only after it (probe-confirmed). The verification codes and invitations Cognito sends are not affected.
- `SendBulkTemplatedEmail` reads every `Destinations.member.N` up to the highest N. A missing `Template` (with no `TemplateArn`), missing `Destinations`, and an entry without a `Destination` or a skipped N are model violations, answered together as one 400 `ValidationError` ("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") ahead of every other check of the request, the address syntax and the destination count included (probe-confirmed). Floci lists the skipped entries of the first 1000 indexes only; a higher index fails the destination count. On both bulk sends an entry whose address lists are empty answers "Missing required header 'To'." on its own when another entry has a recipient, and when none has one every entry answers "Destination cannot be empty" (probe-confirmed). A `DefaultTags` or `ReplacementTags` tag without a `Name` or a `Value` is a model violation too, a skipped tag index listing both, and the top-level members are listed ahead of the nested ones ('template' before 'defaultTags.1.member.name'). A missing or empty `DefaultTemplateData` is a 400 `InvalidParameterValue` ("The default template data does not exist"), answered after the `Source` syntax and the destination count and before the template lookup and the sender verification (probe-confirmed). On `SendBulkTemplatedEmail` an entry with more than 50 recipients ("Recipient count exceeds 50."), template data that is not a JSON object ("The template data is invalid") or a tag with an empty name ("The tag name must be specified.") fails on its own with `InvalidParameterValue`. Invalid `DefaultTemplateData` or an empty `DefaultTags` name fails every entry, and within one entry an address syntax error wins over an empty tag name, which wins over invalid template data, which wins over the recipient count (probe-confirmed). v2 `SendBulkEmail` still rejects the whole call for more than 50 recipients in a destination (not probed).
- `SendBulkTemplatedEmail` reads every `Destinations.member.N` up to the highest N. A missing `Template` (whatever `TemplateArn` holds), missing `Destinations`, and an entry without a `Destination` or a skipped N are model violations, answered together as one 400 `ValidationError` ("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") ahead of every other check of the request, the address syntax and the destination count included (probe-confirmed). Floci lists the skipped entries of the first 1000 indexes only; a higher index fails the destination count. On both bulk sends an entry whose address lists are empty answers "Missing required header 'To'." on its own when another entry has a recipient, and when none has one every entry answers "Destination cannot be empty" (probe-confirmed). A `DefaultTags` or `ReplacementTags` tag without a `Name` or a `Value` is a model violation too, a skipped tag index listing both, and the top-level members are listed ahead of the nested ones ('template' before 'defaultTags.1.member.name'). A missing or empty `DefaultTemplateData` is a 400 `InvalidParameterValue` ("The default template data does not exist"), answered after the `Source` syntax and the destination count and before the template lookup and the sender verification (probe-confirmed). On `SendBulkTemplatedEmail` an entry with more than 50 recipients ("Recipient count exceeds 50."), template data that is not a JSON object ("The template data is invalid") or a tag with an empty name ("The tag name must be specified.") fails on its own with `InvalidParameterValue`. Invalid `DefaultTemplateData` or an empty `DefaultTags` name fails every entry, and within one entry an address syntax error wins over an empty tag name, which wins over invalid template data, which wins over the recipient count (probe-confirmed). v2 `SendBulkEmail` still rejects the whole call for more than 50 recipients in a destination (not probed).
- A `TemplateArn` on v1 `SendTemplatedEmail` and `SendBulkTemplatedEmail` and v2 `SendEmail` and `SendBulkEmail` must be in the request's partition and region, name the `ses` service and start its resource with `template/`; its account is not checked. Each mismatch has its own message ("Invalid template ARN <arn>. Template must be in region <us-east-1>"), a value that does not start with `arn:` answers "ARNs must start with 'arn:': <value>", and an ARN beside a template name must name the same template ("The SES resource '<name>' does not align with the given ARN '<arn>'."). The checks run before the sender verification; v1 answers `InvalidParameterValue` and v2 `BadRequestException` (probe-confirmed). The v1 sends require `Template` even beside a `TemplateArn`, and an empty one answers "Template cannot be empty" ahead of the ARN checks; `SendBulkTemplatedEmail` answers the same for a whitespace-only `Template` (probe-confirmed).
- `SendEmail` stores the text body or the HTML body as the captured message body.
- `SetIdentityNotificationTopic` publishes to the configured topic on a Bounce/Complaint/Delivery event (triggered via the mailbox simulator addresses or the suppression list), independent of any configuration set. The payload uses the legacy format (`notificationType`, no `mail.tags`, headers only when `SetIdentityHeadersInNotificationsEnabled` is on). The topic is checked when it is set: one that does not exist in the identity's region, or whose policy does not let SES publish under IAM enforcement, is refused with `InvalidParameterValue`. A topic of another account that exists in Floci and grants SES is accepted.
- Identity (sending authorization) policies are stored and returned as metadata: the policy document, the per-identity limit of 20, and the create/update/delete error shapes match AWS, but Floci does not evaluate policy authorization (Principal-account existence, Resource-ARN match) or gate sending on it. A send naming another account's identity ARN skips the verified-sender check for the addresses it covers, without looking that identity up or reading its policy.
@@ -648,13 +648,10 @@ public class SesQueryHandler {
String templateArn = getParam(params, "TemplateArn");
String templateDataRaw = getParam(params, "TemplateData");
boolean hasName = templateName != null && !templateName.isBlank();
boolean hasArn = templateArn != null && !templateArn.isBlank();
if (!hasName && !hasArn) {
throw new AwsException("InvalidParameterValue",
"Template or TemplateArn is required.", 400);
if (templateName == null) {
throw SmithyValidationErrors.validationError(SmithyValidationErrors.notNullWithoutValue("template"));
}
String resolvedName = hasName ? templateName : SesTemplateService.templateNameFromArn(templateArn);
String resolvedName = sendTemplateName(templateName.isEmpty(), templateName, templateArn, region);
JsonNode templateData = parseTemplateData(templateDataRaw);
String configurationSetName = getParam(params, "ConfigurationSetName");
@@ -786,7 +783,7 @@ public class SesQueryHandler {
// top-level members before the nested ones ('template' ahead of 'defaultTags.1.member.name'),
// each group in the model's member order (probe-confirmed).
List<String> violations = new ArrayList<>();
if (templateName == null && templateArn == null) {
if (templateName == null) {
violations.add(SmithyValidationErrors.notNullWithoutValue("template"));
}
if (!params.containsKey("Destinations") && !hasParamWithPrefix(params, "Destinations.")) {
@@ -812,13 +809,7 @@ public class SesQueryHandler {
List<String> replyToAddresses = extractMembers(params, "ReplyToAddresses");
String defaultDataRaw = getParam(params, "DefaultTemplateData");
boolean hasName = templateName != null && !templateName.isBlank();
boolean hasArn = templateArn != null && !templateArn.isBlank();
if (!hasName && !hasArn) {
throw new AwsException("InvalidParameterValue",
"Template or TemplateArn is required.", 400);
}
String resolvedName = hasName ? templateName : SesTemplateService.templateNameFromArn(templateArn);
String resolvedName = sendTemplateName(templateName.isBlank(), templateName, templateArn, region);
int lastIndex = destinations.last();
if (lastIndex == 0) {
@@ -1738,6 +1729,19 @@ public class SesQueryHandler {
}
}
// The templated sends require Template whatever TemplateArn holds, word an empty one ahead of
// the ARN checks, and take a TemplateArn only beside the Template it names (probe-confirmed).
// SendBulkTemplatedEmail counts a whitespace-only Template as empty; SendTemplatedEmail does not.
private static String sendTemplateName(boolean empty, String templateName, String templateArn, String region) {
if (empty) {
throw new AwsException("InvalidParameterValue", "Template cannot be empty", 400);
}
if (templateArn != null && !templateArn.isBlank()) {
SesTemplateService.requireNameAlignsWithArn(templateName, templateArn, region);
}
return templateName;
}
private String getParam(MultivaluedMap<String, String> params, String name) {
return params.getFirst(name);
}
@@ -451,16 +451,12 @@ public class SesSendController {
}
String storedName(String region) {
return hasName() ? name : SesTemplateService.sendTemplateNameFromArn(arn, region);
return hasName() ? name : SesTemplateService.templateNameFromArn(arn, region);
}
// AWS accepts a TemplateName beside a TemplateArn when both name the same template, and
// reports a malformed ARN first (probe-confirmed on SendEmail and SendBulkEmail).
void requireNameAlignsWithArn(String region) {
if (hasName() && hasArn()
&& !name.equals(SesTemplateService.sendTemplateNameFromArn(arn, region))) {
throw new AwsException("BadRequestException", "The SES resource '" + name
+ "' does not align with the given ARN '" + arn + "'.", 400);
if (hasName() && hasArn()) {
SesTemplateService.requireNameAlignsWithArn(name, arn, region);
}
}
}
@@ -237,34 +237,11 @@ public class SesTemplateService implements SesTaggable {
}
/**
* Extracts the template name from an SES template ARN of the form
* {@code arn:aws:ses:<region>:<account>:template/<name>}. Region and
* account segments are not validated; only the {@code template/<name>}
* suffix is required.
* The template a send's {@code TemplateArn} names, on v1 and v2 alike. SES checks the ARN's
* partition, service, region and resource type, each with a message of its own, and not its
* account (probe-confirmed). The order among several mismatches at once is not probed.
*/
public static String templateNameFromArn(String arn) {
if (arn == null || arn.isBlank()) {
throw new AwsException("InvalidParameterValue", "TemplateArn is required.", 400);
}
int marker = arn.indexOf(":template/");
if (!AwsArnUtils.looksLikeArn(arn) || marker < 0) {
throw new AwsException("InvalidParameterValue",
"TemplateArn is not a valid SES template ARN: " + arn, 400);
}
String name = arn.substring(marker + ":template/".length());
if (name.isEmpty()) {
throw new AwsException("InvalidParameterValue",
"TemplateArn is missing a template name: " + arn, 400);
}
return name;
}
/**
* The template a v2 send's {@code TemplateArn} names. SES checks the ARN's partition, service,
* region and resource type, each with a message of its own, and not its account
* (probe-confirmed). The order among several mismatches at once is not probed.
*/
public static String sendTemplateNameFromArn(String arn, String region) {
public static String templateNameFromArn(String arn, String region) {
if (!AwsArnUtils.looksLikeArn(arn)) {
throw new AwsException("InvalidParameterValue", "ARNs must start with 'arn:': " + arn, 400);
}
@@ -295,6 +272,17 @@ public class SesTemplateService implements SesTaggable {
return name;
}
/**
* A send may name its template beside a {@code TemplateArn} only when both name the same
* template; a malformed ARN is reported first (probe-confirmed on both protocols).
*/
public static void requireNameAlignsWithArn(String name, String arn, String region) {
if (!name.equals(templateNameFromArn(arn, region))) {
throw new AwsException("InvalidParameterValue", "The SES resource '" + name
+ "' does not align with the given ARN '" + arn + "'.", 400);
}
}
private static AwsException invalidTemplateArn(String arn, String reason) {
return new AwsException("InvalidParameterValue", "Invalid template ARN <" + arn + ">. " + reason, 400);
}
@@ -0,0 +1,95 @@
package io.floci.aws.services.ses;
import io.floci.aws.core.common.AwsException;
import org.junit.jupiter.api.Test;
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 org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* The template ARN parser and the name/ARN alignment check that the v1 and v2 sends share.
*/
class SesTemplateArnTest {
private static final String REGION = "us-west-2";
@Test
void templateNameFromArn_returnsTheRelativeIdAfterTemplate() {
assertEquals("welcome",
SesTemplateService.templateNameFromArn("arn:aws:ses:us-west-2:000000000000:template/welcome", REGION));
}
@Test
void templateNameFromArn_ignoresTheAccount() {
assertEquals("welcome",
SesTemplateService.templateNameFromArn("arn:aws:ses:us-west-2:999999999999:template/welcome", REGION));
}
@Test
void templateNameFromArn_expectsThePartitionOfTheRegion() {
assertEquals("welcome", SesTemplateService.templateNameFromArn(
"arn:aws-cn:ses:cn-north-1:000000000000:template/welcome", "cn-north-1"));
assertInvalid("arn:aws:ses:cn-north-1:000000000000:template/welcome", "cn-north-1",
"Invalid template ARN <arn:aws:ses:cn-north-1:000000000000:template/welcome>. "
+ "Partition should be <aws-cn>");
}
static Stream<Arguments> invalidArns() {
return Stream.of(
Arguments.of("arn:aws-cn:ses:us-west-2:000000000000:template/welcome",
"Invalid template ARN <arn:aws-cn:ses:us-west-2:000000000000:template/welcome>. "
+ "Partition should be <aws>"),
Arguments.of("arn:aws:s3:us-west-2:000000000000:template/welcome",
"Invalid template ARN <arn:aws:s3:us-west-2:000000000000:template/welcome>. "
+ "Vendor should be <ses>"),
Arguments.of("arn:aws:ses:us-east-1:000000000000:template/welcome",
"Invalid template ARN <arn:aws:ses:us-east-1:000000000000:template/welcome>. "
+ "Template must be in region <us-west-2>"),
Arguments.of("arn:aws:ses:us-west-2:000000000000:configuration-set/welcome",
"Invalid template ARN <arn:aws:ses:us-west-2:000000000000:configuration-set/welcome>. "
+ "Relative ID should start with <template/>"),
Arguments.of("arn:aws:ses:us-west-2:000000000000:template/", "The template name must be specified."),
Arguments.of("not-an-arn", "ARNs must start with 'arn:': not-an-arn"));
}
@ParameterizedTest(name = "{0}")
@MethodSource("invalidArns")
void templateNameFromArn_rejectsWithTheProbedMessage(String arn, String message) {
assertInvalid(arn, REGION, message);
}
@Test
void requireNameAlignsWithArn_acceptsTheNameTheArnNames() {
assertDoesNotThrow(() -> SesTemplateService.requireNameAlignsWithArn("welcome",
"arn:aws:ses:us-west-2:000000000000:template/welcome", REGION));
}
@Test
void requireNameAlignsWithArn_rejectsAnotherName() {
String arn = "arn:aws:ses:us-west-2:000000000000:template/other";
AwsException e = assertThrows(AwsException.class,
() -> SesTemplateService.requireNameAlignsWithArn("welcome", arn, REGION));
assertEquals("InvalidParameterValue", e.getErrorCode());
assertEquals("The SES resource 'welcome' does not align with the given ARN '" + arn + "'.", e.getMessage());
}
@Test
void requireNameAlignsWithArn_reportsAMalformedArnFirst() {
AwsException e = assertThrows(AwsException.class,
() -> SesTemplateService.requireNameAlignsWithArn("welcome", "not-an-arn", REGION));
assertEquals("ARNs must start with 'arn:': not-an-arn", e.getMessage());
}
private static void assertInvalid(String arn, String region, String message) {
AwsException e = assertThrows(AwsException.class, () -> SesTemplateService.templateNameFromArn(arn, region));
assertEquals("InvalidParameterValue", e.getErrorCode());
assertEquals(400, e.getHttpStatus());
assertEquals(message, e.getMessage());
}
}
@@ -284,7 +284,7 @@ class SesTemplateV1IntegrationTest {
@Test
@Order(12)
void sendTemplatedEmail_withTemplateArn_resolvesStoredTemplate() {
void sendTemplatedEmail_withTemplateArnOnly_isModelViolation() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
@@ -318,8 +318,10 @@ class SesTemplateV1IntegrationTest {
.when()
.post("/")
.then()
.statusCode(200)
.body(containsString("<MessageId>"));
.statusCode(400)
.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
@@ -350,12 +352,14 @@ class SesTemplateV1IntegrationTest {
.formParam("Action", "SendTemplatedEmail")
.formParam("Source", "v1-arn-sender@example.com")
.formParam("Destination.ToAddresses.member.1", "to@example.com")
.formParam("Template", "v1-arn-welcome")
.formParam("TemplateArn", "not-an-arn")
.formParam("TemplateData", "{}")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"));
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"))
.body("ErrorResponse.Error.Message", equalTo("ARNs must start with 'arn:': not-an-arn"));
}
}
@@ -0,0 +1,141 @@
package io.floci.aws.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.stream.Stream;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/**
* How the v1 templated sends answer their Template and TemplateArn members. The checks and
* messages match the v2 sends' and are probe-confirmed on both operations; the sender is never
* verified, so a request whose template members pass reaches the sender check.
*/
@QuarkusTest
class SesV1TemplateArnIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
private static final String UNVERIFIED = "sender@unverified-v1-template-arn.floci.test";
private static final String NAME = "v1-arn-ghost";
private static final String TEMPLATE_REQUIRED =
"1 validation error detected: Value at 'template' failed to satisfy constraint: Member must not be null";
private static String arn(String partition, String service, String region, String account, String resource) {
return "arn:" + partition + ":" + service + ":" + region + ":" + account + ":" + resource;
}
private static String arn(String partition, String service, String region, String resource) {
return arn(partition, service, region, "000000000000", resource);
}
private static ValidatableResponse send(String operation, String template, String templateArn) {
RequestSpecification request = given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", operation)
.formParam("Source", UNVERIFIED);
if ("SendTemplatedEmail".equals(operation)) {
request.formParam("Destination.ToAddresses.member.1", "success@simulator.amazonses.com")
.formParam("TemplateData", "{}");
} else {
request.formParam("Destinations.member.1.Destination.ToAddresses.member.1",
"success@simulator.amazonses.com")
.formParam("DefaultTemplateData", "{}");
}
if (template != null) {
request.formParam("Template", template);
}
if (templateArn != null) {
request.formParam("TemplateArn", templateArn);
}
return request.when().post("/").then();
}
private static void assertError(ValidatableResponse response, String code, String message) {
response
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo(code))
.body("ErrorResponse.Error.Message", equalTo(message));
}
static Stream<Arguments> invalidTemplateArns() {
String otherRegion = arn("aws", "ses", "eu-west-1", "template/" + NAME);
String otherPartition = arn("aws-cn", "ses", "us-east-1", "template/" + NAME);
String otherService = arn("aws", "s3", "us-east-1", "template/" + NAME);
String otherResource = arn("aws", "ses", "us-east-1", "configuration-set/" + NAME);
String otherTemplate = arn("aws", "ses", "us-east-1", "template/v1-arn-other");
return Stream.of("SendTemplatedEmail", "SendBulkTemplatedEmail").flatMap(operation -> Stream.of(
Arguments.of(operation, otherRegion,
"Invalid template ARN <" + otherRegion + ">. Template must be in region <us-east-1>"),
Arguments.of(operation, otherPartition,
"Invalid template ARN <" + otherPartition + ">. Partition should be <aws>"),
Arguments.of(operation, otherService,
"Invalid template ARN <" + otherService + ">. Vendor should be <ses>"),
Arguments.of(operation, otherResource,
"Invalid template ARN <" + otherResource + ">. Relative ID should start with <template/>"),
Arguments.of(operation, "not-an-arn", "ARNs must start with 'arn:': not-an-arn"),
Arguments.of(operation, arn("aws", "ses", "us-east-1", "template/"),
"The template name must be specified."),
Arguments.of(operation, otherTemplate,
"The SES resource '" + NAME + "' does not align with the given ARN '" + otherTemplate + "'.")));
}
@ParameterizedTest(name = "{0} {1}")
@MethodSource("invalidTemplateArns")
void invalidTemplateArn_isRejectedBeforeTheSenderCheck(String operation, String templateArn, String message) {
assertError(send(operation, NAME, templateArn), "InvalidParameterValue", message);
}
static Stream<Arguments> acceptedTemplateArns() {
return Stream.of("SendTemplatedEmail", "SendBulkTemplatedEmail").flatMap(operation -> Stream.of(
Arguments.of(operation, arn("aws", "ses", "us-east-1", "template/" + NAME)),
Arguments.of(operation, arn("aws", "ses", "us-east-1", "999999999999", "template/" + NAME))));
}
// SES does not check the account of a template ARN.
@ParameterizedTest(name = "{0} {1}")
@MethodSource("acceptedTemplateArns")
void templateArnNamingTheTemplate_reachesTheSenderCheck(String operation, String templateArn) {
send(operation, NAME, templateArn)
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("MessageRejected"));
}
@ParameterizedTest
@ValueSource(strings = {"SendTemplatedEmail", "SendBulkTemplatedEmail"})
void templateArnWithoutTemplate_isModelViolation(String operation) {
assertError(send(operation, null, arn("aws", "ses", "eu-west-1", "template/" + NAME)),
"ValidationError", TEMPLATE_REQUIRED);
}
// An empty Template is reported ahead of the TemplateArn checks (probed on SendTemplatedEmail).
@ParameterizedTest
@ValueSource(strings = {"SendTemplatedEmail", "SendBulkTemplatedEmail"})
void emptyTemplate_isRejectedBeforeTheTemplateArn(String operation) {
assertError(send(operation, "", "not-an-arn"), "InvalidParameterValue", "Template cannot be empty");
}
@ParameterizedTest
@ValueSource(strings = {"", "not-an-arn"})
void sendBulkTemplatedEmail_whitespaceTemplate_isEmpty(String templateArn) {
assertError(send("SendBulkTemplatedEmail", " ", templateArn.isEmpty() ? null : templateArn),
"InvalidParameterValue", "Template cannot be empty");
}
// SendTemplatedEmail does not count a whitespace-only Template as empty.
@Test
void sendTemplatedEmail_whitespaceTemplate_mustAlignWithTheTemplateArn() {
String templateArn = arn("aws", "ses", "us-east-1", "template/" + NAME);
assertError(send("SendTemplatedEmail", " ", templateArn), "InvalidParameterValue",
"The SES resource ' ' does not align with the given ARN '" + templateArn + "'.");
}
}