11package com .auth0 .jwt ;
22
3+ import com .fasterxml .jackson .databind .JsonNode ;
4+ import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
5+ import com .fasterxml .jackson .databind .node .ObjectNode ;
36import org .apache .commons .codec .binary .Base64 ;
47import org .junit .Test ;
58
@@ -48,17 +51,17 @@ public void shouldFailOnNullToken() throws Exception {
4851
4952 @ Test (expected = IllegalStateException .class )
5053 public void shouldFailIfAlgorithmIsNotSetOnToken () throws Exception {
51- new JWTVerifier ("such secret" ).getAlgorithm (Collections .< String , String > emptyMap ());
54+ new JWTVerifier ("such secret" ).getAlgorithm (JsonNodeFactory . instance . objectNode ());
5255 }
5356
5457 @ Test (expected = IllegalStateException .class )
5558 public void shouldFailIfAlgorithmIsNotSupported () throws Exception {
56- new JWTVerifier ("such secret" ).getAlgorithm (Collections . singletonMap ("alg" , "doge-crypt" ));
59+ new JWTVerifier ("such secret" ).getAlgorithm (createSingletonJSONNode ("alg" , "doge-crypt" ));
5760 }
5861
5962 @ Test
6063 public void shouldWorkIfAlgorithmIsSupported () throws Exception {
61- new JWTVerifier ("such secret" ).getAlgorithm (Collections . singletonMap ("alg" , "HS256" ));
64+ new JWTVerifier ("such secret" ).getAlgorithm (createSingletonJSONNode ("alg" , "HS256" ));
6265 }
6366
6467 @ Test (expected = SignatureException .class )
@@ -89,49 +92,49 @@ public void shouldVerifySignature() throws Exception {
8992 @ Test (expected = IllegalStateException .class )
9093 public void shouldFailWhenExpired1SecondAgo () throws Exception {
9194 new JWTVerifier ("such secret" ).verifyExpiration (
92- Collections . singletonMap ("exp" , Long .toString (System .currentTimeMillis () / 1000L - 1L )));
95+ createSingletonJSONNode ("exp" , Long .toString (System .currentTimeMillis () / 1000L - 1L )));
9396 }
9497
9598 @ Test
9699 public void shouldVerifyExpiration () throws Exception {
97100 new JWTVerifier ("such secret" ).verifyExpiration (
98- Collections . singletonMap ("exp" , Long .toString (System .currentTimeMillis () / 1000L + 50L )));
101+ createSingletonJSONNode ("exp" , Long .toString (System .currentTimeMillis () / 1000L + 50L )));
99102 }
100103
101104 @ Test
102105 public void shouldVerifyIssuer () throws Exception {
103106 new JWTVerifier ("such secret" , "amaze audience" , "very issuer" )
104- .verifyIssuer (Collections . singletonMap ("iss" , "very issuer" ));
107+ .verifyIssuer (createSingletonJSONNode ("iss" , "very issuer" ));
105108 }
106109
107110 @ Test (expected = IllegalStateException .class )
108111 public void shouldFailIssuer () throws Exception {
109112 new JWTVerifier ("such secret" , "amaze audience" , "very issuer" )
110- .verifyIssuer (Collections . singletonMap ("iss" , "wow" ));
113+ .verifyIssuer (createSingletonJSONNode ("iss" , "wow" ));
111114 }
112115
113116 @ Test
114117 public void shouldVerifyIssuerWhenNotFoundInClaimsSet () throws Exception {
115118 new JWTVerifier ("such secret" , "amaze audience" , "very issuer" )
116- .verifyIssuer (Collections .< String , String > emptyMap ());
119+ .verifyIssuer (JsonNodeFactory . instance . objectNode ());
117120 }
118121
119122 @ Test
120123 public void shouldVerifyAudience () throws Exception {
121124 new JWTVerifier ("such secret" , "amaze audience" )
122- .verifyAudience (Collections . singletonMap ("aud" , "amaze audience" ));
125+ .verifyAudience (createSingletonJSONNode ("aud" , "amaze audience" ));
123126 }
124127
125128 @ Test (expected = IllegalStateException .class )
126129 public void shouldFailAudience () throws Exception {
127130 new JWTVerifier ("such secret" , "amaze audience" )
128- .verifyAudience (Collections . singletonMap ("aud" , "wow" ));
131+ .verifyAudience (createSingletonJSONNode ("aud" , "wow" ));
129132 }
130133
131134 @ Test
132135 public void shouldVerifyAudienceWhenNotFoundInClaimsSet () throws Exception {
133136 new JWTVerifier ("such secret" , "amaze audience" )
134- .verifyAudience (Collections .< String , String > emptyMap ());
137+ .verifyAudience (JsonNodeFactory . instance . objectNode ());
135138 }
136139
137140 @ Test
@@ -140,12 +143,17 @@ public void decodeAndParse() throws Exception {
140143 final String encodedJSON = new String (encoder .encode ("{\" some\" : \" json\" , \" number\" : 123}" .getBytes ()));
141144 final JWTVerifier jwtVerifier = new JWTVerifier ("secret" , "audience" );
142145
143- final Map < String , String > decodedJSON = jwtVerifier .decodeAndParse (encodedJSON );
146+ final JsonNode decodedJSON = jwtVerifier .decodeAndParse (encodedJSON );
144147
145- assertEquals ("json" , decodedJSON .get ("some" ));
148+ assertEquals ("json" , decodedJSON .get ("some" ). asText () );
146149 assertEquals (null , decodedJSON .get ("unexisting_property" ));
147- assertEquals ("123" , decodedJSON .get ("number" ));
150+ assertEquals ("123" , decodedJSON .get ("number" ). asText () );
148151 }
149152
150153
154+ public static JsonNode createSingletonJSONNode (String key , String value ) {
155+ final ObjectNode jsonNodes = JsonNodeFactory .instance .objectNode ();
156+ jsonNodes .put (key , value );
157+ return jsonNodes ;
158+ }
151159}
0 commit comments