mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): extend tag endpoints to contact lists, custom verification email templates, and dedicated IP pools (#2589)
* feat(ses): extend tag endpoints to contact lists, custom verification email templates, and dedicated IP pools * feat(ses): accept inline Tags on v2 CreateCustomVerificationEmailTemplate * fix(ses): match probed AWS behavior for empty Tags/TagKeys and avoid tag-list aliasing * docs(ses): describe the actual ValidationException wire body
This commit is contained in:
1 parent
f912c3b717
commit
c7cd78e3b3
15 files changed
+1171
-112
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void update_unknown_throwsDoesNotExist() {
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
|
||||
+50
-9
@@ -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 {
|
||||
|
||||
@Test
|
||||
void 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 {
|
||||
|
||||
@Test
|
||||
void create_rejectsBlankName() {
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool(" ", "STANDARD", REGION));
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool(" ", "STANDARD", null, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void create_rejectsInvalidScalingMode() {
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "TURBO", REGION));
|
||||
assertThrows(AwsException.class, () -> service.createDedicatedIpPool("pool-a", "TURBO", null, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 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 {
|
||||
|
||||
@Test
|
||||
void 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));
|
||||
}
|
||||
|
||||
@Test
|
||||
void 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));
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unicodeWhitespace_isAllowed() {
|
||||
// U+00A0 (no-break space) is a Unicode separator (\p{Z}), not the ASCII space. AWS accepts it
|
||||
|
||||
+606
-25
@@ -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/tag-id-1@example.com";
|
||||
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": "tag-cvet-sender@floci.test"}
|
||||
""")
|
||||
.when()
|
||||
.post("/v2/email/identities")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "tag-cvet-1",
|
||||
"FromEmailAddress": "tag-cvet-sender@floci.test",
|
||||
"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": "tag-cvet-sender@floci.test",
|
||||
"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 tag-cvet-sender@floci.test was verified by the lifecycle case at @Order(25).
|
||||
given()
|
||||
.contentType("application/json")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "tag-cvet-inline",
|
||||
"FromEmailAddress": "tag-cvet-sender@floci.test",
|
||||
"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": "tag-cvet-sender@floci.test",
|
||||
"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": "tag-cvet-sender@floci.test",
|
||||
"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++) {
|
||||
|
||||
Reference in new issue
Block a user