diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesListManagementOptionsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSendEmailOptionsTest.java similarity index 60% rename from compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesListManagementOptionsTest.java rename to compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSendEmailOptionsTest.java index ae50e2cac6..e549c93e19 100644 --- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesListManagementOptionsTest.java +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesSendEmailOptionsTest.java @@ -6,13 +6,16 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import software.amazon.awssdk.services.sesv2.SesV2Client; import software.amazon.awssdk.services.sesv2.model.AlreadyExistsException; +import software.amazon.awssdk.services.sesv2.model.BadRequestException; import software.amazon.awssdk.services.sesv2.model.Body; +import software.amazon.awssdk.services.sesv2.model.ConfigurationOverrides; import software.amazon.awssdk.services.sesv2.model.Content; import software.amazon.awssdk.services.sesv2.model.CreateContactListRequest; import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest; import software.amazon.awssdk.services.sesv2.model.DeleteContactListRequest; import software.amazon.awssdk.services.sesv2.model.Destination; import software.amazon.awssdk.services.sesv2.model.EmailContent; +import software.amazon.awssdk.services.sesv2.model.FeatureStatus; import software.amazon.awssdk.services.sesv2.model.GetContactRequest; import software.amazon.awssdk.services.sesv2.model.GetContactResponse; import software.amazon.awssdk.services.sesv2.model.ListManagementOptions; @@ -21,17 +24,24 @@ import software.amazon.awssdk.services.sesv2.model.SendEmailRequest; import software.amazon.awssdk.services.sesv2.model.SendEmailResponse; import software.amazon.awssdk.services.sesv2.model.SubscriptionStatus; import software.amazon.awssdk.services.sesv2.model.Topic; +import software.amazon.awssdk.services.sesv2.model.TrackingConfigurationOverrides; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; /** - * SDK compatibility test for {@code SendEmail} with {@code ListManagementOptions} through the AWS - * Java SDK v2 {@link SesV2Client}. A real SDK round-trip proves the nested {@code ListManagementOptions} - * structure (ContactListName + optional TopicName) marshals as a real client sends it — and that Floci - * actually processes it, since an absent recipient is auto-created as a contact on the list (matches AWS). + * SDK compatibility test for the {@code SendEmail} request options, through the AWS Java SDK v2 + * {@link SesV2Client}. A real SDK round-trip proves each nested structure marshals as a real client + * sends it, and that Floci actually processes it: + * */ -@DisplayName("SES v2 SendEmail ListManagementOptions") -class SesListManagementOptionsTest { +@DisplayName("SES v2 SendEmail request options") +class SesSendEmailOptionsTest { private static final String LIST = "compat-lmo-list"; private static final String TOPIC = "weekly"; @@ -122,4 +132,49 @@ class SesListManagementOptionsTest { assertThat(response.messageId()).isNotBlank(); } + + @Test + void sendWithTrackingOverrides_isAccepted() { + SendEmailResponse response = sesV2.sendEmail(SendEmailRequest.builder() + .fromEmailAddress(FROM) + .destination(Destination.builder() + .toAddresses("tracking-" + TestFixtures.uniqueName() + "@example.com").build()) + .content(EmailContent.builder() + .simple(Message.builder() + .subject(Content.builder().data("compat-tracking").build()) + .body(Body.builder().text(Content.builder().data("hi").build()).build()) + .build()) + .build()) + .configurationOverrides(ConfigurationOverrides.builder() + .tracking(TrackingConfigurationOverrides.builder() + .openTrackingEnabled(FeatureStatus.DISABLED) + .clickTrackingEnabled(FeatureStatus.ENABLED) + .build()) + .build()) + .build()); + + assertThat(response.messageId()).isNotBlank(); + } + + @Test + void sendWithAnInvalidTrackingValue_isRefused() { + assertThatThrownBy(() -> sesV2.sendEmail(SendEmailRequest.builder() + .fromEmailAddress(FROM) + .destination(Destination.builder() + .toAddresses("tracking-" + TestFixtures.uniqueName() + "@example.com").build()) + .content(EmailContent.builder() + .simple(Message.builder() + .subject(Content.builder().data("compat-tracking").build()) + .body(Body.builder().text(Content.builder().data("hi").build()).build()) + .build()) + .build()) + .configurationOverrides(ConfigurationOverrides.builder() + .tracking(TrackingConfigurationOverrides.builder().openTrackingEnabled("yes").build()) + .build()) + .build())) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("1 validation error detected: Value at " + + "'configurationOverrides.tracking.openTrackingEnabled' failed to satisfy constraint: " + + "Member must satisfy enum value set: [ENABLED, DISABLED]"); + } } diff --git a/docs/services/ses.md b/docs/services/ses.md index 0350168d80..cec39b21e1 100644 --- a/docs/services/ses.md +++ b/docs/services/ses.md @@ -473,6 +473,8 @@ 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. +`SendEmail` and `SendBulkEmail` accept [`ConfigurationOverrides`](https://docs.aws.amazon.com/ses/latest/dg/configuration-overrides.html) and validate its `Tracking` values the way real SES does (probed 2026-10-06). Floci has no open or click tracking, so a valid override has no effect, and `ses:ApplyTrackingConfigurationOverrides` is not enforced. An invalid value is reported on its own even when the request has another model violation, such as a missing `Content`, which SES reports together with it in one message. + Tag operations accept `arn:aws:ses:::/` 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//`) 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: \with tenantId: \"). 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"). 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 \ present with 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. diff --git a/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java new file mode 100644 index 0000000000..e10ad0d96a --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java @@ -0,0 +1,29 @@ +package io.github.hectorvent.floci.core.common; + +import java.util.List; + +/** + * The message AWS's Smithy validation layer answers when a request breaks its model's constraints: + * "1 validation error detected: a" or "N validation errors detected: a; b", each violation reading + * "Value at 'path' failed to satisfy constraint: ...". The wording is Smithy's, shared by every + * service built on it; only the error code differs by protocol. + */ +public final class SmithyValidationErrors { + + private SmithyValidationErrors() {} + + public static String message(List violations) { + if (violations.isEmpty()) { + throw new IllegalArgumentException("no violations to report"); + } + String count = violations.size() == 1 + ? "1 validation error detected: " + : violations.size() + " validation errors detected: "; + return count + String.join("; ", violations); + } + + /** The 400 error carrying {@link #message} under the protocol's validation error code. */ + public static AwsException exception(String errorCode, List violations) { + return new AwsException(errorCode, message(violations), 400); + } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java index acd302f72c..f3b5ac2262 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.ses.model.AccountDetails; @@ -199,9 +200,7 @@ public class SesAccountService { } } if (!errors.isEmpty()) { - throw new AwsException("BadRequestException", - errors.size() + " validation error" + (errors.size() > 1 ? "s" : "") - + " detected: " + String.join("; ", errors), 400); + throw SmithyValidationErrors.exception("BadRequestException", errors); } if (!isValidUrl(websiteUrl)) { throw new AwsException("BadRequestException", "Url contains invalid format", 400); diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java index 442734714c..035dbc62fe 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java @@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses; import com.fasterxml.jackson.core.type.TypeReference; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.PaginatedResult; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.ses.model.Contact; @@ -217,9 +218,8 @@ public class SesContactService implements SesTaggable { // SES V2 surfaces missing/invalid input as Smithy validation errors. Field paths and the // enum value order are taken verbatim from real AWS. private static AwsException validationError(String fieldPath, String constraint) { - return new AwsException("BadRequestException", - "1 validation error detected: Value at '" + fieldPath - + "' failed to satisfy constraint: " + constraint, 400); + return SmithyValidationErrors.exception("BadRequestException", + List.of("Value at '" + fieldPath + "' failed to satisfy constraint: " + constraint)); } private static void validateContactListName(String name) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java index cd883f9b90..7a89fb5340 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses; import com.fasterxml.jackson.databind.JsonNode; import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import java.util.ArrayList; import java.util.LinkedHashSet; @@ -92,11 +93,7 @@ final class SesExportFilters { requireFilterBlock(insights.path("Include"), "include", violations); requireFilterBlock(insights.path("Exclude"), "exclude", violations); if (!violations.isEmpty()) { - String header = violations.size() == 1 - ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - throw new AwsException("BadRequestException", - header + String.join("; ", violations), 400); + throw SmithyValidationErrors.exception("BadRequestException", violations); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java index b69bc3132d..39eb37682f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java @@ -9,6 +9,7 @@ import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.PaginatedResult; import io.github.hectorvent.floci.core.common.RequestScopes; import io.github.hectorvent.floci.core.common.Resettable; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; @@ -540,9 +541,8 @@ public class SesExportJobService implements Resettable { } private static AwsException notNull(String member) { - return new AwsException("BadRequestException", - "1 validation error detected: Value at '" + member - + "' failed to satisfy constraint: Member must not be null", 400); + return SmithyValidationErrors.exception("BadRequestException", + List.of("Value at '" + member + "' failed to satisfy constraint: Member must not be null")); } /** diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java index d82db629f2..65f7013390 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java @@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.ses; import com.fasterxml.jackson.databind.JsonNode; import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.services.ses.model.EmailInsights; import io.github.hectorvent.floci.services.ses.model.ExportJob; import io.github.hectorvent.floci.services.ses.model.SentEmail; @@ -70,11 +71,7 @@ final class SesExportMetrics { } validateMetrics(metrics.path("Metrics"), violations); if (!violations.isEmpty()) { - String header = violations.size() == 1 - ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - throw new AwsException("BadRequestException", - header + String.join("; ", violations), 400); + throw SmithyValidationErrors.exception("BadRequestException", violations); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java index 2bd6d33d7e..cea7f2c7f5 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java @@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.DomainNames; import io.github.hectorvent.floci.core.common.PaginatedResult; import io.github.hectorvent.floci.core.common.Pem; import io.github.hectorvent.floci.core.common.PublicKeys; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.acm.AcmService; @@ -348,9 +349,7 @@ public class SesIdentityCertificateService { if (violations.isEmpty()) { return; } - String count = violations.size() == 1 ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - throw badRequest(count + String.join("; ", violations)); + throw SmithyValidationErrors.exception("BadRequestException", violations); } private static AwsException badRequest(String message) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java index 984e40f394..83e83f7f09 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java @@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.PaginatedResult; import io.github.hectorvent.floci.core.common.RequestScopes; import io.github.hectorvent.floci.core.common.Resettable; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; @@ -469,9 +470,8 @@ public class SesImportJobService implements Resettable { } private static AwsException validationError(String path, String constraint) { - return new AwsException("BadRequestException", - "1 validation error detected: Value at '" + path + "' failed to satisfy constraint: " - + constraint, 400); + return SmithyValidationErrors.exception("BadRequestException", + List.of("Value at '" + path + "' failed to satisfy constraint: " + constraint)); } static String key(String region, String jobId) { diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java index 67ee85d083..c361e82fe3 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java @@ -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.common.PaginatedResult; import io.github.hectorvent.floci.core.common.Pagination; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import jakarta.ws.rs.core.UriInfo; import java.time.Instant; @@ -178,20 +179,20 @@ public enum SesListPaging { } static AwsException pageSizeError(int pageSize) { - return badRequest("1 validation error detected: " + pageSizeViolation(pageSize)); + return SmithyValidationErrors.exception("BadRequestException", List.of(pageSizeViolation(pageSize))); } static AwsException tokenError(String token) { if (token.isEmpty()) { - return badRequest("1 validation error detected: " + EMPTY_TOKEN); + return SmithyValidationErrors.exception("BadRequestException", List.of(EMPTY_TOKEN)); } return badRequest("Invalid Next Token"); } /** SES lists the token before the page size. */ static AwsException bothError(int pageSize) { - return badRequest("2 validation errors detected: " + EMPTY_TOKEN + "; " - + pageSizeViolation(pageSize)); + return SmithyValidationErrors.exception("BadRequestException", + List.of(EMPTY_TOKEN, pageSizeViolation(pageSize))); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java index adede49b2f..ca183ff382 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.services.ses.model.SentEmail; import jakarta.inject.Inject; import jakarta.ws.rs.Consumes; @@ -380,10 +381,6 @@ public class SesMetricsController { } private static AwsException aggregated(List violations) { - String header = violations.size() == 1 - ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - return new AwsException("BadRequestException", - header + String.join("; ", violations), 400); + return SmithyValidationErrors.exception("BadRequestException", violations); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java index cfff455ed2..b7351a94af 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java @@ -6,6 +6,7 @@ import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.PaginatedResult; import io.github.hectorvent.floci.core.common.RegionResolver; import io.github.hectorvent.floci.core.common.ServiceCallAuthorizer; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.core.storage.StorageBackend; import io.github.hectorvent.floci.core.storage.StorageFactory; import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator.Decision; @@ -483,9 +484,7 @@ public class SesReceiptRuleService { if (violations.isEmpty()) { return; } - String label = violations.size() == 1 ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - throw new AwsException("ValidationError", label + String.join("; ", violations), 400); + throw SmithyValidationErrors.exception("ValidationError", violations); } /** @@ -774,9 +773,7 @@ public class SesReceiptRuleService { } } if (!violations.isEmpty()) { - String label = violations.size() == 1 ? "1 validation error detected: " - : violations.size() + " validation errors detected: "; - throw new AwsException("ValidationError", label + String.join("; ", violations), 400); + throw SmithyValidationErrors.exception("ValidationError", violations); } } diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java index 5a93e3d1cb..450003b8a8 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import io.github.hectorvent.floci.core.common.AwsException; import io.github.hectorvent.floci.core.common.RegionResolver; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.services.ses.address.SesAddressSyntax; import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry; import io.github.hectorvent.floci.services.ses.model.BulkEmailEntryResult; @@ -59,6 +60,8 @@ public class SesSendController { private static final Logger LOG = Logger.getLogger(SesSendController.class); + private static final List TRACKING_VALUES = List.of("ENABLED", "DISABLED"); + private final SesService sesService; // The bulk send resolves a stored template's content before handing the entries to the facade. private final SesTemplateService templateService; @@ -93,6 +96,7 @@ public class SesSendController { JsonNode request = objectMapper.readTree(body); requireJsonObject(request); SesV2RequestShapes.check("SendEmail", request); + validateTrackingOverrides(request); // FromEmailAddress is optional per the AWS v2 contract. Each content type below // enforces the sender requirement the way AWS does: Raw can take its From from the @@ -245,6 +249,7 @@ public class SesSendController { JsonNode request = objectMapper.readTree(body); requireJsonObject(request); SesV2RequestShapes.check("SendBulkEmail", request); + validateTrackingOverrides(request); String fromEmailAddress = request.path("FromEmailAddress").asText(null); if (fromEmailAddress == null || fromEmailAddress.isBlank()) { throw new AwsException("BadRequestException", @@ -583,15 +588,42 @@ public class SesSendController { private static AwsException constraintViolation(String value, String path, String constraint) { String subject = value == null ? "Value" : "Value '" + value + "'"; - return new AwsException("BadRequestException", - "1 validation error detected: " + subject + " at '" + path - + "' failed to satisfy constraint: " + constraint, 400); + return SmithyValidationErrors.exception("BadRequestException", + List.of(subject + " at '" + path + "' failed to satisfy constraint: " + constraint)); } private static AwsException missingHeaderMember(String location, int index, String member) { return constraintViolation(null, location + "." + index + ".member." + member, "Member must not be null"); } + /** + * {@code ConfigurationOverrides.Tracking}'s enum, checked the way SES checks it (probed + * 2026-10-06): a value outside it is a validation error, both values reported together with the + * click one first. The shapes check has already refused a wrong JSON type. Floci has no open or + * click tracking, so a valid override is accepted and has no effect. + */ + private static void validateTrackingOverrides(JsonNode request) { + JsonNode tracking = request.path("ConfigurationOverrides").path("Tracking"); + String open = tracking.path("OpenTrackingEnabled").asText(null); + String click = tracking.path("ClickTrackingEnabled").asText(null); + List violations = new ArrayList<>(); + if (click != null && !TRACKING_VALUES.contains(click)) { + violations.add(trackingViolation("clickTrackingEnabled")); + } + if (open != null && !TRACKING_VALUES.contains(open)) { + violations.add(trackingViolation("openTrackingEnabled")); + } + if (!violations.isEmpty()) { + throw SmithyValidationErrors.exception("BadRequestException", violations); + } + } + + private static String trackingViolation(String member) { + return "Value at 'configurationOverrides.tracking." + member + + "' failed to satisfy constraint: Member must satisfy enum value set: [" + + String.join(", ", TRACKING_VALUES) + "]"; + } + private static ListManagementOptions parseListManagementOptions(JsonNode node) { if (node.isMissingNode() || node.isNull()) { return null; diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java index e512453f5f..360374a5d6 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.ses; import io.github.hectorvent.floci.core.common.AwsException; +import io.github.hectorvent.floci.core.common.SmithyValidationErrors; import io.github.hectorvent.floci.services.ses.model.Tag; import java.util.ArrayList; @@ -84,9 +85,7 @@ final class SesTags { } } if (!lengthErrors.isEmpty()) { - throw new AwsException("BadRequestException", - lengthErrors.size() + " validation error" + (lengthErrors.size() > 1 ? "s" : "") - + " detected: " + String.join("; ", lengthErrors), 400); + throw SmithyValidationErrors.exception("BadRequestException", lengthErrors); } // An empty key is rejected with an empty body, matching AWS. for (Tag tag : tags) { diff --git a/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java new file mode 100644 index 0000000000..b9983489d7 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java @@ -0,0 +1,36 @@ +package io.github.hectorvent.floci.core.common; + +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +class SmithyValidationErrorsTest { + + @Test + void oneViolation_isSingular() { + assertEquals("1 validation error detected: Value at 'a' failed to satisfy constraint: x", + SmithyValidationErrors.message(List.of("Value at 'a' failed to satisfy constraint: x"))); + } + + @Test + void severalViolations_arePluralAndJoinedInOrder() { + assertEquals("2 validation errors detected: second; first", + SmithyValidationErrors.message(List.of("second", "first"))); + } + + @Test + void exception_carriesTheGivenCodeAsA400() { + AwsException e = SmithyValidationErrors.exception("ValidationError", List.of("v")); + assertEquals("ValidationError", e.getErrorCode()); + assertEquals("1 validation error detected: v", e.getMessage()); + assertEquals(400, e.getHttpStatus()); + } + + @Test + void noViolations_isAProgrammingError() { + assertThrows(IllegalArgumentException.class, () -> SmithyValidationErrors.message(List.of())); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/ses/SesTrackingOverridesV2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ses/SesTrackingOverridesV2IntegrationTest.java new file mode 100644 index 0000000000..5facc03d2b --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/ses/SesTrackingOverridesV2IntegrationTest.java @@ -0,0 +1,155 @@ +package io.github.hectorvent.floci.services.ses; + +import io.github.hectorvent.floci.testutil.SesMailbox; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.response.ValidatableResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import java.nio.charset.StandardCharsets; +import java.util.Base64; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * {@code ConfigurationOverrides.Tracking} on SendEmail and SendBulkEmail. Floci has no open or click + * tracking, so a valid override is accepted and has no effect; an invalid one is refused the way + * SES v2 refuses it (probed in us-west-2 on 2026-10-06). + */ +@QuarkusTest +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class SesTrackingOverridesV2IntegrationTest { + + private static final String AUTH = + "AWS4-HMAC-SHA256 Credential=AKID/20260101/ap-southeast-4/ses/aws4_request"; + // A sender of its own, verified once below: the identity outlives this class, and other SES + // classes that share the application create their own senders. + private static final String SENDER = "tracking-overrides-sender@floci.test"; + private static final String SEND = "/v2/email/outbound-emails"; + private static final String BULK = "/v2/email/outbound-bulk-emails"; + private static final String SIMPLE = "\"Content\": {\"Simple\": {\"Subject\": {\"Data\": \"s\"}, " + + "\"Body\": {\"Text\": {\"Data\": \"b\"}}}}"; + private static final String OPEN_ENUM = "Value at 'configurationOverrides.tracking.openTrackingEnabled' " + + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]"; + private static final String CLICK_ENUM = "Value at 'configurationOverrides.tracking.clickTrackingEnabled' " + + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]"; + + private boolean senderVerified; + + // Not @BeforeAll: the Quarkus test port is only bound once the first test starts. + @BeforeEach + void verifySender() { + if (senderVerified) { + return; + } + send("/v2/email/identities", "{\"EmailIdentity\": \"" + SENDER + "\"}").statusCode(200); + senderVerified = true; + } + + @Test + void sendEmail_acceptsAValidOverride_andOneOfNothing() { + for (String overrides : new String[] { + "{\"Tracking\": {\"OpenTrackingEnabled\": \"DISABLED\", \"ClickTrackingEnabled\": \"ENABLED\"}}", + "{\"Tracking\": {\"ClickTrackingEnabled\": \"DISABLED\", \"Foo\": \"x\"}, \"Bar\": {}}", + "{}", "{\"Tracking\": {}}", "{\"Tracking\": null}", "null"}) { + sendWith(overrides).statusCode(200).body("MessageId", notNullValue()); + } + } + + @Test + void sendEmail_acceptsAnOverrideOnRawContent() { + String mime = "From: " + SENDER + "\r\nTo: alice@example.com\r\nSubject: raw\r\n\r\nbody\r\n"; + String data = Base64.getEncoder().encodeToString(mime.getBytes(StandardCharsets.UTF_8)); + send(SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": " + + "{\"ToAddresses\": [\"alice@example.com\"]}, \"Content\": {\"Raw\": {\"Data\": \"" + data + "\"}}, " + + "\"ConfigurationOverrides\": {\"Tracking\": {\"OpenTrackingEnabled\": \"ENABLED\"}}}") + .statusCode(200); + } + + @Test + void sendEmail_refusesAValueOutsideTheEnum_reportingBothClickFirst() { + String recipient = "refused-send@tracking.test"; + sendWith("{\"Tracking\": {\"OpenTrackingEnabled\": \"disabled\"}}", recipient).statusCode(400) + .body("__type", equalTo("BadRequestException")) + .body("message", equalTo("1 validation error detected: " + OPEN_ENUM)); + sendWith("{\"Tracking\": {\"OpenTrackingEnabled\": \"\", \"ClickTrackingEnabled\": \"yes\"}}", recipient) + .statusCode(400) + .body("message", equalTo("2 validation errors detected: " + CLICK_ENUM + "; " + OPEN_ENUM)); + assertNothingSentTo(recipient); + } + + @Test + void sendEmail_wrongJsonTypes_areSerializationExceptions() { + sendWith("{\"Tracking\": {\"OpenTrackingEnabled\": 1}}").statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("NUMBER_VALUE can not be converted to a String")); + sendWith("{\"Tracking\": \"x\"}").statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("Expected null")); + sendWith("[]").statusCode(400) + .body("__type", equalTo("SerializationException")) + .body("message", equalTo("Start of list found where not expected")); + } + + @Test + void sendEmail_theEnumIsCheckedBeforeTheTagsAndTheConfigurationSet() { + String request = "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": {\"ToAddresses\": " + + "[\"alice@example.com\"]}, " + SIMPLE + ", \"EmailTags\": [{\"Name\": \"a b\", \"Value\": \"v\"}], " + + "\"ConfigurationSetName\": \"tracking-missing\", " + + "\"ConfigurationOverrides\": {\"Tracking\": {\"OpenTrackingEnabled\": \"%s\"}}}"; + send(SEND, request.formatted("yes")).statusCode(400) + .body("message", equalTo("1 validation error detected: " + OPEN_ENUM)); + // With a valid value the same request fails on the tags or the set, so the order above is real. + send(SEND, request.formatted("ENABLED")).statusCode(not(200)) + .body("message", not(containsString("configurationOverrides"))); + } + + @Test + void sendBulkEmail_acceptsAValidOverride_andRefusesAnInvalidOne() { + send(BULK, bulkBody("{\"Tracking\": {\"OpenTrackingEnabled\": \"DISABLED\"}}")).statusCode(200) + .body("BulkEmailEntryResults", hasSize(2)) + .body("BulkEmailEntryResults[0].Status", equalTo("SUCCESS")); + String recipient = "refused-bulk@tracking.test"; + send(BULK, bulkBody("{\"Tracking\": {\"ClickTrackingEnabled\": \"on\"}}", recipient)).statusCode(400) + .body("message", equalTo("1 validation error detected: " + CLICK_ENUM)); + assertNothingSentTo(recipient); + } + + private static ValidatableResponse sendWith(String overrides) { + return sendWith(overrides, "alice@example.com"); + } + + private static ValidatableResponse sendWith(String overrides, String recipient) { + return send(SEND, "{\"FromEmailAddress\": \"" + SENDER + "\", \"Destination\": {\"ToAddresses\": " + + "[\"" + recipient + "\"]}, " + SIMPLE + ", \"ConfigurationOverrides\": " + overrides + "}"); + } + + private static String bulkBody(String overrides) { + return bulkBody(overrides, "bob@example.com"); + } + + private static String bulkBody(String overrides, String secondRecipient) { + return "{\"FromEmailAddress\": \"" + SENDER + "\", \"DefaultContent\": {\"Template\": " + + "{\"TemplateContent\": {\"Subject\": \"s\", \"Text\": \"b\"}, \"TemplateData\": \"{}\"}}, " + + "\"BulkEmailEntries\": [{\"Destination\": {\"ToAddresses\": [\"alice@example.com\"]}}, " + + "{\"Destination\": {\"ToAddresses\": [\"" + secondRecipient + "\"]}}], " + + "\"ConfigurationOverrides\": " + overrides + "}"; + } + + // The check runs before the send reaches the service, so a refused request records nothing. + private static void assertNothingSentTo(String recipient) { + assertTrue(SesMailbox.messagesTo(recipient).isEmpty(), "a refused send recorded a message to " + recipient); + } + + private static ValidatableResponse send(String path, String body) { + return given().contentType("application/json").header("Authorization", AUTH).body(body) + .when().post(path).then(); + } +}