mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(ses): implement custom verification email templates for v1 and v2 (#1840)
* feat(ses): implement custom verification email templates for v1 and v2 Add the SES custom-verification-email-template CRUD APIs across both protocols, backed by one shared StorageFactory store (key cvet::<region>::<name>): - v1 Query: Create/Get/List/Update/DeleteCustomVerificationEmailTemplate. - v2 REST JSON: the same five operations under /v2/email/custom-verification-email-templates. Behaviour and error shapes were verified against real AWS: duplicate create is AlreadyExistsException, missing is NotFoundException, the FromEmailAddress must be a verified identity (NotFoundException otherwise), an invalid redirection URL is BadRequestException, the template body is not content-validated, List omits TemplateContent, and the store is shared between v1 and v2. SendCustomVerification- Email is left as a follow-up. * fix(ses): serialize custom-verification-template mutations under one lock Guard the check-then-write of updateCustomVerificationEmailTemplate and deleteCustomVerificationEmailTemplate on the same lock as create (renamed cvetCreateLock -> cvetMutationLock) so a concurrent delete can't slip between an update's existence check and its put and resurrect the just-deleted template. Also clean up the shared template left by the v1 integration test. * fix(ses): validate custom-verification-template fields before the existence check on update UpdateCustomVerificationEmailTemplate ran the existence check before validating required fields, so omitting TemplateName (possible on the v1 Query API) returned NotFoundException instead of the required-field InvalidParameterValue (v2 BadRequestException). Validate first, matching CreateCustomVerificationEmailTemplate. Also drop an unused Hamcrest import in the v2 integration test. * test(ses): give the custom-verification-template cleanup a unique last order update_missingTemplateName and cleanup_deleteSharedTemplate both used @Order(8); with OrderAnnotation equal values have no guaranteed order and the suite is stateful. Move the cleanup to @Order(9) so it runs last deterministically. * fix(ses): throw v1 error codes for custom-verification-template not-found/duplicate The CVET service methods threw the v2 codes (NotFoundException/404, AlreadyExistsException/400) directly, so remapV1Exception was a no-op and the v1 Query path returned the wrong codes: the v1 SDK's typed CustomVerificationEmailTemplate* exceptions never fired, and not-found used 404 instead of AWS's 400. Throw the v1-native codes (CustomVerificationEmailTemplateDoesNotExist / CustomVerificationEmailTemplateAlreadyExists, both 400, verified against AWS) and map them in remapV1Exception, so v1 is correct while v2 still returns NotFoundException/404 and AlreadyExistsException/400. Also wrap the get/delete CVET endpoints in remapV1Exception (the only two that lacked it) and pin the v1 codes with integration assertions. * fix(ses): throw the v1 code for an unverified custom-verification-template sender An unverified FromEmailAddress threw NotFoundException/404 from the shared CVET validator, so the v1 Query wire carried a v2 code. AWS classic SES returns FromEmailAddressNotVerified/400 (verified); throw that v1-native code and map it in remapV1Exception, so v1 is correct while v2 still returns NotFoundException/404. Pin the v1 code with an integration assertion.
This commit is contained in:
1 parent
d039780e3a
commit
aed50cc2b2
14 files changed
+866
-4
No files matched your search
+121
@@ -0,0 +1,121 @@
|
||||
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.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import software.amazon.awssdk.services.ses.SesClient;
|
||||
import software.amazon.awssdk.services.ses.model.CreateCustomVerificationEmailTemplateRequest;
|
||||
|
||||
import software.amazon.awssdk.services.sesv2.SesV2Client;
|
||||
import software.amazon.awssdk.services.sesv2.model.AlreadyExistsException;
|
||||
import software.amazon.awssdk.services.sesv2.model.CreateEmailIdentityRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.DeleteEmailIdentityRequest;
|
||||
import software.amazon.awssdk.services.sesv2.model.GetCustomVerificationEmailTemplateResponse;
|
||||
import software.amazon.awssdk.services.sesv2.model.NotFoundException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* SDK compatibility test for the SES custom-verification-email-template APIs across both protocols
|
||||
* against a live Floci instance: v2 Create/Get/List/Update/Delete plus the duplicate/not-found
|
||||
* errors, and the shared store (a v1-written template is visible via the v2 Get).
|
||||
*/
|
||||
@DisplayName("SES custom verification email templates (v1 + v2)")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class SesCustomVerificationEmailTemplateTest {
|
||||
|
||||
private static final String FROM = "cvet-sdk-sender@floci-cvet.test";
|
||||
private static final String NAME = "cvet-sdk-a";
|
||||
|
||||
private static SesClient sesV1;
|
||||
private static SesV2Client sesV2;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
sesV1 = TestFixtures.sesClient();
|
||||
sesV2 = TestFixtures.sesV2Client();
|
||||
sesV2.createEmailIdentity(CreateEmailIdentityRequest.builder().emailIdentity(FROM).build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (sesV2 != null) {
|
||||
for (String n : new String[] {NAME, "cvet-sdk-shared"}) {
|
||||
try {
|
||||
sesV2.deleteCustomVerificationEmailTemplate(b -> b.templateName(n));
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort cleanup: the template may already be gone.
|
||||
}
|
||||
}
|
||||
try {
|
||||
sesV2.deleteEmailIdentity(DeleteEmailIdentityRequest.builder().emailIdentity(FROM).build());
|
||||
} catch (Exception ignored) {
|
||||
// Best-effort cleanup.
|
||||
}
|
||||
sesV2.close();
|
||||
}
|
||||
if (sesV1 != null) {
|
||||
sesV1.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void v2_createGetListUpdate() {
|
||||
sesV2.createCustomVerificationEmailTemplate(b -> b
|
||||
.templateName(NAME).fromEmailAddress(FROM).templateSubject("Verify")
|
||||
.templateContent("<html><body>verify</body></html>")
|
||||
.successRedirectionURL("https://example.com/ok")
|
||||
.failureRedirectionURL("https://example.com/fail"));
|
||||
|
||||
GetCustomVerificationEmailTemplateResponse got =
|
||||
sesV2.getCustomVerificationEmailTemplate(b -> b.templateName(NAME));
|
||||
assertThat(got.templateName()).isEqualTo(NAME);
|
||||
assertThat(got.fromEmailAddress()).isEqualTo(FROM);
|
||||
assertThat(got.templateContent()).contains("verify");
|
||||
|
||||
assertThat(sesV2.listCustomVerificationEmailTemplates(b -> {})
|
||||
.customVerificationEmailTemplates())
|
||||
.anyMatch(t -> NAME.equals(t.templateName()));
|
||||
|
||||
sesV2.updateCustomVerificationEmailTemplate(b -> b
|
||||
.templateName(NAME).fromEmailAddress(FROM).templateSubject("Updated")
|
||||
.templateContent("<html><body>verify</body></html>")
|
||||
.successRedirectionURL("https://example.com/ok2")
|
||||
.failureRedirectionURL("https://example.com/fail"));
|
||||
assertThat(sesV2.getCustomVerificationEmailTemplate(b -> b.templateName(NAME)).templateSubject())
|
||||
.isEqualTo("Updated");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void v2_duplicateAndMissingErrors() {
|
||||
assertThatThrownBy(() -> sesV2.createCustomVerificationEmailTemplate(b -> b
|
||||
.templateName(NAME).fromEmailAddress(FROM).templateSubject("x")
|
||||
.templateContent("c").successRedirectionURL("https://e.com/o")
|
||||
.failureRedirectionURL("https://e.com/f")))
|
||||
.isInstanceOf(AlreadyExistsException.class);
|
||||
|
||||
assertThatThrownBy(() -> sesV2.getCustomVerificationEmailTemplate(b -> b.templateName("nope-sdk")))
|
||||
.isInstanceOf(NotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void v1WrittenTemplate_isVisibleViaV2() {
|
||||
sesV1.createCustomVerificationEmailTemplate(CreateCustomVerificationEmailTemplateRequest.builder()
|
||||
.templateName("cvet-sdk-shared").fromEmailAddress(FROM).templateSubject("Shared")
|
||||
.templateContent("<html><body>verify</body></html>")
|
||||
.successRedirectionURL("https://example.com/ok")
|
||||
.failureRedirectionURL("https://example.com/fail").build());
|
||||
|
||||
assertThat(sesV2.getCustomVerificationEmailTemplate(b -> b.templateName("cvet-sdk-shared"))
|
||||
.templateSubject()).isEqualTo("Shared");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user