Skip to content

Commit a701dbf

Browse files
committed
Fixed failing tests
1 parent 96f3b78 commit a701dbf

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

auth0/src/main/java/com/auth0/android/dpop/DPoPKeyStore.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import javax.security.cert.CertificateException
2323
/**
2424
* Class to handle all DPoP related keystore operations
2525
*/
26-
internal class DPoPKeyStore(
27-
private val keyStore: KeyStore =
26+
internal open class DPoPKeyStore {
27+
28+
protected open val keyStore: KeyStore by lazy {
2829
KeyStore.getInstance(ANDROID_KEYSTORE).apply { load(null) }
29-
) {
30+
}
3031

3132
fun generateKeyPair(context: Context) {
3233
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {

auth0/src/main/java/com/auth0/android/provider/OAuthManager.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ internal class OAuthManager(
6060
idTokenVerificationIssuer = if (TextUtils.isEmpty(issuer)) apiClient.baseURL else issuer
6161
}
6262

63-
@RequiresApi(Build.VERSION_CODES.M)
6463
fun startAuthentication(context: Context, redirectUri: String, requestCode: Int) {
6564
OidcUtils.includeDefaultScope(parameters)
6665
addPKCEParameters(parameters, redirectUri, headers)

auth0/src/main/java/com/auth0/android/request/ErrorBody.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public data class ErrorBody(
2020
* Extension method to parse [ErrorBody] from [Response]
2121
*/
2222
public fun Response.getErrorBody(): ErrorBody {
23-
return InputStreamReader(body?.byteStream(), Charsets.UTF_8).use { reader ->
24-
try {
25-
Gson().fromJson(reader, ErrorBody::class.java)
26-
} catch (error: Exception) {
27-
Log.e("ErrorBody", "Error parsing the error body ${error.stackTraceToString()}")
28-
return ErrorBody("", "")
29-
}
23+
return try {
24+
val peekedBody = peekBody(Long.MAX_VALUE)
25+
val bodyString = peekedBody.string()
26+
Gson().fromJson(bodyString, ErrorBody::class.java)
27+
} catch (error: Exception) {
28+
Log.e("ErrorBody", "Error parsing the error body ${error.stackTraceToString()}")
29+
ErrorBody("", "")
3030
}
3131
}

auth0/src/test/java/com/auth0/android/dpop/DPoPKeyStoreTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ import java.security.PublicKey
3535
import java.security.cert.Certificate
3636
import javax.security.auth.x500.X500Principal
3737

38+
/**
39+
* Using a subclass of [DPoPKeyStore] to help with mocking the lazy initialized keyStore property
40+
*/
41+
internal class MockableDPoPKeyStore(private val mockKeyStore: KeyStore) : DPoPKeyStore() {
42+
override val keyStore: KeyStore by lazy { mockKeyStore }
43+
}
44+
3845
@RunWith(PowerMockRunner::class)
3946
@PrepareForTest(
4047
DPoPKeyStore::class,
@@ -73,7 +80,6 @@ public class DPoPKeyStoreTest {
7380
PowerMockito.whenNew(KeyGenParameterSpec.Builder::class.java).withAnyArguments()
7481
.thenReturn(mockSpecBuilder)
7582

76-
// Configure mocks
7783
PowerMockito.`when`(KeyStore.getInstance("AndroidKeyStore")).thenReturn(mockKeyStore)
7884
doNothing().whenever(mockKeyStore).load(anyOrNull())
7985
PowerMockito.`when`(
@@ -94,7 +100,7 @@ public class DPoPKeyStoreTest {
94100
true
95101
)
96102

97-
dpopKeyStore = DPoPKeyStore(mockKeyStore)
103+
dpopKeyStore = MockableDPoPKeyStore(mockKeyStore)
98104
}
99105

100106
@Test

auth0/src/test/java/com/auth0/android/util/AuthenticationAPIMockServer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ internal class AuthenticationAPIMockServer : APIMockServer() {
205205
const val ID_TOKEN = "ID_TOKEN"
206206
const val ACCESS_TOKEN = "ACCESS_TOKEN"
207207
const val SESSION_ID = "SESSION_ID"
208-
private const val BEARER = "BEARER"
208+
private const val BEARER = "Bearer"
209209
private const val CHALLENGE = "CHALLENGE"
210210
}
211211
}

0 commit comments

Comments
 (0)