mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ses): implement SendCustomVerificationEmail for v1 and v2 (#2191)
* feat(ses): implement SendCustomVerificationEmail for v1 and v2
Add the SendCustomVerificationEmail action on both the v1 Query API and the v2 REST
JSON API (POST /v2/email/outbound-custom-verification-emails). The service renders the
stored custom-verification-email template into the inspection mailbox and the SMTP
relay, returns a MessageId, and registers the recipient as a pending-verification
identity, matching AWS. A missing template is the v1-native
CustomVerificationEmailTemplateDoesNotExist (remapped to NotFoundException on v2), with
the v1 send message ("Template <name> does not exist") verified against AWS.
* test(ses): log custom-verification compat cleanup failures instead of swallowing them
The @AfterAll cleanup deleted templates and identities in best-effort try/catch
blocks that swallowed every exception, so a real deletion failure would leave
state behind with no diagnostic. Log the affected template/identity and the
exception message, per AGENTS.md's rule against silently discarding exceptions.
This commit is contained in:
1 parent
ac4b865a34
commit
bd01c1a70b
8 files changed
+576
-8
No files matched your search
+196
@@ -0,0 +1,196 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
/**
|
||||
* Integration tests for the SES V1 Query-protocol {@code SendCustomVerificationEmail}: a successful
|
||||
* send returns a MessageId and registers the recipient as a pending-verification identity, and a
|
||||
* missing template fails with the v1-native {@code CustomVerificationEmailTemplateDoesNotExist} code
|
||||
* and the v1 send message ("Template <name> does not exist"), both verified against real AWS.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSendCustomVerificationEmailV1IntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/email/aws4_request";
|
||||
private static final String FROM = "scve-v1-sender@floci.test";
|
||||
private static final String RECIPIENT = "scve-v1-recipient@floci.test";
|
||||
private static final String NAME = "scve-v1-template";
|
||||
|
||||
private static io.restassured.specification.RequestSpecification query(String action) {
|
||||
return given().contentType("application/x-www-form-urlencoded").header("Authorization", AUTH)
|
||||
.formParam("Action", action);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(0)
|
||||
void setup_verifyFromAndCreateTemplate() {
|
||||
query("VerifyEmailIdentity").formParam("EmailAddress", FROM).when().post("/").then().statusCode(200);
|
||||
query("CreateCustomVerificationEmailTemplate")
|
||||
.formParam("TemplateName", NAME)
|
||||
.formParam("FromEmailAddress", FROM)
|
||||
.formParam("TemplateSubject", "Verify your email")
|
||||
.formParam("TemplateContent", "<html><body>verify</body></html>")
|
||||
.formParam("SuccessRedirectionURL", "https://example.com/ok")
|
||||
.formParam("FailureRedirectionURL", "https://example.com/fail")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void send_returnsMessageId() {
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", RECIPIENT)
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<SendCustomVerificationEmailResponse"))
|
||||
.body(containsString("<MessageId>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void send_registersRecipientAsPendingIdentity() {
|
||||
// AWS registers the recipient as a pending-verification identity as part of the send.
|
||||
query("GetIdentityVerificationAttributes")
|
||||
.formParam("Identities.member.1", RECIPIENT)
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body(containsString("<VerificationStatus>Pending</VerificationStatus>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void send_missingTemplate_returnsDoesNotExistWithV1Message() {
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", RECIPIENT)
|
||||
.formParam("TemplateName", "scve-v1-ghost")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>CustomVerificationEmailTemplateDoesNotExist</Code>"))
|
||||
.body(containsString("Template <scve-v1-ghost> does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void send_templateFromNoLongerVerified_returnsFromEmailAddressNotVerified() {
|
||||
// The template's From was verified at create time; once that identity is deleted, sending
|
||||
// through the template fails with the v1-native FromEmailAddressNotVerified / 400.
|
||||
String from2 = "scve-v1-stale-from@floci.test";
|
||||
String template2 = "scve-v1-stale-template";
|
||||
query("VerifyEmailIdentity").formParam("EmailAddress", from2).when().post("/").then().statusCode(200);
|
||||
query("CreateCustomVerificationEmailTemplate")
|
||||
.formParam("TemplateName", template2)
|
||||
.formParam("FromEmailAddress", from2)
|
||||
.formParam("TemplateSubject", "Verify your email")
|
||||
.formParam("TemplateContent", "<html><body>verify</body></html>")
|
||||
.formParam("SuccessRedirectionURL", "https://example.com/ok")
|
||||
.formParam("FailureRedirectionURL", "https://example.com/fail")
|
||||
.when().post("/").then().statusCode(200);
|
||||
query("DeleteIdentity").formParam("Identity", from2).when().post("/").then().statusCode(200);
|
||||
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", RECIPIENT)
|
||||
.formParam("TemplateName", template2)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>FromEmailAddressNotVerified</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void send_accountSendingDisabled_returnsAccountSendingPaused() {
|
||||
// Like every other v1 send action, the send is refused while account sending is paused.
|
||||
query("UpdateAccountSendingEnabled").formParam("Enabled", "false")
|
||||
.when().post("/").then().statusCode(200);
|
||||
try {
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", RECIPIENT)
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>AccountSendingPausedException</Code>"));
|
||||
} finally {
|
||||
query("UpdateAccountSendingEnabled").formParam("Enabled", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void send_malformedEmailAddress_returnsInvalidParameterValue() {
|
||||
// AWS validates the recipient address before the template check: a value without a single
|
||||
// '@' is InvalidParameterValue / 400 "Invalid email address<addr>." (verified against AWS).
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", "not-an-email")
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("Invalid email address<not-an-email>."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void send_blankEmailAddress_returnsNotSpecified() {
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", "")
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("Email address not specified."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void send_multipleUnquotedAt_returnsInvalidParameterValue() {
|
||||
// AWS rejects an address with more than one unquoted '@' (verified).
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", "a@@b.com")
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("Invalid email address<a@@b.com>."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void send_quotedLocalPartWithAt_passesAddressValidation() {
|
||||
// AWS accepts an RFC-5321 quoted local part that contains '@' (verified), so it must not be
|
||||
// rejected as invalid. A non-existent template proves the address passed validation and the
|
||||
// call reached the template-existence check.
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", "\"a@b\"@example.com")
|
||||
.formParam("TemplateName", "scve-v1-ghost2")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>CustomVerificationEmailTemplateDoesNotExist</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void send_quoteClosesBeforeMultipleAt_isRejected() {
|
||||
// The quoted local part closes before the two '@', so both separators are unquoted — invalid.
|
||||
// Guards against a naive "starts with a quote" exemption that would let this through.
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", "\"a\"@@example.com")
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void send_emptyLocalOrDomain_returnsInvalidParameterValue() {
|
||||
// AWS rejects a boundary '@' — empty local part (@example.com) or empty domain (local@).
|
||||
for (String bad : new String[] {"@example.com", "local@"}) {
|
||||
query("SendCustomVerificationEmail")
|
||||
.formParam("EmailAddress", bad)
|
||||
.formParam("TemplateName", NAME)
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(containsString("<Code>InvalidParameterValue</Code>"))
|
||||
.body(containsString("Invalid email address<" + bad + ">."));
|
||||
}
|
||||
}
|
||||
}
|
||||
+201
@@ -0,0 +1,201 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* Integration tests for the SES V2 REST JSON {@code SendCustomVerificationEmail}
|
||||
* ({@code POST /v2/email/outbound-custom-verification-emails}): a successful send returns a
|
||||
* MessageId, stores the rendered email in the inspection mailbox, and registers the recipient as a
|
||||
* pending identity; a missing template is a {@code NotFoundException}/404 and an unknown
|
||||
* configuration set is likewise remapped to 404, both verified against real AWS.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesSendCustomVerificationEmailV2IntegrationTest {
|
||||
|
||||
private static final String AUTH =
|
||||
"AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/ses/aws4_request";
|
||||
private static final String FROM = "scve-v2-sender@floci.test";
|
||||
private static final String RECIPIENT = "scve-v2-recipient@floci.test";
|
||||
private static final String NAME = "scve-v2-template";
|
||||
private static final String SUBJECT = "Verify your email V2";
|
||||
private static final String SEND = "/v2/email/outbound-custom-verification-emails";
|
||||
|
||||
@Test
|
||||
@Order(0)
|
||||
void setup_verifyFromAndCreateTemplate() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + FROM + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "%s",
|
||||
"FromEmailAddress": "%s",
|
||||
"TemplateSubject": "%s",
|
||||
"TemplateContent": "<html><body>verify</body></html>",
|
||||
"SuccessRedirectionURL": "https://example.com/ok",
|
||||
"FailureRedirectionURL": "https://example.com/fail"
|
||||
}
|
||||
""".formatted(NAME, FROM, SUBJECT))
|
||||
.when().post("/v2/email/custom-verification-email-templates").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void send_returnsMessageId() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + RECIPIENT + "\",\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(200)
|
||||
.body("MessageId", notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void send_storesRenderedEmailInInspectionMailbox() {
|
||||
given().header("Authorization", AUTH).queryParam("email", RECIPIENT)
|
||||
.when().get("/_aws/ses").then().statusCode(200)
|
||||
.body(containsString(FROM))
|
||||
.body(containsString(SUBJECT))
|
||||
// The template body is passed through verbatim (no placeholder substitution)...
|
||||
.body(containsString("<html><body>verify</body></html>"))
|
||||
// ...followed by the fixed, non-removable disclaimer AWS always appends.
|
||||
.body(containsString(
|
||||
"If you did not request to verify this email address, please disregard this message."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void send_registersRecipientAsIdentity() {
|
||||
// The recipient is registered (pending) as part of the send, so GetEmailIdentity finds it.
|
||||
given().header("Authorization", AUTH)
|
||||
.when().get("/v2/email/identities/" + RECIPIENT).then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void send_missingTemplate_returnsNotFound() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + RECIPIENT + "\",\"TemplateName\":\"scve-v2-ghost\"}")
|
||||
.when().post(SEND).then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"))
|
||||
// v2 uses a longer not-found message than the v1 send ("Template <name>..."), verified.
|
||||
.body("message", equalTo(
|
||||
"Custom verification email template <scve-v2-ghost> does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void send_unknownConfigurationSet_returnsNotFound() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + RECIPIENT + "\",\"TemplateName\":\"" + NAME
|
||||
+ "\",\"ConfigurationSetName\":\"scve-v2-ghost-cs\"}")
|
||||
.when().post(SEND).then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void send_missingEmailAddress_returnsBadRequest() {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void send_templateFromNoLongerVerified_remapsToNotFound() {
|
||||
// The template's From was verified at create time; once that identity is deleted, the send
|
||||
// fails FromEmailAddressNotVerified, which the v2 boundary remaps to NotFoundException / 404
|
||||
// (consistent with the CreateCustomVerificationEmailTemplate unverified-From mapping).
|
||||
String from2 = "scve-v2-stale-from@floci.test";
|
||||
String template2 = "scve-v2-stale-template";
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailIdentity\":\"" + from2 + "\"}")
|
||||
.when().post("/v2/email/identities").then().statusCode(200);
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("""
|
||||
{
|
||||
"TemplateName": "%s",
|
||||
"FromEmailAddress": "%s",
|
||||
"TemplateSubject": "%s",
|
||||
"TemplateContent": "<html><body>verify</body></html>",
|
||||
"SuccessRedirectionURL": "https://example.com/ok",
|
||||
"FailureRedirectionURL": "https://example.com/fail"
|
||||
}
|
||||
""".formatted(template2, from2, SUBJECT))
|
||||
.when().post("/v2/email/custom-verification-email-templates").then().statusCode(200);
|
||||
given().header("Authorization", AUTH)
|
||||
.when().delete("/v2/email/identities/" + from2).then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + RECIPIENT + "\",\"TemplateName\":\"" + template2 + "\"}")
|
||||
.when().post(SEND).then().statusCode(404)
|
||||
.body("__type", equalTo("NotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void send_accountSendingDisabled_returnsSendingPaused() {
|
||||
// Like the v2 SendEmail endpoint, the send is refused while account sending is paused.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"SendingEnabled\":false}")
|
||||
.when().put("/v2/email/account/sending").then().statusCode(200);
|
||||
try {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"" + RECIPIENT + "\",\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(400)
|
||||
.body("__type", equalTo("SendingPausedException"));
|
||||
} finally {
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"SendingEnabled\":true}")
|
||||
.when().put("/v2/email/account/sending").then().statusCode(200);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void send_malformedEmailAddress_returnsBadRequestWithAwsMessage() {
|
||||
// AWS returns the same "Invalid email address<addr>." message on v2 as on v1 (verified);
|
||||
// Floci throws the v1-native InvalidParameterValue which remaps to BadRequestException / 400.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"not-an-email\",\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid email address<not-an-email>."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void send_multipleUnquotedAt_returnsBadRequest() {
|
||||
// AWS rejects more than one unquoted '@'; a quoted local part that contains '@' is accepted
|
||||
// (see the v1 test) — the check must only reject the unquoted case.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"a@@b.com\",\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid email address<a@@b.com>."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void send_emptyDomain_returnsBadRequest() {
|
||||
// A trailing '@' is an empty domain, which AWS rejects (verified).
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"EmailAddress\":\"local@\",\"TemplateName\":\"" + NAME + "\"}")
|
||||
.when().post(SEND).then().statusCode(400)
|
||||
.body("__type", equalTo("BadRequestException"))
|
||||
.body("message", equalTo("Invalid email address<local@>."));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user