Skip to content

Commit c42e67f

Browse files
committed
Added UT test caes and changes excluding WebAuthn
1 parent 13da6ba commit c42e67f

File tree

4 files changed

+156
-275
lines changed

4 files changed

+156
-275
lines changed

auth0/src/main/java/com/auth0/android/myaccount/MyAccountAPIClient.kt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
299299

300300
val request = factory.get(
301301
url.toString(),
302-
GsonAdapter(AuthenticationMethods::class.java, gson)
302+
GsonAdapter(AuthenticationMethods::class.java)
303303
)
304304
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
305305

@@ -348,7 +348,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
348348

349349
val request = factory.get(
350350
url.toString(),
351-
GsonAdapter(AuthenticationMethod::class.java, gson)
351+
GsonAdapter(AuthenticationMethod::class.java)
352352
)
353353
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
354354

@@ -391,8 +391,8 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
391391
*/
392392
public fun updateAuthenticationMethodById(
393393
authenticationMethodId: String,
394-
preferredAuthenticationMethod: String,
395-
authenticationMethodName: String
394+
authenticationMethodName: String,
395+
preferredAuthenticationMethod: String
396396
): Request<AuthenticationMethod, MyAccountException> {
397397
val url =
398398
getDomainUrlBuilder()
@@ -401,13 +401,13 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
401401
.build()
402402

403403
val params = ParameterBuilder.newBuilder().apply {
404-
set(PREFERRED_AUTHENTICATION_METHOD, preferredAuthenticationMethod)
405404
set(AUTHENTICATION_METHOD_NAME, authenticationMethodName)
405+
set(PREFERRED_AUTHENTICATION_METHOD, preferredAuthenticationMethod)
406406
}.asDictionary()
407407

408408
val request = factory.patch(
409409
url.toString(),
410-
GsonAdapter(AuthenticationMethod::class.java, gson)
410+
GsonAdapter(AuthenticationMethod::class.java)
411411
)
412412
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
413413
.addParameters(params)
@@ -466,6 +466,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
466466
}
467467
val request = factory.delete(url.toString(), voidAdapter)
468468
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
469+
469470
return request
470471
}
471472

@@ -493,18 +494,13 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
493494
* ```
494495
* @return A request to get the list of available factors.
495496
*/
496-
public fun getFactors(): Request<List<Factor>, MyAccountException> {
497+
public fun getFactors(): Request<Factors, MyAccountException> {
497498
val url = getDomainUrlBuilder()
498499
.addPathSegment(FACTORS)
499500
.build()
500-
val factorListAdapter = object : JsonAdapter<List<Factor>> {
501-
override fun fromJson(reader: Reader, metadata: Map<String, Any>): List<Factor> {
502-
val listType = object : TypeToken<List<Factor>>() {}.type
503-
return gson.fromJson(reader, listType)
504-
}
505-
}
501+
val adapter = GsonAdapter(Factors::class.java, gson)
506502

507-
return factory.get(url.toString(), factorListAdapter)
503+
return factory.get(url.toString(), adapter)
508504
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
509505
}
510506

@@ -678,7 +674,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
678674
* ```
679675
* @return a request that will yield an enrollment challenge.
680676
*/
681-
public fun enrollWebAuthnPlatform(): Request<EnrollmentChallenge, MyAccountException> {
677+
private fun enrollWebAuthnPlatform(): Request<EnrollmentChallenge, MyAccountException> {
682678
val params = ParameterBuilder.newBuilder().set(TYPE_KEY, "webauthn-platform").asDictionary()
683679
return factory.post(
684680
getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS).build().toString(),
@@ -709,7 +705,7 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
709705
* ```
710706
* @return a request that will yield an enrollment challenge.
711707
*/
712-
public fun enrollWebAuthnRoaming(): Request<EnrollmentChallenge, MyAccountException> {
708+
private fun enrollWebAuthnRoaming(): Request<EnrollmentChallenge, MyAccountException> {
713709
val params = ParameterBuilder.newBuilder().set(TYPE_KEY, "webauthn-roaming").asDictionary()
714710
return factory.post(
715711
getDomainUrlBuilder().addPathSegment(AUTHENTICATION_METHODS).build().toString(),
@@ -816,7 +812,6 @@ public class MyAccountAPIClient @VisibleForTesting(otherwise = VisibleForTesting
816812
.addHeader(AUTHORIZATION_KEY, "Bearer $accessToken")
817813
}
818814

819-
820815
private fun getDomainUrlBuilder(): HttpUrl.Builder {
821816
return auth0.getDomainUrl().toHttpUrl().newBuilder()
822817
.addPathSegment(ME_PATH)

auth0/src/main/java/com/auth0/android/result/EnrollmentChallenge.kt

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,46 +51,4 @@ public data class RecoveryCodeEnrollmentChallenge(
5151
public override val authSession: String,
5252
@SerializedName("recovery_code")
5353
public val recoveryCode: String
54-
) : EnrollmentChallenge(id, authSession)
55-
56-
public data class PublicKeyCredentialCreationOptions(
57-
@SerializedName("rp")
58-
public val rp: RelyingParty,
59-
@SerializedName("user")
60-
public val user: User,
61-
@SerializedName("challenge")
62-
public val challenge: String,
63-
@SerializedName("pubKeyCredParams")
64-
public val pubKeyCredParams: List<PubKeyCredParam>,
65-
@SerializedName("timeout")
66-
public val timeout: Long?,
67-
@SerializedName("authenticatorSelection")
68-
public val authenticatorSelection: AuthenticatorSelection?
69-
) {
70-
public data class RelyingParty(
71-
@SerializedName("id")
72-
public val id: String,
73-
@SerializedName("name")
74-
public val name: String
75-
)
76-
public data class User(
77-
@SerializedName("id")
78-
public val id: String,
79-
@SerializedName("name")
80-
public val name: String,
81-
@SerializedName("displayName")
82-
public val displayName: String
83-
)
84-
public data class PubKeyCredParam(
85-
@SerializedName("type")
86-
public val type: String,
87-
@SerializedName("alg")
88-
public val alg: Int
89-
)
90-
public data class AuthenticatorSelection(
91-
@SerializedName("userVerification")
92-
public val userVerification: String?,
93-
@SerializedName("residentKey")
94-
public val residentKey: String?
95-
)
96-
}
54+
) : EnrollmentChallenge(id, authSession)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.auth0.android.result
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* A wrapper class for the list of factors returned by the API.
7+
*/
8+
public data class Factors(
9+
@SerializedName("factors")
10+
public val factors: List<Factor>
11+
)

0 commit comments

Comments
 (0)