mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
74b3cecf78
commit
86371d86cb
16 files changed
+541
-103
No files matched your search
@@ -465,9 +465,9 @@ Import jobs read their source from Floci's own S3 emulation, so the object has t
|
||||
|
||||
For a **single-recipient** list-managed send, Floci injects a functional unsubscribe link (matching AWS, which only does this for one recipient): the `{{amazonSESUnsubscribeUrl}}` body placeholder is replaced (up to twice) and a `List-Unsubscribe` header plus `List-Unsubscribe-Post: List-Unsubscribe=One-Click` are added (applied to the relayed message and shown under `Headers` at `GET /_aws/ses`; a caller-supplied `List-Unsubscribe` is overridden, matching AWS). The `{{amazonSESUnsubscribeUrl}}` placeholder is also preserved through template rendering so a templated body can carry it. On a send without `ListManagementOptions`, the placeholder is left in the body verbatim (neither replaced nor stripped) — this specific behavior is Floci's choice and is not verified against real SES. Unlike AWS's opaque hosted URL, the link points at Floci's own `/_aws/ses/unsubscribe?region=…&contactList=…&address=…&topic=…` endpoint. `GET` (a browser click) only renders a confirmation page and changes nothing — matching AWS's landing-page behavior and avoiding the RFC 8058 hazard where a client or bot that prefetches the link would silently unsubscribe the contact — while `POST` (the one-click request the confirmation form submits) applies the opt-out (a topic → `OPT_OUT` for that topic; no topic → `UnsubscribeAll`), auto-creating the contact if needed. Two deviations from AWS here: the link is carried as readable query parameters rather than an opaque token (so, like the rest of Floci, the endpoint is unauthenticated and only safe on a trusted dev/test network — a `POST` can opt out any contact), and only the one-click URL entry is emitted — its scheme follows Floci's base URL (`http` unless TLS is enabled) — whereas AWS also includes a `mailto:` entry, which Floci can't service since it has no inbound mail endpoint. Raw (MIME) sends do not get link injection yet.
|
||||
|
||||
Tag operations accept `arn:aws:ses:<region>:<account>:<type>/<name>` ARNs for seven resource types: `configuration-set`, `template`, `identity`, `contact-list`, `custom-verification-email-template`, `dedicated-ip-pool`, and `tenant`; other types return `NotFoundException`. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, `CreateEmailIdentity`, `CreateContactList`, `CreateCustomVerificationEmailTemplate`, `CreateDedicatedIpPool`, and `CreateTenant` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` and `UpdateCustomVerificationEmailTemplate` do not modify tags. A tenant ARN has two path segments (`tenant/<name>/<tenantId>`) and resolves by the TenantId alone (the name is never matched, so tags are TenantId-scoped across delete/recreate), with the list ordered by key and the not-found wording reproducing AWS's own missing space ("No Tenant present with name: \<name\>with tenantId: \<id\>"). Tenant tags live on the tenant record (shared with `CreateTenant`/`GetTenant`).
|
||||
Tag operations accept `arn:aws:ses:<region>:<account>:<type>/<name>` ARNs for seven resource types: `configuration-set`, `template`, `identity`, `contact-list`, `custom-verification-email-template`, `dedicated-ip-pool`, and `tenant`. Any other type, or an ARN missing its partition, service, account, or resource name, fails with `BadRequestException` ("ResourceArn is not the expected format"); the partition and service are required but not compared, so any value addresses the same resource. Tags supplied to `CreateConfigurationSet`, `CreateEmailTemplate`, `CreateEmailIdentity`, `CreateContactList`, `CreateCustomVerificationEmailTemplate`, `CreateDedicatedIpPool`, and `CreateTenant` are reachable through `ListTagsForResource`; `UpdateEmailTemplate` and `UpdateCustomVerificationEmailTemplate` do not modify tags. A tenant ARN has two path segments (`tenant/<name>/<tenantId>`) and resolves by the TenantId alone (the name is never matched, so tags are TenantId-scoped across delete/recreate), with the list ordered by key and the not-found wording reproducing AWS's own missing space ("No Tenant present with name: \<name\>with tenantId: \<id\>"). Tenant tags live on the tenant record (shared with `CreateTenant`/`GetTenant`).
|
||||
|
||||
ARN handling is otherwise uniform across the types (probe-confirmed against real AWS). A foreign account id fails first with `BadRequestException` ("Operations on a resource created in a different account is not allowed"). A region differing from the signing region fails `TagResource` / `UntagResource` with `BadRequestException` ("Failed to tag resource" / "Failed to untag resource"); `ListTagsForResource` instead checks existence in the signing region (`NotFoundException`, "No \<Shape\> present with name: \<name\>") and keys tags by the literal ARN, so a mismatched-region ARN returns `200` with an empty tag set. An empty `Tags` array on `TagResource` is not an error (the account, region, and existence checks still run, then the empty merge no-ops), while a missing/empty `TagKeys` on `UntagResource` fails with a message-less `ValidationException` (AWS sends only the error-type header with an empty body; Floci's standard error body carries `"message": null`). A non-string tag `Key`/`Value` or a non-object `Tags` element is rejected with `SerializationException` rather than coerced, matching AWS's restJson1 deserializer.
|
||||
ARN handling is otherwise uniform across the types (probe-confirmed against real AWS). A foreign account id fails first with `BadRequestException` ("Operations on a resource created in a different account is not allowed"). An invalid configuration-set name in the ARN fails next with a message-less `ValidationException`. A region differing from the signing region fails `TagResource` / `UntagResource` with `BadRequestException` ("Failed to tag resource" / "Failed to untag resource"), checked after the resource is found in the signing region; `ListTagsForResource` instead checks existence in the signing region (`NotFoundException`, "No \<Shape\> present with name: \<name\>") and keys tags by the literal ARN, so a mismatched-region ARN returns `200` with an empty tag set. An empty `Tags` array on `TagResource` is not an error (the account, region, and existence checks still run, then the empty merge no-ops), while a missing/empty `TagKeys` on `UntagResource` fails with a message-less `ValidationException` (AWS sends only the error-type header with an empty body; Floci's standard error body carries `"message": null`). An omitted `ResourceArn` is a message-less `ValidationException` on `TagResource` / `UntagResource`; on `ListTagsForResource` AWS answers it with a `500 InternalFailure`, which Floci replaces with `BadRequestException` ("ResourceArn is required."). A non-string tag `Key`/`Value` or a non-object `Tags` element is rejected with `SerializationException` rather than coerced, matching AWS's restJson1 deserializer.
|
||||
|
||||
The same AWS-compatible validation applies wherever tags are set (including `CreateContactList` and `TagResource`): at most 50 tags, unique keys, keys 1–128 / values 0–256 code points, characters limited to letters, numbers, Unicode whitespace and `_ . : / = + - @`, and the reserved `aws:` key prefix. `TagResource` applies the 50-tag limit to the merged (existing + incoming) set. Violations return `BadRequestException` with AWS's messages.
|
||||
|
||||
|
||||
+1
-3
@@ -87,9 +87,7 @@ public class SesConfigurationSetController {
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
String name = request.path("ConfigurationSetName").asText(null);
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
SesConfigurationSetService.validateName(name);
|
||||
ConfigurationSet cs = new ConfigurationSet(name);
|
||||
List<Tag> parsedTags = parseTagsArray(request.path("Tags"));
|
||||
if (parsedTags != null) {
|
||||
|
||||
+18
-10
@@ -48,11 +48,12 @@ import java.util.regex.Pattern;
|
||||
* reasons) and the tenant delete-guard around {@link #remove}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesConfigurationSetService {
|
||||
public class SesConfigurationSetService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesConfigurationSetService.class);
|
||||
|
||||
private static final Pattern CONFIG_SET_NAME = Pattern.compile("^[A-Za-z0-9_-]{1,64}$");
|
||||
private static final Pattern CONFIG_SET_NAME = Pattern.compile("^[A-Za-z0-9_-]+$");
|
||||
private static final int MAX_CONFIG_SET_NAME_LENGTH = 64;
|
||||
private static final Set<String> VDM_FEATURE_STATES = Set.of("ENABLED", "DISABLED");
|
||||
|
||||
private static final Pattern EVENT_DESTINATION_NAME_CHARS = Pattern.compile("^[A-Za-z0-9_-]+$");
|
||||
@@ -85,7 +86,7 @@ public class SesConfigurationSetService {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName is required.", 400);
|
||||
}
|
||||
validateConfigurationSetName(configSet.getName());
|
||||
validateName(configSet.getName());
|
||||
SesTags.validate(configSet.getTags());
|
||||
if (configSet.getSuppressionOptions() != null
|
||||
&& configSet.getSuppressionOptions().getSuppressedReasons() != null) {
|
||||
@@ -343,10 +344,12 @@ public class SesConfigurationSetService {
|
||||
}
|
||||
|
||||
/** The ARN-dispatched tag operations, sharing the store behind {@code CreateConfigurationSet.Tags}. */
|
||||
@Override
|
||||
public List<Tag> listTags(String name, String region) {
|
||||
return new ArrayList<>(requireForTags(name, region).getTags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tag(String name, String region, List<Tag> newTags) {
|
||||
ConfigurationSet cs = requireForTags(name, region);
|
||||
cs.setTags(SesTags.merge(cs.getTags(), newTags));
|
||||
@@ -354,6 +357,7 @@ public class SesConfigurationSetService {
|
||||
LOG.infov("Tagged SES configuration set: {0} (region {1}, +{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String name, String region, List<String> tagKeys) {
|
||||
ConfigurationSet cs = requireForTags(name, region);
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
@@ -384,7 +388,7 @@ public class SesConfigurationSetService {
|
||||
|
||||
/** For guards that must not trip the key derivation's name validation (the tenant gate). */
|
||||
static boolean isValidName(String name) {
|
||||
return name != null && CONFIG_SET_NAME.matcher(name).matches();
|
||||
return name != null && name.length() <= MAX_CONFIG_SET_NAME_LENGTH && CONFIG_SET_NAME.matcher(name).matches();
|
||||
}
|
||||
|
||||
// ──────────────────────── Domain-pure option setters ────────────────────────
|
||||
@@ -723,20 +727,24 @@ public class SesConfigurationSetService {
|
||||
return count;
|
||||
}
|
||||
|
||||
private static void validateConfigurationSetName(String name) {
|
||||
if (name == null || name.isBlank()) {
|
||||
static void validateName(String name) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName is required.", 400);
|
||||
"The configuration set name must be specified.", 400);
|
||||
}
|
||||
if (name.length() > MAX_CONFIG_SET_NAME_LENGTH) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Configuration set name cannot exceed " + MAX_CONFIG_SET_NAME_LENGTH + " characters.", 400);
|
||||
}
|
||||
if (!CONFIG_SET_NAME.matcher(name).matches()) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"ConfigurationSetName must be 1-64 characters and may only contain "
|
||||
+ "alphanumeric characters, underscores, and hyphens.", 400);
|
||||
"Invalid configuration set name <" + name + ">: only alphanumeric ASCII characters, "
|
||||
+ "'_', and '-' are allowed.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String configSetKey(String region, String name) {
|
||||
validateConfigurationSetName(name);
|
||||
validateName(name);
|
||||
return "configSet::" + region + "::" + name;
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ import java.util.regex.Pattern;
|
||||
* with the facade's address extractor injected as a callback.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesContactService {
|
||||
public class SesContactService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesContactService.class);
|
||||
|
||||
@@ -110,6 +110,7 @@ public class SesContactService {
|
||||
.orElseThrow(() -> contactListNotFound(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listTags(String name, String region) {
|
||||
ContactList list = contactListStore.get(contactListKey(region, name))
|
||||
.orElseThrow(() -> tagTargetNotFound(name));
|
||||
@@ -121,6 +122,7 @@ public class SesContactService {
|
||||
* used by deletion, so tagging can't resurrect a concurrently deleted list or overwrite a
|
||||
* concurrent mutation with a stale object.
|
||||
*/
|
||||
@Override
|
||||
public void tag(String name, String region, List<Tag> newTags) {
|
||||
String key = contactListKey(region, name);
|
||||
synchronized (contactMutationLock) {
|
||||
@@ -131,6 +133,7 @@ public class SesContactService {
|
||||
LOG.infov("Tagged SES contact list: {0} in region {1} (+{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String name, String region, List<String> tagKeys) {
|
||||
String key = contactListKey(region, name);
|
||||
synchronized (contactMutationLock) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.Set;
|
||||
* a domain used by the send path is not turned into a cross-service dependency.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesCvetService {
|
||||
public class SesCvetService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesCvetService.class);
|
||||
|
||||
@@ -125,6 +125,7 @@ public class SesCvetService {
|
||||
return cvetStore.get(cvetKey(region, templateName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listTags(String templateName, String region) {
|
||||
CustomVerificationEmailTemplate template = cvetStore.get(cvetKey(region, templateName))
|
||||
.orElseThrow(() -> tagTargetNotFound(templateName));
|
||||
@@ -136,6 +137,7 @@ public class SesCvetService {
|
||||
* lock so a concurrent update can't be overwritten with a stale object and a concurrent delete
|
||||
* can't be resurrected.
|
||||
*/
|
||||
@Override
|
||||
public void tag(String templateName, String region, List<Tag> newTags) {
|
||||
String key = cvetKey(region, templateName);
|
||||
synchronized (cvetMutationLock) {
|
||||
@@ -148,6 +150,7 @@ public class SesCvetService {
|
||||
templateName, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String templateName, String region, List<String> tagKeys) {
|
||||
String key = cvetKey(region, templateName);
|
||||
synchronized (cvetMutationLock) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.function.Function;
|
||||
* checks pool existence through {@link #dedicatedIpPoolExists}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesDedicatedIpService {
|
||||
public class SesDedicatedIpService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesDedicatedIpService.class);
|
||||
|
||||
@@ -107,6 +107,7 @@ public class SesDedicatedIpService {
|
||||
LOG.infov("Deleted SES dedicated IP pool: {0} in region {1}", poolName, region);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listTags(String poolName, String region) {
|
||||
DedicatedIpPool pool = dedicatedIpPoolStore.get(dedicatedIpPoolKey(region, poolName))
|
||||
.orElseThrow(() -> tagTargetNotFound(poolName));
|
||||
@@ -117,6 +118,7 @@ public class SesDedicatedIpService {
|
||||
* Merges the incoming tags into the stored pool. The lookup and write share the mutation lock
|
||||
* so tagging can't resurrect a concurrently deleted pool or lose a concurrent tag update.
|
||||
*/
|
||||
@Override
|
||||
public void tag(String poolName, String region, List<Tag> newTags) {
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
synchronized (poolMutationLock) {
|
||||
@@ -128,6 +130,7 @@ public class SesDedicatedIpService {
|
||||
LOG.infov("Tagged SES dedicated IP pool: {0} in region {1} (+{2} tags)", poolName, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String poolName, String region, List<String> tagKeys) {
|
||||
String key = dedicatedIpPoolKey(region, poolName);
|
||||
synchronized (poolMutationLock) {
|
||||
|
||||
@@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* cascade around {@link #delete}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesIdentityService {
|
||||
public class SesIdentityService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesIdentityService.class);
|
||||
|
||||
@@ -427,10 +427,12 @@ public class SesIdentityService {
|
||||
identityValue, notificationType, enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> listTags(String identityValue, String region) {
|
||||
return new ArrayList<>(requireForTags(identityValue, region).getTags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tag(String identityValue, String region, List<Tag> newTags) {
|
||||
Identity identity = requireForTags(identityValue, region);
|
||||
identity.setTags(SesTags.merge(identity.getTags(), newTags));
|
||||
@@ -438,6 +440,7 @@ public class SesIdentityService {
|
||||
LOG.infov("Tagged SES identity: {0} (region {1}, +{2} tags)", identityValue, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String identityValue, String region, List<String> tagKeys) {
|
||||
Identity identity = requireForTags(identityValue, region);
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
|
||||
@@ -822,10 +822,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleCreateConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSet.Name");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSet.Name is required.", 400);
|
||||
}
|
||||
String name = requireConfigurationSetName(params, "ConfigurationSet.Name");
|
||||
ConfigurationSet configSet = new ConfigurationSet(name);
|
||||
configSet.setReputationMetricsEnabled(false);
|
||||
sesService.createConfigurationSet(configSet, region);
|
||||
@@ -833,10 +830,7 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDescribeConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSetName");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
String name = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
ConfigurationSet cs = configSetService.get(name, region);
|
||||
List<String> attrs = extractMembers(params, "ConfigurationSetAttributeNames");
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
@@ -951,17 +945,14 @@ public class SesQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDeleteConfigurationSet(MultivaluedMap<String, String> params, String region) {
|
||||
String name = getParam(params, "ConfigurationSetName");
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "ConfigurationSetName is required.", 400);
|
||||
}
|
||||
String name = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
sesService.deleteConfigurationSet(name, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult("DeleteConfigurationSet", AwsNamespaces.SES)).build();
|
||||
}
|
||||
|
||||
private Response handleCreateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String edName = requireParam(params, "EventDestination.Name");
|
||||
EventDestination dest = readEventDestination(params, "EventDestination");
|
||||
configSetService.createEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
|
||||
@@ -971,7 +962,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleUpdateConfigurationSetEventDestination(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String edName = requireParam(params, "EventDestination.Name");
|
||||
EventDestination dest = readEventDestination(params, "EventDestination");
|
||||
configSetService.updateEventDestination(configSet, edName, dest, regionResolver.getAccountId(), region);
|
||||
@@ -981,7 +972,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleDeleteConfigurationSetEventDestination(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String edName = requireParam(params, "EventDestinationName");
|
||||
configSetService.deleteEventDestination(configSet, edName, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
@@ -990,7 +981,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleUpdateConfigurationSetSendingEnabled(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
boolean enabled = parseXsdBoolean(params, "Enabled");
|
||||
configSetService.setSendingEnabled(configSet, enabled, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
@@ -999,7 +990,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleCreateConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String domain = getParam(params, "TrackingOptions.CustomRedirectDomain");
|
||||
sesService.createConfigurationSetTrackingOptions(configSet, domain, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
@@ -1008,7 +999,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleUpdateConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String domain = getParam(params, "TrackingOptions.CustomRedirectDomain");
|
||||
sesService.updateConfigurationSetTrackingOptions(configSet, domain, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
@@ -1017,7 +1008,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleDeleteConfigurationSetTrackingOptions(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
configSetService.deleteTrackingOptions(configSet, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
"DeleteConfigurationSetTrackingOptions", AwsNamespaces.SES)).build();
|
||||
@@ -1025,7 +1016,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handleUpdateConfigurationSetReputationMetricsEnabled(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
boolean enabled = parseXsdBoolean(params, "Enabled");
|
||||
configSetService.setReputationMetricsEnabled(configSet, enabled, region);
|
||||
return Response.ok(AwsQueryResponse.envelopeEmptyResult(
|
||||
@@ -1034,7 +1025,7 @@ public class SesQueryHandler {
|
||||
|
||||
private Response handlePutConfigurationSetDeliveryOptions(MultivaluedMap<String, String> params,
|
||||
String region) {
|
||||
String configSet = requireParam(params, "ConfigurationSetName");
|
||||
String configSet = requireConfigurationSetName(params, "ConfigurationSetName");
|
||||
String tlsPolicy = getParam(params, "DeliveryOptions.TlsPolicy");
|
||||
// The V1 API accepts TlsPolicy Require/Optional (PascalCase, case-sensitive). Validate
|
||||
// here so an invalid enum value yields the v1 ValidationError AWS returns rather than the
|
||||
@@ -1513,6 +1504,12 @@ public class SesQueryHandler {
|
||||
return dest;
|
||||
}
|
||||
|
||||
private static String requireConfigurationSetName(MultivaluedMap<String, String> params, String name) {
|
||||
String v = params.getFirst(name);
|
||||
SesConfigurationSetService.validateName(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
private static String requireParam(MultivaluedMap<String, String> params, String name) {
|
||||
String v = params.getFirst(name);
|
||||
if (v == null || v.isBlank()) {
|
||||
|
||||
@@ -136,6 +136,8 @@ public class SesService {
|
||||
// Resolves the caller's account per request so send-event payloads report the sending account, not
|
||||
// the fixed default. Null in the package-private test constructor (falls back to defaultAccountId).
|
||||
private final RegionResolver regionResolver;
|
||||
// The V2 tag endpoints' resource types, keyed by the ARN's type segment.
|
||||
private final Map<String, SesTaggable> taggableDomains;
|
||||
|
||||
@Inject
|
||||
public SesService(SesIdentityService identityService, SesCvetService cvetService,
|
||||
@@ -162,6 +164,7 @@ public class SesService {
|
||||
this.defaultAccountId = config.defaultAccountId();
|
||||
this.baseUrl = config.effectiveBaseUrl();
|
||||
this.regionResolver = regionResolver;
|
||||
this.taggableDomains = taggableDomains();
|
||||
}
|
||||
|
||||
SesService(SesIdentityService identityService,
|
||||
@@ -192,6 +195,18 @@ public class SesService {
|
||||
this.defaultAccountId = "000000000000";
|
||||
this.baseUrl = "http://localhost:4566";
|
||||
this.regionResolver = null;
|
||||
this.taggableDomains = taggableDomains();
|
||||
}
|
||||
|
||||
private Map<String, SesTaggable> taggableDomains() {
|
||||
return Map.of(
|
||||
"configuration-set", configSetService,
|
||||
"template", templateService,
|
||||
"identity", identityService,
|
||||
"contact-list", contactService,
|
||||
"custom-verification-email-template", cvetService,
|
||||
"dedicated-ip-pool", dedicatedIpService,
|
||||
"tenant", tenantService);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1171,19 +1186,15 @@ public class SesService {
|
||||
}
|
||||
|
||||
public List<Tag> listResourceTags(String arn, String region) {
|
||||
if (arn == null) {
|
||||
// AWS answers an omitted ResourceArn on this read with a 500 InternalFailure
|
||||
// (probe-confirmed); Floci keeps a client error rather than mirror a server fault.
|
||||
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
|
||||
}
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
requireCallerAccount(ref);
|
||||
List<Tag> tags = switch (ref.type()) {
|
||||
case "configuration-set" -> configSetService.listTags(ref.name(), region);
|
||||
case "template" -> templateService.listTags(ref.name(), region);
|
||||
case "identity" -> identityService.listTags(ref.name(), region);
|
||||
case "contact-list" -> contactService.listTags(ref.name(), region);
|
||||
case "custom-verification-email-template" -> cvetService.listTags(ref.name(), region);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.listTags(ref.name(), region);
|
||||
case "tenant" -> tenantService.listTags(ref.name(), region);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
};
|
||||
requireValidResourceName(ref);
|
||||
List<Tag> tags = taggableDomains.get(ref.type()).listTags(ref.name(), region);
|
||||
// AWS checks existence against the signing region but keys the tag store by the literal
|
||||
// ARN: a mismatched ARN region passes the existence check above yet addresses an ARN
|
||||
// nothing was ever tagged under, so the result is empty (probe-confirmed across all six
|
||||
@@ -1195,8 +1206,13 @@ public class SesService {
|
||||
}
|
||||
|
||||
public void tagResource(String arn, String region, List<Tag> newTags) {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
ResourceRef ref = parseSesArn(requireResourceArnMember(arn));
|
||||
requireCallerAccount(ref);
|
||||
requireValidResourceName(ref);
|
||||
// Existence in the signing region is checked before the ARN's region is compared: a missing
|
||||
// resource is a 404 even when the regions also differ (probe-confirmed).
|
||||
SesTaggable domain = taggableDomains.get(ref.type());
|
||||
domain.listTags(ref.name(), region);
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to tag resource", 400);
|
||||
}
|
||||
@@ -1204,44 +1220,27 @@ public class SesService {
|
||||
// checks and then applies the empty merge as a no-op (probe-confirmed).
|
||||
List<Tag> tags = newTags == null ? List.of() : newTags;
|
||||
SesTags.validate(tags);
|
||||
switch (ref.type()) {
|
||||
case "configuration-set" -> configSetService.tag(ref.name(), region, tags);
|
||||
case "template" -> templateService.tag(ref.name(), region, tags);
|
||||
case "identity" -> identityService.tag(ref.name(), region, tags);
|
||||
case "contact-list" -> contactService.tag(ref.name(), region, tags);
|
||||
case "custom-verification-email-template" -> cvetService.tag(ref.name(), region, tags);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.tag(ref.name(), region, tags);
|
||||
case "tenant" -> tenantService.tag(ref.name(), region, tags);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
domain.tag(ref.name(), region, tags);
|
||||
}
|
||||
|
||||
public void untagResource(String arn, String region, List<String> tagKeys) {
|
||||
ResourceRef ref = parseSesArn(arn);
|
||||
ResourceRef ref = parseSesArn(requireResourceArnMember(arn));
|
||||
requireCallerAccount(ref);
|
||||
if (tagKeys == null || tagKeys.isEmpty()) {
|
||||
// AWS rejects a missing/empty TagKeys member with a message-less ValidationException
|
||||
// (probe-confirmed: only the error-type header, empty body), after the account guard
|
||||
// and before the region guard. The null message is deliberate — it surfaces through
|
||||
// Floci's standard error body as "message":null, which restJson1 SDKs parse the same
|
||||
// way as AWS's empty body since they read x-amzn-errortype first.
|
||||
// and before the name, existence and region checks. The null message is deliberate: it
|
||||
// surfaces through Floci's standard error body as "message":null, which restJson1 SDKs
|
||||
// parse the same way as AWS's empty body since they read x-amzn-errortype first.
|
||||
throw new AwsException("ValidationException", null, 400);
|
||||
}
|
||||
requireValidResourceName(ref);
|
||||
SesTaggable domain = taggableDomains.get(ref.type());
|
||||
domain.listTags(ref.name(), region);
|
||||
if (!ref.region().equals(region)) {
|
||||
throw new AwsException("BadRequestException", "Failed to untag resource", 400);
|
||||
}
|
||||
switch (ref.type()) {
|
||||
case "configuration-set" -> configSetService.untag(ref.name(), region, tagKeys);
|
||||
case "template" -> templateService.untag(ref.name(), region, tagKeys);
|
||||
case "identity" -> identityService.untag(ref.name(), region, tagKeys);
|
||||
case "contact-list" -> contactService.untag(ref.name(), region, tagKeys);
|
||||
case "custom-verification-email-template" -> cvetService.untag(ref.name(), region, tagKeys);
|
||||
case "dedicated-ip-pool" -> dedicatedIpService.untag(ref.name(), region, tagKeys);
|
||||
case "tenant" -> tenantService.untag(ref.name(), region, tagKeys);
|
||||
default -> throw new AwsException("NotFoundException",
|
||||
"Resource " + arn + " was not found.", 404);
|
||||
}
|
||||
domain.untag(ref.name(), region, tagKeys);
|
||||
}
|
||||
|
||||
// name is everything after the type's first slash and may itself contain one: a tenant ARN's
|
||||
@@ -1261,31 +1260,58 @@ public class SesService {
|
||||
}
|
||||
}
|
||||
|
||||
private static ResourceRef parseSesArn(String arn) {
|
||||
if (arn == null || arn.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
|
||||
// TagResource and UntagResource reject an omitted ResourceArn with the same message-less
|
||||
// ValidationException as an omitted TagKeys (probe-confirmed).
|
||||
private static String requireResourceArnMember(String arn) {
|
||||
if (arn == null) {
|
||||
throw new AwsException("ValidationException", null, 400);
|
||||
}
|
||||
return arn;
|
||||
}
|
||||
|
||||
// A configuration-set name that breaks the naming rule is a message-less ValidationException,
|
||||
// after the account check and before existence (probe-confirmed).
|
||||
private static void requireValidResourceName(ResourceRef ref) {
|
||||
if ("configuration-set".equals(ref.type()) && !SesConfigurationSetService.isValidName(ref.name())) {
|
||||
throw new AwsException("ValidationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS answers every malformed tag ARN with one message (probe-confirmed). The partition and
|
||||
* service are never compared, only required: any value addresses the same resource. The region
|
||||
* may be empty; it only meets the signing-region comparison.
|
||||
*/
|
||||
private ResourceRef parseSesArn(String arn) {
|
||||
AwsArnUtils.Arn parsed;
|
||||
try {
|
||||
parsed = AwsArnUtils.parse(arn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);
|
||||
throw invalidResourceArn();
|
||||
}
|
||||
if (!"ses".equals(parsed.service())) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"ResourceArn must be a SES ARN: " + arn, 400);
|
||||
}
|
||||
if (parsed.region().isEmpty() || parsed.accountId().isEmpty()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"ResourceArn must include region and account: " + arn, 400);
|
||||
if (parsed.partition().isEmpty() || parsed.service().isEmpty() || parsed.accountId().isEmpty()) {
|
||||
throw invalidResourceArn();
|
||||
}
|
||||
String resource = parsed.resource();
|
||||
int slash = resource.indexOf('/');
|
||||
if (slash <= 0 || slash == resource.length() - 1) {
|
||||
throw new AwsException("BadRequestException", "Invalid ARN: " + arn, 400);
|
||||
if (slash < 0) {
|
||||
throw invalidResourceArn();
|
||||
}
|
||||
return new ResourceRef(parsed.accountId(), parsed.region(),
|
||||
resource.substring(0, slash), resource.substring(slash + 1));
|
||||
String type = resource.substring(0, slash);
|
||||
String name = resource.substring(slash + 1);
|
||||
if (!taggableDomains.containsKey(type) || name.isBlank()) {
|
||||
throw invalidResourceArn();
|
||||
}
|
||||
// Identity names keep their pass-through: an email local part may legally hold either character.
|
||||
if (!"identity".equals(type)
|
||||
&& (name.contains(":") || (!"tenant".equals(type) && name.contains("/")))) {
|
||||
throw invalidResourceArn();
|
||||
}
|
||||
return new ResourceRef(parsed.accountId(), parsed.region(), type, name);
|
||||
}
|
||||
|
||||
private static AwsException invalidResourceArn() {
|
||||
return new AwsException("BadRequestException", "ResourceArn is not the expected format", 400);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Suppression list ────────────────────────────
|
||||
|
||||
@@ -20,6 +20,7 @@ import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.List;
|
||||
@@ -63,9 +64,6 @@ public class SesTagController {
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
String arn = request.path("ResourceArn").asText(null);
|
||||
if (arn == null || arn.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "ResourceArn is required.", 400);
|
||||
}
|
||||
List<Tag> tags = parseTagsArray(request.path("Tags"));
|
||||
if (tags == null) {
|
||||
throw new AwsException("BadRequestException", "Tags must be an array.", 400);
|
||||
@@ -82,10 +80,10 @@ public class SesTagController {
|
||||
|
||||
@DELETE
|
||||
@Path("/tags")
|
||||
public Response untagResource(@Context HttpHeaders headers,
|
||||
@QueryParam("ResourceArn") String arn,
|
||||
public Response untagResource(@Context HttpHeaders headers, @Context UriInfo uriInfo,
|
||||
@QueryParam("TagKeys") List<String> tagKeys) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String arn = resourceArn(uriInfo);
|
||||
try {
|
||||
sesService.untagResource(arn, region, tagKeys);
|
||||
LOG.infov("SES V2 UntagResource: {0}", arn);
|
||||
@@ -97,9 +95,9 @@ public class SesTagController {
|
||||
|
||||
@GET
|
||||
@Path("/tags")
|
||||
public Response listTagsForResource(@Context HttpHeaders headers,
|
||||
@QueryParam("ResourceArn") String arn) {
|
||||
public Response listTagsForResource(@Context HttpHeaders headers, @Context UriInfo uriInfo) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String arn = resourceArn(uriInfo);
|
||||
try {
|
||||
List<Tag> tags = sesService.listResourceTags(arn, region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
@@ -115,4 +113,10 @@ public class SesTagController {
|
||||
throw remapV1Exception(e);
|
||||
}
|
||||
}
|
||||
|
||||
// A @QueryParam binds an empty value as null; read it raw so "ResourceArn=" stays a malformed ARN
|
||||
// rather than an omitted one.
|
||||
private static String resourceArn(UriInfo uriInfo) {
|
||||
return uriInfo.getQueryParameters().getFirst("ResourceArn");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.services.ses.model.Tag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A domain whose resources the V2 tag endpoints address by ARN. Each method resolves the resource
|
||||
* in {@code region} and fails with that domain's {@code NotFoundException} when it is missing.
|
||||
*/
|
||||
interface SesTaggable {
|
||||
|
||||
List<Tag> listTags(String name, String region);
|
||||
|
||||
void tag(String name, String region, List<Tag> newTags);
|
||||
|
||||
void untag(String name, String region, List<String> tagKeys);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import java.util.regex.Pattern;
|
||||
* {@link SesTags#validate} rather than depending back on the facade.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesTemplateService {
|
||||
public class SesTemplateService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesTemplateService.class);
|
||||
|
||||
@@ -212,10 +212,12 @@ public class SesTemplateService {
|
||||
}
|
||||
|
||||
/** The ARN-dispatched tag operations, sharing the store behind {@code CreateEmailTemplate.Tags}. */
|
||||
@Override
|
||||
public List<Tag> listTags(String name, String region) {
|
||||
return new ArrayList<>(requireForTags(name, region).getTags());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tag(String name, String region, List<Tag> newTags) {
|
||||
EmailTemplate template = requireForTags(name, region);
|
||||
template.setTags(SesTags.merge(template.getTags(), newTags));
|
||||
@@ -223,6 +225,7 @@ public class SesTemplateService {
|
||||
LOG.infov("Tagged SES template: {0} (region {1}, +{2} tags)", name, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String name, String region, List<String> tagKeys) {
|
||||
EmailTemplate template = requireForTags(name, region);
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
|
||||
@@ -47,7 +47,7 @@ import java.util.regex.Pattern;
|
||||
* {@code DeleteTenant} callback. Tenant-scoped sending is a separate follow-up.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class SesTenantService {
|
||||
public class SesTenantService implements SesTaggable {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(SesTenantService.class);
|
||||
|
||||
@@ -255,6 +255,7 @@ public class SesTenantService {
|
||||
}
|
||||
|
||||
/** The ARN-dispatched tag operations; {@code resourceRemainder} is the ARN's {@code <name>/<tenantId>} part. */
|
||||
@Override
|
||||
public List<Tag> listTags(String resourceRemainder, String region) {
|
||||
Tenant tenant = tenantForTagArn(resourceRemainder, region);
|
||||
// AWS returns a tenant's tags ordered by key (probe-confirmed).
|
||||
@@ -263,12 +264,14 @@ public class SesTenantService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tag(String resourceRemainder, String region, List<Tag> newTags) {
|
||||
mutateTags(resourceRemainder, region, tags -> SesTags.merge(tags, newTags));
|
||||
LOG.infov("Tagged SES tenant <{0}> (region {1}, +{2} tags)",
|
||||
resourceRemainder, region, newTags.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untag(String resourceRemainder, String region, List<String> tagKeys) {
|
||||
Set<String> toRemove = new HashSet<>(tagKeys);
|
||||
mutateTags(resourceRemainder, region, tags -> {
|
||||
|
||||
+164
@@ -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."));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
+205
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user