@@ -35,6 +35,9 @@ void encodeDecodeJWTTest() {
3535 String jwt = jwtAndKey .getValue0 ();
3636 String key = jwtAndKey .getValue1 ();
3737
38+ System .out .println (jwt );
39+ System .out .println (key );
40+
3841 Pair <String , String > decodedJwtAndKey = JWTUtil .decodeJWT (jwt , key );
3942 assertEquals (decodedJwtAndKey .getValue0 (), "{typ=JWT, alg=HS512}" );
4043 assertEquals (decodedJwtAndKey .getValue1 (), "{sub=JWT Encoder, aud=Hello JWT, name=Joe, iss=rrajesh1979, picture=https://example.com/image.png}" );
@@ -76,16 +79,15 @@ void encodeDecodeJWTEmptyPayloadTest() {
7679 @ Test
7780 @ DisplayName ("Test JWT decode with invalid key" )
7881 void encodeDecodeJWTInvalidKeyTest () {
79- String userInput = "{}" ;
80-
81- Pair <String , String > jwtAndKey = JWTUtil .createJWT ("JWT" , "HS512" , userInput ,
82- "rrajesh1979" , "JWT Encoder" , "Hello JWT" , true , 0 );
82+ String jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJKV1QgRW5jb2RlciIsImF1ZCI6IkhlbGxvIEpXVCIsIm5hbWUiOiJKb2UiLCJpc3MiOiJycmFqZXNoMTk3OSIsInBpY3R1cmUiOiJodHRwczovL2V4YW1wbGUuY29tL2ltYWdlLnBuZyJ9.W5xD5SD6VokmsLSg9wvSyPDEoceY_qrDCvkre3WK3nZgxn4do_jTQNI3WYfrnevoKC4VeUc-b-qN1_KWX9driQ" ;
83+ String key = "mS1U8Cvm3VHcS3TwXlnZm5yA6bksHWeNHI4lS4KSKMkOaqW0NNJoghyXwemTkErKCxv26hdqGz9BC1fPm3eCeg==" ;
8384
84- String jwt = jwtAndKey .getValue0 ();
85- String key = jwtAndKey .getValue1 ();
85+ String payload = "{\" sub\" : \" JWT Encoder\" , \" aud\" : \" Hello JWT\" , \" name\" : \" Joe\" , \" iss\" : \" rrajesh1979\" , \" picture\" : \" https://example.com/image.png\" }" ;
8686
8787 Pair <String , String > decodedJwtAndKey = JWTUtil .decodeJWT (jwt , key );
8888 assertEquals (decodedJwtAndKey .getValue0 (), "{typ=JWT, alg=HS512}" );
89- assertNotEquals (decodedJwtAndKey .getValue1 (), "{sub=JWT Encoder, aud=Hello JWT, iss=rrajesh1979}" );
89+ assertEquals (decodedJwtAndKey .getValue1 (), payload . replace ( " \" " , "" ). replace ( ": " , "=" ) );
9090 }
91+
92+
9193}
0 commit comments