feat(ses): extend tag endpoints to v2 EmailIdentity ARNs (#760)

* feat(ses): extend tag endpoints to v2 EmailIdentity ARNs

Adds support for arn:aws:ses:<region>:<account>:identity/<email-or-domain>
ARNs across TagResource / UntagResource / ListTagsForResource. Behaviour
was verified against real AWS via aws sesv2 commands and matches the
EmailTemplate routing exactly:

- Tag region mismatch -> BadRequestException "Failed to tag resource"
- Untag region mismatch -> BadRequestException "Failed to untag resource"
- List region mismatch -> Tags resolved against the signing region
- Missing identity -> NotFoundException with "No EmailIdentity present
  with name: <identity>"

Identity gains a tags field. CreateEmailIdentity accepts an optional
Tags array (validated via the existing validateTag()) and persists it
on the freshly verified Identity record. GetEmailIdentity surfaces
stored tags in the existing Tags response field.

Tests:
- SesTagsV2IntegrationTest gains identity lifecycle, identity-not-found,
  and identity-specific region-mismatch / signing-region-lookup cases.
- SesIdentityAttributesV2IntegrationTest covers create-with-tags ->
  Get/ListTagsForResource round-trip.
- SesTagResourceTest (Java SDK compat) exercises CreateEmailIdentity
  with Tags and the Tag/Untag lifecycle on the identity ARN.

* test(ses): move identity tags round-trip test next to other createEmailIdentity cases

The Tags-on-create round-trip case fits better next to the existing
createEmailIdentity_* cases at the top of SesV2IntegrationTest than
it does in the attributes-focused SesIdentityAttributesV2IntegrationTest,
where DKIM / MAIL FROM / Feedback validation lives.

* chore(ses): drop dead identity.setTags call after CreateEmailIdentity

setIdentityTags already persists the tag list on the stored Identity,
and CreateEmailIdentity does not surface Tags in its response per the
AWS spec, so the in-memory mutation that followed had no observable
effect.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-05-10 10:12:33 -05:00
1 parent 646b4199df
commit bcc36c08e0
7 files changed
+300 -8

No files matched your search

@@ -407,4 +407,127 @@ class SesTagsV2IntegrationTest {
.body("Tags[0].Key", equalTo("owner"))
.body("Tags[0].Value", equalTo("alice"));
}
@Test
@Order(16)
void tags_lifecycle_onEmailIdentity() {
// Seed: create an email identity we can tag against
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"EmailIdentity": "tag-id-1@example.com"}
""")
.when()
.post("/v2/email/identities")
.then()
.statusCode(200);
String arn = "arn:aws:ses:us-east-1:000000000000:identity/tag-id-1@example.com";
// Initially empty
given()
.header("Authorization", AUTH_HEADER)
.queryParam("ResourceArn", arn)
.when()
.get("/v2/email/tags")
.then()
.statusCode(200)
.body("Tags", hasSize(0));
// Tag it
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"ResourceArn": "%s", "Tags": [
{"Key": "env", "Value": "stg"},
{"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));
// Untag 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"));
}
@Test
@Order(17)
void tagResource_unknownEmailIdentity_returns404() {
String arn = "arn:aws:ses:us-east-1:000000000000:identity/missing-id@example.com";
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 EmailIdentity present with name: missing-id@example.com"));
}
@Test
@Order(18)
void untagResource_identity_arnRegionMismatch_returns400() {
// Identity follows the same strict region check as templates for UntagResource.
String arn = "arn:aws:ses:eu-west-1:000000000000:identity/tag-id-1@example.com";
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(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.
String arn = "arn:aws:ses:eu-west-1:000000000000:identity/tag-id-1@example.com";
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"))
.body("Tags[0].Value", equalTo("alice"));
}
}
@@ -329,6 +329,49 @@ class SesV2IntegrationTest {
.body("message", containsString("leading or trailing whitespace"));
}
@Test
@Order(15)
void createEmailIdentity_withTags_visibleViaGetAndListTags() {
// Tags supplied to CreateEmailIdentity must round-trip through GetEmailIdentity
// and ListTagsForResource (template/configuration-set behaviour parallel).
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{
"EmailIdentity": "v2-tag-roundtrip.floci.test",
"Tags": [
{"Key": "team", "Value": "platform"},
{"Key": "env", "Value": "stg"}
]
}
""")
.when()
.post("/v2/email/identities")
.then()
.statusCode(200);
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/identities/v2-tag-roundtrip.floci.test")
.then()
.statusCode(200)
.body("Tags", hasSize(2))
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"))
.body("Tags.find { it.Key == 'env' }.Value", equalTo("stg"));
String arn = "arn:aws:ses:us-east-1:000000000000:identity/v2-tag-roundtrip.floci.test";
given()
.header("Authorization", AUTH_HEADER)
.queryParam("ResourceArn", arn)
.when()
.get("/v2/email/tags")
.then()
.statusCode(200)
.body("Tags", hasSize(2));
}
// ──────────────── DKIM Attributes ────────────────
@Test