[fix] SDKS-5074 Introduce InvalidUriException in mfa-commons for typed OATH URI parse errors#210
[fix] SDKS-5074 Introduce InvalidUriException in mfa-commons for typed OATH URI parse errors#210rodrigoareis wants to merge 2 commits into
Conversation
…d OATH URI parse errors Introduce InvalidUriException (extends MfaException) in mfa:commons so callers — notably the React Native OATH bridge — can distinguish OATH URI structural/parsing failures from general argument-validation failures without sniffing e.message for the substring "uri". URI-structure throw sites in OathUriParser.parse() (invalid scheme, invalid OATH type, missing required secret, catch-all wrapper) and UriParser.parseLabelComponents (issuer/label mismatch) are reclassified to throw InvalidUriException. Value-validation errors (digits, period, counter) remain IllegalArgumentException. Reaches parity with iOS OathError.invalidUri. Phases: - phase 1: Add InvalidUriException type to mfa-commons - phase 2: Reclassify UriParser issuer/label-mismatch throw to InvalidUriException - phase 3: Reclassify OathUriParser URI-structure throws to InvalidUriException - phase 4: Tests for typed InvalidUriException + full module build - reviewer fix: copyright year + test message assertions CHANGELOG: entry added for SDKS-5074. Refs: SDKS-5074
📝 WalkthroughWalkthroughThis PR introduces ChangesException Type Standardization for URI Parsing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #210 +/- ##
==============================================
+ Coverage 26.11% 44.42% +18.31%
- Complexity 1016 1393 +377
==============================================
Files 308 315 +7
Lines 9374 9627 +253
Branches 1408 1474 +66
==============================================
+ Hits 2448 4277 +1829
+ Misses 6646 4788 -1858
- Partials 280 562 +282
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for pushing this improvement so quickly. Two minor things:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
mfa/push/src/test/kotlin/com/pingidentity/mfa/push/PushUriParserTest.kt (1)
2-2:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate the modified-file copyright year range.
Line 2 still uses a single year (
2025), but this file is modified in 2026 and should use a range (2025-2026) per repository convention.Based on learnings, modified Kotlin/Java files in this repository should use a creation-year-to-current-year range in the copyright header.
🤖 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 `@mfa/push/src/test/kotlin/com/pingidentity/mfa/push/PushUriParserTest.kt` at line 2, Update the copyright year on line 2 of PushUriParserTest.kt from the single year format "2025" to the year range format "2025-2026" to follow the repository convention for modified files. Change the copyright header to use the creation year and current year as a range.Source: Learnings
mfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushUriParser.kt (1)
48-51:⚠️ Potential issue | 🟠 Major | ⚡ Quick winUse
InvalidUriExceptionfor scheme mismatch to keep structural failures typed.At Line 50, scheme mismatch still throws
IllegalArgumentException, which conflicts with the updated contract/KDoc (Lines 40-41) that structural URI failures areInvalidUriException. This leaks the wrong type to callers.Suggested fix
val scheme = parsedUri.scheme?.lowercase() ?: "" if (scheme != PUSHAUTH_SCHEME && scheme != MFAUTH_SCHEME) { - throw IllegalArgumentException("Invalid URI scheme: $scheme, expected: $PUSHAUTH_SCHEME or $MFAUTH_SCHEME") + throw InvalidUriException("Invalid URI scheme: $scheme, expected: $PUSHAUTH_SCHEME or $MFAUTH_SCHEME") }🤖 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 `@mfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushUriParser.kt` around lines 48 - 51, The scheme validation in PushUriParser.kt is throwing IllegalArgumentException when the URI scheme does not match PUSHAUTH_SCHEME or MFAUTH_SCHEME, but the contract documented in the KDoc specifies that structural URI failures should throw InvalidUriException. Replace the IllegalArgumentException with InvalidUriException at the scheme mismatch check to maintain consistent exception typing for structural URI validation failures.
🤖 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.
Outside diff comments:
In `@mfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushUriParser.kt`:
- Around line 48-51: The scheme validation in PushUriParser.kt is throwing
IllegalArgumentException when the URI scheme does not match PUSHAUTH_SCHEME or
MFAUTH_SCHEME, but the contract documented in the KDoc specifies that structural
URI failures should throw InvalidUriException. Replace the
IllegalArgumentException with InvalidUriException at the scheme mismatch check
to maintain consistent exception typing for structural URI validation failures.
In `@mfa/push/src/test/kotlin/com/pingidentity/mfa/push/PushUriParserTest.kt`:
- Line 2: Update the copyright year on line 2 of PushUriParserTest.kt from the
single year format "2025" to the year range format "2025-2026" to follow the
repository convention for modified files. Change the copyright header to use the
creation year and current year as a range.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b93e61ea-ef2c-43a0-b209-d874e0fe13aa
📒 Files selected for processing (5)
CHANGELOG.mdmfa/oath/src/main/kotlin/com/pingidentity/mfa/oath/OathCredential.ktmfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushCredential.ktmfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushUriParser.ktmfa/push/src/test/kotlin/com/pingidentity/mfa/push/PushUriParserTest.kt
✅ Files skipped from review due to trivial changes (3)
- CHANGELOG.md
- mfa/push/src/main/kotlin/com/pingidentity/mfa/push/PushCredential.kt
- mfa/oath/src/main/kotlin/com/pingidentity/mfa/oath/OathCredential.kt
JIRA Ticket
SDKS-5074 "[Android] Add dedicated InvalidUriException to mfa-commons for OATH URI parsing errors"
Description
Introduce a dedicated, typed
InvalidUriExceptioninmfa:commonsso callers — notably the React Native OATH bridge (OathErrorMapper.kt) — can distinguish OATH URI structural/parsing failures from general argument-validation failures without sniffinge.messagefor the substring"uri". The new exception extends the module'sMfaExceptionfamily. URI-structure throw sites inOathUriParser.parse()(invalid scheme, invalid OATH type, missing requiredsecret, the catch-all wrapper) and the sharedUriParser.parseLabelComponentsissuer/label-mismatch check are reclassified to throwInvalidUriException, while genuine value-validation errors (invalid digits, period, counter) remainIllegalArgumentException. This reaches parity with the iOSOathError.invalidUricase. The exception is placed incommons(notoath) so the parallelPushUriParsercan adopt it later with no further module changes.Phases completed:
InvalidUriExceptiontype to mfa-commons: AddedInvalidUriException : MfaExceptiontoMfaException.ktUriParser.parseLabelComponentsissuer/label mismatch →InvalidUriExceptionInvalidUriException; value-validation staysIllegalArgumentExceptionmfa:oath+mfa:commonsbuildNote: The downstream React Native bridge (
OathErrorMapper.kt, RN repo) must be updated separately tocatch (e: InvalidUriException)and remove thee.messagestring-sniffing heuristic. Coordinate that PR alongside this SDK release.Summary by CodeRabbit
New Features
InvalidUriExceptionfor structurally invalid/unparseable MFA URIs.Bug Fixes
InvalidUriException(instead of generic exceptions) for structural/validation issues like scheme/type/secret requirements and issuer mismatches.Documentation
Tests
InvalidUriExceptionis raised for URI structural problems, while parameter validation errors remainIllegalArgumentException.Chores
.sdk/to.gitignore.