Repository navigation
fix: stop reporting an unrecognized biometric as a final failure - #1098
Conversation
…ack when a wrong fingerprint/pin is entered
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
|
||
| @Test | ||
| @ExperimentalCoroutinesApi | ||
| public fun shouldThrowOnlyTheFinalErrorOnAwaitCredentialsWhenUnrecognizedBiometricIsFollowedByError(): Unit = |
There was a problem hiding this comment.
The bug was that a biometric session got started even though the app saw a failure. Could we also check the session here: invalid after lockout, valid after success?
There was a problem hiding this comment.
Added case for the same
| * unrecognized biometric before delivering [finalResult], mirroring how BiometricPrompt | ||
| * keeps the prompt open after a failed attempt. | ||
| */ | ||
| private fun simulatePromptWithUnrecognizedBiometric( |
There was a problem hiding this comment.
Could we add one test of the callback API (getCredentials(callback)) using it, checking that onSuccess is called exactly once and onFailure is never called? That's the path react-native-auth0 actually uses, and right now it's only covered at the LocalAuthenticationManager level.
There was a problem hiding this comment.
Added in ac017cb: shouldDeliverOnlySuccessAndStartBiometricSessionWhenUnrecognizedBiometricIsFollowedBySuccess drives getCredentials(callback) through a real LocalAuthenticationManager (not recognized → success) and verifies onSuccess exactly once and onFailure never. It also runs under BiometricPolicy.Session and asserts the session is valid afterwards .
Changes
SecureCredentialsManagerwithLocalAuthenticationOptionscould deliver two results for a singlegetCredentials()/getApiCredentials()call when the user presented an unrecognized biometric and then authenticated successfully (for example via the device credential fallback).LocalAuthenticationManager.onAuthenticationFailed()calledresultCallback.onFailure(BIOMETRICS_INVALID_USER).BiometricPromptinvokesonAuthenticationFailed()when a biometric is read but not recognized; it is not a terminal event, and the prompt stays open. The terminal result always arrives later viaonAuthenticationSucceeded()oronAuthenticationError().Impact before this change:
onFailure(BIOMETRICS_INVALID_USER)while the prompt was still open, thenonSuccessafter the user authenticated. Callers that settle on the first result (e.g. react-native-auth0) showed a failure and dropped the success, while the biometric session was still started.awaitCredentials/awaitApiCredentials): the continuation was resumed twice, throwingIllegalStateException: Already resumed.runCatchingOnExecutorconverted that into anUNKNOWN_ERRORfailure, which attempted a third resume and threw again from the executor thread.References
Testing
New unit tests in
LocalAuthenticationManagerTest:onSuccess(true).ERROR_LOCKOUTdelivers onlyBIOMETRIC_ERROR_LOCKOUT.New coroutine tests in
SecureCredentialsManagerTest, using a realLocalAuthenticationManager(spy with onlyauthenticate()stubbed) so the actualonAuthenticationFailed()path is exercised:awaitCredentials()returns credentials when an unrecognized biometric is followed by success.awaitCredentials()throws onlyBIOMETRIC_ERROR_LOCKOUTwhen an unrecognized biometric is followed by lockout.awaitApiCredentials()returns API credentials when an unrecognized biometric is followed by success.With the old
onFailurecall restored, all six new tests fail, and the three coroutine tests fail withIllegalStateException: Already resumed. With the fix,LocalAuthenticationManagerTest(40) andSecureCredentialsManagerTest(135) pass.This change adds unit test coverage
This change adds integration test coverage
This change has been tested on the latest version of the platform/language or why not
Checklist
I have read the Auth0 general contribution guidelines
I have read the Auth0 Code of Conduct
All existing and new tests complete without errors