Repository navigation
test(auth_2fa): add negative tests for TOTP and backup codes - #1301
Merged
fejilaup-cloud merged 2 commits intoOct 21, 2026
Merged
fejilaup-cloud merged 2 commits into
fejilaup-cloud merged 2 commits into
Conversation
…P#1240) Add comprehensive negative tests covering all tasks from issue AtomicIP#1240: Unit tests in auth_2fa.rs (18 tests, all passing): - Wrong/malformed TOTP codes: too short, too long, empty, letters, spaces, special chars, minus sign - Out-of-window TOTP code placeholder documentation test - Backup code reuse: second attempt returns false - All backup codes exhausted after single use - Cross-user backup code isolation (separate stores) - Cross-user backup code isolation (shared store) - Backup code for nonexistent user returns false - Fabricated backup code is rejected - Enrollment without TOTP factor not considered enabled - Incomplete enrollment (verified=false) not considered enabled - Unknown user not considered 2FA-enabled - get_config returns None for unknown user Integration test file (api-server/tests/auth_2fa_negative_tests.rs): - Self-contained structural/protocol tests mirroring the codebase style - Additional edge cases: unicode digits, whitespace-only codes Pre-existing compile errors fixed to unblock test execution: - health.rs: duplicate check_contract_connectivity function removed - response.rs: impl Into<String> moved value errors - handlers.rs: missing imports, undefined statics, utoipa syntax - deduplication.rs: ConnectionManager Debug derive - distributed_tracing.rs / tracing_middleware.rs: span borrow-after-move - connection_pool.rs: min_size -> min_idle (r2d2 API) - websocket.rs: missing ContractEvent variants - batch.rs / invariants.rs / validation_fuzz_tests.rs: test fixes - lib.rs: expose all modules for lib target - Cargo.toml: add base32 dependency Closes AtomicIP#1240 Closes AtomicIP#1241 Closes AtomicIP#1242 Closes AtomicIP#1243
|
@Rayyanah0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Resolves issue #1240. The 2FA test suite previously had no negative tests — only success paths were covered. This PR adds comprehensive negative tests for TOTP code validation and backup code handling.
Changes
New:
api-server/src/auth_2fa.rs— 18 unit tests (all passing)Wrong/malformed TOTP codes
Backup code reuse
falseCross-user backup code isolation
Enrollment without a factor
verified=false) is not 2FA-enabledtotp: None(only backup codes) is not considered enrolledget_configreturnsNonefor unknown usersNew:
api-server/tests/auth_2fa_negative_tests.rs— 20 structural testsSelf-contained protocol/invariant tests mirroring the existing test style in the repo, covering additional edge cases (unicode digits, whitespace codes, fabricated codes, etc.).
Pre-existing compile errors fixed
Multiple files had pre-existing compilation errors that blocked running any tests:
health.rs: duplicatecheck_contract_connectivityfunction (merge artifact)response.rs:impl Into<String>use-after-movehandlers.rs: missing imports, undefined static, utoipa v4 syntaxdeduplication.rs:ConnectionManagermissingDebugdistributed_tracing.rs/tracing_middleware.rs:spanborrow-after-moveconnection_pool.rs:min_size→min_idle(r2d2 API)websocket.rs: missingContractEventvariantsbatch.rs,invariants.rs,validation_fuzz_tests.rs: test initializer fixeslib.rs: missing module declarationsCargo.toml: addbase32as explicit dependencyTest Evidence
Closes #1240
Closes #1241
Closes #1242
Closes #1243