Skip to content

Commit

Permalink
Merge pull request #32771 from sberyozkin/oidc_userinfo_npe
Browse files Browse the repository at this point in the history
Prevent NPE for UserInfo String and Boolean properties
  • Loading branch information
gastaldi authored Apr 19, 2023
2 parents 08b2235 + f2f1b0c commit e0db4a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public AbstractJsonObjectResponse(JsonObject json) {
}

public String getString(String name) {
return json.getString(name);
return contains(name) ? json.getString(name) : null;
}

public Boolean getBoolean(String name) {
return json.getBoolean(name);
return contains(name) ? json.getBoolean(name) : null;
}

public Long getLong(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.oidc.runtime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import io.quarkus.oidc.UserInfo;

public class UserInfoTest {
UserInfo userInfo = new UserInfo(
"{"
+ "\"name\": \"alice\","
+ "\"admin\": true"
+ "}");

@Test
public void testGetString() {
assertEquals("alice", userInfo.getString("name"));
assertNull(userInfo.getString("names"));
}

@Test
public void testGetBoolean() {
assertTrue(userInfo.getBoolean("admin"));
assertNull(userInfo.getBoolean("admins"));
}
}

0 comments on commit e0db4a4

Please sign in to comment.