refactor(cognito): extract user-status wire values into constants#309
Merged
vieiralucas merged 1 commit intomainfrom Apr 12, 2026
Merged
refactor(cognito): extract user-status wire values into constants#309vieiralucas merged 1 commit intomainfrom
vieiralucas merged 1 commit intomainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cognito user account states (
UNCONFIRMED,CONFIRMED,FORCE_CHANGE_PASSWORD,RESET_REQUIRED, etc.) were scattered as bare string literals acrossservice/auth.rs,service/users.rsandservice/mod.rs. The auth state machine has ~20 transition points that set one of these.Introduces
crate::user_statuswith a named constant for each wire value. Production call sites now use the constant, which means: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 statusesavailable/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 --workspacecargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo test -p fakecloud-cognito— 72 passed, 0 failedSummary by cubic
Extracted Cognito user-status wire values into
crate::user_statusconstants to replace scattered string literals and prevent typos. No behavior change; wire JSON stays the same.crate::user_statuswith constants (e.g.,CONFIRMED,UNCONFIRMED,FORCE_CHANGE_PASSWORD,RESET_REQUIRED).service/auth.rsandservice/users.rswith these constants.Written for commit 6b1e747. Summary will update on new commits.