fix(ses): match AWS tag ARN parsing and configuration set name errors (#5235)

* fix(ses): match AWS tag ARN parsing and configuration set name errors

The SES v2 tag endpoints rejected malformed ARNs with messages that were
never checked against AWS, refused ARNs whose service was not "ses", and
compared the region before checking the resource exists. Configuration
set names were rejected with an invented message on both APIs.

Probed against AWS in us-west-2:

- Every malformed ARN (missing partition, service, account or resource
  name, unknown type, ":" or "/" in the name) is BadRequestException
  "ResourceArn is not the expected format", including an unknown type,
  which was a 404.
- The partition and service are required but never compared.
- An invalid configuration-set name in the ARN is a message-less
  ValidationException after the account check.
- TagResource and UntagResource check existence before the region.
- An omitted ResourceArn on Tag/Untag is a message-less
  ValidationException. ListTagsForResource keeps a 400 where AWS
  answers 500.
- "ResourceArn=" is read raw, since @QueryParam binds an empty value
  as null.
- Configuration set names use AWS's three messages on every v1 and v2
  operation, including sends: must be specified, cannot exceed 64
  characters, and invalid characters.

* refactor(ses): share the configuration set name check and map tag domains by type

The v1 helper and the v2 CreateConfigurationSet handler now call the
service's validateName instead of repeating the empty-name check, and the
name pattern no longer restates the 64-character limit the length check
owns.

The seven taggable domain services implement SesTaggable, and SesService
keys them by ARN type in one map. That map replaces the type set and the
three dispatch switches, whose default arms could no longer be reached.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-10-07 14:27:36 -04:00
1 parent 74b3cecf78
commit 86371d86cb
16 files changed
+541 -103

No files matched your search

@@ -0,0 +1,164 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
/**
* Configuration-set name validation messages, shared by the V1 Query and V2 REST JSON operations.
*/
@QuarkusTest
class SesConfigurationSetNameIntegrationTest {
private static final String V2_AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String V1_AUTH =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
private static final String SIXTY_FIVE =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
@Test
void v2_invalidCharacters_nameTheOffendingValue() {
given()
.header("Authorization", V2_AUTH)
.when()
.get("/v2/email/configuration-sets/a.b")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo(
"Invalid configuration set name <a.b>: only alphanumeric ASCII characters, '_', and '-' are allowed."));
}
@Test
void v2_lengthIsCheckedBeforeCharacters() {
given()
.header("Authorization", V2_AUTH)
.when()
.delete("/v2/email/configuration-sets/b." + SIXTY_FIVE)
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("Configuration set name cannot exceed 64 characters."));
}
@Test
void v2_createWithEmptyName_mustBeSpecified() {
given()
.contentType("application/json")
.header("Authorization", V2_AUTH)
.body("{\"ConfigurationSetName\": \"\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("The configuration set name must be specified."));
}
@Test
void v2_createWithInvalidName_rejectsBeforeStoring() {
given()
.contentType("application/json")
.header("Authorization", V2_AUTH)
.body("{\"ConfigurationSetName\": \"bad name\"}")
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(400)
.body("message", equalTo(
"Invalid configuration set name <bad name>: only alphanumeric ASCII characters, '_', and '-' are allowed."));
}
@Test
void v1_invalidCharacters_sameMessageAsV2() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", V1_AUTH)
.formParam("Action", "DescribeConfigurationSet")
.formParam("ConfigurationSetName", "a.b")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"))
.body("ErrorResponse.Error.Message", equalTo(
"Invalid configuration set name <a.b>: only alphanumeric ASCII characters, '_', and '-' are allowed."));
}
@Test
void v1_tooLong() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", V1_AUTH)
.formParam("Action", "DeleteConfigurationSet")
.formParam("ConfigurationSetName", SIXTY_FIVE)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Message", equalTo("Configuration set name cannot exceed 64 characters."));
}
@Test
void v1_emptyName_mustBeSpecified() {
for (String[] action : new String[][] {
{"CreateConfigurationSet", "ConfigurationSet.Name"},
{"DescribeConfigurationSet", "ConfigurationSetName"},
{"DeleteConfigurationSet", "ConfigurationSetName"},
{"UpdateConfigurationSetSendingEnabled", "ConfigurationSetName"},
}) {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", V1_AUTH)
.formParam("Action", action[0])
.formParam(action[1], "")
.formParam("Enabled", "true")
.when()
.post("/")
.then()
.statusCode(400)
.body(containsString("<Code>InvalidParameterValue</Code>"))
.body("ErrorResponse.Error.Message", equalTo("The configuration set name must be specified."));
}
}
@Test
void v1_updateSendingEnabled_validatesTheName() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", V1_AUTH)
.formParam("Action", "UpdateConfigurationSetSendingEnabled")
.formParam("ConfigurationSetName", "a.b")
.formParam("Enabled", "true")
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"))
.body("ErrorResponse.Error.Message", equalTo(
"Invalid configuration set name <a.b>: only alphanumeric ASCII characters, '_', and '-' are allowed."));
}
@Test
void v1_sendEmail_validatesTheConfigurationSetName() {
given()
.contentType("application/x-www-form-urlencoded")
.header("Authorization", V1_AUTH)
.formParam("Action", "SendEmail")
.formParam("Source", "sender@example.com")
.formParam("Destination.ToAddresses.member.1", "success@simulator.amazonses.com")
.formParam("Message.Subject.Data", "s")
.formParam("Message.Body.Text.Data", "t")
.formParam("ConfigurationSetName", SIXTY_FIVE)
.when()
.post("/")
.then()
.statusCode(400)
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"))
.body("ErrorResponse.Error.Message", equalTo("Configuration set name cannot exceed 64 characters."));
}
}
@@ -388,7 +388,7 @@ class SesEmailIdentityConfigurationSetV2IntegrationTest {
.body("{\"EmailIdentity\":\"" + id + "\",\"ConfigurationSetName\":\" \"}")
.when().post("/v2/email/identities").then().statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("ConfigurationSetName is required."));
.body("message", equalTo("Invalid configuration set name < >: only alphanumeric ASCII characters, '_', and '-' are allowed."));
given().header("Authorization", SES_AUTH)
.when().get("/v2/email/identities/" + id).then().statusCode(404);
}
@@ -0,0 +1,205 @@
package io.github.hectorvent.floci.services.ses;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
/**
* ResourceArn parsing and check order on the SES V2 tag endpoints, as probed against AWS.
*/
@QuarkusTest
class SesTagArnV2IntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
private static final String PREFIX = "arn:aws:ses:us-east-1:000000000000:";
private static final String BARE_VALIDATION = "{\"__type\":\"ValidationException\",\"message\":null}";
@ParameterizedTest
@ValueSource(strings = {
"",
" ",
"invalid-arn",
"arn:",
"arn:aws:ses:us-east-1:000000000000",
"arn::ses:us-east-1:000000000000:configuration-set/tagarn-any",
"arn:aws::us-east-1:000000000000:configuration-set/tagarn-any",
"arn:aws:ses:us-east-1::configuration-set/tagarn-any",
"arn:aws:ses:us-east-1:000000000000:",
"arn:aws:ses:us-east-1:000000000000:configuration-set",
"arn:aws:ses:us-east-1:000000000000:configuration-set/",
"arn:aws:ses:us-east-1:000000000000:configuration-set/ ",
"arn:aws:ses:us-east-1:000000000000:configuration-set/tagarn-any:extra",
"arn:aws:ses:us-east-1:000000000000:configuration-set/tagarn-any/extra",
"arn:aws:ses:us-east-1:000000000000:configuration-set:tagarn-any",
"arn:aws:ses:us-east-1:000000000000:foo/bar",
"arn:aws:ses:us-east-1:000000000000:dedicated-ip-pool/a:b",
})
void malformedArn_isOneFormatErrorOnEveryOperation(String arn) {
assertExpectedFormatError(listTags(arn));
assertExpectedFormatError(tag(arn));
assertExpectedFormatError(untag(arn));
}
@Test
void partitionAndService_addressTheSameResource() {
String name = createConfigurationSet("tagarn-alias", "keep", "yes");
for (String alias : new String[] {
"arn:aws-cn:ses:us-east-1:000000000000:configuration-set/" + name,
"arn:bogus:ses:us-east-1:000000000000:configuration-set/" + name,
"arn:aws:s3:us-east-1:000000000000:configuration-set/" + name,
}) {
listTags(alias).then().statusCode(200)
.body("Tags", hasSize(1))
.body("Tags[0].Key", equalTo("keep"));
}
tagWith("arn:aws:s3:us-east-1:000000000000:configuration-set/" + name, "via", "s3")
.then().statusCode(200);
listTags(PREFIX + "configuration-set/" + name).then().statusCode(200)
.body("Tags.Key", hasItem("via"));
}
@Test
void emptyRegion_readsAsAnotherRegion() {
String name = createConfigurationSet("tagarn-noregion", "keep", "yes");
String arn = "arn:aws:ses::000000000000:configuration-set/" + name;
listTags(arn).then().statusCode(200).body("Tags", hasSize(0));
tag(arn).then().statusCode(400).body("message", equalTo("Failed to tag resource"));
untag(arn).then().statusCode(400).body("message", equalTo("Failed to untag resource"));
}
@Test
void malformedAccount_isTheDifferentAccountError() {
String arn = "arn:aws:ses:us-east-1:12345:configuration-set/tagarn-any";
listTags(arn).then().statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("Operations on a resource created in a different account is not allowed"));
}
@ParameterizedTest
@ValueSource(strings = {"a.b", "bad name", "badé",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"})
void invalidConfigurationSetName_isMessagelessValidation(String name) {
String arn = PREFIX + "configuration-set/" + name;
listTags(arn).then().statusCode(400).body(equalTo(BARE_VALIDATION));
tag(arn).then().statusCode(400).body(equalTo(BARE_VALIDATION));
untag(arn).then().statusCode(400).body(equalTo(BARE_VALIDATION));
}
@Test
void differentAccount_winsOverInvalidName() {
listTags("arn:aws:ses:us-east-1:111111111111:configuration-set/bad name").then().statusCode(400)
.body("message", equalTo("Operations on a resource created in a different account is not allowed"));
}
@Test
void missingResource_winsOverRegionMismatchOnTagAndUntag() {
String arn = "arn:aws:ses:us-west-2:000000000000:configuration-set/tagarn-nowhere";
tag(arn).then().statusCode(404)
.body("message", equalTo("No ConfigurationSet present with name: tagarn-nowhere"));
untag(arn).then().statusCode(404)
.body("message", equalTo("No ConfigurationSet present with name: tagarn-nowhere"));
}
@Test
void omittedResourceArn_onTagAndUntag_isMessagelessValidation() {
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("{\"Tags\": [{\"Key\": \"k\", \"Value\": \"v\"}]}")
.when()
.post("/v2/email/tags")
.then()
.statusCode(400)
.body(equalTo(BARE_VALIDATION));
given()
.header("Authorization", AUTH_HEADER)
.queryParam("TagKeys", "k")
.when()
.delete("/v2/email/tags")
.then()
.statusCode(400)
.body(equalTo(BARE_VALIDATION));
}
@Test
void omittedResourceArn_onList_staysAClientError() {
// AWS answers this with a 500 InternalFailure; Floci keeps a 400 on purpose.
given()
.header("Authorization", AUTH_HEADER)
.when()
.get("/v2/email/tags")
.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("ResourceArn is required."));
}
private static void assertExpectedFormatError(Response response) {
response.then()
.statusCode(400)
.body("__type", equalTo("BadRequestException"))
.body("message", equalTo("ResourceArn is not the expected format"));
}
private static String createConfigurationSet(String prefix, String key, String value) {
String name = prefix + "-" + System.nanoTime();
given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"ConfigurationSetName": "%s", "Tags": [{"Key": "%s", "Value": "%s"}]}
""".formatted(name, key, value))
.when()
.post("/v2/email/configuration-sets")
.then()
.statusCode(200);
return name;
}
private static Response listTags(String arn) {
return given()
.header("Authorization", AUTH_HEADER)
.queryParam("ResourceArn", arn)
.when()
.get("/v2/email/tags");
}
private static Response tag(String arn) {
return tagWith(arn, "probe", "1");
}
private static Response tagWith(String arn, String key, String value) {
return given()
.contentType("application/json")
.header("Authorization", AUTH_HEADER)
.body("""
{"ResourceArn": "%s", "Tags": [{"Key": "%s", "Value": "%s"}]}
""".formatted(arn, key, value))
.when()
.post("/v2/email/tags");
}
private static Response untag(String arn) {
return given()
.header("Authorization", AUTH_HEADER)
.queryParam("ResourceArn", arn)
.queryParam("TagKeys", "probe")
.when()
.delete("/v2/email/tags");
}
}