Skip to content

refactor(cognito): extract user-status wire values into constants#309

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+magic-strings
Apr 12, 2026
Merged

refactor(cognito): extract user-status wire values into constants#309
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+magic-strings

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 12, 2026

Summary

Cognito user account states (UNCONFIRMED, CONFIRMED, FORCE_CHANGE_PASSWORD, RESET_REQUIRED, etc.) were scattered as bare string literals across service/auth.rs, service/users.rs and service/mod.rs. The auth state machine has ~20 transition points that set one of these.

Introduces crate::user_status with a named constant for each wire value. Production call sites now use the constant, which means:

  • Typos in status names fail at compile time, not at runtime with a silent wire-format drift.
  • Grepping for every place that sets a particular status is one command (grep 'user_status::FORCE_CHANGE_PASSWORD') instead of needing to know the exact string.

Test-only assertions that verify the wire format are left as literals on purpose — those tests want to assert against the exact wire value, not the constant's definition.

Scope note: this PR only const-ifies Cognito user statuses. Other audit-flagged candidates (KMS policy version 2012-10-17, ElastiCache statuses available/primary, Kinesis stream statuses) were considered but left as literals — they're well-known AWS wire values where a named constant would add import noise without improving readability or catching real bugs.

Test plan

  • cargo build --workspace
  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test -p fakecloud-cognito — 72 passed, 0 failed
  • CI green

Summary by cubic

Extracted Cognito user-status wire values into crate::user_status constants to replace scattered string literals and prevent typos. No behavior change; wire JSON stays the same.

  • Refactors
    • Added crate::user_status with constants (e.g., CONFIRMED, UNCONFIRMED, FORCE_CHANGE_PASSWORD, RESET_REQUIRED).
    • Replaced literals in service/auth.rs and service/users.rs with these constants.
    • Kept test assertions as string literals to validate exact wire values.

Written for commit 6b1e747. Summary will update on new commits.

Cognito represents a user account state as one of a small set of string
literals (``UNCONFIRMED``, ``CONFIRMED``, ``FORCE_CHANGE_PASSWORD``,
``RESET_REQUIRED``, etc.). These were scattered as bare literals across
``service/auth.rs``, ``service/users.rs`` and ``service/mod.rs``.

Introduces ``crate::user_status`` with a named constant for each wire
value and replaces the production call sites. This removes the risk of
silently misspelling ``FORCE_CHANGE_PASSWORD`` at one of the twenty-odd
transition points in the auth state machine and makes grepping for every
place that sets a particular status trivial.

Test-only assertions that verify the wire format are left as literals —
the point of those tests is that the wire value is exactly that string.

No behavior change.
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.

No issues found across 4 files

@vieiralucas vieiralucas merged commit cf0cef9 into main Apr 12, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup+magic-strings branch April 12, 2026 22:36
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