refactor(cognito): split 9,058-line service.rs into sub-modules#282
Merged
vieiralucas merged 1 commit intomainfrom Apr 12, 2026
Merged
refactor(cognito): split 9,058-line service.rs into sub-modules#282vieiralucas merged 1 commit intomainfrom
vieiralucas merged 1 commit intomainfrom
Conversation
Split monolithic service.rs into 8 files following the SSM pattern: - mod.rs: struct, dispatch, helpers, tests (3,487 lines) - auth.rs: auth flows (2,060 lines) - users.rs: admin + self-service user ops (1,056 lines) - user_pools.rs: pool + client CRUD (732 lines) - misc.rs: domains, devices, tags, imports (621 lines) - groups.rs: group operations (507 lines) - identity_providers.rs: IdP + resource servers (482 lines) - mfa.rs: MFA config + TOTP (394 lines)
There was a problem hiding this comment.
3 issues found across 9 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/service/mfa.rs">
<violation number="1" location="crates/fakecloud-cognito/src/service/mfa.rs:310">
P1: `associate_software_token` returns a `Session` token that is never stored in `state.sessions`, so session-based `verify_software_token` calls fail with `Invalid session`.</violation>
</file>
<file name="crates/fakecloud-cognito/src/service/user_pools.rs">
<violation number="1" location="crates/fakecloud-cognito/src/service/user_pools.rs:307">
P2: `NextToken` fallback to index 0 silently restarts pagination when the token is invalid.</violation>
<violation number="2" location="crates/fakecloud-cognito/src/service/user_pools.rs:704">
P2: `list_user_pool_clients` also resets to page 1 on unknown `NextToken` instead of rejecting it.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| user.totp_verified = false; | ||
| user.user_last_modified_date = Utc::now(); | ||
|
|
||
| let new_session = Uuid::new_v4().to_string(); |
There was a problem hiding this comment.
P1: associate_software_token returns a Session token that is never stored in state.sessions, so session-based verify_software_token calls fail with Invalid session.
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/mfa.rs, line 310:
<comment>`associate_software_token` returns a `Session` token that is never stored in `state.sessions`, so session-based `verify_software_token` calls fail with `Invalid session`.</comment>
<file context>
@@ -0,0 +1,394 @@
+ user.totp_verified = false;
+ user.user_last_modified_date = Utc::now();
+
+ let new_session = Uuid::new_v4().to_string();
+
+ Ok(AwsResponse::ok_json(json!({
</file context>
| clients | ||
| .iter() | ||
| .position(|c| c.client_id == token) | ||
| .unwrap_or(0) |
There was a problem hiding this comment.
P2: list_user_pool_clients also resets to page 1 on unknown NextToken instead of rejecting it.
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/user_pools.rs, line 704:
<comment>`list_user_pool_clients` also resets to page 1 on unknown `NextToken` instead of rejecting it.</comment>
<file context>
@@ -0,0 +1,732 @@
+ clients
+ .iter()
+ .position(|c| c.client_id == token)
+ .unwrap_or(0)
+ } else {
+ 0
</file context>
Suggested change
| .unwrap_or(0) | |
| .ok_or_else(|| { | |
| AwsServiceError::aws_error( | |
| StatusCode::BAD_REQUEST, | |
| "InvalidParameterException", | |
| "Invalid NextToken", | |
| ) | |
| })? |
|
|
||
| // Find start index from NextToken | ||
| let start_idx = if let Some(token) = next_token { | ||
| pools.iter().position(|p| p.id == token).unwrap_or(0) |
There was a problem hiding this comment.
P2: NextToken fallback to index 0 silently restarts pagination when the token is invalid.
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/user_pools.rs, line 307:
<comment>`NextToken` fallback to index 0 silently restarts pagination when the token is invalid.</comment>
<file context>
@@ -0,0 +1,732 @@
+
+ // Find start index from NextToken
+ let start_idx = if let Some(token) = next_token {
+ pools.iter().position(|p| p.id == token).unwrap_or(0)
+ } else {
+ 0
</file context>
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
service.rsinto 8 focused sub-modules following the established SSM patternmod.rs(3,487 lines): struct, dispatch match, helper functions, testsauth.rs(2,060 lines): all authentication flowsusers.rs(1,056 lines): admin + self-service user operationsuser_pools.rs(732 lines): pool + client CRUDmisc.rs(621 lines): domains, devices, tags, import jobsgroups.rs(507 lines): group operationsidentity_providers.rs(482 lines): IdP + resource serversmfa.rs(394 lines): MFA config + TOTPTest plan
cargo clippy --workspace --all-targets -- -D warningspasses cleanSummary by cubic
Split the 9,058-line
fakecloud-cognitoservice.rsinto 8 focused sub-modules that follow the SSM layout for easier navigation and testing. No behavior changes.Refactors
mod.rs— service struct, request dispatch, helpers, tests.auth.rs(auth flows),users.rs(admin/self-service).user_pools.rs(pools/clients),groups.rs(groups),identity_providers.rs(IdPs/resource servers).mfa.rs(MFA/TOTP),misc.rs(domains, devices, tags, import jobs).Migration
Written for commit 742e816. Summary will update on new commits.