mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): extend tag endpoints to v2 EmailTemplate ARNs (#759)
Adds support for arn:aws:ses:<region>:<account>:template/<name> ARNs across TagResource / UntagResource / ListTagsForResource. Behaviour was verified against real AWS via aws sesv2 commands and aligned where it diverged. - EmailTemplate gains a tags field. CreateEmailTemplate accepts an optional Tags array; tag validation reuses validateTag(). - UpdateEmailTemplate intentionally preserves the existing tags so that AWS-style "tags only mutated via Tag/UntagResource" semantics hold. - GetEmailTemplate response surfaces stored tags. - Missing templates return NotFoundException with the AWS-canonical "No Template present with name: <name>" message — AWS uses the bare "Template" (not "EmailTemplate") for tag-endpoint lookups even though the SDK type is EmailTemplate. Resource-type-specific routing in the tag endpoints: - TagResource on a template ARN strictly validates ARN/signing region match (BadRequestException "Failed to tag resource" on mismatch), matching the existing ConfigurationSet behaviour. - UntagResource on a template ARN strictly validates ARN/signing region match (BadRequestException "Failed to untag resource"), whereas ConfigurationSet's lenient ARN-region lookup is preserved. AWS treats the two resource types asymmetrically here. - ListTagsForResource on a template ARN ignores the ARN region and resolves the template against the signing region. ConfigurationSet continues to route by ARN region. Three small refactors that fall out naturally from adding a second taggable resource: - Tag is promoted from ConfigurationSet.Tag to a top-level services/ses/model/Tag so EmailTemplate and the shared helpers no longer reference a Configuration-scoped name. JSON serialization is unchanged. - A private mergeTags(existing, incoming) helper centralizes the LinkedHashMap merge previously duplicated between tagConfigurationSet and tagEmailTemplate. - A private parseTagsArray(JsonNode) helper centralizes the JSON Tags array parse previously duplicated across createConfigurationSet, createEmailTemplate, and tagResource. The helper returns null for missing/null nodes; the required caller (tagResource) treats null as BadRequestException. Tests: - SesTagsV2IntegrationTest gains a template lifecycle case, a template-not-found assertion, and the two template-specific region-mismatch / signing-region-lookup cases. - SesTemplateV2IntegrationTest covers create-with-tags, list-via-tags endpoint, and update-preserves-tags round-trips. - SesTagResourceTest (Java SDK compat) exercises CreateEmailTemplate with Tags and the Tag/Untag lifecycle on the template ARN.
This commit is contained in:
1 parent
ce2012de45
commit
646b4199df
9 files changed
+425
-62
No files matched your search
+139
-9
@@ -120,6 +120,98 @@ class SesTagsV2IntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void tags_lifecycle_onEmailTemplate() {
|
||||
// Seed: create an email template we can tag against
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "tag-tpl-1",
|
||||
"TemplateContent": {"Subject": "S", "Text": "T"}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/templates")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:template/tag-tpl-1";
|
||||
|
||||
// Initially empty
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(0));
|
||||
|
||||
// Tag the template
|
||||
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));
|
||||
|
||||
// Remove 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(3)
|
||||
void tagResource_unknownEmailTemplate_returns404() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:template/missing-tpl";
|
||||
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 Template present with name: missing-tpl"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void tagResource_unknownConfigurationSet_returns404() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/missing-cs";
|
||||
given()
|
||||
@@ -135,7 +227,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@Order(5)
|
||||
void listTagsForResource_unsupportedResourceType_returns404() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:identity/example.com";
|
||||
given()
|
||||
@@ -148,7 +240,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@Order(6)
|
||||
void tagResource_invalidArn_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
@@ -163,7 +255,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
@Order(7)
|
||||
void tagResource_emptyTags_returns400() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
@@ -179,7 +271,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@Order(8)
|
||||
void untagResource_missingTagKeys_returns400() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
@@ -192,7 +284,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
@Order(9)
|
||||
void tagResource_arnMissingRegion_returns400() {
|
||||
String arn = "arn:aws:ses::000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
@@ -208,7 +300,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
@Order(10)
|
||||
void tagResource_nonSesArn_returns400() {
|
||||
String arn = "arn:aws:s3:us-east-1:000000000000:bucket/my-bucket";
|
||||
given()
|
||||
@@ -224,7 +316,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@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
|
||||
@@ -244,7 +336,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
@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.
|
||||
@@ -261,7 +353,7 @@ class SesTagsV2IntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@Order(13)
|
||||
void tagResource_invalidConfigurationSetName_returns400() {
|
||||
// Whitespace in configuration-set name fails configSetKey validation,
|
||||
// which is remapped from InvalidParameterValue -> BadRequestException at the controller.
|
||||
@@ -277,4 +369,42 @@ class SesTagsV2IntegrationTest {
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
void untagResource_template_arnRegionMismatch_returns400() {
|
||||
// For template ARNs AWS rejects UntagResource on signing/ARN region mismatch with
|
||||
// BadRequestException ("Failed to untag resource"), unlike ConfigurationSet which
|
||||
// routes the lookup to the ARN's region and surfaces NotFound instead.
|
||||
String arn = "arn:aws:ses:eu-west-1:000000000000:template/tag-tpl-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(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.
|
||||
String arn = "arn:aws:ses:eu-west-1:000000000000:template/tag-tpl-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("owner"))
|
||||
.body("Tags[0].Value", equalTo("alice"));
|
||||
}
|
||||
}
|
||||
+82
@@ -551,6 +551,88 @@ class SesTemplateV2IntegrationTest {
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(21)
|
||||
void createEmailTemplate_withTags_visibleViaGet() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "tpl-with-tags",
|
||||
"TemplateContent": {
|
||||
"Subject": "S",
|
||||
"Text": "T"
|
||||
},
|
||||
"Tags": [
|
||||
{"Key": "env", "Value": "stg"},
|
||||
{"Key": "team", "Value": "platform"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/templates")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/templates/tpl-with-tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TemplateName", equalTo("tpl-with-tags"))
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("stg"))
|
||||
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(22)
|
||||
void createEmailTemplate_withTags_visibleViaListTagsForResource() {
|
||||
// tpl-with-tags is created in @Order(21) above
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:template/tpl-with-tags";
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("stg"))
|
||||
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
void updateEmailTemplate_preservesTags() {
|
||||
// tpl-with-tags has 2 tags from @Order(21)
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"TemplateContent": {
|
||||
"Subject": "S2",
|
||||
"Text": "T2"
|
||||
}
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.put("/v2/email/templates/tpl-with-tags")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.get("/v2/email/templates/tpl-with-tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("TemplateContent.Subject", equalTo("S2"))
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("stg"))
|
||||
.body("Tags.find { it.Key == 'team' }.Value", equalTo("platform"));
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@MethodSource("malformedSendEmailBodies")
|
||||
@Order(50)
|
||||
|
||||
Reference in new issue
Block a user