Skip to content

feat(cognito): route verification email -> SES, SMS -> SNS; add CustomEmailSender/CustomSMSSender triggers#736

Merged
vieiralucas merged 2 commits intomainfrom
worktree-integrations-batch2-cognito-ses-sns
Apr 24, 2026
Merged

feat(cognito): route verification email -> SES, SMS -> SNS; add CustomEmailSender/CustomSMSSender triggers#736
vieiralucas merged 2 commits intomainfrom
worktree-integrations-batch2-cognito-ses-sns

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 24, 2026

Summary

Closes the Cognito-side gap from the integrations audit. Verification codes generated by Cognito now actually go somewhere instead of being silently swallowed:

  • Email: SignUp / ResendConfirmationCode / ForgotPassword / GetUserAttributeVerificationCode (email attr) dispatch through SES, observable at GET /_fakecloud/ses/emails.
  • SMS: GetUserAttributeVerificationCode (phone attr) dispatches through SNS, observable at the new GET /_fakecloud/sns/sms.
  • CustomEmailSender / CustomSMSSender precedence: when configured on the pool, these Lambdas are invoked instead of going through SES/SNS — matching AWS behavior. Both triggers are also added to the TriggerSource enum (full set of 12 now wired).

Architecture: two new tiny traits in fakecloud-core (EmailDispatcher, SmsDispatcher) keep the Cognito crate from taking direct deps on SES/SNS. The server crate provides the impls that write into the SES sent_emails table and the SNS sms_messages list.

Test plan

  • Unit tests for dispatch_verification_email / dispatch_verification_sms paths
  • E2E cognito_signup_dispatches_verification_email_via_ses — round-trips the verification code from /_fakecloud/cognito/confirmation-codes to the SES sent-emails body
  • E2E cognito_get_user_attribute_phone_dispatches_sms_via_sns — phone-attribute verification produces an SNS SMS entry with the 6-digit code
  • E2E cognito_custom_email_sender_lambda_takes_precedence_over_ses — pool with LambdaConfig.CustomEmailSender set suppresses the SES path
  • All 61 existing cognito E2E tests still green (one was updated to reflect the new SignUp-generates-code behavior)
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo fmt --check clean

Summary by cubic

Routes Cognito verification emails through SES and SMS through SNS, with CustomEmailSender/CustomSMSSender triggers taking precedence to match AWS. Invokes CustomMessage to allow subject/body overrides and adds an SMS introspection endpoint; completes coverage of all 12 Cognito trigger sources.

  • New Features

    • Email verification for SignUp, ResendConfirmationCode, ForgotPassword, and GetUserAttributeVerificationCode (email) now dispatches via SES; visible at GET /_fakecloud/ses/emails.
    • Phone verification via GetUserAttributeVerificationCode (phone) now dispatches via SNS; new GET /_fakecloud/sns/sms endpoint.
    • CustomEmailSender/CustomSMSSender Lambdas take precedence; all 12 trigger sources supported. SignUp now generates a verification code.
  • Bug Fixes

    • Use customSMSSenderRequestV1 for CustomSMSSender events (was incorrectly using the email request type).
    • Invoke CustomMessage for SignUp, ResendConfirmationCode, ForgotPassword, and VerifyUserAttribute so its response can override email subject/body before SES send.

Written for commit 692b20c. Summary will update on new commits.

…tomEmailSender/CustomSMSSender triggers

Cognito previously stored EmailSendingAccount and accepted the
verification message templates but never actually dispatched anything.
Verification codes generated by SignUp / ResendConfirmationCode /
ForgotPassword / GetUserAttributeVerificationCode now route through:

- SES for email (visible at /_fakecloud/ses/emails)
- SNS for SMS  (visible at the new /_fakecloud/sns/sms endpoint)
- Or the CustomEmailSender / CustomSMSSender Lambda when configured on
  the pool (real AWS behavior — these take precedence over the default
  SES/SNS path).

Trigger source coverage increases from 10 to 12 by adding
CustomEmailSender and CustomSMSSender (with all their flow variants).

DeliveryBus picks up two small new traits — EmailDispatcher and
SmsDispatcher — implemented in the server crate against the SES
sent_emails table and the SNS sms_messages list, so test code can
assert on the dispatched payloads without needing real network
delivery.

Also adds the SnsSmsResponse / SnsSmsMessage types to the introspection
SDK, the Cognito service-page coverage notes, the cross-service
integration matrix update, and the README support-table line.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-cognito/src/triggers.rs">

<violation number="1" location="crates/fakecloud-cognito/src/triggers.rs:483">
P2: Custom SMS sender events are emitted with the email request type (`customEmailSenderRequestV1`) instead of `customSMSSenderRequestV1`.</violation>
</file>

<file name="crates/fakecloud-cognito/src/service/auth.rs">

<violation number="1" location="crates/fakecloud-cognito/src/service/auth.rs:1712">
P2: The new SignUp verification path does not invoke `CustomMessage_SignUp`, so pools that rely on that trigger won't run their sign-up message customization logic.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-cognito/src/triggers.rs Outdated
.find(|a| a.name == "email")
.map(|a| a.value.clone())
{
self.dispatch_verification_email(
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new SignUp verification path does not invoke CustomMessage_SignUp, so pools that rely on that trigger won't run their sign-up message customization logic.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/fakecloud-cognito/src/service/auth.rs, line 1712:

<comment>The new SignUp verification path does not invoke `CustomMessage_SignUp`, so pools that rely on that trigger won't run their sign-up message customization logic.</comment>

<file context>
@@ -1685,6 +1685,43 @@ impl CognitoService {
+                .find(|a| a.name == "email")
+                .map(|a| a.value.clone())
+            {
+                self.dispatch_verification_email(
+                    &pool_id,
+                    Some(client_id),
</file context>
Fix with Cubic

Two findings from Cubic on PR #736:

- `customSMSSenderRequestV1` was being emitted as `customEmailSenderRequestV1`. The build_custom_sender_event helper now picks the right request type based on the trigger source.

- The new SignUp verification path skipped the CustomMessage_SignUp Lambda. Routing now invokes the trigger synchronously and uses its `emailSubject` / `emailMessage` response to override the default templates before sending through SES, matching AWS.

Same wiring is applied for ForgotPassword / ResendCode / VerifyUserAttribute since they share the dispatch helper.
@vieiralucas vieiralucas merged commit f721e26 into main Apr 24, 2026
48 checks passed
@vieiralucas vieiralucas deleted the worktree-integrations-batch2-cognito-ses-sns branch April 24, 2026 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant