Light, fluffy, and always free - The AWS Local Emulator alternative
feat(ses): extend tag endpoints to contact lists, custom verification email templates, and dedicated IP pools (#2589)
Kenshin Okinakac7cd78e3b366
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTagResourceTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTagResourceTest.javaindex e068d88607..9d4c610b8c 100644--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTagResourceTest.java+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesTagResourceTest.java@@ -10,12 +10,20 @@ import org.junit.jupiter.api.TestMethodOrder;import software.amazon.awssdk.services.sesv2.SesV2Client;import software.amazon.awssdk.services.sesv2.model.CreateConfigurationSetRequest;+import software.amazon.awssdk.services.sesv2.model.CreateContactListRequest;+import software.amazon.awssdk.services.sesv2.model.CreateCustomVerificationEmailTemplateRequest;+import software.amazon.awssdk.services.sesv2.model.CreateDedicatedIpPoolRequest;import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;import software.amazon.awssdk.services.sesv2.model.CreateEmailTemplateRequest;import software.amazon.awssdk.services.sesv2.model.DeleteConfigurationSetRequest;+import software.amazon.awssdk.services.sesv2.model.DeleteContactListRequest;+import software.amazon.awssdk.services.sesv2.model.DeleteCustomVerificationEmailTemplateRequest;+import software.amazon.awssdk.services.sesv2.model.DeleteDedicatedIpPoolRequest;import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;import software.amazon.awssdk.services.sesv2.model.DeleteEmailTemplateRequest;import software.amazon.awssdk.services.sesv2.model.EmailTemplateContent;+import software.amazon.awssdk.services.sesv2.model.GetContactListRequest;+import software.amazon.awssdk.services.sesv2.model.GetContactListResponse;import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityRequest;import software.amazon.awssdk.services.sesv2.model.GetEmailIdentityResponse;import software.amazon.awssdk.services.sesv2.model.GetEmailTemplateRequest;@@ -43,6 +51,13 @@ class SesTagResourceTest {private static String templateArn;private static String identityValue;private static String identityArn;+ private static String contactListName;+ private static String contactListArn;+ private static String cvetFrom;+ private static String cvetName;+ private static String cvetArn;+ private static String poolName;+ private static String poolArn;@BeforeAllstatic void setup() {@@ -54,6 +69,13 @@ class SesTagResourceTest {templateArn = "arn:aws:ses:us-east-1:000000000000:template/" + templateName;identityValue = "sdk-tag-id-" + suffix + "@example.com";identityArn = "arn:aws:ses:us-east-1:000000000000:identity/" + identityValue;+ contactListName = "sdk-tag-cl-" + suffix;+ contactListArn = "arn:aws:ses:us-east-1:000000000000:contact-list/" + contactListName;+ cvetFrom = "sdk-tag-cvet-sender-" + suffix + "@example.com";+ cvetName = "sdk-tag-cvet-" + suffix;+ cvetArn = "arn:aws:ses:us-east-1:000000000000:custom-verification-email-template/" + cvetName;+ poolName = "sdk-tag-pool-" + suffix;+ poolArn = "arn:aws:ses:us-east-1:000000000000:dedicated-ip-pool/" + poolName;sesV2.createConfigurationSet(CreateConfigurationSetRequest.builder().configurationSetName(configSetName)@@ -75,6 +97,32 @@ class SesTagResourceTest {sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(identityValue).build());} catch (Exception ignored) {}+ // Freeing the one-contact-list-per-account slot matters for later test classes; the+ // others are best-effort tidiness. Log failures so a real problem is diagnosable.+ try {+ sesV2.deleteContactList(DeleteContactListRequest.builder()+ .contactListName(contactListName).build());+ } catch (Exception e) {+ System.out.println("Cleanup: failed to delete contact list " + contactListName + ": " + e.getMessage());+ }+ try {+ sesV2.deleteCustomVerificationEmailTemplate(DeleteCustomVerificationEmailTemplateRequest.builder()+ .templateName(cvetName).build());+ } catch (Exception e) {+ System.out.println("Cleanup: failed to delete template " + cvetName + ": " + e.getMessage());+ }+ try {+ sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder()+ .emailIdentity(cvetFrom).build());+ } catch (Exception e) {+ System.out.println("Cleanup: failed to delete identity " + cvetFrom + ": " + e.getMessage());+ }+ try {+ sesV2.deleteDedicatedIpPool(DeleteDedicatedIpPoolRequest.builder()+ .poolName(poolName).build());+ } catch (Exception e) {+ System.out.println("Cleanup: failed to delete pool " + poolName + ": " + e.getMessage());+ }sesV2.close();}}@@ -245,4 +293,114 @@ class SesTagResourceTest {assertThat(afterUntag.tags()).hasSize(1);assertThat(afterUntag.tags().get(0).key()).isEqualTo("owner");}++ @Test+ @Order(30)+ void contactList_createWithTags_visibleViaListTagsAndGet() {+ sesV2.createContactList(CreateContactListRequest.builder()+ .contactListName(contactListName)+ .tags(+ Tag.builder().key("env").value("dev").build(),+ Tag.builder().key("team").value("platform").build())+ .build());++ ListTagsForResourceResponse listed = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(contactListArn).build());+ assertThat(listed.tags()).hasSize(2);++ GetContactListResponse got = sesV2.getContactList(GetContactListRequest.builder()+ .contactListName(contactListName).build());+ assertThat(got.tags())+ .extracting(Tag::key)+ .containsExactlyInAnyOrder("env", "team");+ }++ @Test+ @Order(31)+ void contactList_tagAndUntag_lifecycle() {+ sesV2.tagResource(TagResourceRequest.builder()+ .resourceArn(contactListArn)+ .tags(Tag.builder().key("owner").value("alice").build())+ .build());++ ListTagsForResourceResponse afterTag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(contactListArn).build());+ assertThat(afterTag.tags()).hasSize(3);++ sesV2.untagResource(UntagResourceRequest.builder()+ .resourceArn(contactListArn)+ .tagKeys("env", "team")+ .build());++ ListTagsForResourceResponse afterUntag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(contactListArn).build());+ assertThat(afterUntag.tags()).hasSize(1);+ assertThat(afterUntag.tags().get(0).key()).isEqualTo("owner");+ }++ @Test+ @Order(40)+ void customVerificationEmailTemplate_createWithTags_tagAndUntag_lifecycle() {+ // CVET creation requires the From address to be a verified identity. The v2 create API+ // accepts inline Tags; the update API has no Tags member.+ sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(cvetFrom).build());+ sesV2.createCustomVerificationEmailTemplate(CreateCustomVerificationEmailTemplateRequest.builder()+ .templateName(cvetName)+ .fromEmailAddress(cvetFrom)+ .templateSubject("Verify")+ .templateContent("<html><body>verify</body></html>")+ .successRedirectionURL("https://example.com/ok")+ .failureRedirectionURL("https://example.com/no")+ .tags(Tag.builder().key("env").value("dev").build())+ .build());++ ListTagsForResourceResponse initial = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(cvetArn).build());+ assertThat(initial.tags()).hasSize(1);+ assertThat(initial.tags().get(0).key()).isEqualTo("env");++ sesV2.tagResource(TagResourceRequest.builder()+ .resourceArn(cvetArn)+ .tags(Tag.builder().key("owner").value("alice").build())+ .build());++ sesV2.untagResource(UntagResourceRequest.builder()+ .resourceArn(cvetArn)+ .tagKeys("env")+ .build());++ ListTagsForResourceResponse afterUntag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(cvetArn).build());+ assertThat(afterUntag.tags()).hasSize(1);+ assertThat(afterUntag.tags().get(0).key()).isEqualTo("owner");+ }++ @Test+ @Order(50)+ void dedicatedIpPool_createWithTags_tagAndUntag_lifecycle() {+ sesV2.createDedicatedIpPool(CreateDedicatedIpPoolRequest.builder()+ .poolName(poolName)+ .tags(Tag.builder().key("env").value("dev").build())+ .build());++ ListTagsForResourceResponse listed = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(poolArn).build());+ assertThat(listed.tags()).hasSize(1);+ assertThat(listed.tags().get(0).key()).isEqualTo("env");++ sesV2.tagResource(TagResourceRequest.builder()+ .resourceArn(poolArn)+ .tags(Tag.builder().key("owner").value("alice").build())+ .build());++ sesV2.untagResource(UntagResourceRequest.builder()+ .resourceArn(poolArn)+ .tagKeys("env")+ .build());++ ListTagsForResourceResponse afterUntag = sesV2.listTagsForResource(ListTagsForResourceRequest.builder()+ .resourceArn(poolArn).build());+ assertThat(afterUntag.tags()).hasSize(1);+ assertThat(afterUntag.tags().get(0).key()).isEqualTo("owner");+ }}diff --git a/docs/services/ses.md b/docs/services/ses.mdindex 77cdf8a424..f792ee3c4d 100644--- a/docs/services/ses.md+++ b/docs/services/ses.md@@ -288,7 +288,9 @@ Suppressed recipients are filtered out of the SMTP relay step (non-suppressed reFor a **single-recipient** list-managed send, Floci injects a functional unsubscribe link (matching AWS, which only does this for one recipient): the `{{amazonSESUnsubscribeUrl}}` body placeholder is replaced (up to twice) and a `List-Unsubscribe` header plus `List-Unsubscribe-Post: List-Unsubscribe=One-Click` are added (applied to the relayed message and shown under `Headers` at `GET /_aws/ses`; a caller-supplied `List-Unsubscribe` is overridden, matching AWS). The `{{amazonSESUnsubscribeUrl}}` placeholder is also preserved through template rendering so a templated body can carry it. On a send without `ListManagementOptions`, the placeholder is left in the body verbatim (neither replaced nor stripped) — this specific behavior is Floci's choice and is not verified against real SES. Unlike AWS's opaque hosted URL, the link points at Floci's own `/_aws/ses/unsubscribe?region=…&contactList=…&address=…&topic=…` endpoint. `GET` (a browser click) only renders a confirmation page and changes nothing — matching AWS's landing-page behavior and avoiding the RFC 8058 hazard where a client or bot that prefetches the link would silently unsubscribe the contact — while `POST` (the one-click request the confirmation form submits) applies the opt-out (a topic → `OPT_OUT` for that topic; no topic → `UnsubscribeAll`), auto-creating the contact if needed. Two deviations from AWS here: the link is carried as readable query parameters rather than an opaque token (so, like the rest of Floci, the endpoint is unauthenticated and only safe on a trusted dev/test network — a `POST` can opt out any contact), and only the one-click URL entry is emitted — its scheme follows Floci's base URL (`http` unless TLS is enabled) — whereas AWS also includes a `mailto:` entry, which Floci can't service since it has no inbound mail endpoint. Raw (MIME) sends do not get link injection yet.-Tag operations support these ARN forms: `arn:aws:ses:<region>:<account>:configuration-set/<name>`, `arn:aws:ses:<region>:<account>:template/<name>`, and `arn:aws:ses:<region>:<account>:identity/<email-or-domain>`. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, and `CreateEmailIdentity` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` does not modify tags. Other resource types return `NotFoundException`. A non-string tag `Key` or `Value` (number, boolean, object, array), or a `Tags` element that is not an object, is rejected with `SerializationException` rather than being coerced, matching AWS's restJson1 deserializer.+Tag operations accept `arn:aws:ses:<region>:<account>:<type>/<name>` ARNs for six resource types — `configuration-set`, `template`, `identity`, `contact-list`, `custom-verification-email-template`, and `dedicated-ip-pool`; other types return `NotFoundException`. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, `CreateEmailIdentity`, `CreateContactList`, `CreateCustomVerificationEmailTemplate`, and `CreateDedicatedIpPool` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` and `UpdateCustomVerificationEmailTemplate` do not modify tags.++ARN handling is uniform across the six types (probe-confirmed against real AWS). A foreign account id fails first with `BadRequestException` ("Operations on a resource created in a different account is not allowed"). A region differing from the signing region fails `TagResource` / `UntagResource` with `BadRequestException` ("Failed to tag resource" / "Failed to untag resource"); `ListTagsForResource` instead checks existence in the signing region (`NotFoundException`, "No \<Shape\> present with name: \<name\>") and keys tags by the literal ARN, so a mismatched-region ARN returns `200` with an empty tag set. An empty `Tags` array on `TagResource` is not an error — the account, region, and existence checks still run, then the empty merge no-ops — while a missing/empty `TagKeys` on `UntagResource` fails with a message-less `ValidationException` (AWS sends only the error-type header with an empty body; Floci's standard error body carries `"message": null`). A non-string tag `Key`/`Value` or a non-object `Tags` element is rejected with `SerializationException` rather than coerced, matching AWS's restJson1 deserializer.The same AWS-compatible validation applies wherever tags are set (including `CreateContactList` and `TagResource`): at most 50 tags, unique keys, keys 1–128 / values 0–256 code points, characters limited to letters, numbers, Unicode whitespace and `_ . : / = + - @`, and the reserved `aws:` key prefix. `TagResource` applies the 50-tag limit to the merged (existing + incoming) set. Violations return `BadRequestException` with AWS's messages.diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.javaindex c4f622e01c..fea8d2495e 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java@@ -105,6 +105,48 @@ public class SesContactService {.orElseThrow(() -> contactListNotFound(name));}+ public List<Tag> listTags(String name, String region) {+ ContactList list = contactListStore.get(contactListKey(region, name))+ .orElseThrow(() -> tagTargetNotFound(name));+ return new ArrayList<>(list.getTags());+ }++ /**+ * Merges the incoming tags into the stored list. The lookup and write share the mutation lock+ * used by deletion, so tagging can't resurrect a concurrently deleted list or overwrite a+ * concurrent mutation with a stale object.+ */+ public void tag(String name, String region, List<Tag> newTags) {+ String key = contactListKey(region, name);+ synchronized (contactMutationLock) {+ ContactList list = contactListStore.get(key).orElseThrow(() -> tagTargetNotFound(name));+ list.setTags(SesTags.merge(list.getTags(), newTags));+ contactListStore.put(key, list);+ }+ LOG.infov("Tagged SES contact list: {0} in region {1} (+{2} tags)", name, region, newTags.size());+ }++ public void untag(String name, String region, List<String> tagKeys) {+ String key = contactListKey(region, name);+ synchronized (contactMutationLock) {+ ContactList list = contactListStore.get(key).orElseThrow(() -> tagTargetNotFound(name));+ Set<String> toRemove = new HashSet<>(tagKeys);+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(list.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ list.setTags(remaining);+ contactListStore.put(key, list);+ }+ LOG.infov("Untagged SES contact list: {0} in region {1} (-{2} keys)", name, region, tagKeys.size());+ }++ private static AwsException tagTargetNotFound(String name) {+ // The tag endpoints use AWS's "No ContactList present with name" wording+ // (probe-confirmed), unlike the CRUD "List with name: X doesn't exist."+ return new AwsException("NotFoundException",+ "No ContactList present with name: " + name, 404);+ }+public List<ContactList> listContactLists(String region) {String prefix = "contactList::" + region + "::";return contactListStore.scan(k -> k.startsWith(prefix)).stream()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 e1b9c3fe98..b2430b2cae 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@@ -722,7 +722,11 @@ public class SesController {public Response createCustomVerificationEmailTemplate(@Context HttpHeaders headers, String body) {String region = regionResolver.resolveRegion(headers);try {- CustomVerificationEmailTemplate t = parseCvet(objectMapper.readTree(body));+ JsonNode request = objectMapper.readTree(body);+ CustomVerificationEmailTemplate t = parseCvet(request);+ // Tags exist only on the create request; UpdateCustomVerificationEmailTemplate has no+ // Tags member and preserves the stored ones.+ t.setTags(parseTagsArray(request.path("Tags")));sesService.createCustomVerificationEmailTemplate(t, region);return Response.ok(objectMapper.createObjectNode()).build();} catch (AwsException e) {@@ -1468,7 +1472,8 @@ public class SesController {} else {scalingMode = scalingNode.asText();}- sesService.createDedicatedIpPool(poolName, scalingMode, region);+ List<Tag> tags = parseTagsArray(request.path("Tags"));+ sesService.createDedicatedIpPool(poolName, scalingMode, tags, region);LOG.infov("SES V2 CreateDedicatedIpPool: {0}", poolName);return Response.ok(objectMapper.createObjectNode()).build();} catch (AwsException e) {@@ -1495,7 +1500,11 @@ public class SesController {String region = regionResolver.resolveRegion(headers);DedicatedIpPool pool = sesService.getDedicatedIpPool(poolName, region);ObjectNode result = objectMapper.createObjectNode();- result.set("DedicatedIpPool", objectMapper.valueToTree(pool));+ // Built explicitly: the AWS DedicatedIpPool shape carries only PoolName and ScalingMode;+ // the model's tags are exposed via ListTagsForResource, not here.+ ObjectNode poolNode = result.putObject("DedicatedIpPool");+ poolNode.put("PoolName", pool.getPoolName());+ poolNode.put("ScalingMode", pool.getScalingMode());return Response.ok(result).build();}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesCvetService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesCvetService.javaindex 76086794b4..be600b591a 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesCvetService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesCvetService.java@@ -5,14 +5,18 @@ import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.storage.StorageBackend;import io.github.hectorvent.floci.core.storage.StorageFactory;import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;+import io.github.hectorvent.floci.services.ses.model.Tag;import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import org.jboss.logging.Logger;+import java.util.ArrayList;import java.util.Comparator;+import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Optional;+import java.util.Set;/*** Storage for custom verification email templates (the {@code cvetStore}), extracted from@@ -47,6 +51,7 @@ public class SesCvetService {}public void createCustomVerificationEmailTemplate(CustomVerificationEmailTemplate template, String region) {+ SesTags.validate(template.getTags());String key = cvetKey(region, template.getTemplateName());// Lock only the check-then-put so concurrent creates for the same name can't both observe// the key as absent; the facade's validation and this logging stay outside the lock.@@ -80,9 +85,11 @@ public class SesCvetService {// Guard the existence check and the put together so a concurrent delete can't slip between// them and have the update resurrect the just-deleted template.synchronized (cvetMutationLock) {- if (cvetStore.get(key).isEmpty()) {- throw cvetNotFound(template.getTemplateName());- }+ CustomVerificationEmailTemplate existing = cvetStore.get(key)+ .orElseThrow(() -> cvetNotFound(template.getTemplateName()));+ // The update request has no Tags member — preserve the stored ones (copied, so the+ // two objects never share a list instance).+ template.setTags(new ArrayList<>(existing.getTags()));cvetStore.put(key, template);}LOG.infov("Updated custom verification email template {0} in region {1}",@@ -110,6 +117,52 @@ public class SesCvetService {return cvetStore.get(cvetKey(region, templateName));}+ public List<Tag> listTags(String templateName, String region) {+ CustomVerificationEmailTemplate template = cvetStore.get(cvetKey(region, templateName))+ .orElseThrow(() -> tagTargetNotFound(templateName));+ return new ArrayList<>(template.getTags());+ }++ /**+ * Merges the incoming tags into the stored template. The lookup and write share the mutation+ * lock so a concurrent update can't be overwritten with a stale object and a concurrent delete+ * can't be resurrected.+ */+ public void tag(String templateName, String region, List<Tag> newTags) {+ String key = cvetKey(region, templateName);+ synchronized (cvetMutationLock) {+ CustomVerificationEmailTemplate template = cvetStore.get(key)+ .orElseThrow(() -> tagTargetNotFound(templateName));+ template.setTags(SesTags.merge(template.getTags(), newTags));+ cvetStore.put(key, template);+ }+ LOG.infov("Tagged custom verification email template {0} in region {1} (+{2} tags)",+ templateName, region, newTags.size());+ }++ public void untag(String templateName, String region, List<String> tagKeys) {+ String key = cvetKey(region, templateName);+ synchronized (cvetMutationLock) {+ CustomVerificationEmailTemplate template = cvetStore.get(key)+ .orElseThrow(() -> tagTargetNotFound(templateName));+ Set<String> toRemove = new HashSet<>(tagKeys);+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(template.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ template.setTags(remaining);+ cvetStore.put(key, template);+ }+ LOG.infov("Untagged custom verification email template {0} in region {1} (-{2} keys)",+ templateName, region, tagKeys.size());+ }++ private static AwsException tagTargetNotFound(String templateName) {+ // The v2 tag endpoints use AWS's "No CustomVerificationEmailTemplate present with name"+ // wording (probe-confirmed), not the v1-native CRUD message above.+ return new AwsException("NotFoundException",+ "No CustomVerificationEmailTemplate present with name: " + templateName, 404);+ }+private static AwsException cvetNotFound(String templateName) {// v1-native code (verified: CustomVerificationEmailTemplateDoesNotExist / 400).// SesController.remapV1Exception translates it to NotFoundException / 404 for the v2 boundary.diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpService.javaindex af196dc063..855b56033c 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpService.java@@ -5,10 +5,13 @@ import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.storage.StorageBackend;import io.github.hectorvent.floci.core.storage.StorageFactory;import io.github.hectorvent.floci.services.ses.model.DedicatedIpPool;+import io.github.hectorvent.floci.services.ses.model.Tag;import jakarta.enterprise.context.ApplicationScoped;import jakarta.inject.Inject;import org.jboss.logging.Logger;+import java.util.ArrayList;+import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.Set;@@ -27,6 +30,9 @@ public class SesDedicatedIpService {private static final Set<String> SCALING_MODES = Set.of("STANDARD", "MANAGED");private final StorageBackend<String, DedicatedIpPool> dedicatedIpPoolStore;+ // Serializes pool check-then-write mutations (create/delete/tag) so concurrent creates for the+ // same name can't both succeed and tagging can't resurrect a concurrently deleted pool.+ private final Object poolMutationLock = new Object();@Injectpublic SesDedicatedIpService(StorageFactory storageFactory) {@@ -38,7 +44,8 @@ public class SesDedicatedIpService {this.dedicatedIpPoolStore = dedicatedIpPoolStore;}- public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, String region) {+ public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, List<Tag> tags,+ String region) {if (poolName == null || poolName.isBlank()) {throw new AwsException("BadRequestException", "PoolName is required.", 400);}@@ -46,13 +53,17 @@ public class SesDedicatedIpService {if (!SCALING_MODES.contains(effectiveScaling)) {throw new AwsException("BadRequestException", "The ScalingMode parameter is invalid.", 400);}+ SesTags.validate(tags);String key = dedicatedIpPoolKey(region, poolName);- if (dedicatedIpPoolStore.get(key).isPresent()) {- throw new AwsException("AlreadyExistsException",- "The pool <" + poolName + "> already exists.", 400);- }DedicatedIpPool pool = new DedicatedIpPool(poolName, effectiveScaling);- dedicatedIpPoolStore.put(key, pool);+ pool.setTags(tags);+ synchronized (poolMutationLock) {+ if (dedicatedIpPoolStore.get(key).isPresent()) {+ throw new AwsException("AlreadyExistsException",+ "The pool <" + poolName + "> already exists.", 400);+ }+ dedicatedIpPoolStore.put(key, pool);+ }LOG.infov("Created SES dedicated IP pool: {0} in region {1}", poolName, region);return pool;}@@ -77,14 +88,59 @@ public class SesDedicatedIpService {public void deleteDedicatedIpPool(String poolName, String region) {String key = dedicatedIpPoolKey(region, poolName);- if (dedicatedIpPoolStore.get(key).isEmpty()) {- throw new AwsException("NotFoundException",- "The requested pool <" + poolName + "> does not exist.", 404);+ synchronized (poolMutationLock) {+ if (dedicatedIpPoolStore.get(key).isEmpty()) {+ throw new AwsException("NotFoundException",+ "The requested pool <" + poolName + "> does not exist.", 404);+ }+ dedicatedIpPoolStore.delete(key);}- dedicatedIpPoolStore.delete(key);LOG.infov("Deleted SES dedicated IP pool: {0} in region {1}", poolName, region);}+ public List<Tag> listTags(String poolName, String region) {+ DedicatedIpPool pool = dedicatedIpPoolStore.get(dedicatedIpPoolKey(region, poolName))+ .orElseThrow(() -> tagTargetNotFound(poolName));+ return new ArrayList<>(pool.getTags());+ }++ /**+ * Merges the incoming tags into the stored pool. The lookup and write share the mutation lock+ * so tagging can't resurrect a concurrently deleted pool or lose a concurrent tag update.+ */+ public void tag(String poolName, String region, List<Tag> newTags) {+ String key = dedicatedIpPoolKey(region, poolName);+ synchronized (poolMutationLock) {+ DedicatedIpPool pool = dedicatedIpPoolStore.get(key)+ .orElseThrow(() -> tagTargetNotFound(poolName));+ pool.setTags(SesTags.merge(pool.getTags(), newTags));+ dedicatedIpPoolStore.put(key, pool);+ }+ LOG.infov("Tagged SES dedicated IP pool: {0} in region {1} (+{2} tags)", poolName, region, newTags.size());+ }++ public void untag(String poolName, String region, List<String> tagKeys) {+ String key = dedicatedIpPoolKey(region, poolName);+ synchronized (poolMutationLock) {+ DedicatedIpPool pool = dedicatedIpPoolStore.get(key)+ .orElseThrow(() -> tagTargetNotFound(poolName));+ Set<String> toRemove = new HashSet<>(tagKeys);+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(pool.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ pool.setTags(remaining);+ dedicatedIpPoolStore.put(key, pool);+ }+ LOG.infov("Untagged SES dedicated IP pool: {0} in region {1} (-{2} keys)", poolName, region, tagKeys.size());+ }++ private static AwsException tagTargetNotFound(String poolName) {+ // The tag endpoints use AWS's "No DedicatedIpPool present with name" wording+ // (probe-confirmed), unlike the CRUD "The requested pool <X> does not exist."+ return new AwsException("NotFoundException",+ "No DedicatedIpPool present with name: " + poolName, 404);+ }+private static String dedicatedIpPoolKey(String region, String name) {return "dedicatedIpPool::" + region + "::" + name;}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.javaindex 13539a5540..77b1133425 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesService.java@@ -1671,8 +1671,9 @@ public class SesService {// Storage lives in SesDedicatedIpService; the facade forwards.- public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, String region) {- return dedicatedIpService.createDedicatedIpPool(poolName, scalingMode, region);+ public DedicatedIpPool createDedicatedIpPool(String poolName, String scalingMode, List<Tag> tags,+ String region) {+ return dedicatedIpService.createDedicatedIpPool(poolName, scalingMode, tags, region);}public DedicatedIpPool getDedicatedIpPool(String poolName, String region) {@@ -2040,33 +2041,44 @@ public class SesService {public List<Tag> listResourceTags(String arn, String region) {ResourceRef ref = parseSesArn(arn);- return switch (ref.type()) {- case "configuration-set" -> listConfigurationSetTags(ref.name(), ref.region());- // AWS ListTagsForResource on template / identity ARNs uses the signing region- // for lookup (the ARN region is effectively ignored), unlike configuration-set- // which routes by the ARN's region.+ requireCallerAccount(ref);+ List<Tag> tags = switch (ref.type()) {+ case "configuration-set" -> listConfigurationSetTags(ref.name(), region);case "template" -> listEmailTemplateTags(ref.name(), region);case "identity" -> listIdentityTags(ref.name(), region);+ case "contact-list" -> contactService.listTags(ref.name(), region);+ case "custom-verification-email-template" -> cvetService.listTags(ref.name(), region);+ case "dedicated-ip-pool" -> dedicatedIpService.listTags(ref.name(), region);default -> throw new AwsException("NotFoundException","Resource " + arn + " was not found.", 404);};+ // AWS checks existence against the signing region but keys the tag store by the literal+ // ARN: a mismatched ARN region passes the existence check above yet addresses an ARN+ // nothing was ever tagged under, so the result is empty (probe-confirmed across all six+ // resource types).+ if (!ref.region().equals(region)) {+ return List.of();+ }+ return tags;}public void tagResource(String arn, String region, List<Tag> newTags) {ResourceRef ref = parseSesArn(arn);+ requireCallerAccount(ref);if (!ref.region().equals(region)) {throw new AwsException("BadRequestException", "Failed to tag resource", 400);}- if (newTags == null || newTags.isEmpty()) {- throw new AwsException("BadRequestException",- "1 validation error detected: Value at 'tags' failed to satisfy constraint: "- + "Member must have length greater than or equal to 1", 400);- }- SesTags.validate(newTags);+ // An empty Tags list is not an error: AWS still runs the account, region, and existence+ // checks and then applies the empty merge as a no-op (probe-confirmed).+ List<Tag> tags = newTags == null ? List.of() : newTags;+ SesTags.validate(tags);switch (ref.type()) {- case "configuration-set" -> tagConfigurationSet(ref.name(), ref.region(), newTags);- case "template" -> tagEmailTemplate(ref.name(), ref.region(), newTags);- case "identity" -> tagIdentity(ref.name(), ref.region(), newTags);+ case "configuration-set" -> tagConfigurationSet(ref.name(), region, tags);+ case "template" -> tagEmailTemplate(ref.name(), region, tags);+ case "identity" -> tagIdentity(ref.name(), region, tags);+ case "contact-list" -> contactService.tag(ref.name(), region, tags);+ case "custom-verification-email-template" -> cvetService.tag(ref.name(), region, tags);+ case "dedicated-ip-pool" -> dedicatedIpService.tag(ref.name(), region, tags);default -> throw new AwsException("NotFoundException","Resource " + arn + " was not found.", 404);}@@ -2074,29 +2086,25 @@ public class SesService {public void untagResource(String arn, String region, List<String> tagKeys) {ResourceRef ref = parseSesArn(arn);+ requireCallerAccount(ref);if (tagKeys == null || tagKeys.isEmpty()) {- throw new AwsException("BadRequestException",- "1 validation error detected: Value at 'tagKeys' failed to satisfy constraint: "- + "Member must have length greater than or equal to 1", 400);+ // AWS rejects a missing/empty TagKeys member with a message-less ValidationException+ // (probe-confirmed: only the error-type header, empty body), after the account guard+ // and before the region guard. The null message is deliberate — it surfaces through+ // Floci's standard error body as "message":null, which restJson1 SDKs parse the same+ // way as AWS's empty body since they read x-amzn-errortype first.+ throw new AwsException("ValidationException", null, 400);+ }+ if (!ref.region().equals(region)) {+ throw new AwsException("BadRequestException", "Failed to untag resource", 400);}switch (ref.type()) {- case "configuration-set" -> untagConfigurationSet(ref.name(), ref.region(), tagKeys);- case "template" -> {- // AWS UntagResource on template / identity ARNs strictly requires the ARN- // region to match the signing region (rejects mismatch with- // BadRequestException), unlike configuration-set which routes the lookup- // to the ARN's region.- if (!ref.region().equals(region)) {- throw new AwsException("BadRequestException", "Failed to untag resource", 400);- }- untagEmailTemplate(ref.name(), region, tagKeys);- }- case "identity" -> {- if (!ref.region().equals(region)) {- throw new AwsException("BadRequestException", "Failed to untag resource", 400);- }- untagIdentity(ref.name(), region, tagKeys);- }+ case "configuration-set" -> untagConfigurationSet(ref.name(), region, tagKeys);+ case "template" -> untagEmailTemplate(ref.name(), region, tagKeys);+ case "identity" -> untagIdentity(ref.name(), region, tagKeys);+ case "contact-list" -> contactService.untag(ref.name(), region, tagKeys);+ case "custom-verification-email-template" -> cvetService.untag(ref.name(), region, tagKeys);+ case "dedicated-ip-pool" -> dedicatedIpService.untag(ref.name(), region, tagKeys);default -> throw new AwsException("NotFoundException","Resource " + arn + " was not found.", 404);}@@ -2114,7 +2122,7 @@ public class SesService {ConfigurationSet cs = configSetStore.get(key).orElseThrow(() -> new AwsException("NotFoundException","No ConfigurationSet present with name: " + name, 404));- cs.setTags(mergeTags(cs.getTags(), newTags));+ cs.setTags(SesTags.merge(cs.getTags(), newTags));configSetStore.put(key, cs);LOG.infov("Tagged SES configuration set: {0} (region {1}, +{2} tags)", name, region, newTags.size());}@@ -2125,7 +2133,10 @@ public class SesService {.orElseThrow(() -> new AwsException("NotFoundException","No ConfigurationSet present with name: " + name, 404));Set<String> toRemove = new HashSet<>(tagKeys);- cs.getTags().removeIf(t -> toRemove.contains(t.key()));+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(cs.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ cs.setTags(remaining);configSetStore.put(key, cs);LOG.infov("Untagged SES configuration set: {0} (region {1}, -{2} keys)", name, region, tagKeys.size());}@@ -2141,26 +2152,11 @@ public class SesService {EmailTemplate template = templateService.find(name, region).orElseThrow(() -> new AwsException("NotFoundException","No Template present with name: " + name, 404));- template.setTags(mergeTags(template.getTags(), newTags));+ template.setTags(SesTags.merge(template.getTags(), newTags));templateService.save(template, region);LOG.infov("Tagged SES template: {0} (region {1}, +{2} tags)", name, region, newTags.size());}- private static List<Tag> mergeTags(List<Tag> existing,- List<Tag> incoming) {- Map<String, String> merged = new LinkedHashMap<>();- for (Tag t : existing) {- merged.put(t.key(), t.value());- }- for (Tag t : incoming) {- merged.put(t.key(), t.value());- }- SesTags.validateMergedCount(merged.size());- List<Tag> out = new ArrayList<>();- merged.forEach((k, v) -> out.add(new Tag(k, v)));- return out;- }-private List<Tag> listIdentityTags(String identityValue, String region) {Identity identity = identityStore.get(identityKey(region, identityValue)).orElseThrow(() -> new AwsException("NotFoundException",@@ -2173,7 +2169,7 @@ public class SesService {Identity identity = identityStore.get(key).orElseThrow(() -> new AwsException("NotFoundException","No EmailIdentity present with name: " + identityValue, 404));- identity.setTags(mergeTags(identity.getTags(), newTags));+ identity.setTags(SesTags.merge(identity.getTags(), newTags));identityStore.put(key, identity);LOG.infov("Tagged SES identity: {0} (region {1}, +{2} tags)", identityValue, region, newTags.size());}@@ -2184,7 +2180,10 @@ public class SesService {.orElseThrow(() -> new AwsException("NotFoundException","No EmailIdentity present with name: " + identityValue, 404));Set<String> toRemove = new HashSet<>(tagKeys);- identity.getTags().removeIf(t -> toRemove.contains(t.key()));+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(identity.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ identity.setTags(remaining);identityStore.put(key, identity);LOG.infov("Untagged SES identity: {0} (region {1}, -{2} keys)", identityValue, region, tagKeys.size());}@@ -2204,12 +2203,28 @@ public class SesService {.orElseThrow(() -> new AwsException("NotFoundException","No Template present with name: " + name, 404));Set<String> toRemove = new HashSet<>(tagKeys);- template.getTags().removeIf(t -> toRemove.contains(t.key()));+ // Copy-on-write: the stored list may be immutable, and unlocked readers iterate it.+ List<Tag> remaining = new ArrayList<>(template.getTags());+ remaining.removeIf(t -> toRemove.contains(t.key()));+ template.setTags(remaining);templateService.save(template, region);LOG.infov("Untagged SES template: {0} (region {1}, -{2} keys)", name, region, tagKeys.size());}- private record ResourceRef(String region, String type, String name) {}+ private record ResourceRef(String account, String region, String type, String name) {}++ /**+ * AWS rejects a tag operation whose ARN carries a different account id before any region or+ * existence check (probe-confirmed): the account error wins even when the region is also+ * mismatched or the resource doesn't exist anywhere.+ */+ private void requireCallerAccount(ResourceRef ref) {+ String callerAccountId = regionResolver != null ? regionResolver.getAccountId() : defaultAccountId;+ if (!ref.account().equals(callerAccountId)) {+ throw new AwsException("BadRequestException",+ "Operations on a resource created in a different account is not allowed", 400);+ }+ }private static ResourceRef parseSesArn(String arn) {if (arn == null || arn.isBlank()) {@@ -2234,7 +2249,8 @@ public class SesService {if (slash <= 0 || slash == resource.length() - 1) {throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);}- return new ResourceRef(parsed.region(), resource.substring(0, slash), resource.substring(slash + 1));+ return new ResourceRef(parsed.accountId(), parsed.region(),+ resource.substring(0, slash), resource.substring(slash + 1));}// ──────────────────── Suppression (account attributes + list) ────────────────────diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.javaindex ffc592f6ef..e512453f5f 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java@@ -5,7 +5,9 @@ import io.github.hectorvent.floci.services.ses.model.Tag;import java.util.ArrayList;import java.util.HashSet;+import java.util.LinkedHashMap;import java.util.List;+import java.util.Map;import java.util.Set;import java.util.regex.Pattern;@@ -112,6 +114,24 @@ final class SesTags {}}+ /**+ * {@code TagResource} merge semantics: incoming keys overwrite existing values, insertion order+ * is preserved, and the 50-tag ceiling applies to the merged result.+ */+ static List<Tag> merge(List<Tag> existing, List<Tag> incoming) {+ Map<String, String> merged = new LinkedHashMap<>();+ for (Tag t : existing) {+ merged.put(t.key(), t.value());+ }+ for (Tag t : incoming) {+ merged.put(t.key(), t.value());+ }+ validateMergedCount(merged.size());+ List<Tag> out = new ArrayList<>();+ merged.forEach((k, v) -> out.add(new Tag(k, v)));+ return out;+ }+// A null value counts as a character-set violation (AWS requires a string value; empty is allowed).private static boolean charsetOk(String s) {return s != null && TAG_CHARS.matcher(s).matches();diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateService.javaindex 27e681f6d8..43e11a0be0 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateService.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTemplateService.java@@ -74,8 +74,9 @@ public class SesTemplateService {"Template " + template.getTemplateName() + " does not exist.", 400));template.setCreatedTimestamp(existing.getCreatedTimestamp());template.setLastUpdatedTimestamp(Instant.now());- // Tags are managed exclusively via Tag/UntagResource — preserve them on update.- template.setTags(existing.getTags());+ // Tags are managed exclusively via Tag/UntagResource — preserve them on update (copied,+ // so the two objects never share a list instance).+ template.setTags(new ArrayList<>(existing.getTags()));templateStore.put(key, template);LOG.infov("Updated SES template: {0} in region {1}", template.getTemplateName(), region);return template;diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/CustomVerificationEmailTemplate.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/CustomVerificationEmailTemplate.javaindex 7cde112ca2..2d15989367 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/model/CustomVerificationEmailTemplate.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/CustomVerificationEmailTemplate.java@@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;import com.fasterxml.jackson.annotation.JsonProperty;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.ArrayList;+import java.util.List;+/*** A custom verification email template: the branded email SES sends when verifying a new* sender email address (as opposed to {@link EmailTemplate}, which is for the emails a caller@@ -31,6 +34,9 @@ public class CustomVerificationEmailTemplate {@JsonProperty("FailureRedirectionURL")private String failureRedirectionURL;+ @JsonProperty("Tags")+ private List<Tag> tags = new ArrayList<>();+public CustomVerificationEmailTemplate() {}public String getTemplateName() { return templateName; }@@ -54,4 +60,9 @@ public class CustomVerificationEmailTemplate {public void setFailureRedirectionURL(String failureRedirectionURL) {this.failureRedirectionURL = failureRedirectionURL;}++ public List<Tag> getTags() { return tags; }+ public void setTags(List<Tag> tags) {+ this.tags = tags == null ? new ArrayList<>() : tags;+ }}diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/model/DedicatedIpPool.java b/src/main/java/io/github/hectorvent/floci/services/ses/model/DedicatedIpPool.javaindex 1de5009453..3859627eb3 100644--- a/src/main/java/io/github/hectorvent/floci/services/ses/model/DedicatedIpPool.java+++ b/src/main/java/io/github/hectorvent/floci/services/ses/model/DedicatedIpPool.java@@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;import com.fasterxml.jackson.annotation.JsonProperty;import io.quarkus.runtime.annotations.RegisterForReflection;+import java.util.ArrayList;+import java.util.List;+/*** A SES V2 dedicated IP pool. Mirrors the AWS {@code DedicatedIpPool} shape:* a pool name and its scaling mode ({@code STANDARD} or {@code MANAGED}).@@ -20,6 +23,9 @@ public class DedicatedIpPool {@JsonProperty("ScalingMode")private String scalingMode;+ @JsonProperty("Tags")+ private List<Tag> tags = new ArrayList<>();+public DedicatedIpPool() {}public DedicatedIpPool(String poolName, String scalingMode) {@@ -32,4 +38,9 @@ public class DedicatedIpPool {public String getScalingMode() { return scalingMode; }public void setScalingMode(String scalingMode) { this.scalingMode = scalingMode; }++ public List<Tag> getTags() { return tags; }+ public void setTags(List<Tag> tags) {+ this.tags = tags == null ? new ArrayList<>() : tags;+ }}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesCvetServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesCvetServiceTest.javaindex c3cfb956ef..b277079161 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesCvetServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesCvetServiceTest.java@@ -3,6 +3,9 @@ package io.github.hectorvent.floci.services.ses;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.services.ses.model.CustomVerificationEmailTemplate;+import io.github.hectorvent.floci.services.ses.model.Tag;++import java.util.List;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;@@ -66,6 +69,29 @@ class SesCvetServiceTest {assertTrue(service.find("t1", REGION).isEmpty());}+ @Test+ void create_invalidTags_isAtomic_templateNotPersisted() {+ CustomVerificationEmailTemplate t = template("t1");+ t.setTags(List.of(new Tag("dup", "1"), new Tag("dup", "2")));+ assertThrows(AwsException.class,+ () -> service.createCustomVerificationEmailTemplate(t, REGION));+ assertTrue(service.find("t1", REGION).isEmpty());+ }++ @Test+ void update_preservesTags() {+ service.createCustomVerificationEmailTemplate(template("t1"), REGION);+ service.tag("t1", REGION, List.of(new Tag("env", "dev")));++ CustomVerificationEmailTemplate replacement = template("t1");+ replacement.setTemplateSubject("Verify again");+ service.updateCustomVerificationEmailTemplate(replacement, REGION);++ CustomVerificationEmailTemplate updated = service.getCustomVerificationEmailTemplate("t1", REGION);+ assertEquals("Verify again", updated.getTemplateSubject());+ assertEquals(List.of(new Tag("env", "dev")), updated.getTags());+ }+@Testvoid update_unknown_throwsDoesNotExist() {AwsException e = assertThrows(AwsException.class,diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpServiceTest.javaindex b4cbccc963..197092f4fb 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesDedicatedIpServiceTest.java@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;import io.github.hectorvent.floci.core.common.AwsException;import io.github.hectorvent.floci.core.storage.InMemoryStorage;import io.github.hectorvent.floci.services.ses.model.DedicatedIpPool;+import io.github.hectorvent.floci.services.ses.model.Tag;import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.Test;@@ -30,7 +31,7 @@ class SesDedicatedIpServiceTest {@Testvoid create_defaultsScalingModeToStandard() {- DedicatedIpPool pool = service.createDedicatedIpPool("pool-a", null, REGION);+ DedicatedIpPool pool = service.createDedicatedIpPool("pool-a", null, null, REGION);assertEquals("pool-a", pool.getPoolName());assertEquals("STANDARD", pool.getScalingMode());assertTrue(service.dedicatedIpPoolExists("pool-a", REGION));@@ -38,18 +39,58 @@ class SesDedicatedIpServiceTest {@Testvoid create_rejectsBlankName() {- assertThrows(AwsException.class, () -> service.createDedicatedIpPool(" ", "STANDARD", REGION));+ assertThrows(AwsException.class, () -> service.createDedicatedIpPool(" ", "STANDARD", null, REGION));}@Testvoid create_rejectsInvalidScalingMode() {- assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "TURBO", REGION));+ assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "TURBO", null, REGION));}@Testvoid create_rejectsDuplicate() {- service.createDedicatedIpPool("pool-a", "STANDARD", REGION);- assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "STANDARD", REGION));+ service.createDedicatedIpPool("pool-a", "STANDARD", null, REGION);+ assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "STANDARD", null, REGION));+ }++ @Test+ void create_storesTags() {+ DedicatedIpPool pool = service.createDedicatedIpPool("pool-a", "STANDARD",+ List.of(new Tag("env", "dev")), REGION);+ assertEquals(List.of(new Tag("env", "dev")), pool.getTags());+ assertEquals(List.of(new Tag("env", "dev")),+ service.getDedicatedIpPool("pool-a", REGION).getTags());+ }++ @Test+ void create_invalidTags_isAtomic_poolNotPersisted() {+ assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "STANDARD",+ List.of(new Tag("aws:reserved", "x")), REGION));+ assertFalse(service.dedicatedIpPoolExists("pool-a", REGION));+ }++ @Test+ void tag_mergesAndUntagRemoves() {+ service.createDedicatedIpPool("pool-a", "STANDARD", List.of(new Tag("env", "dev")), REGION);+ service.tag("pool-a", REGION, List.of(new Tag("env", "prod"), new Tag("owner", "alice")));+ assertEquals(List.of(new Tag("env", "prod"), new Tag("owner", "alice")),+ service.listTags("pool-a", REGION));++ service.untag("pool-a", REGION, List.of("env"));+ assertEquals(List.of(new Tag("owner", "alice")), service.listTags("pool-a", REGION));+ }++ @Test+ void untag_immediatelyAfterCreateWithImmutableTags_works() {+ service.createDedicatedIpPool("pool-a", "STANDARD", List.of(new Tag("env", "dev")), REGION);+ service.untag("pool-a", REGION, List.of("env"));+ assertEquals(List.of(), service.listTags("pool-a", REGION));+ }++ @Test+ void tag_missingPool_throws() {+ assertThrows(AwsException.class,+ () -> service.tag("ghost", REGION, List.of(new Tag("env", "dev"))));}@Test@@ -59,16 +100,16 @@ class SesDedicatedIpServiceTest {@Testvoid list_isSortedAndPerRegion() {- service.createDedicatedIpPool("pool-b", "STANDARD", REGION);- service.createDedicatedIpPool("pool-a", "STANDARD", REGION);- service.createDedicatedIpPool("pool-other", "STANDARD", "eu-west-1");+ service.createDedicatedIpPool("pool-b", "STANDARD", null, REGION);+ service.createDedicatedIpPool("pool-a", "STANDARD", null, REGION);+ service.createDedicatedIpPool("pool-other", "STANDARD", null, "eu-west-1");assertEquals(List.of("pool-a", "pool-b"), service.listDedicatedIpPools(REGION));}@Testvoid delete_removesPool() {- service.createDedicatedIpPool("pool-a", "MANAGED", REGION);+ service.createDedicatedIpPool("pool-a", "MANAGED", null, REGION);service.deleteDedicatedIpPool("pool-a", REGION);assertFalse(service.dedicatedIpPoolExists("pool-a", REGION));}diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsTest.javaindex 5edffae091..b8b2c6591c 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsTest.java@@ -180,6 +180,38 @@ class SesTagsTest {assertDoesNotThrow(() -> SesTags.validateMergedCount(0));}+ @Test+ void merge_overwritesExistingKeys_appendsNewOnes_preservingInsertionOrder() {+ List<Tag> merged = SesTags.merge(+ List.of(tag("env", "dev"), tag("owner", "alice")),+ List.of(tag("env", "prod"), tag("team", "mail")));+ assertEquals(List.of(tag("env", "prod"), tag("owner", "alice"), tag("team", "mail")), merged);+ }++ @Test+ void merge_updatingExistingKeyAtFifty_ok() {+ List<Tag> existing = new ArrayList<>();+ for (int i = 0; i < 50; i++) {+ existing.add(tag("k" + i, "v"));+ }+ List<Tag> merged = assertDoesNotThrow(() -> SesTags.merge(existing, List.of(tag("k0", "v2"))));+ assertEquals(50, merged.size());+ assertEquals(tag("k0", "v2"), merged.get(0));+ }++ @Test+ void merge_overFiftyUniqueKeys_rejectedWithMergeMessage() {+ List<Tag> existing = new ArrayList<>();+ for (int i = 0; i < 50; i++) {+ existing.add(tag("k" + i, "v"));+ }+ AwsException e = assertThrows(AwsException.class,+ () -> SesTags.merge(existing, List.of(tag("k50", "v"))));+ assertEquals("BadRequestException", e.getErrorCode());+ assertEquals("Maximum of 50 user tags are allowed per resource, consider reducing the number "+ + "of tags in the request or delete existing tags and retry", e.getMessage());+ }+@Testvoid unicodeWhitespace_isAllowed() {// U+00A0 (no-break space) is a Unicode separator (\p{Z}), not the ASCII space. AWS accepts itdiff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsV2IntegrationTest.javaindex fce4297cc0..11bba2b88f 100644--- a/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsV2IntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTagsV2IntegrationTest.java@@ -256,7 +256,9 @@ class SesTagsV2IntegrationTest {@Test@Order(7)- void tagResource_emptyTags_returns400() {+ void tagResource_emptyTags_isNoOp() {+ // An empty Tags list is not an error (probe-confirmed): the existence check still runs,+ // then the empty merge no-ops. tag-cs-1 was left with a single "owner" tag by @Order(1).String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";given().contentType("application/json")@@ -267,12 +269,37 @@ class SesTagsV2IntegrationTest {.when().post("/v2/email/tags").then()- .statusCode(400);+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("owner"));++ // The no-op still checks existence: an unknown resource stays NotFound.+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "arn:aws:ses:us-east-1:000000000000:configuration-set/nowhere", "Tags": []}+ """)+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(404);}@Test@Order(8)- void untagResource_missingTagKeys_returns400() {+ void untagResource_missingTagKeys_returnsBareValidationException() {+ // A missing/empty TagKeys member is a message-less ValidationException (probe-confirmed:+ // AWS sends only the error-type header with an empty body; Floci's standard error body+ // carries "message":null, which restJson1 SDKs parse identically).String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";given().header("Authorization", AUTH_HEADER)@@ -280,7 +307,10 @@ class SesTagsV2IntegrationTest {.when().delete("/v2/email/tags").then()- .statusCode(400);+ .statusCode(400)+ .header("X-Amzn-Errortype", containsString("ValidationException"))+ .body("__type", equalTo("ValidationException"))+ .body("message", nullValue());}@Test@@ -319,8 +349,7 @@ class SesTagsV2IntegrationTest {@Order(11)void tagResource_arnRegionMismatch_returns400() {// AWS rejects TagResource on ARN/signing region mismatch with BadRequestException- // ("Failed to tag resource"). The behaviour differs from UntagResource, which- // routes the lookup to the ARN's region and surfaces NotFoundException instead.+ // ("Failed to tag resource") for every resource type (probe-confirmed).String arn = "arn:aws:ses:eu-west-1:000000000000:configuration-set/tag-cs-1";given().contentType("application/json")@@ -337,9 +366,10 @@ class SesTagsV2IntegrationTest {@Test@Order(12)- void untagResource_arnRegionMismatch_returns404() {- // tag-cs-1 exists in us-east-1 but the ARN points to eu-west-1, so AWS- // returns NotFoundException with the resource-specific message.+ void untagResource_arnRegionMismatch_returns400() {+ // AWS rejects UntagResource on ARN/signing region mismatch with BadRequestException+ // ("Failed to untag resource") for every resource type, configuration sets included+ // (probe-confirmed).String arn = "arn:aws:ses:eu-west-1:000000000000:configuration-set/tag-cs-1";given().header("Authorization", AUTH_HEADER)@@ -348,8 +378,8 @@ class SesTagsV2IntegrationTest {.when().delete("/v2/email/tags").then()- .statusCode(404)- .body(containsString("No ConfigurationSet present with name: tag-cs-1"));+ .statusCode(400)+ .body(containsString("Failed to untag resource"));}@Test@@ -390,11 +420,11 @@ class SesTagsV2IntegrationTest {@Test@Order(15)- void listTagsForResource_template_arnRegionIgnored_usesSigningRegion() {- // For template ARNs AWS ignores the ARN region for ListTagsForResource and- // resolves the template against the signing region instead. The seeded- // tag-tpl-1 lives in us-east-1 and was left with a single "owner=alice" tag- // by the lifecycle case at @Order(2); an eu-west-1 ARN must still surface it.+ void listTagsForResource_template_arnRegionMismatch_returnsEmpty() {+ // AWS checks existence against the signing region but keys tags by the literal ARN+ // (probe-confirmed): tag-tpl-1 exists in us-east-1 (seeded with tags by the+ // lifecycle case at @Order(2)), so an eu-west-1 ARN passes the existence check yet+ // addresses an ARN nothing was tagged under — 200 with an empty tag set.String arn = "arn:aws:ses:eu-west-1:000000000000:template/tag-tpl-1";given().header("Authorization", AUTH_HEADER)@@ -403,9 +433,7 @@ class SesTagsV2IntegrationTest {.get("/v2/email/tags").then().statusCode(200)- .body("Tags", hasSize(1))- .body("Tags[0].Key", equalTo("owner"))- .body("Tags[0].Value", equalTo("alice"));+ .body("Tags", hasSize(0));}@Test@@ -515,9 +543,10 @@ class SesTagsV2IntegrationTest {@Test@Order(19)- void listTagsForResource_identity_arnRegionIgnored_usesSigningRegion() {- // tag-id-1 lives in us-east-1 and was left with a single "owner=alice" tag by- // the lifecycle case at @Order(16); an eu-west-1 ARN must still surface it.+ void listTagsForResource_identity_arnRegionMismatch_returnsEmpty() {+ // tag-id-1 exists in us-east-1 (tagged by the lifecycle case at @Order(16)), so the+ // signing-region existence check passes, but the eu-west-1 ARN addresses an ARN nothing+ // was tagged under — 200 with an empty tag set (probe-confirmed).String arn = "arn:aws:ses:eu-west-1:000000000000:identity/[email protected]";given().header("Authorization", AUTH_HEADER)@@ -526,9 +555,7 @@ class SesTagsV2IntegrationTest {.get("/v2/email/tags").then().statusCode(200)- .body("Tags", hasSize(1))- .body("Tags[0].Key", equalTo("owner"))- .body("Tags[0].Value", equalTo("alice"));+ .body("Tags", hasSize(0));}@Test@@ -631,6 +658,560 @@ class SesTagsV2IntegrationTest {.statusCode(404);}+ @Test+ @Order(23)+ void tags_lifecycle_onContactList() {+ // Seed: create a contact list with inline tags+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ContactListName": "tag-cl-1", "Tags": [{"Key": "env", "Value": "dev"}]}+ """)+ .when()+ .post("/v2/email/contact-lists")+ .then()+ .statusCode(200);++ String arn = "arn:aws:ses:us-east-1:000000000000:contact-list/tag-cl-1";++ // Inline create tags are visible via ListTagsForResource+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("env"));++ // TagResource merges an additional key+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "owner", "Value": "alice"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(2));++ // UntagResource removes a key+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "env")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("owner"));++ // Region mismatch handling (probe-confirmed): UntagResource rejects an+ // ARN/signing region mismatch, and ListTagsForResource passes the signing-region+ // existence check but returns an empty set for the untagged mismatched ARN.+ String euArn = "arn:aws:ses:eu-west-1:000000000000:contact-list/tag-cl-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", euArn)+ .queryParam("TagKeys", "k")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Failed to untag resource"));++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", euArn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(0));++ // Free the one-list-per-account slot so later contact-list tests aren't order-dependent.+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .delete("/v2/email/contact-lists/tag-cl-1")+ .then()+ .statusCode(200);+ }++ @Test+ @Order(24)+ void tagResource_unknownContactList_returns404() {+ String arn = "arn:aws:ses:us-east-1:000000000000:contact-list/missing-cl";+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "env", "Value": "dev"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(404)+ .body(containsString("No ContactList present with name: missing-cl"));+ }++ @Test+ @Order(25)+ void tags_lifecycle_onCustomVerificationEmailTemplate() {+ // Seed: CVET creation requires a verified From identity+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"EmailIdentity": "[email protected]"}+ """)+ .when()+ .post("/v2/email/identities")+ .then()+ .statusCode(200);++ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "TemplateName": "tag-cvet-1",+ "FromEmailAddress": "[email protected]",+ "TemplateSubject": "Verify",+ "TemplateContent": "<html><body>verify</body></html>",+ "SuccessRedirectionURL": "https://example.com/ok",+ "FailureRedirectionURL": "https://example.com/no"+ }+ """)+ .when()+ .post("/v2/email/custom-verification-email-templates")+ .then()+ .statusCode(200);++ String arn = "arn:aws:ses:us-east-1:000000000000:custom-verification-email-template/tag-cvet-1";++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(0));++ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [+ {"Key": "env", "Value": "dev"},+ {"Key": "owner", "Value": "alice"}+ ]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(200);++ // UpdateCustomVerificationEmailTemplate must not wipe the tags+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "FromEmailAddress": "[email protected]",+ "TemplateSubject": "Verify again",+ "TemplateContent": "<html><body>verify</body></html>",+ "SuccessRedirectionURL": "https://example.com/ok",+ "FailureRedirectionURL": "https://example.com/no"+ }+ """)+ .when()+ .put("/v2/email/custom-verification-email-templates/tag-cvet-1")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(2));++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "env")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("owner"));+ }++ @Test+ @Order(26)+ void tagResource_unknownCustomVerificationEmailTemplate_returns404() {+ String arn = "arn:aws:ses:us-east-1:000000000000:custom-verification-email-template/missing-cvet";+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "env", "Value": "dev"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(404)+ .body(containsString("No CustomVerificationEmailTemplate present with name: missing-cvet"));+ }++ @Test+ @Order(27)+ void tags_lifecycle_onDedicatedIpPool() {+ // Seed: create a pool with inline tags+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"PoolName": "tag-pool-1", "Tags": [{"Key": "env", "Value": "dev"}]}+ """)+ .when()+ .post("/v2/email/dedicated-ip-pools")+ .then()+ .statusCode(200);++ String arn = "arn:aws:ses:us-east-1:000000000000:dedicated-ip-pool/tag-pool-1";++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("env"));++ // GetDedicatedIpPool keeps the AWS shape: no Tags member+ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/v2/email/dedicated-ip-pools/tag-pool-1")+ .then()+ .statusCode(200)+ .body("DedicatedIpPool.PoolName", equalTo("tag-pool-1"))+ .body("DedicatedIpPool.Tags", nullValue());++ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "owner", "Value": "alice"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "env")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("owner"));+ }++ @Test+ @Order(28)+ void tagResource_unknownDedicatedIpPool_returns404() {+ String arn = "arn:aws:ses:us-east-1:000000000000:dedicated-ip-pool/missing-pool";+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "env", "Value": "dev"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(404)+ .body(containsString("No DedicatedIpPool present with name: missing-pool"));+ }++ @Test+ @Order(29)+ void createDedicatedIpPool_invalidInlineTags_isAtomic_poolNotPersisted() {+ // A semantic tag error must fail CreateDedicatedIpPool before the pool is persisted, so a+ // corrected retry does not hit AlreadyExistsException.+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"PoolName": "atomic-tag-pool", "Tags": [+ {"Key": "dup", "Value": "1"},+ {"Key": "dup", "Value": "2"}+ ]}+ """)+ .when()+ .post("/v2/email/dedicated-ip-pools")+ .then()+ .statusCode(400)+ .body("__type", equalTo("BadRequestException"))+ .body("message", equalTo("Cannot provide multiple tags with the same key"));++ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/v2/email/dedicated-ip-pools/atomic-tag-pool")+ .then()+ .statusCode(404);+ }++ @Test+ @Order(30)+ void untagResource_cvet_arnRegionMismatch_returns400() {+ // Probe-confirmed.+ String arn = "arn:aws:ses:eu-west-1:000000000000:custom-verification-email-template/tag-cvet-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "k")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Failed to untag resource"));+ }++ @Test+ @Order(31)+ void listTagsForResource_cvet_arnRegionMismatch_returnsEmpty() {+ // tag-cvet-1 exists in us-east-1 (tagged by the lifecycle case at @Order(25)), so the+ // signing-region existence check passes, but the eu-west-1 ARN addresses an ARN nothing+ // was tagged under — 200 with an empty tag set (probe-confirmed).+ String arn = "arn:aws:ses:eu-west-1:000000000000:custom-verification-email-template/tag-cvet-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(0));+ }++ @Test+ @Order(32)+ void untagResource_dedicatedIpPool_arnRegionMismatch_returns400() {+ // Probe-confirmed.+ String arn = "arn:aws:ses:eu-west-1:000000000000:dedicated-ip-pool/tag-pool-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "k")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Failed to untag resource"));+ }++ @Test+ @Order(33)+ void listTagsForResource_dedicatedIpPool_arnRegionMismatch_returnsEmpty() {+ // tag-pool-1 exists in us-east-1 (tagged by the lifecycle case at @Order(27)), so the+ // signing-region existence check passes, but the eu-west-1 ARN addresses an ARN nothing+ // was tagged under — 200 with an empty tag set (probe-confirmed).+ String arn = "arn:aws:ses:eu-west-1:000000000000:dedicated-ip-pool/tag-pool-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(0));+ }++ @Test+ @Order(34)+ void listTagsForResource_foreignAccountArn_returns400_beforeExistenceCheck() {+ // A foreign-account ARN is rejected before any existence check (probe-confirmed):+ // the name here exists nowhere, yet the account error wins over NotFound.+ String arn = "arn:aws:ses:us-east-1:999999999999:configuration-set/nowhere";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Operations on a resource created in a different account is not allowed"));+ }++ @Test+ @Order(35)+ void tagResource_foreignAccountArn_returns400() {+ String arn = "arn:aws:ses:us-east-1:999999999999:configuration-set/tag-cs-1";+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {"ResourceArn": "%s", "Tags": [{"Key": "k", "Value": "v"}]}+ """.formatted(arn))+ .when()+ .post("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Operations on a resource created in a different account is not allowed"));+ }++ @Test+ @Order(36)+ void untagResource_foreignAccountAndRegionMismatch_accountErrorWins() {+ // With both the account and the region mismatched, AWS reports the account error,+ // not "Failed to untag resource" (probe-confirmed).+ String arn = "arn:aws:ses:eu-west-1:999999999999:configuration-set/tag-cs-1";+ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn", arn)+ .queryParam("TagKeys", "k")+ .when()+ .delete("/v2/email/tags")+ .then()+ .statusCode(400)+ .body(containsString("Operations on a resource created in a different account is not allowed"));+ }++ @Test+ @Order(37)+ void createCustomVerificationEmailTemplate_inlineTags_storedAndAtomic() {+ // v2 CreateCustomVerificationEmailTemplate accepts Tags (probe-confirmed); the From+ // identity [email protected] was verified by the lifecycle case at @Order(25).+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "TemplateName": "tag-cvet-inline",+ "FromEmailAddress": "[email protected]",+ "TemplateSubject": "Verify",+ "TemplateContent": "<html><body>verify</body></html>",+ "SuccessRedirectionURL": "https://example.com/ok",+ "FailureRedirectionURL": "https://example.com/no",+ "Tags": [{"Key": "env", "Value": "dev"}]+ }+ """)+ .when()+ .post("/v2/email/custom-verification-email-templates")+ .then()+ .statusCode(200);++ given()+ .header("Authorization", AUTH_HEADER)+ .queryParam("ResourceArn",+ "arn:aws:ses:us-east-1:000000000000:custom-verification-email-template/tag-cvet-inline")+ .when()+ .get("/v2/email/tags")+ .then()+ .statusCode(200)+ .body("Tags", hasSize(1))+ .body("Tags[0].Key", equalTo("env"));++ // A semantic tag error fails the create before anything is persisted, so a corrected+ // retry does not hit AlreadyExistsException (probe-confirmed message and atomicity).+ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "TemplateName": "tag-cvet-atomic",+ "FromEmailAddress": "[email protected]",+ "TemplateSubject": "Verify",+ "TemplateContent": "<html><body>verify</body></html>",+ "SuccessRedirectionURL": "https://example.com/ok",+ "FailureRedirectionURL": "https://example.com/no",+ "Tags": [{"Key": "dup", "Value": "1"}, {"Key": "dup", "Value": "2"}]+ }+ """)+ .when()+ .post("/v2/email/custom-verification-email-templates")+ .then()+ .statusCode(400)+ .body(containsString("Cannot provide multiple tags with the same key"));++ given()+ .header("Authorization", AUTH_HEADER)+ .when()+ .get("/v2/email/custom-verification-email-templates/tag-cvet-atomic")+ .then()+ .statusCode(404);++ given()+ .contentType("application/json")+ .header("Authorization", AUTH_HEADER)+ .body("""+ {+ "TemplateName": "tag-cvet-atomic",+ "FromEmailAddress": "[email protected]",+ "TemplateSubject": "Verify",+ "TemplateContent": "<html><body>verify</body></html>",+ "SuccessRedirectionURL": "https://example.com/ok",+ "FailureRedirectionURL": "https://example.com/no",+ "Tags": [{"Key": "env", "Value": "dev"}]+ }+ """)+ .when()+ .post("/v2/email/custom-verification-email-templates")+ .then()+ .statusCode(200);+ }+private static String tagArray(int from, int to) {StringBuilder sb = new StringBuilder("[");for (int i = from; i < to; i++) {