1616
1717package org .rrajesh1979 .tool ;
1818
19+ import io .jsonwebtoken .io .Encoders ;
20+ import org .javatuples .Pair ;
1921import org .junit .jupiter .api .DisplayName ;
2022import org .junit .jupiter .api .Test ;
23+ import org .rrajesh1979 .utils .JWTUtil ;
2124import picocli .CommandLine ;
2225
26+ import java .security .Key ;
27+ import java .util .Base64 ;
28+
2329import static org .junit .jupiter .api .Assertions .*;
2430
2531class JWTCTest {
@@ -36,23 +42,27 @@ void mainEncodeTest() {
3642 }
3743
3844
39- //FIXME
40- // @Test
41- // @DisplayName("Test JWTC Main - decode")
42- // void mainDecodeTest() {
43- // String jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJKV1QgRW5jb2RlciIsImF1ZCI6IkhlbGxvIEpXVCIsIm5hbWUiOiJKb2UiLCJpc3MiOiJycmFqZXNoMTk3OSIsInBpY3R1cmUiOiJodHRwczovL2V4YW1wbGUuY29tL2ltYWdlLnBuZyJ9.l1j1JyW3nvWJ90De8taOe1tZ80sHHHDMaibYEPv78LfA3Bw-uGgCECy5MwkE6nY3hP7isup433X5VqS2xP22fw";
44- // String key = "mOYKXJKdhBYQFWNr9cHHsgGvHseKRR9Rw7E379oeUuzfG18MmlcO3c8i7tBMMufziy6xMoZZAiO7bNKxZl7Rfw==";
45- //
46- // String[] args = {
47- // "decode",
48- // "-j=\"" + jwt + "\"",
49- // "-k=\""+ key + "\""
50- // };
51- // System.out.println(String.join(" ", args));
52- // CommandLine jwtcCommandLine = new CommandLine(new JWTC());
53- // int exitCode = jwtcCommandLine
54- // .setColorScheme(JWTC.getColorScheme())
55- // .execute(args);
56- // assertEquals(0, exitCode);
57- // }
45+ @ Test
46+ @ DisplayName ("Test JWTC Main - decode" )
47+ void mainDecodeTest () {
48+ String userInput = "{}" ;
49+
50+ Pair <String , String > jwtAndKey = JWTUtil .createJWT ("JWT" , "HS512" , userInput ,
51+ "rrajesh1979" , "JWT Encoder" , "Hello JWT" , false , 0 );
52+
53+ String jwt = jwtAndKey .getValue0 ();
54+ String key = jwtAndKey .getValue1 ();
55+
56+ String [] args = {
57+ "decode" ,
58+ "-j=" + jwt + " " ,
59+ "-k=\" " + key + "\" "
60+ };
61+ System .out .println (String .join (" " , args ));
62+ CommandLine jwtcCommandLine = new CommandLine (new JWTC ());
63+ int exitCode = jwtcCommandLine
64+ .setColorScheme (JWTC .getColorScheme ())
65+ .execute (args );
66+ assertEquals (0 , exitCode );
67+ }
5868}
0 commit comments