Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): honor ConfigurationSetName on CreateEmailIdentity (v2) (#1812)
Kenshin Okinakacd3588b517c2
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailIdentityConfigurationSetTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailIdentityConfigurationSetTest.javaindex 1892ccf304..65fe10ea48 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailIdentityConfigurationSetTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailIdentityConfigurationSetTest.java@@ -104,4 +104,19 @@ class SesEmailIdentityConfigurationSetTest {.build())).isInstanceOf(NotFoundException.class);}++ @Test+ @Order(4)+ void createEmailIdentity_withConfigurationSet_readsBack() {+ String id = "sdk-cs-oncreate-" + TestFixtures.uniqueName() + "@example.com";+ sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder()+ .emailIdentity(id).configurationSetName(configSet).build());+ try {+ assertThat(sesV2.getEmailIdentity(GetEmailIdentityRequest.builder()+ .emailIdentity(id).build()).configurationSetName())+ .isEqualTo(configSet);+ } finally {+ sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(id).build());+ }+ }}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.javaindex ea4c5bbfee..086cb81c0d 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesController.java@@ -89,21 +89,58 @@ public class SesController {String region = regionResolver.resolveRegion(headers);try {JsonNode request = objectMapper.readTree(body);- String emailIdentity = request.path("EmailIdentity").asText(null);+ JsonNode emailIdentityNode = request.path("EmailIdentity");+ if (!emailIdentityNode.isMissingNode() && !emailIdentityNode.isNull()+ && !emailIdentityNode.isTextual()) {+ // A non-string EmailIdentity is rejected rather than coerced (asText would turn 123+ // into "123"), the same as ConfigurationSetName below.+ throw new AwsException("SerializationException", null, 400);+ }+ String emailIdentity = emailIdentityNode.asText(null);if (emailIdentity == null || emailIdentity.isBlank()) {throw new AwsException("BadRequestException", "EmailIdentity is required.", 400);}+ // ConfigurationSetName must be a String; AWS rejects a non-string, so reject it here too+ // rather than coercing via asText (which would turn 123 into "123"). Floci surfaces this+ // as a 400 SerializationException, rendered as a JSON error body by AwsExceptionMapper.+ JsonNode configSetNode = request.path("ConfigurationSetName");+ String configurationSetName = null;+ if (!configSetNode.isMissingNode() && !configSetNode.isNull()) {+ if (!configSetNode.isTextual()) {+ throw new AwsException("SerializationException", null, 400);+ }+ configurationSetName = configSetNode.textValue();+ }if (sesService.getIdentityVerificationAttributes(emailIdentity, region) != null) {throw new AwsException("AlreadyExistsException","Email identity " + emailIdentity + " already exist.", 400);}+ // Parse Tags up front. parseTagsArray is pure (it only reads the node), so validating the+ // shape before creating the identity keeps the call atomic — a malformed Tags value fails+ // without leaving a half-created identity behind, matching AWS and the ConfigurationSetName+ // pre-check below.+ List<Tag> parsedTags = parseTagsArray(request.path("Tags"));++ // Verified against AWS: a non-existent ConfigurationSetName fails the whole call+ // (NotFoundException) without creating the identity, so validate it before creating.+ // Only the empty string means "no default configuration set" (consistent with the+ // PutEmailIdentityConfigurationSetAttributes path); a whitespace-only name flows through+ // name validation and is rejected as invalid input, rather than being silently ignored.+ boolean hasConfigSet = configurationSetName != null && !configurationSetName.isEmpty();+ if (hasConfigSet) {+ sesService.getConfigurationSet(configurationSetName, region);+ }+Identity identity = emailIdentity.contains("@")? sesService.verifyEmailIdentity(emailIdentity, region): sesService.verifyDomainIdentity(emailIdentity, region);- List<Tag> parsedTags = parseTagsArray(request.path("Tags"));+ if (hasConfigSet) {+ sesService.setEmailIdentityConfigurationSet(emailIdentity, configurationSetName, region);+ }+if (parsedTags != null) {sesService.setIdentityTags(emailIdentity, region, parsedTags);}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesEmailIdentityConfigurationSetV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesEmailIdentityConfigurationSetV2IntegrationTest.javaindex f8b87ffc9d..8760cb9ec8 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesEmailIdentityConfigurationSetV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesEmailIdentityConfigurationSetV2IntegrationTest.java@@ -301,6 +301,111 @@ class SesEmailIdentityConfigurationSetV2IntegrationTest {.body("message", equalTo("Configuration set <" + cs + "> does not exist."));}+ @Test+ @Order(11)+ void createEmailIdentity_withConfigurationSet_surfacesInGet() {+ String cs = "cs-attr-oncreate-cs";+ String id = "[email protected]";+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"ConfigurationSetName\":\"" + cs + "\"}")+ .when().post("/v2/email/configuration-sets").then().statusCode(200);++ // CreateEmailIdentity accepts a ConfigurationSetName and sets it as the identity default.+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"" + id + "\",\"ConfigurationSetName\":\"" + cs + "\"}")+ .when().post("/v2/email/identities").then().statusCode(200);++ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/" + id)+ .then().statusCode(200).body("ConfigurationSetName", equalTo(cs));+ }++ @Test+ @Order(12)+ void createEmailIdentity_withMissingConfigurationSet_returns404AndDoesNotCreate() {+ String id = "[email protected]";+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"" + id + "\",\"ConfigurationSetName\":\"cs-attr-ghost-oncreate\"}")+ .when().post("/v2/email/identities").then().statusCode(404)+ .body("__type", equalTo("NotFoundException"))+ .body("message", equalTo("Configuration set <cs-attr-ghost-oncreate> does not exist."));++ // The identity must not have been created (AWS is atomic on the config-set validation).+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/" + id).then().statusCode(404);+ }++ @Test+ @Order(17)+ void createEmailIdentity_withNonArrayTags_returns400AndDoesNotCreate() {+ String id = "[email protected]";+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"" + id + "\",\"Tags\":\"oops\"}")+ .when().post("/v2/email/identities").then().statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo("Tags must be an array."));++ // Tags is validated before the identity is persisted, so nothing is created.+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/" + id).then().statusCode(404);+ }++ @Test+ @Order(13)+ void createEmailIdentity_withNonStringConfigurationSet_returns400() {+ // ConfigurationSetName is a string; a non-string must be rejected, not coerced.+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"[email protected]\",\"ConfigurationSetName\":123}")+ .when().post("/v2/email/identities").then().statusCode(400)+ .body("__type", equalTo("SerializationException"));+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/[email protected]").then().statusCode(404);+ }++ @Test+ @Order(14)+ void createEmailIdentity_withEmptyConfigurationSet_createsWithoutDefault() {+ // Floci treats an empty-string ConfigurationSetName as "no default configuration set"+ // (consistent with the PutEmailIdentityConfigurationSetAttributes path). This is a deliberate+ // deviation from AWS, which stores "" verbatim and echoes it back; Floci keeps the two paths+ // aligned instead.+ String id = "[email protected]";+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"" + id + "\",\"ConfigurationSetName\":\"\"}")+ .when().post("/v2/email/identities").then().statusCode(200);+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/" + id).then().statusCode(200)+ .body("$", org.hamcrest.Matchers.not(org.hamcrest.Matchers.hasKey("ConfigurationSetName")));+ }++ @Test+ @Order(15)+ void createEmailIdentity_withWhitespaceConfigurationSet_returns400AndDoesNotCreate() {+ // A whitespace-only name is not "absent": it flows through name validation and is rejected+ // as invalid input (the same 400 the Put path yields), rather than being silently ignored.+ String id = "[email protected]";+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":\"" + id + "\",\"ConfigurationSetName\":\" \"}")+ .when().post("/v2/email/identities").then().statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo("ConfigurationSetName is required."));+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/" + id).then().statusCode(404);+ }++ @Test+ @Order(16)+ void createEmailIdentity_withNonStringEmailIdentity_returns400() {+ // EmailIdentity is a string; a non-string must be rejected (not coerced into "123"), the same+ // as a non-string ConfigurationSetName.+ given().contentType("application/json").header("Authorization", SES_AUTH)+ .body("{\"EmailIdentity\":123}")+ .when().post("/v2/email/identities").then().statusCode(400)+ .body("__type", equalTo("SerializationException"));+ given().header("Authorization", SES_AUTH)+ .when().get("/v2/email/identities/123").then().statusCode(404);+ }+private void drainQueue() {for (int i = 0; i < 5; i++) {Response r = given().contentType(JSON_10).header("Authorization", SQS_AUTH)