Skip to content

Commit 5ec1081

Browse files
committed
Revert "catch nullpointerexception when getting credentials during deserialization of json"
This reverts commit 9b213f3.
1 parent ca48468 commit 5ec1081

File tree

2 files changed

+6
-57
lines changed

2 files changed

+6
-57
lines changed

auth0/src/main/java/com/auth0/android/authentication/storage/SecureCredentialsManager.kt

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import androidx.annotation.VisibleForTesting
1616
import androidx.lifecycle.Lifecycle
1717
import com.auth0.android.Auth0Exception
1818
import com.auth0.android.authentication.AuthenticationAPIClient
19+
import com.auth0.android.authentication.AuthenticationException
20+
import com.auth0.android.callback.AuthenticationCallback
1921
import com.auth0.android.callback.Callback
2022
import com.auth0.android.request.internal.GsonProvider
2123
import com.auth0.android.result.Credentials
@@ -144,14 +146,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
144146
return false
145147
}
146148
if (resultCode == Activity.RESULT_OK) {
147-
continueGetCredentials(
148-
scope,
149-
minTtl,
150-
emptyMap(),
151-
emptyMap(),
152-
forceRefresh,
153-
decryptCallback!!
154-
)
149+
continueGetCredentials(scope, minTtl, emptyMap(), emptyMap(), forceRefresh, decryptCallback!!)
155150
} else {
156151
decryptCallback!!.onFailure(CredentialsManagerException("The user didn't pass the authentication challenge."))
157152
decryptCallback = null
@@ -552,16 +547,7 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
552547
decryptCallback = null
553548
return@execute
554549
}
555-
556-
val bridgeCredentials: OptionalCredentials
557-
try {
558-
bridgeCredentials = gson.fromJson(json, OptionalCredentials::class.java)
559-
} catch (ex: NullPointerException) {
560-
callback.onFailure(CredentialsManagerException("Credentials could not be retrieved."))
561-
decryptCallback = null
562-
return@execute
563-
}
564-
550+
val bridgeCredentials = gson.fromJson(json, OptionalCredentials::class.java)
565551
/* OPTIONAL CREDENTIALS
566552
* This bridge is required to prevent users from being logged out when
567553
* migrating from Credentials with optional Access Token and ID token
@@ -655,9 +641,8 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
655641
callback.onSuccess(freshCredentials)
656642
} catch (error: CredentialsManagerException) {
657643
val exception = CredentialsManagerException(
658-
"An error occurred while saving the refreshed Credentials.", error
659-
)
660-
if (error.cause is IncompatibleDeviceException || error.cause is CryptoException) {
644+
"An error occurred while saving the refreshed Credentials.", error)
645+
if(error.cause is IncompatibleDeviceException || error.cause is CryptoException) {
661646
exception.refreshedCredentials = freshCredentials
662647
}
663648
callback.onFailure(exception)
@@ -670,7 +655,6 @@ public class SecureCredentialsManager @VisibleForTesting(otherwise = VisibleForT
670655
private val TAG = SecureCredentialsManager::class.java.simpleName
671656
private const val KEY_CREDENTIALS = "com.auth0.credentials"
672657
private const val KEY_EXPIRES_AT = "com.auth0.credentials_access_token_expires_at"
673-
674658
// This is no longer used as we get the credentials expiry from the access token only,
675659
// but we still store it so users can rollback to versions where it is required.
676660
private const val LEGACY_KEY_CACHE_EXPIRES_AT = "com.auth0.credentials_expires_at"

auth0/src/test/java/com/auth0/android/authentication/storage/SecureCredentialsManagerTest.kt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -460,41 +460,6 @@ public class SecureCredentialsManagerTest {
460460
MatcherAssert.assertThat(retrievedCredentials.scope, Is.`is`("different scope"))
461461
}
462462

463-
@Test
464-
public fun shouldFailOnGetCredentialsWhenNullPointerExceptionIsThrown() {
465-
verifyNoMoreInteractions(client)
466-
val expiresAt = Date(CredentialsMock.ONE_HOUR_AHEAD_MS)
467-
val storedJson = insertTestCredentials(
468-
hasIdToken = true,
469-
hasAccessToken = true,
470-
hasRefreshToken = true,
471-
willExpireAt = expiresAt,
472-
scope = "scope"
473-
)
474-
475-
Mockito.`when`(crypto.decrypt(storedJson.toByteArray()))
476-
.thenReturn("".toByteArray())
477-
478-
manager.getCredentials(callback)
479-
verify(callback).onFailure(
480-
exceptionCaptor.capture()
481-
)
482-
val exception = exceptionCaptor.firstValue
483-
MatcherAssert.assertThat(exception, Is.`is`(Matchers.notNullValue()))
484-
MatcherAssert.assertThat(
485-
exception, IsInstanceOf.instanceOf(
486-
CredentialsManagerException::class.java
487-
)
488-
)
489-
MatcherAssert.assertThat(
490-
exception.message,
491-
Is.`is`("Credentials could not be retrieved.")
492-
)
493-
verify(storage, never()).remove("com.auth0.credentials")
494-
verify(storage, never()).remove("com.auth0.credentials_expires_at")
495-
verify(storage, never()).remove("com.auth0.credentials_can_refresh")
496-
}
497-
498463
@Test
499464
public fun shouldFailOnSavingRefreshedCredentialsInGetCredentialsWhenIncompatibleDeviceExceptionIsThrown() {
500465
val expiresAt = Date(CredentialsMock.ONE_HOUR_AHEAD_MS) // non expired credentials

0 commit comments

Comments
 (0)