fix(ses): refuse more than 50 bulk destinations the way SES does (#6430)

* fix(ses): refuse more than 50 bulk destinations the way SES does

SendBulkEmail and SendBulkTemplatedEmail answered MessageRejected
"Number of destinations (N) exceeds the maximum of 50." after resolving
the stored template, configuration set and tenant. SES answers "You must
specify at least 1 destination, and no more than 50 destinations"
(BadRequestException on v2, InvalidParameterValue on v1) before those
lookups, and v2 answers an empty BulkEmailEntries the same way. An
absent v2 BulkEmailEntries is now the Smithy not-null violation.

* fix(ses): keep a null bulk entry list on the count error
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-24 13:35:47 -04:00
1 parent c854046523
commit e1796b33b1
5 files changed
+216 -41

No files matched your search

@@ -215,26 +215,23 @@ class SesBulkV1IntegrationTest {
}
}
// AWS counts the destinations before it looks the template up (probed 2026-10-24).
@Test
@Order(8)
void sendBulkTemplatedEmail_destinationsExceeds50_returnsMessageRejected() {
RequestSpecification spec = given()
void sendBulkTemplatedEmail_destinationsExceed50_isCountedBeforeTheTemplateLookup() {
destinations(given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Template", "v1-bulk-welcome");
for (int i = 1; i <= 51; i++) {
spec = spec.formParam(
"Destinations.member." + i + ".Destination.ToAddresses.member.1",
"user" + i + "@example.com");
}
spec
.formParam("Template", "ghost"), 51)
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>MessageRejected</Code>"));
.body(containsString("<Code>InvalidParameterValue</Code>"))
.body(containsString(
"<Message>You must specify at least 1 destination, and no more than 50 destinations</Message>"));
}
@Test
@@ -314,4 +311,31 @@ class SesBulkV1IntegrationTest {
.statusCode(400)
.body(containsString("<Code>MessageRejected</Code>"));
}
@Test
@Order(13)
void sendBulkTemplatedEmail_fiftyDestinations_sendsEachDestination() {
String body = destinations(given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", AUTH)
.formParam("Action", "SendBulkTemplatedEmail")
.formParam("Source", "bulk@example.com")
.formParam("Template", "v1-bulk-welcome")
.formParam("DefaultTemplateData", "{\"name\":\"X\",\"team\":\"floci\"}"), 50)
.when()
.post("/")
.then()
.statusCode(200)
.extract().body().asString();
assertEquals(50L, body.split("<Status>Success</Status>", -1).length - 1L);
}
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",
"user" + i + "@example.com");
}
return spec;
}
}
@@ -13,6 +13,7 @@ import java.util.stream.Stream;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
@@ -26,6 +27,9 @@ class SesBulkV2IntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String DESTINATION_COUNT_MESSAGE =
"You must specify at least 1 destination, and no more than 50 destinations";
@Test
@Order(1)
void createTemplate() {
@@ -234,7 +238,8 @@ class SesBulkV2IntegrationTest {
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(DESTINATION_COUNT_MESSAGE));
}
@Test
@@ -261,13 +266,7 @@ class SesBulkV2IntegrationTest {
@Test
@Order(7)
void sendBulkEmail_entriesExceeds50_returnsMessageRejected() {
StringBuilder entries = new StringBuilder();
for (int i = 1; i <= 51; i++) {
if (i > 1) entries.append(",");
entries.append("{\"Destination\":{\"ToAddresses\":[\"user")
.append(i).append("@example.com\"]}}");
}
void sendBulkEmail_entriesExceeds50_returnsBadRequest() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
@@ -279,12 +278,13 @@ class SesBulkV2IntegrationTest {
},
"BulkEmailEntries": [%s]
}
""".formatted(entries))
""".formatted(entries(51)))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("MessageRejected"));
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(DESTINATION_COUNT_MESSAGE));
}
@Test
@@ -494,4 +494,148 @@ class SesBulkV2IntegrationTest {
.statusCode(400)
.body("__type", equalTo("MessageRejected"));
}
@Test
@Order(14)
void sendBulkEmail_fiftyEntries_sendsEachEntry() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"DefaultContent": {
"Template": {
"TemplateName": "v2-bulk-welcome",
"TemplateData": "{\\"name\\":\\"X\\",\\"team\\":\\"floci\\"}"
}
},
"BulkEmailEntries": [%s]
}
""".formatted(entries(50)))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(200)
.body("BulkEmailEntryResults", hasSize(50))
.body("BulkEmailEntryResults.Status", everyItem(equalTo("SUCCESS")));
}
@ParameterizedTest(name = "{0}")
@MethodSource("missingEntriesMembers")
@Order(15)
void sendBulkEmail_missingEntries_isAModelViolation(String label, String entriesMember) {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"FromEmailAddress": "bulk@example.com",
"DefaultContent": {
"Template": {"TemplateName": "v2-bulk-welcome"}
}%s
}
""".formatted(entriesMember))
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("1 validation error detected: Value at 'bulkEmailEntries' "
+ "failed to satisfy constraint: Member must not be null"));
}
static Stream<Arguments> missingEntriesMembers() {
return Stream.of(
Arguments.of("absent", ""),
Arguments.of("null", ", \"BulkEmailEntries\": null"));
}
// AWS counts the entries before it resolves the stored template, the configuration set and the
// tenant, each of which would otherwise answer 404 (probed 2026-10-24).
@ParameterizedTest(name = "{0}")
@MethodSource("countBeforeLookupBodies")
@Order(16)
void sendBulkEmail_entryCountIsCheckedBeforeLookups(String label, String body) {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body(body)
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(DESTINATION_COUNT_MESSAGE));
}
static Stream<Arguments> countBeforeLookupBodies() {
String inline = "\"DefaultContent\": {\"Template\": {\"TemplateContent\": {\"Subject\": \"s\", \"Text\": \"t\"}}}";
return Stream.of(
Arguments.of("ghost stored template", """
{"FromEmailAddress": "bulk@example.com",
"DefaultContent": {"Template": {"TemplateName": "ghost-template"}},
"BulkEmailEntries": [%s]}
""".formatted(entries(51))),
Arguments.of("ghost stored template by ARN", """
{"FromEmailAddress": "bulk@example.com",
"DefaultContent": {"Template": {
"TemplateArn": "arn:aws:ses:us-east-1:000000000000:template/ghost-template"}},
"BulkEmailEntries": [%s]}
""".formatted(entries(51))),
Arguments.of("ghost configuration set", """
{"FromEmailAddress": "bulk@example.com", "ConfigurationSetName": "ghost-cs", %s,
"BulkEmailEntries": [%s]}
""".formatted(inline, entries(51))),
Arguments.of("ghost tenant", """
{"FromEmailAddress": "bulk@example.com", "TenantName": "ghost-tenant", %s,
"BulkEmailEntries": [%s]}
""".formatted(inline, entries(51))),
Arguments.of("empty entries with a ghost tenant", """
{"FromEmailAddress": "bulk@example.com", "TenantName": "ghost-tenant", %s,
"BulkEmailEntries": []}
""".formatted(inline)));
}
@ParameterizedTest(name = "{0}")
@MethodSource("checkedBeforeCountBodies")
@Order(17)
void sendBulkEmail_earlierChecksWinOverEntryCount(String label, String body, String message) {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body(body)
.when()
.post("/v2/email/outbound-bulk-emails")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(message));
}
static Stream<Arguments> checkedBeforeCountBodies() {
return Stream.of(
Arguments.of("malformed From", """
{"FromEmailAddress": "not an address",
"DefaultContent": {"Template": {"TemplateContent": {"Subject": "s", "Text": "t"}}},
"BulkEmailEntries": [%s]}
""".formatted(entries(51)), "Invalid email address<not an address>."),
Arguments.of("empty inline content", """
{"FromEmailAddress": "bulk@example.com",
"DefaultContent": {"Template": {"TemplateContent": {}}},
"BulkEmailEntries": [%s]}
""".formatted(entries(51)), "Template must have at least a subject, text, or html part."));
}
private static String entries(int count) {
StringBuilder entries = new StringBuilder();
for (int i = 1; i <= count; i++) {
if (i > 1) {
entries.append(",");
}
entries.append("{\"Destination\":{\"ToAddresses\":[\"user")
.append(i).append("@example.com\"]}}");
}
return entries.toString();
}
}