mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): add SES v2 GetEmailAddressInsights (#6573)
* feat(ses): add SES v2 GetEmailAddressInsights Answer GetEmailAddressInsights offline with verdicts derived from the address alone. Malformed and over-long addresses answer 200 with every verdict LOW, the operation is not gated on Virtual Deliverability Manager, and only suppressionlist@simulator.amazonses.com reports a missing mailbox, as real SES does. Domains reserved by RFC 2606 and RFC 6761 have no valid DNS records; every other domain is taken to have them. * docs(ses): scope the non-ASCII insights deviation to unquoted parts A send does not inspect a quoted local part, so GetEmailAddressInsights rates "é"@gmail.com like any other address. Say so in the deviation note and pin it, with the unquoted and domain cases, in unit tests.
This commit is contained in:
1 parent
b29c8f8a60
commit
7f5f1b554d
9 files changed
+442
-8
No files matched your search
+76
@@ -0,0 +1,76 @@
|
||||
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.equalTo;
|
||||
|
||||
/**
|
||||
* Integration tests for {@code POST /v2/email/email-address-insights/} (GetEmailAddressInsights).
|
||||
* The verdict rules are covered by {@link SesMailboxValidationTest}; these pin the wire shape, the
|
||||
* missing VDM gate and the request errors. Uses a region no other test enables VDM in.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class SesEmailAddressInsightsV2IntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/ca-west-1/ses/aws4_request";
|
||||
private static final String PATH = "/v2/email/email-address-insights/";
|
||||
|
||||
@Test
|
||||
void answersEveryVerdictWithoutVdm() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"admin@example.com\"}")
|
||||
.when().post(PATH).then().statusCode(200)
|
||||
.body("MailboxValidation.IsValid.ConfidenceVerdict", equalTo("LOW"))
|
||||
.body("MailboxValidation.Evaluations.HasValidSyntax.ConfidenceVerdict", equalTo("HIGH"))
|
||||
.body("MailboxValidation.Evaluations.HasValidDnsRecords.ConfidenceVerdict", equalTo("LOW"))
|
||||
.body("MailboxValidation.Evaluations.MailboxExists.ConfidenceVerdict", equalTo("MEDIUM"))
|
||||
.body("MailboxValidation.Evaluations.IsRoleAddress.ConfidenceVerdict", equalTo("HIGH"))
|
||||
.body("MailboxValidation.Evaluations.IsDisposable.ConfidenceVerdict", equalTo("LOW"))
|
||||
.body("MailboxValidation.Evaluations.IsRandomInput.ConfidenceVerdict", equalTo("LOW"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedAddressAnswersOkWithLowVerdicts() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"no-at-sign\"}")
|
||||
.when().post(PATH).then().statusCode(200)
|
||||
.body("MailboxValidation.IsValid.ConfidenceVerdict", equalTo("LOW"))
|
||||
.body("MailboxValidation.Evaluations.HasValidSyntax.ConfidenceVerdict", equalTo("LOW"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathWithoutTrailingSlashIsServed() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"alice@gmail.com\"}")
|
||||
.when().post("/v2/email/email-address-insights").then().statusCode(200)
|
||||
.body("MailboxValidation.IsValid.ConfidenceVerdict", equalTo("HIGH"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyAddressIsRejected() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"\"}")
|
||||
.when().post(PATH).then().statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Email address must not be null nor empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAddressIsRejected() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{}")
|
||||
.when().post(PATH).then().statusCode(400)
|
||||
.body("message", equalTo("Email address must not be null nor empty"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonStringAddressIsASerializationError() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":1}")
|
||||
.when().post(PATH).then().statusCode(400)
|
||||
.header("x-amzn-ErrorType", equalTo("SerializationException"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.github.hectorvent.floci.services.ses.SesMailboxValidation.Result;
|
||||
import io.github.hectorvent.floci.services.ses.SesMailboxValidation.Verdict;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesMailboxValidation.Verdict.HIGH;
|
||||
import static io.github.hectorvent.floci.services.ses.SesMailboxValidation.Verdict.LOW;
|
||||
import static io.github.hectorvent.floci.services.ses.SesMailboxValidation.Verdict.MEDIUM;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class SesMailboxValidationTest {
|
||||
|
||||
private static final Result ALL_LOW = new Result(LOW, LOW, LOW, LOW, LOW, LOW, LOW);
|
||||
|
||||
private static Result result(Verdict isValid, Verdict syntax, Verdict dns, Verdict mailbox, Verdict role) {
|
||||
return new Result(isValid, syntax, dns, mailbox, role, LOW, LOW);
|
||||
}
|
||||
|
||||
// The expected rows below marked "probed" are AWS's answers for the same address (2026-10-25).
|
||||
|
||||
@Test
|
||||
void ordinaryDomainIsValid() {
|
||||
assertEquals(result(HIGH, HIGH, HIGH, MEDIUM, LOW), SesMailboxValidation.evaluate("alice@gmail.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void exampleDomainHasNoDnsRecords() {
|
||||
// probed
|
||||
assertEquals(result(LOW, HIGH, LOW, MEDIUM, LOW), SesMailboxValidation.evaluate("user@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void subdomainOfAReservedDomainHasNoDnsRecords() {
|
||||
assertEquals(result(LOW, HIGH, LOW, MEDIUM, LOW), SesMailboxValidation.evaluate("user@mail.example.org"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidTopLevelDomainLowersSyntaxAndHasNoDnsRecords() {
|
||||
// probed
|
||||
assertEquals(result(LOW, MEDIUM, LOW, MEDIUM, LOW),
|
||||
SesMailboxValidation.evaluate("user@floci-probe-nonexistent-7f3a.invalid"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void singleLabelDomainIsTreatedAsAnUnrecognisedTopLevelDomain() {
|
||||
assertEquals(result(LOW, MEDIUM, LOW, MEDIUM, LOW), SesMailboxValidation.evaluate("user@localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void displayNameLowersSyntax() {
|
||||
// probed
|
||||
assertEquals(result(LOW, MEDIUM, LOW, MEDIUM, LOW),
|
||||
SesMailboxValidation.evaluate("Alice <alice@example.com>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void displayNameOnAnOrdinaryDomainStaysValid() {
|
||||
assertEquals(result(HIGH, MEDIUM, HIGH, MEDIUM, LOW),
|
||||
SesMailboxValidation.evaluate("Alice <alice@gmail.com>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void angleBracketsWithoutANameLowerSyntax() {
|
||||
assertEquals(result(HIGH, MEDIUM, HIGH, MEDIUM, LOW), SesMailboxValidation.evaluate("<alice@gmail.com>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void simulatorBounceAndComplaintAreNotSpecial() {
|
||||
// probed
|
||||
Result expected = result(HIGH, HIGH, HIGH, MEDIUM, LOW);
|
||||
assertEquals(expected, SesMailboxValidation.evaluate("success@simulator.amazonses.com"));
|
||||
assertEquals(expected, SesMailboxValidation.evaluate("bounce@simulator.amazonses.com"));
|
||||
assertEquals(expected, SesMailboxValidation.evaluate("complaint@simulator.amazonses.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void simulatorSuppressionListMailboxDoesNotExist() {
|
||||
// probed
|
||||
assertEquals(result(LOW, HIGH, HIGH, LOW, LOW),
|
||||
SesMailboxValidation.evaluate("suppressionlist@simulator.amazonses.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void labelledSimulatorSuppressionListMailboxDoesNotExist() {
|
||||
assertEquals(result(LOW, HIGH, HIGH, LOW, LOW),
|
||||
SesMailboxValidation.evaluate("suppressionlist+run-1@simulator.amazonses.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void roleAddressIsReportedWithoutChangingValidity() {
|
||||
// probed on example.com; gmail.com isolates the role from the DNS verdict
|
||||
assertEquals(result(LOW, HIGH, LOW, MEDIUM, HIGH), SesMailboxValidation.evaluate("admin@example.com"));
|
||||
assertEquals(result(HIGH, HIGH, HIGH, MEDIUM, HIGH), SesMailboxValidation.evaluate("Support+eu@gmail.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedAddressIsLowEverywhere() {
|
||||
// probed
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate("no-at-sign"));
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate("user@"));
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate("a b@example.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonAsciiOutsideQuotesIsLowEverywhere() {
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate("é@gmail.com"));
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate("user@bücher.de"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonAsciiInAQuotedLocalPartIsRatedAsASendAcceptsIt() {
|
||||
// a send does not inspect a quoted local part, so the verdicts follow the send check
|
||||
assertEquals(result(HIGH, HIGH, HIGH, MEDIUM, LOW), SesMailboxValidation.evaluate("\"é\"@gmail.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void blankAddressIsLowEverywhere() {
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void overLongAddressIsLowEverywhere() {
|
||||
// probed for the verdicts other than IsRandomInput, which AWS rated HIGH for a run of one letter
|
||||
String address = "a".repeat(309) + "@example.com";
|
||||
assertEquals(321, address.length());
|
||||
assertEquals(ALL_LOW, SesMailboxValidation.evaluate(address));
|
||||
}
|
||||
|
||||
@Test
|
||||
void addressAtTheLengthLimitIsEvaluated() {
|
||||
String address = "a".repeat(310) + "@gmail.com";
|
||||
assertEquals(320, address.length());
|
||||
assertEquals(result(HIGH, HIGH, HIGH, MEDIUM, LOW), SesMailboxValidation.evaluate(address));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user