Conversation
Remove strtolower() from recovery code type comparison (line 4945) Remove strtolower() from match statement (line 4967) Add comprehensive test for recovery code challenge validation Fixes issue where recovery codes fail with 'Invalid token' error Fixes #10740
…ession remove unnecessary 'origin' headers to match other tests set status code to 201 for MFA challenge creation endpoint
- Fixed HTTP status code: POST /v1/account/mfa/recovery-codes now returns 201 (CREATED) instead of 200 - Updated testMFARecoveryCodeChallenge to expect 201 status code - Added array_merge with origin header to all API calls in test for proper CORS validation - Removed trailing whitespace for PSR-12 compliance Fixes #10740
…de-validation fix: resolve MFA recovery code validation in 1.8.0
📝 WalkthroughWalkthroughThe changes modify MFA challenge and recovery code response handling in the Account module. Two files now explicitly set HTTP 201 Created status codes when returning newly created MFA challenges and recovery codes. In the MFA challenge Update handler, type comparisons for recovery code detection switch from lowercased string checks to direct constant comparisons. A new end-to-end test validates the complete MFA recovery code challenge workflow, including code validation, consumption, and reuse prevention. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10–15 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/e2e/Services/Account/AccountCustomClientTest.php (1)
3099-3176: End-to-end recovery-code challenge test is thorough and aligned with behaviorThe new
testMFARecoveryCodeChallengeneatly covers:
- Successful verification with a valid recovery code (and factor recorded as
recoveryCode),- One-time use semantics (second use of the same code returns 401),
- Failure on a clearly invalid code.
Status-code assertions (201 for create, 200/401 for update) match the updated handlers. This gives solid coverage for the bugfix and creation semantics.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php(1 hunks)src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php(2 hunks)src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php(1 hunks)tests/e2e/Services/Account/AccountCustomClientTest.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php (1)
src/Appwrite/Utopia/Response.php (2)
Response(159-983)dynamic(703-736)
tests/e2e/Services/Account/AccountCustomClientTest.php (3)
tests/e2e/Client.php (1)
Client(8-342)src/Appwrite/Event/Event.php (1)
getProject(153-156)tests/e2e/Scopes/Scope.php (2)
getProject(150-150)getHeaders(145-145)
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php (1)
src/Appwrite/Utopia/Response.php (2)
Response(159-983)dynamic(703-736)
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php (1)
src/Appwrite/Auth/MFA/Type.php (1)
Type(8-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: Setup & Build Appwrite Image
🔇 Additional comments (3)
src/Appwrite/Platform/Modules/Account/Http/Account/MFA/RecoveryCodes/Create.php (1)
104-106: Explicit 201 for recovery-codes creation is correct and consistentSetting
STATUS_CODE_CREATEDbeforedynamic()aligns runtime behavior with the SDK response metadata and standard “create” semantics. Looks good.src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Create.php (1)
336-338: 201 status for MFA challenge creation is appropriateChaining
setStatusCode(Response::STATUS_CODE_CREATED)beforedynamic($challenge, MODEL_MFA_CHALLENGE)makes the HTTP contract explicit and consistent with the declared SDK responses.src/Appwrite/Platform/Modules/Account/Http/Account/MFA/Challenges/Update.php (1)
110-129: UsingType::RECOVERY_CODEdirectly fixes the recovery-code matching bugSwitching both the closure guard and the
matcharm to compare againstType::RECOVERY_CODEmakes the logic consistent with how the challengetypeis stored (from thefactorwhitelist) and removes the casing mismatch issue. Recovery-code consumption and factor tracking via$session->getAttribute('factors')remain correct.Also applies to: 131-137
✨ Benchmark results
⚡ Benchmark Comparison
|
What does this PR do?
Update 1.8.x with changes from main
Test Plan
Automated tests should pass
Related PRs and Issues
Checklist