feat(ses): add v2 BatchGetMetricData (#4302)

Aggregates the per-recipient timelines already stored at send time, so the
batch metrics and GetMessageInsights cannot disagree about what a send
produced. Buckets are whole UTC days, the series is sparse rather than zero
filled, the end of the range is exclusive, and counting is per recipient.

SentEmail gains the configuration set the send resolved to, which the
CONFIGURATION_SET dimension filters on. The VDM gate moves into a shared
SesVdmGate so the two gated operations keep one copy of the probed message.

Metrics that need a real mailbox to act stay empty, as does TRANSIENT_BOUNCE,
since every bounce Floci derives is permanent.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-24 08:34:15 -04:00
1 parent 55f9ff5a8b
commit 34be03b334
21 files changed
+1718 -82

No files matched your search

@@ -1130,7 +1130,7 @@ class CognitoLambdaTriggersTest {
eq(List.of()), eq(List.of()), eq(List.of()), isNull(),
eq("TRIGGER-FIRED"),
eq("TRIGGER-FIRED code=246962"),
any(), any(), eq(List.of()), eq(List.of()), any(), anyString());
any(), any(), eq(List.of()), eq(List.of()), any(), isNull(), anyString());
}
@Test
@@ -1187,7 +1187,7 @@ class CognitoLambdaTriggersTest {
any(), any(), any(), isNull(),
eq("Your verification code"),
eq("Your verification code is 246962."),
any(), any(), any(), any(), any(), anyString());
any(), any(), any(), any(), any(), isNull(), anyString());
}
@Test
@@ -1211,7 +1211,7 @@ class CognitoLambdaTriggersTest {
any(), any(), any(), isNull(),
eq("Your verification code"),
eq("Your verification code is 246962."),
any(), any(), any(), any(), any(), anyString());
any(), any(), any(), any(), any(), isNull(), anyString());
}
@Test
@@ -50,7 +50,7 @@ class CognitoMessageDispatcherTest {
eq("Verify your account"),
eq("Hi! Your code is 123456."),
isNull(), isNull(), eq(List.of()), eq(List.of()),
isNull(), eq("us-east-1"));
isNull(), isNull(), eq("us-east-1"));
verifyNoInteractions(sns);
}
@@ -123,7 +123,7 @@ class CognitoMessageDispatcherTest {
eq(List.of()), eq(List.of()), eq(List.of()), isNull(),
eq("Your verification code"),
eq("Your verification code is 111222."),
isNull(), isNull(), eq(List.of()), eq(List.of()), isNull(), eq("us-east-1"));
isNull(), isNull(), eq(List.of()), eq(List.of()), isNull(), isNull(), eq("us-east-1"));
}
@Test
@@ -139,7 +139,7 @@ class CognitoMessageDispatcherTest {
eq(List.of()), eq(List.of()), eq(List.of()), isNull(),
anyString(),
eq("Welcome, please verify.\nCode: 999000"),
isNull(), isNull(), eq(List.of()), eq(List.of()), isNull(), eq("us-east-1"));
isNull(), isNull(), eq(List.of()), eq(List.of()), isNull(), isNull(), eq("us-east-1"));
}
@Test
@@ -152,7 +152,7 @@ class CognitoMessageDispatcherTest {
verify(ses).sendEmail(anyString(), eq(List.of("alice@example.com")),
any(), any(), any(), isNull(), anyString(), anyString(), isNull(), isNull(), any(), any(),
isNull(), anyString());
isNull(), isNull(), anyString());
verifyNoInteractions(sns);
}
@@ -99,4 +99,19 @@ class SesAccountServiceTest {
assertFalse(service.isDedicatedIpAutoWarmupEnabled(REGION));
assertTrue(service.isDedicatedIpAutoWarmupEnabled("eu-west-1"));
}
@Test
void requireVdmEnabled_rejectsAnUnconfiguredRegionAndADisabledOne() {
AwsException unconfigured = assertThrows(AwsException.class,
() -> service.requireVdmEnabled("eu-north-1"));
assertEquals("NotFoundException", unconfigured.getErrorCode());
assertEquals("To use this feature you must enable Virtual Deliverability Manager",
unconfigured.getMessage());
service.putAccountVdmAttributes("eu-north-1", new AccountVdmAttributes(false, false, false));
assertThrows(AwsException.class, () -> service.requireVdmEnabled("eu-north-1"));
service.putAccountVdmAttributes("eu-north-1", new AccountVdmAttributes(true, false, false));
service.requireVdmEnabled("eu-north-1");
}
}
@@ -18,6 +18,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@@ -45,9 +46,12 @@ class SesInsightsControllerTest {
}
private void vdmEnabled(boolean enabled) {
when(accountService.findAccountVdmAttributes(REGION))
.thenReturn(enabled ? Optional.of(new AccountVdmAttributes(true, false, false))
: Optional.empty());
if (enabled) {
return;
}
doThrow(new AwsException("NotFoundException",
"To use this feature you must enable Virtual Deliverability Manager", 404))
.when(accountService).requireVdmEnabled(REGION);
}
@Test
@@ -59,19 +63,8 @@ class SesInsightsControllerTest {
assertEquals("NotFoundException", thrown.getErrorCode());
assertTrue(thrown.getMessage().contains("Virtual Deliverability Manager"), thrown.getMessage());
// The integration test can only infer the ordering from the response; this pins it.
verifyNoInteractions(sentEmailService);
}
@Test
void vdmConfiguredButDisabledIsStillGated() {
when(accountService.findAccountVdmAttributes(REGION))
.thenReturn(Optional.of(new AccountVdmAttributes(false, false, false)));
AwsException thrown = assertThrows(AwsException.class,
() -> controller.getMessageInsights(null, "any-id"));
assertTrue(thrown.getMessage().contains("Virtual Deliverability Manager"), thrown.getMessage());
// The integration test can only infer the ordering from the response; this pins it. What
// the gate itself decides is SesAccountServiceTest's business.
verifyNoInteractions(sentEmailService);
}
@@ -0,0 +1,244 @@
package io.github.hectorvent.floci.services.ses;
import io.github.hectorvent.floci.services.ses.model.EmailInsights;
import io.github.hectorvent.floci.services.ses.model.InsightsBounce;
import io.github.hectorvent.floci.services.ses.model.InsightsEvent;
import io.github.hectorvent.floci.services.ses.model.InsightsEventDetails;
import io.github.hectorvent.floci.services.ses.model.SentEmail;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* The daily aggregation behind BatchGetMetricData. The bucketing rules asserted here are
* probe-confirmed: whole UTC days, a sparse series, and an exclusive end of range.
*/
class SesMetricDataTest {
private static final Instant DAY_ONE = Instant.parse("2026-09-21T00:00:00Z");
private static final Instant DAY_TWO = DAY_ONE.plus(1, ChronoUnit.DAYS);
private static final Instant DAY_FOUR = DAY_ONE.plus(3, ChronoUnit.DAYS);
private static SentEmail email(Instant sentAt, String source, String configurationSet,
EmailInsights... recipients) {
return emailForTenant(sentAt, source, configurationSet, null, recipients);
}
private static SentEmail emailForTenant(Instant sentAt, String source, String configurationSet,
String tenant, EmailInsights... recipients) {
SentEmail email = new SentEmail();
email.setSource(source);
email.setConfigurationSetName(configurationSet);
email.setTenantName(tenant);
email.setSentAt(sentAt);
email.setInsights(List.of(recipients));
return email;
}
private static EmailInsights recipient(Instant at, String destination, String... types) {
List<InsightsEvent> events = new ArrayList<>();
for (String type : types) {
events.add(InsightsEvent.of(at, type));
}
return new EmailInsights(destination, "UNKNOWN_ISP", events);
}
private static EmailInsights bounced(Instant at, String destination, String bounceType) {
return new EmailInsights(destination, "UNKNOWN_ISP", List.of(
InsightsEvent.of(at, "SEND"),
new InsightsEvent(at, "BOUNCE", new InsightsEventDetails(
new InsightsBounce(bounceType, "General", null), null))));
}
private static SesMetricData.Query query(String metric, Instant start, Instant end) {
return new SesMetricData.Query("q", metric, Map.of(), start, end);
}
@Test
void countsOneBucketPerUtcDay() {
// Two sends four hours apart on the same day land in one bucket at that day's midnight.
List<SentEmail> emails = List.of(
email(DAY_ONE.plus(1, ChronoUnit.HOURS), "sender@example.com", null,
recipient(DAY_ONE.plus(1, ChronoUnit.HOURS), "a@example.com", "SEND")),
email(DAY_ONE.plus(5, ChronoUnit.HOURS), "sender@example.com", null,
recipient(DAY_ONE.plus(5, ChronoUnit.HOURS), "b@example.com", "SEND")));
SesMetricData.Series series = SesMetricData.aggregate(emails,
query("SEND", DAY_ONE, DAY_ONE.plus(7, ChronoUnit.DAYS)));
assertEquals(List.of(DAY_ONE), series.timestamps());
assertEquals(List.of(2L), series.values());
}
@Test
void skipsDaysWithoutData() {
List<SentEmail> emails = List.of(
email(DAY_ONE, "sender@example.com", null, recipient(DAY_ONE, "a@example.com", "SEND")),
email(DAY_FOUR, "sender@example.com", null, recipient(DAY_FOUR, "b@example.com", "SEND")));
SesMetricData.Series series = SesMetricData.aggregate(emails,
query("SEND", DAY_ONE, DAY_ONE.plus(7, ChronoUnit.DAYS)));
// Sparse, not zero filled: the two quiet days in between are absent entirely.
assertEquals(List.of(DAY_ONE, DAY_FOUR), series.timestamps());
assertEquals(List.of(1L, 1L), series.values());
}
@Test
void endOfRangeIsExclusive() {
List<SentEmail> emails = List.of(
email(DAY_ONE, "sender@example.com", null, recipient(DAY_ONE, "a@example.com", "SEND")),
email(DAY_TWO, "sender@example.com", null, recipient(DAY_TWO, "b@example.com", "SEND")));
SesMetricData.Series series = SesMetricData.aggregate(emails, query("SEND", DAY_ONE, DAY_TWO));
assertEquals(List.of(DAY_ONE), series.timestamps());
}
@Test
void countsOnePerRecipientNotPerMessage() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "a@example.com", "SEND"),
recipient(DAY_ONE, "b@example.com", "SEND"),
recipient(DAY_ONE, "c@example.com", "SEND")));
SesMetricData.Series series = SesMetricData.aggregate(emails,
query("SEND", DAY_ONE, DAY_TWO));
assertEquals(List.of(3L), series.values());
}
@Test
void separatesPermanentFromTransientBounces() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
bounced(DAY_ONE, "a@example.com", "PERMANENT"),
bounced(DAY_ONE, "b@example.com", "TRANSIENT")));
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
query("PERMANENT_BOUNCE", DAY_ONE, DAY_TWO)).values());
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
query("TRANSIENT_BOUNCE", DAY_ONE, DAY_TWO)).values());
}
@Test
void deliveryComplaintCountsADeliveredRecipientThatThenComplained() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "a@example.com", "SEND", "DELIVERY", "COMPLAINT"),
// Complained without a delivery, so it is a complaint but not a delivered one.
recipient(DAY_ONE, "b@example.com", "SEND", "COMPLAINT")));
assertEquals(List.of(2L), SesMetricData.aggregate(emails,
query("COMPLAINT", DAY_ONE, DAY_TWO)).values());
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
query("DELIVERY_COMPLAINT", DAY_ONE, DAY_TWO)).values());
}
@Test
void metricsThatNeedARealRecipientStayEmpty() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "a@example.com", "SEND", "DELIVERY")));
for (String metric : List.of("OPEN", "CLICK", "DELIVERY_OPEN", "DELIVERY_CLICK")) {
SesMetricData.Series series = SesMetricData.aggregate(emails,
query(metric, DAY_ONE, DAY_TWO));
assertTrue(series.timestamps().isEmpty(), metric + " should report nothing");
assertTrue(series.values().isEmpty(), metric + " should report nothing");
}
}
@Test
void identityDimensionMatchesTheAddressOrItsDomain() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "a@example.com", "SEND")));
for (String identity : List.of("sender@example.com", "example.com", "EXAMPLE.COM")) {
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("EMAIL_IDENTITY", identity),
DAY_ONE, DAY_TWO)).values(), identity);
}
assertTrue(SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("EMAIL_IDENTITY", "other.example.com"),
DAY_ONE, DAY_TWO)).values().isEmpty());
}
@Test
void identityDimensionMatchesASourceCarryingADisplayName() {
// The send path stores Source verbatim, so it can carry "Name <addr>".
List<SentEmail> emails = List.of(email(DAY_ONE, "Sender Name <sender@example.com>", null,
recipient(DAY_ONE, "a@example.com", "SEND")));
for (String identity : List.of("sender@example.com", "example.com")) {
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("EMAIL_IDENTITY", identity),
DAY_ONE, DAY_TWO)).values(), identity);
}
}
@Test
void configurationSetDimensionFiltersOnTheResolvedSet() {
List<SentEmail> emails = List.of(
email(DAY_ONE, "sender@example.com", "tracked",
recipient(DAY_ONE, "a@example.com", "SEND")),
email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "b@example.com", "SEND")));
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("CONFIGURATION_SET", "tracked"),
DAY_ONE, DAY_TWO)).values());
assertTrue(SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("CONFIGURATION_SET", "absent"),
DAY_ONE, DAY_TWO)).values().isEmpty());
}
@Test
void tenantDimensionFiltersOnTheTenantTheSendNamed() {
// AWS accepts TENANT_NAME as a fourth dimension; the pinned SDK model still lists three.
List<SentEmail> emails = List.of(
emailForTenant(DAY_ONE, "sender@example.com", null, "blue",
recipient(DAY_ONE, "a@example.com", "SEND")),
emailForTenant(DAY_ONE, "sender@example.com", null, null,
recipient(DAY_ONE, "b@example.com", "SEND")));
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("TENANT_NAME", "blue"),
DAY_ONE, DAY_TWO)).values());
assertTrue(SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("TENANT_NAME", "green"),
DAY_ONE, DAY_TWO)).values().isEmpty());
}
@Test
void ispDimensionMatchesOnlyTheValueFlociReports() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", null,
recipient(DAY_ONE, "a@example.com", "SEND")));
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("ISP", "UNKNOWN_ISP"),
DAY_ONE, DAY_TWO)).values());
assertTrue(SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND", Map.of("ISP", "gmail.com"),
DAY_ONE, DAY_TWO)).values().isEmpty());
}
@Test
void severalDimensionsAllHaveToMatch() {
List<SentEmail> emails = List.of(email(DAY_ONE, "sender@example.com", "tracked",
recipient(DAY_ONE, "a@example.com", "SEND")));
assertEquals(List.of(1L), SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND",
Map.of("EMAIL_IDENTITY", "example.com", "CONFIGURATION_SET", "tracked",
"ISP", "UNKNOWN_ISP"), DAY_ONE, DAY_TWO)).values());
assertTrue(SesMetricData.aggregate(emails,
new SesMetricData.Query("q", "SEND",
Map.of("EMAIL_IDENTITY", "example.com", "CONFIGURATION_SET", "other"),
DAY_ONE, DAY_TWO)).values().isEmpty());
}
}
@@ -0,0 +1,515 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
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.time.Duration;
import java.time.Instant;
import java.util.Base64;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
/**
* Integration tests for {@code POST /v2/email/metrics/batch} (BatchGetMetricData).
*
* <p>The wire behaviour asserted here is probe-confirmed against real SES (2026-09-23, us-east-1):
* the VDM gate, daily buckets, a sparse series, the 60 day interval cap, and the order in which the
* request is validated. The exclusive end of the range is pinned in {@code SesMetricDataTest},
* which can put an event on the boundary instant. Uses an isolated signing region so no other
* test's sends reach these counts.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesMetricsV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/sa-east-1/ses/aws4_request";
private static final String SENDER = "metrics-sender@example.com";
private static final long DAY = Duration.ofDays(1).toSeconds();
// One reading of the clock for the whole class: two calls a second apart would turn the
// equal-dates case below into a valid one-second interval.
private static final long NOW = Instant.now().getEpochSecond();
private static long start() {
return NOW - Duration.ofDays(1).toSeconds();
}
private static long end() {
return NOW + Duration.ofDays(1).toSeconds();
}
private static String query(String id, String metric) {
return """
{"Id": "%s", "Namespace": "VDM", "Metric": "%s", "StartDate": %d, "EndDate": %d}
""".formatted(id, metric, start(), end());
}
private static Response post(String queriesJson) {
return given().contentType("application/json").header("Authorization", AUTH)
.body("{\"Queries\": [" + queriesJson + "]}")
.when().post("/v2/email/metrics/batch");
}
private static void badValue(String dimension, String value, String message) {
dimensionQuery(dimension, value).then().statusCode(400)
.body("message", equalTo(message));
}
private static void goodValue(String dimension, String value) {
dimensionQuery(dimension, value).then().statusCode(200);
}
private static Response dimensionQuery(String dimension, String value) {
return given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "v", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"%s": "%s"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(dimension, value, start(), end()))
.when().post("/v2/email/metrics/batch");
}
private static int total(Response response, String id) {
List<Integer> values = response.path("Results.find { it.Id == '" + id + "' }.Values");
return values.stream().mapToInt(Integer::intValue).sum();
}
private static void send(String destination) {
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{
"FromEmailAddress": "%s",
"Destination": {"ToAddresses": ["%s"]},
"Content": {"Simple": {"Subject": {"Data": "metrics"},
"Body": {"Text": {"Data": "hi"}}}}
}
""".formatted(SENDER, destination))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
}
@Test
@Order(0)
void batchGetMetricData_vdmDisabled_reportsTheGateBeforeItValidatesTheRequest() {
// The body is invalid in three ways; with VDM off none of that is reached.
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"Queries\": []}")
.when().post("/v2/email/metrics/batch").then().statusCode(404)
.body("message", containsString(
"To use this feature you must enable Virtual Deliverability Manager"));
}
@Test
@Order(1)
void enableVdmAndVerifyTheSender() {
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"VdmAttributes\":{\"VdmEnabled\":\"ENABLED\"}}")
.when().put("/v2/email/account/vdm").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"EmailIdentity\":\"" + SENDER + "\"}")
.when().post("/v2/email/identities").then().statusCode(200);
}
@Test
@Order(2)
void sendOneOfEachOutcome() {
send("ordinary@example.com");
send("bounce@simulator.amazonses.com");
send("complaint@simulator.amazonses.com");
}
@Test
@Order(3)
void batchGetMetricData_countsEachOutcomeOnce() {
Response response = post(String.join(",",
query("send", "SEND"),
query("delivery", "DELIVERY"),
query("bounce", "PERMANENT_BOUNCE"),
query("complaint", "COMPLAINT"),
query("delivered", "DELIVERY_COMPLAINT")));
response.then().statusCode(200);
// Summed across buckets, since the three sends can straddle UTC midnight. Results come
// back keyed by Id, in an order AWS does not promise.
assertEquals(3, total(response, "send"));
assertEquals(2, total(response, "delivery"));
assertEquals(1, total(response, "bounce"));
assertEquals(1, total(response, "complaint"));
assertEquals(1, total(response, "delivered"));
}
@Test
@Order(4)
void batchGetMetricData_aMetricWithNoDataKeepsItsMembers() {
// Probed: an empty series is a Results entry with empty arrays, never an omission or a zero,
// and Errors is present on every response even though nothing ever populates it.
post(String.join(",", query("open", "OPEN"), query("transient", "TRANSIENT_BOUNCE")))
.then().statusCode(200)
.body("Results", hasSize(2))
.body("Results.find { it.Id == 'open' }.Timestamps", empty())
.body("Results.find { it.Id == 'open' }.Values", empty())
.body("Results.find { it.Id == 'transient' }.Values", empty())
.body("Errors", empty());
}
@Test
@Order(5)
void batchGetMetricData_bucketsByDay() {
Response response = post(query("buckets", "SEND"));
response.then().statusCode(200);
List<Float> timestamps = response.path("Results[0].Timestamps");
List<Integer> values = response.path("Results[0].Values");
// The boundary is read from the response rather than the wall clock, so the assertions
// hold even when the suite crosses UTC midnight between the sends and this test.
for (Float timestamp : timestamps) {
assertEquals(0L, timestamp.longValue() % DAY, "bucket is not a whole UTC day");
}
assertEquals(3, values.stream().mapToInt(Integer::intValue).sum());
// A window ending at the first bucket stops before it.
long firstBucket = timestamps.get(0).longValue();
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "before", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d}]}
""".formatted(firstBucket - DAY, firstBucket))
.when().post("/v2/email/metrics/batch").then().statusCode(200)
.body("Results[0].Values", empty());
}
@Test
@Order(6)
void batchGetMetricData_filtersOnTheIdentityDimension() {
Response response = given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "mine", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"EMAIL_IDENTITY": "example.com"},
"StartDate": %d, "EndDate": %d},
{"Id": "theirs", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"EMAIL_IDENTITY": "elsewhere.example"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end(), start(), end()))
.when().post("/v2/email/metrics/batch");
response.then().statusCode(200)
.body("Results.find { it.Id == 'theirs' }.Values", empty());
// Summed, since the sends can straddle UTC midnight and land in two buckets.
assertEquals(3, total(response, "mine"));
}
@Test
@Order(7)
void batchGetMetricData_filtersOnTheConfigurationSetEverySendPathResolves() {
// One send down each of the three paths, all naming the same set. A regression in any one
// of the three assignments shows up here as a count below three.
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"ConfigurationSetName\": \"metrics-set\"}")
.when().post("/v2/email/configuration-sets").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"FromEmailAddress": "%s", "ConfigurationSetName": "metrics-set",
"Destination": {"ToAddresses": ["simple@example.com"]},
"Content": {"Simple": {"Subject": {"Data": "s"},
"Body": {"Text": {"Data": "hi"}}}}}
""".formatted(SENDER))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
String raw = "From: " + SENDER + "\r\nTo: raw@example.com\r\nSubject: r\r\n\r\nhi\r\n";
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"FromEmailAddress": "%s", "ConfigurationSetName": "metrics-set",
"Destination": {"ToAddresses": ["raw@example.com"]},
"Content": {"Raw": {"Data": "%s"}}}
""".formatted(SENDER, Base64.getEncoder()
.encodeToString(raw.getBytes(StandardCharsets.UTF_8))))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"TemplateName": "metrics-cvet", "FromEmailAddress": "%s",
"TemplateSubject": "verify", "TemplateContent": "<p>verify</p>",
"SuccessRedirectionURL": "https://example.com/ok",
"FailureRedirectionURL": "https://example.com/no"}
""".formatted(SENDER))
.when().post("/v2/email/custom-verification-email-templates").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"EmailAddress": "cvet@example.com", "TemplateName": "metrics-cvet",
"ConfigurationSetName": "metrics-set"}
""")
.when().post("/v2/email/outbound-custom-verification-emails").then().statusCode(200);
Response response = given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "set", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"CONFIGURATION_SET": "metrics-set"},
"StartDate": %d, "EndDate": %d},
{"Id": "other", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"CONFIGURATION_SET": "no-such-set"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end(), start(), end()))
.when().post("/v2/email/metrics/batch");
response.then().statusCode(200).body("Results.find { it.Id == 'other' }.Values", empty());
assertEquals(3, total(response, "set"));
// A send naming a blank set resolves to no set, so it must not join any set's count. A
// blank dimension value cannot be used to check that: AWS refuses one outright.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"FromEmailAddress": "%s", "ConfigurationSetName": "",
"Destination": {"ToAddresses": ["blank@example.com"]},
"Content": {"Simple": {"Subject": {"Data": "b"},
"Body": {"Text": {"Data": "hi"}}}}}
""".formatted(SENDER))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
Response after = given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "set", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"CONFIGURATION_SET": "metrics-set"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end()))
.when().post("/v2/email/metrics/batch");
after.then().statusCode(200);
assertEquals(3, total(after, "set"));
}
@Test
@Order(8)
void batchGetMetricData_filtersOnTheTenantTheSendNamed() {
// Without a send that actually names a tenant, dropping the setTenantName assignments
// would leave every positive tenant metric at zero and the suite green.
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"TenantName\": \"metrics-tenant\"}")
.when().post("/v2/email/tenants").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"TenantName": "metrics-tenant",
"ResourceArn": "arn:aws:ses:sa-east-1:000000000000:identity/%s"}
""".formatted(SENDER))
.when().post("/v2/email/tenants/resources").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"FromEmailAddress": "%s", "TenantName": "metrics-tenant",
"Destination": {"ToAddresses": ["tenant@example.com"]},
"Content": {"Simple": {"Subject": {"Data": "t"},
"Body": {"Text": {"Data": "hi"}}}}}
""".formatted(SENDER))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
// The raw path stores the tenant too, and only a raw send covers its own assignment.
String raw = "From: " + SENDER + "\r\nTo: tenant-raw@example.com\r\nSubject: t\r\n\r\nhi\r\n";
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"FromEmailAddress": "%s", "TenantName": "metrics-tenant",
"Destination": {"ToAddresses": ["tenant-raw@example.com"]},
"Content": {"Raw": {"Data": "%s"}}}
""".formatted(SENDER, Base64.getEncoder()
.encodeToString(raw.getBytes(StandardCharsets.UTF_8))))
.when().post("/v2/email/outbound-emails").then().statusCode(200);
Response response = given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "mine", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"TENANT_NAME": "metrics-tenant"},
"StartDate": %d, "EndDate": %d},
{"Id": "theirs", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"TENANT_NAME": "another-tenant"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end(), start(), end()))
.when().post("/v2/email/metrics/batch");
response.then().statusCode(200)
.body("Results.find { it.Id == 'theirs' }.Values", empty());
assertEquals(2, total(response, "mine"));
}
@Test
@Order(9)
void batchGetMetricData_validatesInTheProbedOrder() {
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"Queries\": []}")
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("1 validation error detected: Value at 'queries' failed "
+ "to satisfy constraint: Member must have length greater than or equal to 1"));
StringBuilder eleven = new StringBuilder(query("q0", "SEND"));
for (int i = 1; i < 11; i++) {
eleven.append(",").append(query("q" + i, "SEND"));
}
post(eleven.toString()).then().statusCode(400)
.body("message", containsString("Member must have length less than or equal to 10"));
// A duplicate id outranks both the reversed dates and the interval cap.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "same", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d},
{"Id": "same", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d}]}
""".formatted(end(), start(), end(), start()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("All queries must have a unique identifier."));
// TENANT_NAME is a valid dimension on AWS even though the pinned SDK model omits it, so it
// must not be refused as unsupported.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "tenant", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"TENANT_NAME": "no-such-tenant"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end()))
.when().post("/v2/email/metrics/batch").then().statusCode(200)
.body("Results[0].Values", empty());
// An unknown dimension name outranks the member constraints.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "d", "Namespace": "VDM", "Metric": "NOT_A_METRIC",
"Dimensions": {"NOT_A_DIMENSION": "x"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Unsupported dimension provided."));
// Member constraints aggregate into one message, metric first, then namespace, then id.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "", "Namespace": "NOT_VDM", "Metric": "NOT_A_METRIC",
"StartDate": %d, "EndDate": %d}]}
""".formatted(end(), start()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", containsString("3 validation errors detected:"))
.body("message", containsString("'queries.1.member.metric'"))
.body("message", containsString("'queries.1.member.namespace'"))
.body("message", containsString("'queries.1.member.id'"));
// Each dimension validates its own value, with its own message; all probe-confirmed.
badValue("EMAIL_IDENTITY", "", "Invalid email identity provided.");
badValue("EMAIL_IDENTITY", "*", "Invalid email identity provided.");
badValue("EMAIL_IDENTITY", "user@", "Invalid email identity provided.");
badValue("ISP", "", "Invalid ISP name provided.");
badValue("ISP", "Gmail.com", "Invalid ISP name provided.");
badValue("CONFIGURATION_SET", "", "The configuration set name must be specified.");
badValue("CONFIGURATION_SET", "has space", "Invalid configuration set name <has space>: "
+ "only alphanumeric ASCII characters, '_', and '-' are allowed.");
badValue("TENANT_NAME", "", "TenantName cannot be empty");
badValue("TENANT_NAME", "*", "Invalid tenant name <*>: "
+ "only alphanumeric ASCII characters, '_', and '-' are allowed.");
// The shapes the probe accepted still pass.
goodValue("EMAIL_IDENTITY", "UPPER@Example.COM");
goodValue("ISP", "Not-An_Isp");
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "same-instant", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), start()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Expected start date to be before the end date."));
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "wide", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d}]}
""".formatted(end() - 61 * DAY, end()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Invalid interval, can request at most 60 days. "
+ "Please partition your requested interval."));
// Four keys became reachable when TENANT_NAME was added; the model caps the map at three.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "four", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"ISP": "UNKNOWN_ISP", "EMAIL_IDENTITY": "example.com",
"CONFIGURATION_SET": "s", "TENANT_NAME": "t"},
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("1 validation error detected: Value at "
+ "'queries.1.member.dimensions' failed to satisfy constraint: "
+ "Member must have length less than or equal to 3"));
// Probed request-wide: a bad dimension value in any query outranks a bad date in any other.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "dates", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d},
{"Id": "value", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": {"EMAIL_IDENTITY": ""},
"StartDate": %d, "EndDate": %d}]}
""".formatted(end(), start(), start(), end()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Invalid email identity provided."));
// A timestamp outside Instant's range is the caller's problem, not a server error.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "huge", "Namespace": "VDM", "Metric": "SEND",
"StartDate": 1, "EndDate": 999999999999999999}]}
""")
.when().post("/v2/email/metrics/batch").then().statusCode(400);
// A window that parses but sits within a day of Instant's upper bound must still answer,
// rather than overflowing while the aggregation window is widened.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "edge", "Namespace": "VDM", "Metric": "SEND",
"StartDate": "+1000000000-12-01T00:00:00Z",
"EndDate": "+1000000000-12-31T00:00:00Z"}]}
""")
.when().post("/v2/email/metrics/batch").then().statusCode(200)
.body("Results[0].Values", empty());
// A list member that is not an array is a deserialization failure too, not an empty list.
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"Queries\": {}}")
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Start of structure or map found where not expected."));
// A map member that is not an object is a deserialization failure, not an absent filter.
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "shape", "Namespace": "VDM", "Metric": "SEND",
"Dimensions": [],
"StartDate": %d, "EndDate": %d}]}
""".formatted(start(), end()))
.when().post("/v2/email/metrics/batch").then().statusCode(400)
.body("message", equalTo("Start of list found where not expected"));
// Sixty days exactly is accepted. Both ends come from one reading of the clock, so a
// second boundary between two calls cannot turn this into sixty days and one second.
long capEnd = end();
given().contentType("application/json").header("Authorization", AUTH)
.body("""
{"Queries": [{"Id": "cap", "Namespace": "VDM", "Metric": "SEND",
"StartDate": %d, "EndDate": %d}]}
""".formatted(capEnd - 60 * DAY, capEnd))
.when().post("/v2/email/metrics/batch").then().statusCode(200);
}
@Test
@Order(10)
void cleanUpVdmAndIdentity() {
given().contentType("application/json").header("Authorization", AUTH)
.body("{\"VdmAttributes\":{\"VdmEnabled\":\"DISABLED\"}}")
.when().put("/v2/email/account/vdm");
given().header("Authorization", AUTH)
.when().delete("/v2/email/identities/" + SENDER);
}
}
@@ -65,7 +65,7 @@ class SesServiceListManagementTest {
private void send(List<String> to, String topicName) {
service.sendEmail(FROM, to, null, null, null, null, "Subject", "body", null,
null, List.of(), List.of(), new ListManagementOptions(LIST, topicName), REGION);
null, List.of(), List.of(), new ListManagementOptions(LIST, topicName), null, REGION);
}
private SmtpRelay.RelayMessage capturedRelay() {
@@ -124,7 +124,7 @@ class SesServiceListManagementTest {
AwsException ex = assertThrows(AwsException.class, () ->
service.sendEmail(FROM, List.of("sportsin@example.com"), null, null, null, null,
"Subject", "body", null, null, List.of(), List.of(),
new ListManagementOptions("ghost-list", null), REGION));
new ListManagementOptions("ghost-list", null), null, REGION));
assertEquals(404, ex.getHttpStatus());
}
@@ -134,7 +134,7 @@ class SesServiceListManagementTest {
AwsException ex = assertThrows(AwsException.class, () ->
service.sendEmail(FROM, List.of("sportsin@example.com"), null, null, null, null,
"Subject", "body", null, null, List.of(), List.of(),
new ListManagementOptions(LIST, "GhostTopic"), REGION));
new ListManagementOptions(LIST, "GhostTopic"), null, REGION));
assertEquals(400, ex.getHttpStatus());
}
@@ -143,7 +143,7 @@ class SesServiceListManagementTest {
// Without ListManagementOptions the contact list is never consulted: an unsubscribed contact
// is not suppressed and no contact is auto-created.
service.sendEmail(FROM, List.of("unsub@example.com"), null, null, null, null,
"Subject", "body", null, null, List.of(), List.of(), null, REGION);
"Subject", "body", null, null, List.of(), List.of(), null, null, REGION);
assertEquals(List.of("unsub@example.com"), capturedRelayTo());
}
@@ -152,7 +152,7 @@ class SesServiceListManagementTest {
// newbie is not a contact (auto-created, Sports defaults OPT_IN) so the send reaches the relay.
service.sendEmail(FROM, List.of("newbie@example.com"), null, null, null, null,
"Subject", "text", "<p>Unsub: {{amazonSESUnsubscribeUrl}}</p>",
null, List.of(), List.of(), new ListManagementOptions(LIST, "Sports"), REGION);
null, List.of(), List.of(), new ListManagementOptions(LIST, "Sports"), null, REGION);
String html = capturedRelayBodyHtml();
assertTrue(html.contains("http://localhost:4566/_aws/ses/unsubscribe?"), html);
assertTrue(html.contains("contactList=" + LIST), html);
@@ -164,7 +164,7 @@ class SesServiceListManagementTest {
void multiRecipient_doesNotReplacePlaceholder() {
service.sendEmail(FROM, List.of("newbie@example.com", "sportsin@example.com"), null, null, null,
null, "Subject", "text", "<p>Unsub: {{amazonSESUnsubscribeUrl}}</p>",
null, List.of(), List.of(), new ListManagementOptions(LIST, "Sports"), REGION);
null, List.of(), List.of(), new ListManagementOptions(LIST, "Sports"), null, REGION);
assertTrue(capturedRelayBodyHtml().contains("{{amazonSESUnsubscribeUrl}}"),
"multi-recipient send must not inject the unsubscribe link");
}
@@ -217,7 +217,7 @@ class SesServiceListManagementTest {
void singleRecipient_addsListUnsubscribeHeadersToRelay() {
service.sendEmail(FROM, List.of("newbie@example.com"), null, null, null, null,
"Subject", "text", "<p>x</p>", null, List.of(), List.of(),
new ListManagementOptions(LIST, "Sports"), REGION);
new ListManagementOptions(LIST, "Sports"), null, REGION);
List<MessageHeader> headers = capturedRelayHeaders();
assertTrue(headers.stream().anyMatch(h -> "List-Unsubscribe".equals(h.name())
&& h.value().contains("/_aws/ses/unsubscribe")), "List-Unsubscribe header must reach the relay");
@@ -230,7 +230,7 @@ class SesServiceListManagementTest {
service.sendEmail(FROM, List.of("newbie@example.com"), null, null, null, null,
"Subject", "text", "<p>x</p>", null, List.of(),
List.of(new MessageHeader("List-Unsubscribe", "<https://caller.example/u>")),
new ListManagementOptions(LIST, "Sports"), REGION);
new ListManagementOptions(LIST, "Sports"), null, REGION);
long count = capturedRelayHeaders().stream()
.filter(h -> "List-Unsubscribe".equalsIgnoreCase(h.name())).count();
assertEquals(1L, count);
@@ -129,7 +129,7 @@ class SesServiceSmtpTest {
List.of("bcc@example.com"),
List.of("reply@example.com"),
null,
"Subject", "text body", "<p>html</p>", null, List.of(), List.of(), null, "us-east-1");
"Subject", "text body", "<p>html</p>", null, List.of(), List.of(), null, null, "us-east-1");
SmtpRelay.RelayMessage relayed = capturedRelay();
assertEquals("from@example.com", relayed.from());
@@ -148,7 +148,7 @@ class SesServiceSmtpTest {
void sendEmail_storesAndRelays() {
String messageId = service.sendEmail("from@example.com",
List.of("to@example.com"), null, null, null, null,
"Subject", "text", null, null, List.of(), List.of(), null, "us-east-1");
"Subject", "text", null, null, List.of(), List.of(), null, null, "us-east-1");
assertNotNull(messageId);
assertFalse(emailStore.scan(k -> true).isEmpty());
@@ -159,7 +159,7 @@ class SesServiceSmtpTest {
void sendEmail_noReturnPath_fallsBackToSource() {
service.sendEmail("from@example.com",
List.of("to@example.com"), null, null, null, null,
"Subject", "text", null, null, List.of(), List.of(), null, "us-east-1");
"Subject", "text", null, null, List.of(), List.of(), null, null, "us-east-1");
assertEquals("from@example.com", capturedRelay().returnPath());
}
@@ -168,7 +168,7 @@ class SesServiceSmtpTest {
void sendEmail_explicitReturnPath_isRelayedAndStored() {
String messageId = service.sendEmail("from@example.com",
List.of("to@example.com"), null, null, null, "bounces@example.com",
"Subject", "text", null, null, List.of(), List.of(), null, "us-east-1");
"Subject", "text", null, null, List.of(), List.of(), null, null, "us-east-1");
assertEquals("bounces@example.com", capturedRelay().returnPath());
assertEquals("bounces@example.com", storedEmail(messageId).getReturnPath());
@@ -182,7 +182,7 @@ class SesServiceSmtpTest {
+ "Subject: " + SesContentScan.signature() + "\r\n\r\nbody\r\n";
String messageId = service.sendRawEmail("from@example.com", List.of("to@example.com"), raw,
"bounces@example.com", null, List.of(), null, "us-east-1");
"bounces@example.com", null, List.of(), null, null, "us-east-1");
assertEquals("bounces@example.com", storedEmail(messageId).getReturnPath());
assertEquals("Bad content", storedEmail(messageId).getRejectReason());
@@ -196,7 +196,7 @@ class SesServiceSmtpTest {
String raw = "Content-Type: message/rfc822\r\n\r\n".repeat(100_000) + "Subject: deep\r\n\r\nx\r\n";
AwsException e = assertThrows(AwsException.class, () -> service.sendRawEmail("from@example.com",
List.of("to@example.com"), raw, null, null, List.of(), null, "us-east-1"));
List.of("to@example.com"), raw, null, null, List.of(), null, null, "us-east-1"));
assertEquals(400, e.getHttpStatus());
assertTrue(sentEmails.listAll().isEmpty());
@@ -206,7 +206,7 @@ class SesServiceSmtpTest {
@Test
void sendRawEmail_callsRelayRaw() {
String messageId = service.sendRawEmail("from@example.com",
List.of("to@example.com"), "raw MIME", null, null, List.of(), null, "us-east-1");
List.of("to@example.com"), "raw MIME", null, null, List.of(), null, null, "us-east-1");
SmtpRelay.RawRelayMessage relayed = capturedRawRelay();
assertEquals("from@example.com", relayed.from());
@@ -223,7 +223,7 @@ class SesServiceSmtpTest {
+ "Subject: x\r\n\r\nbody";
String messageId = service.sendRawEmail("from@example.com", List.of("to@example.com"), raw,
"request-bounces@example.com", null, List.of(), null, "us-east-1");
"request-bounces@example.com", null, List.of(), null, null, "us-east-1");
assertEquals("mime-bounces@example.com", capturedRawRelay().returnPath());
assertEquals("mime-bounces@example.com", storedEmail(messageId).getReturnPath());
@@ -234,7 +234,7 @@ class SesServiceSmtpTest {
String raw = "From: from@example.com\r\nTo: to@example.com\r\nSubject: x\r\n\r\nbody";
service.sendRawEmail("from@example.com", List.of("to@example.com"), raw,
"request-bounces@example.com", null, List.of(), null, "us-east-1");
"request-bounces@example.com", null, List.of(), null, null, "us-east-1");
assertEquals("request-bounces@example.com", capturedRawRelay().returnPath());
}
@@ -242,7 +242,7 @@ class SesServiceSmtpTest {
@Test
void sendRawEmail_storesAndRelays() {
String messageId = service.sendRawEmail("from@example.com",
List.of("to@example.com"), "raw", null, null, List.of(), null, "us-east-1");
List.of("to@example.com"), "raw", null, null, List.of(), null, null, "us-east-1");
assertNotNull(messageId);
assertFalse(emailStore.scan(k -> true).isEmpty());
@@ -254,7 +254,7 @@ class SesServiceSmtpTest {
service.sendEmail("from@example.com",
List.of("to@example.com"),
null, null, null, null,
"Subject", null, "<p>html only</p>", null, List.of(), List.of(), null, "us-east-1");
"Subject", null, "<p>html only</p>", null, List.of(), List.of(), null, null, "us-east-1");
SmtpRelay.RelayMessage relayed = capturedRelay();
assertEquals(List.of("to@example.com"), relayed.to());
@@ -274,7 +274,7 @@ class SesServiceSmtpTest {
List.of("to@example.com"),
List.of("cc@example.com"),
null, null, null,
"Subject", "text body", null, null, List.of(), List.of(), null, "us-east-1");
"Subject", "text body", null, null, List.of(), List.of(), null, null, "us-east-1");
assertNotNull(messageId);
assertFalse(emailStore.scan(k -> true).isEmpty(),
@@ -291,7 +291,7 @@ class SesServiceSmtpTest {
List.of("to@example.com", "suppressed@example.com"),
List.of("cc-keep@example.com"),
null, null, null,
"Subject", "text body", null, null, List.of(), List.of(), null, "us-east-1");
"Subject", "text body", null, null, List.of(), List.of(), null, null, "us-east-1");
SmtpRelay.RelayMessage relayed = capturedRelay();
assertEquals(List.of("to@example.com"), relayed.to());
@@ -303,7 +303,7 @@ class SesServiceSmtpTest {
suppression.putSuppressedDestination("us-east-1", "to@example.com", "BOUNCE");
String messageId = service.sendRawEmail("from@example.com",
List.of("to@example.com"), "raw MIME", null, null, List.of(), null, "us-east-1");
List.of("to@example.com"), "raw MIME", null, null, List.of(), null, null, "us-east-1");
assertNotNull(messageId);
assertFalse(emailStore.scan(k -> true).isEmpty());
@@ -316,7 +316,7 @@ class SesServiceSmtpTest {
service.sendRawEmail("from@example.com",
List.of("to@example.com", "suppressed@example.com"),
"raw MIME", null, null, List.of(), null, "us-east-1");
"raw MIME", null, null, List.of(), null, null, "us-east-1");
assertEquals(List.of("to@example.com"), capturedRawRelay().destinations());
}
@@ -335,7 +335,7 @@ class SesServiceSmtpTest {
service.sendEmail("from@example.com",
List.of("to@example.com"), null, null, null, null,
"Subject", "text body", null, "cs-no-suppression", List.of(), List.of(), null, "us-east-1");
"Subject", "text body", null, "cs-no-suppression", List.of(), List.of(), null, null, "us-east-1");
assertEquals(List.of("to@example.com"), capturedRelay().to());
}
@@ -351,7 +351,7 @@ class SesServiceSmtpTest {
service.sendEmail("from@example.com",
List.of("complainer@example.com"), null, null, null, null,
"Subject", "text body", null, "cs-bounce-only", List.of(), List.of(), null, "us-east-1");
"Subject", "text body", null, "cs-bounce-only", List.of(), List.of(), null, null, "us-east-1");
assertEquals(List.of("complainer@example.com"), capturedRelay().to());
}
@@ -366,7 +366,7 @@ class SesServiceSmtpTest {
service.sendEmail("from@example.com",
List.of("to@example.com"), null, null, null, null,
"Subject", "text body", null, "cs-default", List.of(), List.of(), null, "us-east-1");
"Subject", "text body", null, "cs-default", List.of(), List.of(), null, null, "us-east-1");
verify(smtpRelay, never()).relay(any(SmtpRelay.RelayMessage.class));
}
@@ -378,7 +378,7 @@ class SesServiceSmtpTest {
configSets.putSuppressionOptions("cs-no-suppression-raw", List.of(), "us-east-1");
service.sendRawEmail("from@example.com",
List.of("to@example.com"), "raw MIME", null, "cs-no-suppression-raw", List.of(), null,
List.of("to@example.com"), "raw MIME", null, "cs-no-suppression-raw", List.of(), null, null,
"us-east-1");
assertEquals(List.of("to@example.com"), capturedRawRelay().destinations());