|
27 | 27 |
|
28 | 28 | import org.junit.Assert; |
29 | 29 |
|
| 30 | +import java.io.IOException; |
30 | 31 | import java.io.StringWriter; |
31 | 32 | import java.lang.reflect.Array; |
32 | 33 | import java.util.ArrayList; |
@@ -90,6 +91,42 @@ public void testFromJson() throws Exception { |
90 | 91 |
|
91 | 92 | // New tests -> |
92 | 93 |
|
| 94 | + @Test |
| 95 | + public void testFromJWT() throws IOException { |
| 96 | + // TODO: FromJWT does not verify signature. Once that is supported update this test. |
| 97 | + String idToken = "eyJraWQiOiIxZTlnZGs3IiwiYWxnIjoiUlMyNTYifQ.ewogImlz" |
| 98 | + + "cyI6ICJodHRwOi8vc2VydmVyLmV4YW1wbGUuY29tIiwKICJzdWIiOiAiMjQ4" |
| 99 | + + "Mjg5NzYxMDAxIiwKICJhdWQiOiAiczZCaGRSa3F0MyIsCiAibm9uY2UiOiAi" |
| 100 | + + "bi0wUzZfV3pBMk1qIiwKICJleHAiOiAxMzExMjgxOTcwLAogImlhdCI6IDEz" |
| 101 | + + "MTEyODA5NzAsCiAibmFtZSI6ICJKYW5lIERvZSIsCiAiZ2l2ZW5fbmFtZSI6" |
| 102 | + + "ICJKYW5lIiwKICJmYW1pbHlfbmFtZSI6ICJEb2UiLAogImdlbmRlciI6ICJm" |
| 103 | + + "ZW1hbGUiLAogImJpcnRoZGF0ZSI6ICIwMDAwLTEwLTMxIiwKICJlbWFpbCI6" |
| 104 | + + "ICJqYW5lZG9lQGV4YW1wbGUuY29tIiwKICJwaWN0dXJlIjogImh0dHA6Ly9l" |
| 105 | + + "eGFtcGxlLmNvbS9qYW5lZG9lL21lLmpwZyIKfQ.rHQjEmBqn9Jre0OLykYNn" |
| 106 | + + "spA10Qql2rvx4FsD00jwlB0Sym4NzpgvPKsDjn_wMkHxcp6CilPcoKrWHcip" |
| 107 | + + "R2iAjzLvDNAReF97zoJqq880ZD1bwY82JDauCXELVR9O6_B0w3K-E7yM2mac" |
| 108 | + + "AAgNCUwtik6SjoSUZRcf-O5lygIyLENx882p6MtmwaL1hd6qn5RZOQ0TLrOY" |
| 109 | + + "u0532g9Exxcm-ChymrB4xLykpDj3lUivJt63eEGGN6DH5K6o33TcxkIjNrCD" |
| 110 | + + "4XB1CKKumZvCedgHHF3IAK4dVEDSUoGlH9z4pP_eWYNXvqQOjGs-rDaQzUHl" + "6cQQWNiDpWOl_lxXjQEvQ"; |
| 111 | + HashMap<String, Object> claims = new HashMap<>(); |
| 112 | + MockMessage mockMessage = new MockMessage(claims); |
| 113 | + mockMessage.fromJwt(idToken); |
| 114 | + Assert.assertEquals("http://server.example.com", mockMessage.getClaims().get("iss")); |
| 115 | + Assert.assertEquals("248289761001", mockMessage.getClaims().get("sub")); |
| 116 | + Assert.assertEquals("s6BhdRkqt3", mockMessage.getClaims().get("aud")); |
| 117 | + Assert.assertEquals("n-0S6_WzA2Mj", mockMessage.getClaims().get("nonce")); |
| 118 | + Assert.assertEquals(1311281970, mockMessage.getClaims().get("exp")); |
| 119 | + Assert.assertEquals(1311280970, mockMessage.getClaims().get("iat")); |
| 120 | + Assert.assertEquals("Jane Doe", mockMessage.getClaims().get("name")); |
| 121 | + Assert.assertEquals("Jane", mockMessage.getClaims().get("given_name")); |
| 122 | + Assert.assertEquals("Doe", mockMessage.getClaims().get("family_name")); |
| 123 | + Assert.assertEquals("female", mockMessage.getClaims().get("gender")); |
| 124 | + Assert.assertEquals("0000-10-31", mockMessage.getClaims().get("birthdate")); |
| 125 | + Assert. assertEquals( "[email protected]", mockMessage. getClaims(). get( "email")); |
| 126 | + Assert.assertEquals("http://example.com/janedoe/me.jpg", |
| 127 | + mockMessage.getClaims().get("picture")); |
| 128 | + } |
| 129 | + |
93 | 130 | @Test(expected = InvalidClaimException.class) |
94 | 131 | public void failureMissingRequiredParam() throws InvalidClaimException { |
95 | 132 | HashMap<String, Object> claims = new HashMap<>(); |
|
0 commit comments