Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELY-2714] Attempting to read address data from an OIDC id token caus…
…es ClassCastException
- Loading branch information
Showing
2 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
http/oidc/src/test/java/org/wildfly/security/http/oidc/IDTokenTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.wildfly.security.http.oidc; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonObject; | ||
import org.jose4j.jwt.JwtClaims; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.wildfly.common.Assert.assertNotNull; | ||
|
||
public class IDTokenTest { | ||
|
||
@Test | ||
public void testIDTokenWithAddressClaim() { | ||
JwtClaims jwtClaims = new JwtClaims(); | ||
JsonObject jsonObject = Json.createObjectBuilder() | ||
.add("address", Json.createObjectBuilder() | ||
.add("region", "US") | ||
.add("country", "New York") | ||
.add("locality", "NY") | ||
.add("postal_code", "10021")) | ||
.build(); | ||
jwtClaims.setClaim("given_name", "Alice"); | ||
jwtClaims.setClaim("family_name", "Smith"); | ||
jwtClaims.setClaim("address", jsonObject.get("address")); | ||
IDToken idToken = new IDToken(jwtClaims); | ||
assertNotNull(idToken); | ||
assertEquals("NY", idToken.getAddress().getLocality()); | ||
assertEquals("10021", idToken.getAddress().getPostalCode()); | ||
assertEquals("US", idToken.getAddress().getRegion()); | ||
assertEquals("New York", idToken.getAddress().getCountry()); | ||
assertEquals("Alice", idToken.getGivenName()); | ||
assertEquals("Smith", idToken.getFamilyName()); | ||
} | ||
} |