fix(ses): validate EventBridge default bus ARNs (#4677)

* fix(ses): validate EventBridge default bus ARNs

Signed-off-by: boulea7 <zln1905391059@163.com>

* fix(ses): reject EventBridge bus account and Region mismatches

Signed-off-by: boulea7 <zln1905391059@163.com>

---------

Signed-off-by: boulea7 <zln1905391059@163.com>
This commit is contained in:
Langning Zhang authored and GitHub committed 2026-09-30 10:00:19 -04:00
1 parent 8ff1eae121
commit d267ba3a9d
8 files changed
+652 -34

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.ses.model.CloudWatchDestination;
import io.github.hectorvent.floci.services.ses.model.CloudWatchDimensionConfiguration;
import io.github.hectorvent.floci.services.ses.model.EventBridgeDestination;
import io.github.hectorvent.floci.services.ses.model.EventDestination;
import io.github.hectorvent.floci.services.ses.model.KinesisFirehoseDestination;
import io.github.hectorvent.floci.services.ses.model.PinpointDestination;
@@ -18,11 +19,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Unit tests for the static input validation behind the SES V2
* ConfigurationSetEventDestination operations. These fail-closed paths are
* pure logic and live here rather than in the integration test. Error
* messages mirror the real AWS SESv2 wire responses.
* pure logic and live here rather than in the integration test. Protocol
* integration tests cover the AWS-modeled error responses.
*/
class SesConfigurationSetEventDestinationTest {
private static final String ACCOUNT_ID = "000000000000";
private static final String REGION = "us-east-1";
private static EventDestination withSns(List<String> matchingEventTypes) {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(matchingEventTypes);
@@ -63,13 +67,14 @@ class SesConfigurationSetEventDestinationTest {
@Test
void validDestination_passes() {
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(withSns(List.of("SEND", "BOUNCE"))));
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(
withSns(List.of("SEND", "BOUNCE")), ACCOUNT_ID, REGION));
}
@Test
void emptyMatchingEventTypes_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(withSns(List.of())));
() -> SesConfigurationSetService.validateEventDestination(withSns(List.of()), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("At least one event type must be specified.", ex.getMessage());
}
@@ -77,7 +82,8 @@ class SesConfigurationSetEventDestinationTest {
@Test
void invalidEventType_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(withSns(List.of("SEND", "NOPE"))));
() -> SesConfigurationSetService.validateEventDestination(
withSns(List.of("SEND", "NOPE")), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Invalid event type: NOPE. Valid values are [SEND, REJECT, BOUNCE, COMPLAINT, "
+ "DELIVERY, OPEN, CLICK, RENDERING_FAILURE, DELIVERY_DELAY, SUBSCRIPTION].", ex.getMessage());
@@ -88,7 +94,7 @@ class SesConfigurationSetEventDestinationTest {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Event destination is not provided.", ex.getMessage());
}
@@ -98,7 +104,7 @@ class SesConfigurationSetEventDestinationTest {
EventDestination ed = withSns(List.of("SEND"));
ed.setCloudWatchDestination(cloudWatch());
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Please provide only one destination with each request. Either a Firehose Destination "
+ "or a Cloudwatch Destination or an SNS Destination or an EventBridge Destination.",
@@ -111,7 +117,7 @@ class SesConfigurationSetEventDestinationTest {
ed.setMatchingEventTypes(List.of("SEND"));
ed.setCloudWatchDestination(new CloudWatchDestination());
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("CloudWatch metrics dimension configuration list cannot be empty.", ex.getMessage());
}
@@ -121,7 +127,7 @@ class SesConfigurationSetEventDestinationTest {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
ed.setCloudWatchDestination(cloudWatch());
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed));
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
@@ -130,7 +136,7 @@ class SesConfigurationSetEventDestinationTest {
ed.setMatchingEventTypes(List.of("SEND"));
ed.setPinpointDestination(new PinpointDestination());
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Invalid Pinpoint application ARN provided: null.", ex.getMessage());
}
@@ -142,7 +148,7 @@ class SesConfigurationSetEventDestinationTest {
PinpointDestination pp = new PinpointDestination();
pp.setApplicationArn("arn:aws:mobiletargeting:us-east-1:000000000000:apps/abc");
ed.setPinpointDestination(pp);
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed));
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
@@ -153,7 +159,7 @@ class SesConfigurationSetEventDestinationTest {
sns.setTopicArn("");
ed.setSnsDestination(sns);
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("SnsDestination requires a non-blank TopicArn.", ex.getMessage());
}
@@ -164,7 +170,7 @@ class SesConfigurationSetEventDestinationTest {
ed.setMatchingEventTypes(List.of("SEND"));
ed.setSnsDestination(new SnsDestination()); // TopicArn left null
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("SnsDestination requires a non-blank TopicArn.", ex.getMessage());
}
@@ -178,7 +184,7 @@ class SesConfigurationSetEventDestinationTest {
// DeliveryStreamArn left null
ed.setKinesisFirehoseDestination(fh);
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("KinesisFirehoseDestination requires both IamRoleArn and DeliveryStreamArn.",
ex.getMessage());
@@ -192,7 +198,8 @@ class SesConfigurationSetEventDestinationTest {
fh.setDeliveryStreamArn("arn:aws:firehose:us-east-1:000000000000:deliverystream/ses");
// IamRoleArn left null
ed.setKinesisFirehoseDestination(fh);
assertThrows(AwsException.class, () -> SesConfigurationSetService.validateEventDestination(ed));
assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
@@ -203,7 +210,7 @@ class SesConfigurationSetEventDestinationTest {
fh.setIamRoleArn("arn:aws:iam::000000000000:role/ses-firehose");
fh.setDeliveryStreamArn("arn:aws:firehose:us-east-1:000000000000:deliverystream/ses");
ed.setKinesisFirehoseDestination(fh);
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed));
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
@@ -218,7 +225,7 @@ class SesConfigurationSetEventDestinationTest {
cw.setDimensionConfigurations(List.of(dim));
ed.setCloudWatchDestination(cw);
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed));
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
// Member index 1-based for callers, included in the error message.
assertEquals("CloudWatchDestination dimension configurations require "
@@ -237,7 +244,8 @@ class SesConfigurationSetEventDestinationTest {
dim.setDefaultDimensionValue("default");
cw.setDimensionConfigurations(List.of(dim));
ed.setCloudWatchDestination(cw);
assertThrows(AwsException.class, () -> SesConfigurationSetService.validateEventDestination(ed));
assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
@@ -251,7 +259,97 @@ class SesConfigurationSetEventDestinationTest {
// DefaultDimensionValue left null
cw.setDimensionConfigurations(List.of(dim));
ed.setCloudWatchDestination(cw);
assertThrows(AwsException.class, () -> SesConfigurationSetService.validateEventDestination(ed));
assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(ed, ACCOUNT_ID, REGION));
}
@Test
void eventBridgeDefaultBusCommercialPartition_passes() {
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("arn:aws:events:us-east-1:000000000000:event-bus/default"), ACCOUNT_ID, REGION));
}
@Test
void eventBridgeDefaultBusNonCommercialPartition_passes() {
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("arn:aws-cn:events:cn-north-1:000000000000:event-bus/default"),
ACCOUNT_ID, "cn-north-1"));
}
@Test
void eventBridgeDefaultBusMatchingNonDefaultRequestScope_passes() {
assertDoesNotThrow(() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("arn:aws:events:eu-west-1:111111111111:event-bus/default"),
"111111111111", "eu-west-1"));
}
@Test
void eventBridgeMismatchedAccount_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("arn:aws:events:us-east-1:111111111111:event-bus/default"),
ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
}
@Test
void eventBridgeMismatchedRegion_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("arn:aws:events:us-west-2:000000000000:event-bus/default"),
ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
}
@Test
void eventBridgeNullBusArn_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(withEventBridge(null), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
@Test
void eventBridgeBlankBusArn_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(withEventBridge(" "), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
@Test
void eventBridgeCustomBus_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(
withEventBridge(
"arn:aws:events:us-east-1:000000000000:event-bus/custom-bus"), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
@Test
void eventBridgeWrongServiceWithDefaultSuffix_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(
withEventBridge(
"arn:aws:sns:us-east-1:000000000000:event-bus/default"), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
@Test
void eventBridgeMalformedArn_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesConfigurationSetService.validateEventDestination(
withEventBridge("not-an-arn"), ACCOUNT_ID, REGION));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
private static EventDestination withEventBridge(String busArn) {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
EventBridgeDestination eventBridge = new EventBridgeDestination();
eventBridge.setEventBusArn(busArn);
ed.setEventBridgeDestination(eventBridge);
return ed;
}
private static CloudWatchDestination cloudWatch() {
@@ -5,11 +5,16 @@ 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 org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.nullValue;
/**
* Integration tests for SES V2 ConfigurationSetEventDestination endpoints under
@@ -24,6 +29,11 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
private static final String CS = "v2-cs-ed";
private static final String SCOPED_AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=111111111111/20260101/us-west-2/ses/aws4_request";
private static final String SCOPED_DEFAULT_BUS_ARN =
"arn:aws:events:us-west-2:111111111111:event-bus/default";
@Test
@Order(1)
void createConfigurationSet() {
@@ -370,4 +380,362 @@ class SesConfigurationSetEventDestinationV2IntegrationTest {
.body("EventDestinations[0].SnsDestination.TopicArn",
equalTo("arn:aws:sns:us-east-1:000000000000:ed-a-updated"));
}
@Test
@Order(16)
void createEventBridgeConfigurationSet() {
String cs = "v2-cs-ed-ebus";
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{\"ConfigurationSetName\": \"" + cs + "\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
}
@Test
@Order(17)
void createEventDestination_eventBridgeCustomBusRejected() {
String cs = "v2-cs-ed-ebus";
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-eb-custom",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {
"EventBusArn": "arn:aws:events:us-east-1:000000000000:event-bus/custom-bus"
}
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
// The rejected destination must not have been stored.
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(0));
}
@Test
@Order(18)
void updateEventDestination_eventBridgeCustomBusRejectedAndDefaultPreserved() {
String cs = "v2-cs-ed-ebus";
String defaultBusArn = "arn:aws:events:us-east-1:000000000000:event-bus/default";
// Seed a destination on the default event bus.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-eb-default",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(defaultBusArn))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200);
// An otherwise identical ARN naming a custom event bus must be rejected.
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {
"EventBusArn": "arn:aws:events:us-east-1:000000000000:event-bus/custom-bus"
}
}
}
""")
.when()
.put("/v2/email/configuration-sets/" + cs + "/event-destinations/ed-eb-default")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
// The stored destination must still point at the default event bus.
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(1))
.body("EventDestinations[0].Name", equalTo("ed-eb-default"))
.body("EventDestinations[0].EventBridgeDestination.EventBusArn",
equalTo(defaultBusArn));
}
@Test
@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 cnDefaultBusArn =
"arn:aws-cn:events:cn-north-1:000000000000:event-bus/default";
given()
.contentType("application/json")
.header("Authorization", cnAuthHeader)
.body("{\"ConfigurationSetName\": \"" + cs + "\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.contentType("application/json")
.header("Authorization", cnAuthHeader)
.body("""
{
"EventDestinationName": "ed-eb-default-cn",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(cnDefaultBusArn))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200);
given()
.header("Authorization", cnAuthHeader)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations.find { it.Name == 'ed-eb-default-cn' }"
+ ".EventBridgeDestination.EventBusArn",
equalTo(cnDefaultBusArn));
}
@Test
@Order(20)
void createEventDestination_eventBridgeBlankBusArnRejected() {
String cs = "v2-cs-ed-ebus";
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-eb-blank",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": ""}
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@ParameterizedTest(name = "{0}")
@CsvSource({
"empty-fields,arn::events:::event-bus/default",
"missing-partition,arn::events:us-east-1:000000000000:event-bus/default",
"missing-region,arn:aws:events::000000000000:event-bus/default",
"missing-account,arn:aws:events:us-east-1::event-bus/default",
"invalid-partition,arn:example:events:us-east-1:000000000000:event-bus/default",
"short-account,arn:aws:events:us-east-1:123:event-bus/default",
"mismatched-account,arn:aws:events:us-east-1:111111111111:event-bus/default",
"mismatched-region,arn:aws:events:us-west-2:000000000000:event-bus/default"
})
@Order(21)
void createEventDestination_eventBridgeInvalidArnRejected(String caseName, String busArn) {
String cs = "v2-cs-ed-ebus";
String destinationName = "ed-eb-invalid-create-" + caseName;
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "%s",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(destinationName, busArn))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations.find { it.Name == '" + destinationName + "' }", nullValue());
}
@ParameterizedTest(name = "{0}")
@CsvSource({
"empty-fields,arn::events:::event-bus/default",
"missing-partition,arn::events:us-east-1:000000000000:event-bus/default",
"missing-region,arn:aws:events::000000000000:event-bus/default",
"missing-account,arn:aws:events:us-east-1::event-bus/default",
"invalid-partition,arn:example:events:us-east-1:000000000000:event-bus/default",
"short-account,arn:aws:events:us-east-1:123:event-bus/default",
"mismatched-account,arn:aws:events:us-east-1:111111111111:event-bus/default",
"mismatched-region,arn:aws:events:us-west-2:000000000000:event-bus/default"
})
@Order(22)
void updateEventDestination_eventBridgeInvalidArnRejectedAndDefaultPreserved(
String caseName, String busArn) {
String cs = "v2-cs-ed-ebus";
String destinationName = "ed-eb-invalid-update-" + caseName;
String defaultBusArn = "arn:aws:events:us-east-1:000000000000:event-bus/default";
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "%s",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(destinationName, defaultBusArn))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200);
try {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"Enabled": false,
"MatchingEventTypes": ["BOUNCE"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(busArn))
.when()
.put("/v2/email/configuration-sets/" + cs + "/event-destinations/" + destinationName)
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations.find { it.Name == '" + destinationName + "' }"
+ ".Enabled", equalTo(true))
.body("EventDestinations.find { it.Name == '" + destinationName + "' }"
+ ".MatchingEventTypes", equalTo(List.of("SEND")))
.body("EventDestinations.find { it.Name == '" + destinationName + "' }"
+ ".EventBridgeDestination.EventBusArn", equalTo(defaultBusArn));
} finally {
given()
.header("Authorization", AUTH_HEADER)
.when()
.delete("/v2/email/configuration-sets/" + cs + "/event-destinations/" + destinationName)
.then()
.statusCode(200);
}
}
@Test
@Order(23)
void eventBridgeDefaultBusMatchingNonDefaultRequestScopeSucceeds() {
String cs = "v2-cs-ed-request-scope";
given()
.contentType("application/json")
.header("Authorization", SCOPED_AUTH_HEADER)
.body("{\"ConfigurationSetName\": \"" + cs + "\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
given()
.contentType("application/json")
.header("Authorization", SCOPED_AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-eb-scoped-default",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(SCOPED_DEFAULT_BUS_ARN))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200);
given()
.contentType("application/json")
.header("Authorization", SCOPED_AUTH_HEADER)
.body("""
{
"EventDestination": {
"Enabled": false,
"MatchingEventTypes": ["BOUNCE"],
"EventBridgeDestination": {"EventBusArn": "%s"}
}
}
""".formatted(SCOPED_DEFAULT_BUS_ARN))
.when()
.put("/v2/email/configuration-sets/" + cs + "/event-destinations/ed-eb-scoped-default")
.then()
.statusCode(200);
given()
.header("Authorization", SCOPED_AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(1))
.body("EventDestinations[0].Enabled", equalTo(false))
.body("EventDestinations[0].MatchingEventTypes", equalTo(List.of("BOUNCE")))
.body("EventDestinations[0].EventBridgeDestination.EventBusArn",
equalTo(SCOPED_DEFAULT_BUS_ARN));
}
}
@@ -21,6 +21,7 @@ import java.time.Instant;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -103,6 +104,35 @@ class SesEventPublisherTest {
assertEquals(arn, arr.get(0).asText());
}
@Test
void publishEventBridge_failedEntries_doesNotThrow() {
when(eventBridgeService.putEvents(any(), anyString()))
.thenReturn(new EventBridgeService.PutEventsResult(1, List.of(Map.of("ErrorCode", "InternalFailure"))));
// A failed PutEvents entry is logged by the publisher but must not propagate
// back into the SES send path.
assertDoesNotThrow(() -> publisher.publish(
configurationSetWithEventBridgeDestination(DEFAULT_BUS_ARN),
SesRecipientEvent.of("SEND", Cause.SIMULATOR, List.of()), "msg-2", null, null,
"000000000000", "subj", List.of("to@example.com"), null, null,
List.of("to@example.com"), null, null, Instant.now(), "us-east-1"));
verify(eventBridgeService).putEvents(any(), anyString());
}
@Test
void publishEventBridge_putEventsThrows_doesNotThrow() {
when(eventBridgeService.putEvents(any(), anyString()))
.thenThrow(new RuntimeException("event bridge unavailable"));
// Downstream delivery failures must never fail the email send.
assertDoesNotThrow(() -> publisher.publish(
configurationSetWithEventBridgeDestination(DEFAULT_BUS_ARN),
SesRecipientEvent.of("SEND", Cause.SIMULATOR, List.of()), "msg-3", null, null,
"000000000000", "subj", List.of("to@example.com"), null, null,
List.of("to@example.com"), null, null, Instant.now(), "us-east-1"));
verify(eventBridgeService).putEvents(any(), anyString());
}
@SuppressWarnings("unchecked")
private Map<String, Object> captureSingleEntry() {
ArgumentCaptor<List<Map<String, Object>>> captor =
@@ -25,6 +25,7 @@ import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -957,7 +958,7 @@ class SesEventPublishingV2IntegrationTest {
@Test
@Order(22)
void eventBridge_unknownBusName_sendStillSucceeds() {
void eventBridge_unknownBusName_createRejected() {
String csUnknown = "ses-events-eb-cs-unknown";
String bogusBusArn =
"arn:aws:events:us-east-1:000000000000:event-bus/does-not-exist";
@@ -971,6 +972,8 @@ class SesEventPublishingV2IntegrationTest {
.then()
.statusCode(200);
// SES only supports the account default event bus, so a custom bus ARN is
// rejected at create time and never stored.
given()
.contentType("application/json")
.header("Authorization", SES_AUTH)
@@ -987,11 +990,16 @@ class SesEventPublishingV2IntegrationTest {
.when()
.post("/v2/email/configuration-sets/" + csUnknown + "/event-destinations")
.then()
.statusCode(200);
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
// putEvents records a failed entry for an unknown bus but does not throw — SES send
// must still return 200.
sendEmailToConfigSet(csUnknown, "recipient@example.com", "eb-unknown");
given()
.header("Authorization", SES_AUTH)
.when()
.get("/v2/email/configuration-sets/" + csUnknown + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(0));
}
// ============================ CloudWatch =============================