mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): add v2 TagResource / UntagResource / ListTagsForResource (#749)
* feat(ses): add v2 TagResource / UntagResource / ListTagsForResource
Implements the v2 SES tag endpoints at /v2/email/tags. Initial scope
covers ConfigurationSet ARNs only
(arn:aws:ses:<region>:<account>:configuration-set/<name>); other
resource types return NotFoundException so follow-up PRs can extend
coverage to Identity, EmailTemplate, etc.
Behavior aligned with observed AWS responses:
- TagResource enforces ARN/signing region match strictly and rejects
mismatches with BadRequestException ("Failed to tag resource").
- UntagResource and ListTagsForResource route lookups to the ARN's
region instead, so a region mismatch surfaces as NotFoundException
with the resource-specific message (e.g. "No ConfigurationSet
present with name: <name>").
- TagResource merges by key (existing keys are replaced, others
retained); UntagResource silently skips keys not present.
- Empty Tags / TagKeys lists are rejected with BadRequestException to
match AWS validation.
- ARN parsing uses the shared AwsArnUtils helper; missing region or
account in the ARN is rejected as BadRequest, matching AWS.
Tests:
- New SesTagsV2IntegrationTest for endpoint-focused coverage (lifecycle,
region-mismatch asymmetry, validation errors).
- Cross-feature round-trip in SesConfigurationSetV2IntegrationTest
verifying that tags supplied to CreateConfigurationSet are reachable
via ListTagsForResource.
- New SesTagResourceTest in the Java SDK compatibility suite.
* refactor(ses): drop unused region parameter from list/untag tag service methods
listResourceTags and untagResource route lookups by the ARN's region, so
the request signing region they accepted was never read. Remove it and
stop resolving it in the controller. tagResource still takes region
because it strictly validates it against the ARN.
This commit is contained in:
1 parent
1ffe905271
commit
9b68bd0377
6 files changed
+631
No files matched your search
+36
@@ -9,6 +9,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
||||
/**
|
||||
* Integration tests for SES V2 ConfigurationSet endpoints under /v2/email/configuration-sets.
|
||||
@@ -284,4 +285,39 @@ class SesConfigurationSetV2IntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(16)
|
||||
void listTagsForResource_returnsTagsSetAtCreation() {
|
||||
// Tags supplied to CreateConfigurationSet must also be reachable through
|
||||
// the ListTagsForResource endpoint, not just GET configuration-sets/{name}.
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"ConfigurationSetName": "v2-cs-tag-roundtrip",
|
||||
"Tags": [
|
||||
{"Key": "team", "Value": "platform"},
|
||||
{"Key": "env", "Value": "stg"}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/v2-cs-tag-roundtrip";
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.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"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Integration tests for the SES V2 tag endpoints
|
||||
* (TagResource / UntagResource / ListTagsForResource at /v2/email/tags).
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesTagsV2IntegrationTest {
|
||||
|
||||
private static final String AUTH_HEADER =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void tags_lifecycle_onConfigurationSet() {
|
||||
// Seed: create a configuration set we can tag against
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ConfigurationSetName": "tag-cs-1"}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/configuration-sets")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";
|
||||
|
||||
// Initially empty
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(0));
|
||||
|
||||
// TagResource
|
||||
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);
|
||||
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("Tags", hasSize(2))
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("dev"))
|
||||
.body("Tags.find { it.Key == 'owner' }.Value", equalTo("alice"));
|
||||
|
||||
// TagResource on existing key replaces value (merge semantics)
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn": "%s", "Tags": [
|
||||
{"Key": "env", "Value": "prod"}
|
||||
]}
|
||||
""".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))
|
||||
.body("Tags.find { it.Key == 'env' }.Value", equalTo("prod"));
|
||||
|
||||
// UntagResource removes specific keys
|
||||
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(2)
|
||||
void tagResource_unknownConfigurationSet_returns404() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/missing-cs";
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void listTagsForResource_unsupportedResourceType_returns404() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:identity/example.com";
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.get("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void tagResource_invalidArn_returns400() {
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn": "not-an-arn", "Tags": [{"Key": "env", "Value": "dev"}]}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void tagResource_emptyTags_returns400() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{"ResourceArn": "%s", "Tags": []}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void untagResource_missingTagKeys_returns400() {
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.when()
|
||||
.delete("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void tagResource_arnMissingRegion_returns400() {
|
||||
String arn = "arn:aws:ses::000000000000: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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void tagResource_nonSesArn_returns400() {
|
||||
String arn = "arn:aws:s3:us-east-1:000000000000:bucket/my-bucket";
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
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.
|
||||
String arn = "arn:aws:ses:eu-west-1:000000000000: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("Failed to tag resource"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
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.
|
||||
String arn = "arn:aws:ses:eu-west-1:000000000000:configuration-set/tag-cs-1";
|
||||
given()
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.queryParam("ResourceArn", arn)
|
||||
.queryParam("TagKeys", "k")
|
||||
.when()
|
||||
.delete("/v2/email/tags")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("No ConfigurationSet present with name: tag-cs-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void tagResource_invalidConfigurationSetName_returns400() {
|
||||
// Whitespace in configuration-set name fails configSetKey validation,
|
||||
// which is remapped from InvalidParameterValue -> BadRequestException at the controller.
|
||||
String arn = "arn:aws:ses:us-east-1:000000000000:configuration-set/has spaces";
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user