test(ses): build the region-scoped SES v2 headers with authFor (#9194)

This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-11-22 08:06:22 -04:00
1 parent 076f6ed504
commit f41fad028c
20 files changed
+33 -62

No files matched your search

@@ -24,8 +24,7 @@ import static org.hamcrest.Matchers.notNullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesAccountDetailsV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ca-central-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ca-central-1");
@Test
@Order(0)
@@ -249,7 +248,7 @@ class SesAccountDetailsV2IntegrationTest {
// has no sandbox and runs no production-access review, so the top-level flag stays true
// regardless of the value sent to PutAccountDetails, and it never appears inside Details. Use a
// dedicated region so this is independent of the other ordered cases.
String euAuth = "AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-west-2/ses/aws4_request";
String euAuth = SesV2Requests.authFor("eu-west-2");
given().contentType("application/json").header("Authorization", euAuth)
.body("""
{"MailType":"MARKETING","WebsiteURL":"https://example.org",
@@ -21,8 +21,7 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesAccountVdmV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-central-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("eu-central-1");
@Test
@Order(0)
@@ -20,8 +20,7 @@ import static org.hamcrest.Matchers.equalTo;
class SesBooleanCoercionV2IntegrationTest {
private static final String REGION = "il-central-1";
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + REGION + "/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor(REGION);
private static final String DOMAIN = "coercion.example.com";
private static final String CS = "coercion-cs";
private static final String ED = "coercion-ed";
@@ -497,8 +497,7 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
@Order(19)
void createEventDestination_eventBridgeDefaultBusNonCommercialPartitionSucceeds() {
String cs = "v2-cs-ed-ebus";
String cnAuthHeader =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/cn-north-1/ses/aws4_request";
String cnAuthHeader = SesV2Requests.authFor("cn-north-1");
String cnDefaultBusArn =
"arn:aws-cn:events:cn-north-1:000000000000:event-bus/default";
given()
@@ -28,8 +28,7 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesConfigurationSetPagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-west-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("us-west-1");
private static final String V1_ROOT = "ListConfigurationSetsResponse.ListConfigurationSetsResult.";
@Test
@@ -23,10 +23,8 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesContactPagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-2/ses/aws4_request";
private static final String OTHER_REGION_AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ap-northeast-2");
private static final String OTHER_REGION_AUTH = SesV2Requests.authFor("eu-north-1");
private static final String LIST = "page-list";
private static final String CONTACTS = "/v2/email/contact-lists/" + LIST + "/contacts";
@@ -28,8 +28,7 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesCustomVerificationEmailTemplatePagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-south-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("eu-south-1");
private static final String BASE = "/v2/email/custom-verification-email-templates";
private static final String FROM = "cvet-page-sender@floci.test";
private static final String V1_ROOT =
@@ -22,10 +22,8 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesDedicatedIpPagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-3/ses/aws4_request";
private static final String OTHER_REGION_AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ap-northeast-3");
private static final String OTHER_REGION_AUTH = SesV2Requests.authFor("eu-north-1");
private static final String POOLS = "/v2/email/dedicated-ip-pools";
private static final String IPS = "/v2/email/dedicated-ips";
@@ -14,8 +14,7 @@ import static org.hamcrest.Matchers.equalTo;
@QuarkusTest
class SesEmailAddressInsightsV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ca-west-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ca-west-1");
private static final String PATH = "/v2/email/email-address-insights/";
@Test
@@ -1246,8 +1246,7 @@ class SesEventPublishingV2IntegrationTest {
"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/sqs/aws4_request";
String eventsAuth =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/events/aws4_request";
String sesAuth =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/" + region + "/ses/aws4_request";
String sesAuth = SesV2Requests.authFor(region);
String euQueueUrl = given()
.contentType(SQS_CONTENT_TYPE)
@@ -39,8 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesExportJobV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-west-2/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("eu-west-2");
private static final String SENDER = "export-sender@example.com";
private static long midnightToday() {
@@ -28,10 +28,8 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesIdentityPagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-south-1/ses/aws4_request";
private static final String OTHER_REGION_AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ap-south-1");
private static final String OTHER_REGION_AUTH = SesV2Requests.authFor("eu-north-1");
private static final String V1_ROOT = "ListIdentitiesResponse.ListIdentitiesResult.";
@Test
@@ -31,8 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesImportJobV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-west-3/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("eu-west-3");
private static final String BUCKET = "ses-import-job-it";
private static final String LIST = "import-job-list";
@@ -24,8 +24,7 @@ import static org.hamcrest.Matchers.not;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesListManagementOptionsV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-west-2/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("us-west-2");
private static final String LIST = "lmo-newsletter";
private static final String FROM = "lmo-sender@floci.test";
@@ -33,8 +33,7 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesMessageInsightsV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-north-1/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("eu-north-1");
private static final String SENDER = "insights-sender@example.com";
private static final String ACCOUNT_A_AUTH =
"AWS4-HMAC-SHA256 Credential=111122223333/20260101/eu-north-1/ses/aws4_request";
@@ -34,8 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
@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 AUTH = SesV2Requests.authFor("sa-east-1");
private static final String SENDER = "metrics-sender@example.com";
private static final long DAY = Duration.ofDays(1).toSeconds();
@@ -28,11 +28,9 @@ import static org.hamcrest.Matchers.nullValue;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesTemplatePagingIntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-southeast-2/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ap-southeast-2");
// A second region holding eleven templates, one more than the default page.
private static final String AUTH_ELEVEN =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-southeast-3/ses/aws4_request";
private static final String AUTH_ELEVEN = SesV2Requests.authFor("ap-southeast-3");
private static final String V1_ROOT = "ListTemplatesResponse.ListTemplatesResult.";
@Test
@@ -505,8 +505,7 @@ class SesTemplateV2IntegrationTest {
// ──────────────── Cross-region isolation ────────────────
private static final String AUTH_EU_WEST_1 =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/eu-west-1/ses/aws4_request";
private static final String AUTH_EU_WEST_1 = SesV2Requests.authFor("eu-west-1");
@Test
@Order(20)
@@ -10,7 +10,7 @@ import org.junit.jupiter.api.TestInstance;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import static io.restassured.RestAssured.given;
import static io.floci.aws.services.ses.SesV2Requests.post;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
@@ -27,8 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class SesTrackingOverridesV2IntegrationTest {
private static final String AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-southeast-4/ses/aws4_request";
private static final String AUTH = SesV2Requests.authFor("ap-southeast-4");
// A sender of its own, verified once below: the identity outlives this class, and other SES
// classes that share the application create their own senders.
private static final String SENDER = "tracking-overrides-sender@floci.test";
@@ -49,7 +48,7 @@ class SesTrackingOverridesV2IntegrationTest {
if (senderVerified) {
return;
}
send("/v2/email/identities", "{\"EmailIdentity\": \"" + SENDER + "\"}").statusCode(200);
post(AUTH, "/v2/email/identities", "{\"EmailIdentity\": \"" + SENDER + "\"}").statusCode(200);
senderVerified = true;
}
@@ -67,7 +66,7 @@ class SesTrackingOverridesV2IntegrationTest {
void sendEmail_acceptsAnOverrideOnRawContent() {
String mime = "From: " + SENDER + "\r\nTo: alice@example.com\r\nSubject: raw\r\n\r\nbody\r\n";
String data = Base64.getEncoder().encodeToString(mime.getBytes(StandardCharsets.UTF_8));
send(SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": "
post(AUTH, SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": "
+ "{\"ToAddresses\": [\"alice@example.com\"]}, \"Content\": {\"Raw\": {\"Data\": \"" + data + "\"}}, "
+ "\"ConfigurationOverrides\": {\"Tracking\": {\"OpenTrackingEnabled\": \"ENABLED\"}}}")
.statusCode(200);
@@ -104,20 +103,20 @@ class SesTrackingOverridesV2IntegrationTest {
+ "[\"alice@example.com\"]}, " + SIMPLE + ", \"EmailTags\": [{\"Name\": \"a b\", \"Value\": \"v\"}], "
+ "\"ConfigurationSetName\": \"tracking-missing\", "
+ "\"ConfigurationOverrides\": {\"Tracking\": {\"OpenTrackingEnabled\": \"%s\"}}}";
send(SEND, request.formatted("yes")).statusCode(400)
post(AUTH, SEND, request.formatted("yes")).statusCode(400)
.body("message", equalTo("1 validation error detected: " + OPEN_ENUM));
// With a valid value the same request fails on the tags or the set, so the order above is real.
send(SEND, request.formatted("ENABLED")).statusCode(not(200))
post(AUTH, SEND, request.formatted("ENABLED")).statusCode(not(200))
.body("message", not(containsString("configurationOverrides")));
}
@Test
void sendBulkEmail_acceptsAValidOverride_andRefusesAnInvalidOne() {
send(BULK, bulkBody("{\"Tracking\": {\"OpenTrackingEnabled\": \"DISABLED\"}}")).statusCode(200)
post(AUTH, BULK, bulkBody("{\"Tracking\": {\"OpenTrackingEnabled\": \"DISABLED\"}}")).statusCode(200)
.body("BulkEmailEntryResults", hasSize(2))
.body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS"));
String recipient = "refused-bulk@tracking.test";
send(BULK, bulkBody("{\"Tracking\": {\"ClickTrackingEnabled\": \"on\"}}", recipient)).statusCode(400)
post(AUTH, BULK, bulkBody("{\"Tracking\": {\"ClickTrackingEnabled\": \"on\"}}", recipient)).statusCode(400)
.body("message", equalTo("1 validation error detected: " + CLICK_ENUM));
assertNothingSentTo(recipient);
}
@@ -127,7 +126,7 @@ class SesTrackingOverridesV2IntegrationTest {
}
private static ValidatableResponse sendWith(String overrides, String recipient) {
return send(SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": {\"ToAddresses\": "
return post(AUTH, SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": {\"ToAddresses\": "
+ "[\"" + recipient + "\"]}, " + SIMPLE + ", \"ConfigurationOverrides\": " + overrides + "}");
}
@@ -147,9 +146,4 @@ class SesTrackingOverridesV2IntegrationTest {
private static void assertNothingSentTo(String recipient) {
assertTrue(SesMailbox.messagesTo(recipient).isEmpty(), "a refused send recorded a message to " + recipient);
}
private static ValidatableResponse send(String path, String body) {
return given().contentType("application/json").header("Authorization", AUTH).body(body)
.when().post(path).then();
}
}
@@ -1267,8 +1267,7 @@ class SesV2IntegrationTest {
// Send from ap-northeast-1
given()
.contentType("application/json")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-northeast-1/ses/aws4_request")
.header("Authorization", SesV2Requests.authFor("ap-northeast-1"))
.body("""
{
"FromEmailAddress": "multi@example.com",