feat(ses): add SES V2 configuration set event destination operations (#1079)

* feat(ses): add SES V2 configuration set event destination operations

Implement CreateConfigurationSetEventDestination, GetConfigurationSetEventDestinations,
UpdateConfigurationSetEventDestination, and DeleteConfigurationSetEventDestination on
the SES V2 REST JSON API. Event destinations are stored on the configuration set;
validation and error messages mirror the real AWS SESv2 responses. Includes REST
integration, service unit, and AWS SDK compatibility tests.

* fix(ses): return defensive copy from event destination getter and preserve order on update

GetConfigurationSetEventDestinations now returns an unmodifiable copy so callers
cannot mutate stored state outside the service. UpdateConfigurationSetEventDestination
replaces the destination in place (by index) instead of remove+add, keeping the
list order stable when a configuration set has multiple event destinations.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-29 18:08:59 -05:00
1 parent 2581837881
commit bd6ec2d5c6
14 files changed
+1190 -2

No files matched your search

@@ -0,0 +1,373 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
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 static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
/**
* Integration tests for SES V2 ConfigurationSetEventDestination endpoints under
* /v2/email/configuration-sets/{name}/event-destinations.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class SesConfigurationSetEventDestinationV2IntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String CS = "v2-cs-ed";
@Test
@Order(1)
void createConfigurationSet() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{\"ConfigurationSetName\": \"" + CS + "\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
}
@Test
@Order(2)
void createEventDestination() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-sns",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND", "BOUNCE"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:ses-events"}
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + CS + "/event-destinations")
.then()
.statusCode(200);
}
@Test
@Order(3)
void getEventDestinations_returnsRoundTrip() {
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-sns"))
.body("EventDestinations[0].Enabled", equalTo(true))
.body("EventDestinations[0].MatchingEventTypes", hasItem("SEND"))
.body("EventDestinations[0].MatchingEventTypes", hasItem("BOUNCE"))
.body("EventDestinations[0].SnsDestination.TopicArn",
equalTo("arn:aws:sns:us-east-1:000000000000:ses-events"));
}
@Test
@Order(4)
void createEventDestination_duplicateRejected() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-sns",
"EventDestination": {
"MatchingEventTypes": ["SEND"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:dup"}
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + CS + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("AlreadyExistsException"))
.body("message", equalTo(
"An event destination with name <ed-sns> already exists for configuration set <v2-cs-ed>."));
}
@Test
@Order(5)
void createEventDestination_unknownConfigSetReturns404() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-x",
"EventDestination": {
"MatchingEventTypes": ["SEND"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:ghost"}
}
}
""")
.when()
.post("/v2/email/configuration-sets/v2-cs-ghost/event-destinations")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("Configuration set <v2-cs-ghost> does not exist."));
}
@Test
@Order(6)
void createEventDestination_emptyMatchingEventTypes_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-empty",
"EventDestination": {
"MatchingEventTypes": [],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:x"}
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + CS + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(7)
void createEventDestination_noDestination_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "ed-nodest",
"EventDestination": {
"MatchingEventTypes": ["SEND"]
}
}
""")
.when()
.post("/v2/email/configuration-sets/" + CS + "/event-destinations")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"));
}
@Test
@Order(8)
void updateEventDestination_replacesDefinition() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"Enabled": false,
"MatchingEventTypes": ["DELIVERY"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:ses-events-2"}
}
}
""")
.when()
.put("/v2/email/configuration-sets/" + CS + "/event-destinations/ed-sns")
.then()
.statusCode(200);
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-sns"))
.body("EventDestinations[0].Enabled", equalTo(false))
.body("EventDestinations[0].MatchingEventTypes", hasItem("DELIVERY"))
.body("EventDestinations[0].SnsDestination.TopicArn",
equalTo("arn:aws:sns:us-east-1:000000000000:ses-events-2"));
}
@Test
@Order(9)
void updateEventDestination_unknownReturns404() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"MatchingEventTypes": ["SEND"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:x"}
}
}
""")
.when()
.put("/v2/email/configuration-sets/" + CS + "/event-destinations/ed-ghost")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo(
"An event destination with name <ed-ghost> does not exist for configuration set <v2-cs-ed>."));
}
@Test
@Order(10)
void deleteEventDestination() {
given()
.header("Authorization", AUTH_HEADER)
.when()
.delete("/v2/email/configuration-sets/" + CS + "/event-destinations/ed-sns")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + CS + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(0));
}
@Test
@Order(11)
void deleteEventDestination_unknownReturns404() {
given()
.header("Authorization", AUTH_HEADER)
.when()
.delete("/v2/email/configuration-sets/" + CS + "/event-destinations/ed-ghost")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo(
"An event destination with name <ed-ghost> does not exist for configuration set <v2-cs-ed>."));
}
@Test
@Order(12)
void getEventDestinations_unknownConfigSetReturns404() {
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/v2-cs-ghost/event-destinations")
.then()
.statusCode(404)
.body("__type", equalTo("NotFoundException"))
.body("message", equalTo("Configuration set <v2-cs-ghost> does not exist."));
}
@Test
@Order(13)
void updateEventDestination_invalidName_returns400() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"MatchingEventTypes": ["SEND"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:x"}
}
}
""")
.when()
.put("/v2/email/configuration-sets/" + CS + "/event-destinations/bad.name")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("Invalid event destination name <bad.name>: only alphanumeric ASCII "
+ "characters, '_', and '-' are allowed."));
}
@Test
@Order(14)
void deleteEventDestination_invalidName_returns400() {
given()
.header("Authorization", AUTH_HEADER)
.when()
.delete("/v2/email/configuration-sets/" + CS + "/event-destinations/bad.name")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("Invalid event destination name <bad.name>: only alphanumeric ASCII "
+ "characters, '_', and '-' are allowed."));
}
@Test
@Order(15)
void updateEventDestination_preservesOrderAmongMultiple() {
String cs = "v2-cs-ed-multi";
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{\"ConfigurationSetName\": \"" + cs + "\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
for (String n : new String[]{"ed-a", "ed-b"}) {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestinationName": "%s",
"EventDestination": {
"Enabled": true,
"MatchingEventTypes": ["SEND"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:%s"}
}
}
""".formatted(n, n))
.when()
.post("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200);
}
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EventDestination": {
"Enabled": false,
"MatchingEventTypes": ["DELIVERY"],
"SnsDestination": {"TopicArn": "arn:aws:sns:us-east-1:000000000000:ed-a-updated"}
}
}
""")
.when()
.put("/v2/email/configuration-sets/" + cs + "/event-destinations/ed-a")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/configuration-sets/" + cs + "/event-destinations")
.then()
.statusCode(200)
.body("EventDestinations", hasSize(2))
.body("EventDestinations[0].Name", equalTo("ed-a"))
.body("EventDestinations[1].Name", equalTo("ed-b"))
.body("EventDestinations[0].Enabled", equalTo(false))
.body("EventDestinations[0].SnsDestination.TopicArn",
equalTo("arn:aws:sns:us-east-1:000000000000:ed-a-updated"));
}
}
@@ -0,0 +1,156 @@
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.EventDestination;
import io.github.hectorvent.floci.services.ses.model.PinpointDestination;
import io.github.hectorvent.floci.services.ses.model.SnsDestination;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
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.
*/
class SesServiceEventDestinationTest {
private static EventDestination withSns(List<String> matchingEventTypes) {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(matchingEventTypes);
SnsDestination sns = new SnsDestination();
sns.setTopicArn("arn:aws:sns:us-east-1:000000000000:ses-events");
ed.setSnsDestination(sns);
return ed;
}
@Test
void validName_passes() {
assertDoesNotThrow(() -> SesService.validateEventDestinationName("my-dest_1"));
}
@Test
void blankName_throwsInvalidParameterValue() {
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestinationName(" "));
assertEquals("InvalidParameterValue", ex.getErrorCode());
}
@Test
void invalidNameCharacters_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestinationName("bad name!"));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Invalid event destination name <bad name!>: only alphanumeric ASCII characters, "
+ "'_', and '-' are allowed.", ex.getMessage());
}
@Test
void nameTooLong_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestinationName("a".repeat(65)));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Event destination name cannot exceed 64 characters.", ex.getMessage());
}
@Test
void validDestination_passes() {
assertDoesNotThrow(() -> SesService.validateEventDestination(withSns(List.of("SEND", "BOUNCE"))));
}
@Test
void emptyMatchingEventTypes_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(withSns(List.of())));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("At least one event type must be specified.", ex.getMessage());
}
@Test
void invalidEventType_throws() {
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(withSns(List.of("SEND", "NOPE"))));
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());
}
@Test
void zeroDestinations_throws() {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(ed));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Event destination is not provided.", ex.getMessage());
}
@Test
void multipleDestinations_throws() {
EventDestination ed = withSns(List.of("SEND"));
ed.setCloudWatchDestination(cloudWatch());
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(ed));
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.",
ex.getMessage());
}
@Test
void cloudWatchEmptyDimensions_throws() {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
ed.setCloudWatchDestination(new CloudWatchDestination());
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(ed));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("CloudWatch metrics dimension configuration list cannot be empty.", ex.getMessage());
}
@Test
void validCloudWatchDestination_passes() {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
ed.setCloudWatchDestination(cloudWatch());
assertDoesNotThrow(() -> SesService.validateEventDestination(ed));
}
@Test
void pinpointNullArn_throws() {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
ed.setPinpointDestination(new PinpointDestination());
AwsException ex = assertThrows(AwsException.class,
() -> SesService.validateEventDestination(ed));
assertEquals("InvalidParameterValue", ex.getErrorCode());
assertEquals("Invalid Pinpoint application ARN provided: null.", ex.getMessage());
}
@Test
void validPinpointDestination_passes() {
EventDestination ed = new EventDestination();
ed.setMatchingEventTypes(List.of("SEND"));
PinpointDestination pp = new PinpointDestination();
pp.setApplicationArn("arn:aws:mobiletargeting:us-east-1:000000000000:apps/abc");
ed.setPinpointDestination(pp);
assertDoesNotThrow(() -> SesService.validateEventDestination(ed));
}
private static CloudWatchDestination cloudWatch() {
CloudWatchDestination cw = new CloudWatchDestination();
CloudWatchDimensionConfiguration dim = new CloudWatchDimensionConfiguration();
dim.setDimensionName("floci-dim");
dim.setDimensionValueSource("MESSAGE_TAG");
dim.setDefaultDimensionValue("default");
cw.setDimensionConfigurations(List.of(dim));
return cw;
}
}