fix: mfa_requirements in MFARequiredErrorPayload made optional - #1272
fix: mfa_requirements in MFARequiredErrorPayload made optional#1272NandanPrabhu wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughMFA-required error payload decoding now explicitly decodes its fields, defaults missing MFA requirements, documents optional requirement lists, and adds tests for present and absent ChangesMFA payload decoding
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
When the server omits mfa_requirements from the mfa_required error response, the custom init(from:) now falls back to MFARequirements() (enroll and challenge both nil) instead of failing to decode the entire payload.
da0569b to
b28bb2f
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Auth0/MFARequiredErrorPayload.swift`:
- Line 52: Add a DocC comment immediately before
MFARequiredErrorPayload.init(from:) describing that it decodes the payload from
a Decoder and can throw decoding errors. Keep the initializer’s behavior
unchanged.
In `@Auth0Tests/AuthenticationErrorSpec.swift`:
- Around line 419-449: The newly added MFA decoding examples do not follow the
required test naming conventions. Update both descriptions in the
`AuthenticationErrorSpec` examples to present-tense declarative `should … when
…` wording, and rename local test constants such as `values`, `error`, and
`payload` to UpperCamelCase names (`Values`, `Error`, and `Payload`) while
preserving the existing assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c18e766d-9419-4b51-a9d2-e47dc22a89f0
📒 Files selected for processing (2)
Auth0/MFARequiredErrorPayload.swiftAuth0Tests/AuthenticationErrorSpec.swift
| it("should decode mfa required payload with mfa_requirements") { | ||
| let values: [String: Any] = [ | ||
| "error": "mfa_required", | ||
| "error_description": "MFA Required", | ||
| "mfa_token": "test-mfa-token", | ||
| "mfa_requirements": [ | ||
| "enroll": [["type": "otp"]], | ||
| "challenge": [["type": "otp"]] | ||
| ] | ||
| ] | ||
| let error = AuthenticationError(info: values, statusCode: 403) | ||
| let payload = error.mfaRequiredErrorPayload | ||
| expect(payload).toNot(beNil()) | ||
| expect(payload?.mfaToken) == "test-mfa-token" | ||
| expect(payload?.mfaRequirements.enroll?.first?.type) == "otp" | ||
| expect(payload?.mfaRequirements.challenge?.first?.type) == "otp" | ||
| } | ||
|
|
||
| it("should decode mfa required payload without mfa_requirements") { | ||
| let values: [String: Any] = [ | ||
| "error": "mfa_required", | ||
| "error_description": "MFA Required", | ||
| "mfa_token": "test-mfa-token" | ||
| ] | ||
| let error = AuthenticationError(info: values, statusCode: 403) | ||
| let payload = error.mfaRequiredErrorPayload | ||
| expect(payload).toNot(beNil()) | ||
| expect(payload?.mfaToken) == "test-mfa-token" | ||
| expect(payload?.mfaRequirements.enroll).to(beNil()) | ||
| expect(payload?.mfaRequirements.challenge).to(beNil()) | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Match the required test naming conventions.
Use should … when … descriptions and UpperCamelCase test constants for the newly added cases, e.g. Values, Error, and Payload. As per coding guidelines, “it descriptions must use present tense, declarative style: "should ... when ..."” and “Test constants must use UpperCamelCase.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@Auth0Tests/AuthenticationErrorSpec.swift` around lines 419 - 449, The newly
added MFA decoding examples do not follow the required test naming conventions.
Update both descriptions in the `AuthenticationErrorSpec` examples to
present-tense declarative `should … when …` wording, and rename local test
constants such as `values`, `error`, and `payload` to UpperCamelCase names
(`Values`, `Error`, and `Payload`) while preserving the existing assertions.
Sources: Coding guidelines, Path instructions
Changes
init(from:)onMFARequiredErrorPayload(via aDecodableextension) that usesdecodeIfPresentformfa_requirementsand falls back toMFARequirements()when the key is absent from the server response.inittoMFARequirements(with defaultednilparameters) to make the fallback expression concise.mfaRequirementsremains non-optional onMFARequiredErrorPayload— callers don't need to unwrap it.Test plan
should decode mfa required payload with mfa_requirements— verifiesenrollandchallengeare decoded correctly when present.should decode mfa required payload without mfa_requirements— verifiesmfaRequirements.enrollandmfaRequirements.challengearenilwhen the key is absent.swift test.