Files
floci/src/main/java/io/github/hectorvent
Hector VenturaandRicardo Medina d7f9f95873 feat(cognito): add verification code subsystem (store, dispatcher, SNS/SES inspection) (#1249)
* chore(fixtures): capture AWS Cognito auth flow fixtures for contract tests

Captures 7 wire-format fixtures against wirebit stg pool for use as ground truth
in floci compatibility tests. Includes capture script with PII sanitization and
best-effort user cleanup.

Empirical findings vs spec:
- No client-side rate-limit observed on back-to-back ResendConfirmationCode
- PreventUserExistenceErrors=LEGACY in wirebit prod/stg (older pools)
- Email Destination masking is aggressive: f***@e***

* feat(cognito): add verification code store, message dispatcher and SNS inspection

Introduces the foundation for full Cognito auth flow emulation:

- VerificationCodeService: 6-digit codes hashed with per-code salt, persisted
  via StorageFactory with TTL + 30s rate-limit + 5-attempt invalidation.
- VerificationCode model: serializable to disk for filesystem storage mode.
- CognitoMessageDispatcher: renders VerificationMessageTemplate ({####}
  placeholder + failsafe), dispatches via SesService (email) or SnsService
  (SMS) honoring DeliveryMediums.
- SnsService: now persists every phone publish() as a SentSms record and
  exposes getSentMessages()/clearSentMessages().
- SnsInspectionController: GET/DELETE /_aws/sns mirroring SesInspectionController.
- FixtureLoader + 7 AWS Cognito fixtures captured against wirebit-stg pool
  (sign-up, confirm-signup error, resend, forgot-password unknown-user, SRP
  unknown-user). Relocated from compatibility-tests/ to src/test/resources/
  so JUnit can load them via classpath.

Not yet wired to any flow — that's PR #2-5 in a stacked series.

Tests: 22 new (9 VerificationCodeService + 6 dispatcher + 4 SNS inspection +
3 FixtureLoader). Full suite 4336 passing (was 4314), ElastiCacheIntegrationTest
excluded due to local port-6379 collision.

* feat(ses): SesInspectionController supports ?email= filter

Symmetric to SnsInspectionController.?phone= (added in the verification
code store commit). Lets test helpers retrieve the latest email sent to
a specific recipient without filtering client-side over the full message
list.

GET /_aws/ses?email=user@example.com → only messages where the address
is in ToAddresses.

* fix(cognito): align verification dispatcher with AWS and current SES API

Adapt the adopted verification-code foundation to current main and AWS:
- update CognitoMessageDispatcher to the 12-arg SesService.sendEmail signature
- source the MFA SMS message from the user pool's top-level SmsAuthenticationMessage
  (it is not part of VerificationMessageTemplate, which only holds SmsMessage)
- match AWS's out-of-the-box default verification message text
- document the 30s resend window and 5-attempt cap as emulation heuristics (not
  AWS-published constants) and add TODOs for DefaultEmailOption, medium preference,
  and per-purpose TTL that the auth-flow wiring must honour

Co-authored-by: Ricardo Medina <34877263+ricardomedina98@users.noreply.github.com>

* refactor(cognito): drop dead code flagged by static analysis

- remove no-op ctorRequest local in scripts/aws-fixtures-capture.mjs
- drop the unused purpose parameter from emailTemplateKey() and its call site

Co-authored-by: Ricardo Medina <34877263+ricardomedina98@users.noreply.github.com>

* chore(cognito): remove the one-off AWS fixture-capture dev script

The captured aws-cognito/*.json fixtures remain (FixtureLoader uses those); the Node capture tool is not needed in the repo.

---------

Co-authored-by: Ricardo Medina <34877263+ricardomedina98@users.noreply.github.com>
2026-06-11 00:47:33 -05:00
..