Skip to content

Commit

Permalink
Merge pull request #516 from auth0/fix-userprofile
Browse files Browse the repository at this point in the history
Prevent NPE when parsing email_verified boolean
  • Loading branch information
lbalmaceda authored Sep 28, 2021
2 parents 23d375a + 635a06b commit 2b91d8f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public UserProfile deserialize(JsonElement json, Type typeOfT, JsonDeserializati
final String email = context.deserialize(object.remove("email"), String.class);
final String givenName = context.deserialize(object.remove("given_name"), String.class);
final String familyName = context.deserialize(object.remove("family_name"), String.class);
final boolean emailVerified = object.has("email_verified") ? context.<Boolean>deserialize(object.remove("email_verified"), Boolean.class) : false;
final Boolean emailVerified = object.has("email_verified") ? context.<Boolean>deserialize(object.remove("email_verified"), Boolean.class) : false;
final Date createdAt = context.deserialize(object.remove("created_at"), Date.class);

final Type identitiesType = new TypeToken<List<UserIdentity>>() {}.getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public class AuthenticationExceptionTest {
@Throws(Exception::class)
public fun shouldHaveNotStrongPasswordWithDetailedDescription() {
val fr = FileReader(PASSWORD_STRENGTH_ERROR_RESPONSE)
val mapType = object : TypeToken<Map<String?, Any?>?>() {}.type
val mapPayload = GsonProvider.gson.fromJson<Map<String, Any>>(fr, mapType)
val mapType = object : TypeToken<Map<String, Any>>() {}
val mapPayload: Map<String, Any> = GsonProvider.gson.getAdapter(mapType).fromJson(fr)
val ex = AuthenticationException(mapPayload)
MatcherAssert.assertThat(ex.isPasswordNotStrongEnough, CoreMatchers.`is`(true))
val expectedDescription =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public class UserProfileGsonTest : GsonBaseTest() {
}
}

@Test
@Throws(Exception::class)
public fun shouldHandleNullBooleans() {
val userProfile = pojoFrom(
StringReader(
"""{"email_verified": null}"""
), UserProfile::class.java
)
assertThat(userProfile, `is`(notNullValue()))
}

@Test
@Throws(Exception::class)
public fun shouldNotRequireUserId() {
Expand Down

0 comments on commit 2b91d8f

Please sign in to comment.