diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailAddressInsightsTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailAddressInsightsTest.java new file mode 100644 index 0000000000..18bf765387 --- /dev/null +++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/SesEmailAddressInsightsTest.java @@ -0,0 +1,79 @@ +package com.floci.test; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +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.BadRequestException; +import software.amazon.awssdk.services.sesv2.model.EmailAddressInsightsConfidenceVerdict; +import software.amazon.awssdk.services.sesv2.model.EmailAddressInsightsMailboxEvaluations; +import software.amazon.awssdk.services.sesv2.model.GetEmailAddressInsightsRequest; +import software.amazon.awssdk.services.sesv2.model.MailboxValidation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * SDK compatibility test for SES v2 GetEmailAddressInsights: the response deserializes into the + * SDK's verdict model, and an empty address is a BadRequestException. + */ +@DisplayName("SES v2 Email Address Insights") +class SesEmailAddressInsightsTest { + + private static SesV2Client sesV2; + + @BeforeAll + static void setup() { + sesV2 = TestFixtures.sesV2Client(); + } + + @AfterAll + static void cleanup() { + if (sesV2 != null) { + sesV2.close(); + } + } + + @Test + @DisplayName("GetEmailAddressInsights returns every verdict") + void returnsEveryVerdict() { + MailboxValidation validation = sesV2.getEmailAddressInsights(GetEmailAddressInsightsRequest.builder() + .emailAddress("support@simulator.amazonses.com").build()).mailboxValidation(); + EmailAddressInsightsMailboxEvaluations evaluations = validation.evaluations(); + + assertThat(validation.isValid().confidenceVerdict()).isEqualTo(EmailAddressInsightsConfidenceVerdict.HIGH); + assertThat(evaluations.hasValidSyntax().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.HIGH); + assertThat(evaluations.hasValidDnsRecords().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.HIGH); + assertThat(evaluations.mailboxExists().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.MEDIUM); + assertThat(evaluations.isRoleAddress().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.HIGH); + assertThat(evaluations.isDisposable().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.LOW); + assertThat(evaluations.isRandomInput().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.LOW); + } + + @Test + @DisplayName("GetEmailAddressInsights answers a malformed address with LOW verdicts") + void malformedAddressIsLow() { + MailboxValidation validation = sesV2.getEmailAddressInsights(GetEmailAddressInsightsRequest.builder() + .emailAddress("no-at-sign").build()).mailboxValidation(); + + assertThat(validation.isValid().confidenceVerdict()).isEqualTo(EmailAddressInsightsConfidenceVerdict.LOW); + assertThat(validation.evaluations().hasValidSyntax().confidenceVerdict()) + .isEqualTo(EmailAddressInsightsConfidenceVerdict.LOW); + } + + @Test + @DisplayName("GetEmailAddressInsights rejects an empty address") + void emptyAddressIsRejected() { + assertThatThrownBy(() -> sesV2.getEmailAddressInsights(GetEmailAddressInsightsRequest.builder() + .emailAddress("").build())) + .isInstanceOf(BadRequestException.class) + .hasMessageContaining("Email address must not be null nor empty"); + } +} diff --git a/docs/services/ses.md b/docs/services/ses.md index 00a96fbdcc..1b6ea3a724 100644 --- a/docs/services/ses.md +++ b/docs/services/ses.md @@ -425,6 +425,7 @@ Alongside the classic Query API, Floci implements a subset of the SES v2 REST JS | `GET` | `/v2/email/reputation/entities/{ReputationEntityType}/{ReputationEntityReference}` | `GetReputationEntity` | | `PUT` | `/v2/email/reputation/entities/{ReputationEntityType}/{ReputationEntityReference}/policy` | `UpdateReputationEntityPolicy` | | `PUT` | `/v2/email/reputation/entities/{ReputationEntityType}/{ReputationEntityReference}/customer-managed-status` | `UpdateReputationEntityCustomerManagedStatus` | +| `POST` | `/v2/email/email-address-insights/` | `GetEmailAddressInsights` | Floci models no leased dedicated IPs: `GetDedicatedIps` is empty and IP-targeted operations return `NotFoundException`, as real AWS does for an account with no leased IPs, with required request members validated first (`BadRequestException`). `PutDedicatedIpPoolScalingAttributes` rejects downgrading a `MANAGED` pool to `STANDARD`, and `PutAccountDedicatedIpWarmupAttributes` stores the flag behind `GetAccount.DedicatedIpAutoWarmupEnabled` (default `true`). @@ -510,9 +511,21 @@ registered Easy DKIM domain do not report this SES-hosted zone. S/MIME certificate associations are stored per region and never used: Floci does not sign mail. Associating validates the request as SES does (a domain identity needs a `FromAddress` in the domain or one of its subdomains, one certificate per address regardless of case) but, like SES, does not inspect the certificate. `ListEmailIdentityCertificates` reports `ACTIVE` while the association meets the [S/MIME certificate considerations](https://docs.aws.amazon.com/ses/latest/dg/send-email-authentication-smime.html#send-email-authentication-smime-certificate-considerations), plus the requirements a probe found SES also enforces (an end-entity certificate whose key usage includes `digitalSignature` and whose extended key usage includes `emailProtection`), checked against Floci's ACM and identity verification when the list is read, with the certificate's expiry as `CertificateExpiryTime`, and `FAILED` otherwise. There is no `PROVISIONING` phase, `DisassociateEmailIdentityCertificate` removes an association at once, and the certificate is not listed as in use by ACM. As on SES, `DeleteEmailIdentity` refuses an identity that still has a certificate associated, whatever its status. The v1 `DeleteIdentity` and `DeleteVerifiedEmailAddress` share the identities and refuse it too, with the same `BadRequestException` the tenant-association guard returns there; SES's v1 behaviour was not probed. +[`GetEmailAddressInsights`](https://docs.aws.amazon.com/ses/latest/dg/email-validation-api.html) is answered offline: Floci performs no DNS lookup and no mailbox probe, and charges nothing. As on AWS (probed 2026-10-25), it answers with Virtual Deliverability Manager disabled, a malformed or over-long address returns 200 with every verdict `LOW` rather than an error, an empty `EmailAddress` is a `BadRequestException` (an absent one, which the AWS CLI refuses to send, is assumed to answer the same), and `IsValid` is `LOW` whenever `HasValidSyntax`, `HasValidDnsRecords` or `MailboxExists` is `LOW` and `HIGH` otherwise. The verdicts follow fixed rules: + +| Evaluation | Floci's verdict | +|---|---| +| `HasValidSyntax` | `LOW` for an address a send would reject; `MEDIUM` when the address carries a display name, a comment or angle brackets, or when the domain has a single label or ends in `.example`, `.invalid`, `.localhost` or `.test`; otherwise `HIGH` | +| `HasValidDnsRecords` | `LOW` for those top-level domains and for `example.com`, `example.net`, `example.org` and their subdomains; otherwise `HIGH`, including `simulator.amazonses.com` | +| `MailboxExists` | `LOW` for `suppressionlist@simulator.amazonses.com` (with or without a `+label`); otherwise `MEDIUM`. The other simulator addresses are not special, as on AWS | +| `IsRoleAddress` | `HIGH` when the local part, without a `+label`, is a common role name such as `admin`, `info`, `noreply`, `postmaster` or `support`; otherwise `LOW` | +| `IsDisposable`, `IsRandomInput` | Always `LOW` | + +Deviations from AWS: every domain that is not reserved is taken to have valid DNS records, Floci keeps no disposable-domain list and detects no random input, and an address with a non-ASCII character in its domain (an internationalized domain name included) or in an unquoted local part is rated `LOW` everywhere, as a send would reject it, while a quoted local part, which a send does not inspect, is rated like any other; AWS's verdicts for such addresses were not probed. + ### Request member types -The operations whose body nests a structure in a structure, or holds a list of structures, check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does: the send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`), `CreateConfigurationSet`, `UpdateConfigurationSet`, `PutConfigurationSetSuppressionOptions`, `PutConfigurationSetVdmOptions`, `CreateConfigurationSetEventDestination`, `UpdateConfigurationSetEventDestination`, `CreateContactList`, `UpdateContactList`, `CreateContact`, `UpdateContact`, `ListContacts`, `PutAccountSuppressionAttributes`, `PutAccountVdmAttributes`, `BatchGetMetricData`, `CreateImportJob` and `CreateExportJob`. `ListReputationEntities`, `UpdateReputationEntityPolicy` and `UpdateReputationEntityCustomerManagedStatus` run the same check although their bodies are flat. In those operations, the first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message: +The operations whose body nests a structure in a structure, or holds a list of structures, check the request body against the SES v2 service model before anything else is validated, as AWS's restJson1 deserializer does: the send operations (`SendEmail`, `SendBulkEmail`, `SendCustomVerificationEmail`), `CreateConfigurationSet`, `UpdateConfigurationSet`, `PutConfigurationSetSuppressionOptions`, `PutConfigurationSetVdmOptions`, `CreateConfigurationSetEventDestination`, `UpdateConfigurationSetEventDestination`, `CreateContactList`, `UpdateContactList`, `CreateContact`, `UpdateContact`, `ListContacts`, `PutAccountSuppressionAttributes`, `PutAccountVdmAttributes`, `BatchGetMetricData`, `CreateImportJob` and `CreateExportJob`. `ListReputationEntities`, `UpdateReputationEntityPolicy`, `UpdateReputationEntityCustomerManagedStatus` and `GetEmailAddressInsights` run the same check although their bodies are flat. In those operations, the first body member of the wrong JSON type, in body order, is a `SerializationException` with AWS's deserializer message: | Member type | Value sent | Message | |---|---|---| diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java index 714242aeef..b0c5fa0e9e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesInsightsController.java @@ -1,10 +1,13 @@ package io.github.hectorvent.floci.services.ses; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; 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.services.ses.SesMailboxValidation.Result; +import io.github.hectorvent.floci.services.ses.SesMailboxValidation.Verdict; import io.github.hectorvent.floci.services.ses.model.EmailInsights; import io.github.hectorvent.floci.services.ses.model.InsightsBounce; import io.github.hectorvent.floci.services.ses.model.InsightsComplaint; @@ -15,6 +18,7 @@ import io.github.hectorvent.floci.services.ses.model.SentEmail; import jakarta.inject.Inject; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; @@ -26,6 +30,7 @@ import jakarta.ws.rs.core.Response; import java.util.List; import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp; +import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody; /** * SES V2 message insights ({@code /v2/email/insights/{MessageId}/}), the read side of the @@ -35,6 +40,10 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp; * gated on Virtual Deliverability Manager and the gate is checked before the message id, so an * unparseable id in a VDM-disabled region still reports the VDM error. A message that is absent * reports the account id alongside the id. + * + *
Email address insights ({@code /v2/email/email-address-insights/}) share the name but not the + * gate: they answer with Virtual Deliverability Manager disabled (probe-confirmed 2026-10-25), and + * {@link SesMailboxValidation} derives the verdicts. */ @Path("/v2/email") @Produces(MediaType.APPLICATION_JSON) @@ -68,6 +77,33 @@ public class SesInsightsController { return Response.ok(render(email)).build(); } + @POST + @Path("/email-address-insights") + public Response getEmailAddressInsights(String body) { + JsonNode request = readOptionBody(objectMapper, body); + SesV2RequestShapes.check("GetEmailAddressInsights", request); + String emailAddress = request.path("EmailAddress").textValue(); + if (emailAddress == null || emailAddress.isEmpty()) { + throw new AwsException("BadRequestException", "Email address must not be null nor empty", 400); + } + Result result = SesMailboxValidation.evaluate(emailAddress); + ObjectNode response = objectMapper.createObjectNode(); + ObjectNode validation = response.putObject("MailboxValidation"); + putVerdict(validation, "IsValid", result.isValid()); + ObjectNode evaluations = validation.putObject("Evaluations"); + putVerdict(evaluations, "HasValidSyntax", result.hasValidSyntax()); + putVerdict(evaluations, "HasValidDnsRecords", result.hasValidDnsRecords()); + putVerdict(evaluations, "MailboxExists", result.mailboxExists()); + putVerdict(evaluations, "IsRoleAddress", result.isRoleAddress()); + putVerdict(evaluations, "IsDisposable", result.isDisposable()); + putVerdict(evaluations, "IsRandomInput", result.isRandomInput()); + return Response.ok(response).build(); + } + + private static void putVerdict(ObjectNode parent, String field, Verdict verdict) { + parent.putObject(field).put("ConfidenceVerdict", verdict.name()); + } + private ObjectNode render(SentEmail email) { ObjectNode result = objectMapper.createObjectNode(); result.put("MessageId", email.getMessageId()); diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesMailboxValidation.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesMailboxValidation.java new file mode 100644 index 0000000000..36c217c6c7 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesMailboxValidation.java @@ -0,0 +1,88 @@ +package io.github.hectorvent.floci.services.ses; + +import io.github.hectorvent.floci.services.ses.address.SesAddressLength; +import io.github.hectorvent.floci.services.ses.address.SesAddressSyntax; + +import java.util.List; +import java.util.Locale; +import java.util.Set; + +/** + * The verdicts {@code GetEmailAddressInsights} answers for one address, derived offline so the same + * address always gets the same answer. Floci performs no DNS lookup and no mailbox probe, so the + * rules reproduce what AWS was seen to return (probe-confirmed 2026-10-25, ap-northeast-1) and fill + * the rest with fixed values. + * + *
Probe-confirmed: a malformed or over-long address answers 200 with every evaluation LOW, not a + * 400; a display-name form or an unrecognised top-level domain lowers the syntax verdict to MEDIUM; + * {@code example.com} and an {@code .invalid} domain have no valid DNS records; the mailbox + * simulator's domain has them, its suppression-list address is the only one whose mailbox is LOW, + * and its bounce and complaint addresses are not special; an ordinary mailbox is MEDIUM; and the + * overall verdict is LOW whenever the syntax, DNS or mailbox verdict is LOW, HIGH otherwise (no + * MEDIUM overall verdict was observed). + * + *
Floci's own choices: every domain that is not reserved by RFC 2606 or RFC 6761 is taken to have
+ * valid DNS records, the role-address check is a fixed list of local parts, and the disposable and
+ * random-input checks always answer LOW (AWS rated a long run of one letter as random input).
+ */
+final class SesMailboxValidation {
+
+ enum Verdict { LOW, MEDIUM, HIGH }
+
+ record Result(Verdict isValid, Verdict hasValidSyntax, Verdict hasValidDnsRecords, Verdict mailboxExists,
+ Verdict isRoleAddress, Verdict isDisposable, Verdict isRandomInput) {
+ }
+
+ private static final String SIMULATOR_DOMAIN = "simulator.amazonses.com";
+ private static final Set