Skip to content

Commit 5e1c735

Browse files
🐛 Fixing bug in decode test case
1 parent 7258a73 commit 5e1c735

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/main/java/org/rrajesh1979/utils/JWTUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static Pair<String, String> createJWT(String typ, String alg, String user
9494
return new Pair<>(jws, Encoders.BASE64.encode(key.getEncoded()));
9595
}
9696

97-
private static Key signingKey(String algorithm) {
97+
public static Key signingKey(String algorithm) {
9898
SignatureAlgorithm signatureAlgorithm = (SignatureAlgorithm) algMap.get(algorithm);
9999
return Keys.secretKeyFor(signatureAlgorithm);
100100
}

src/test/java/org/rrajesh1979/tool/JWTCTest.java

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@
1616

1717
package org.rrajesh1979.tool;
1818

19+
import io.jsonwebtoken.io.Encoders;
20+
import org.javatuples.Pair;
1921
import org.junit.jupiter.api.DisplayName;
2022
import org.junit.jupiter.api.Test;
23+
import org.rrajesh1979.utils.JWTUtil;
2124
import picocli.CommandLine;
2225

26+
import java.security.Key;
27+
import java.util.Base64;
28+
2329
import static org.junit.jupiter.api.Assertions.*;
2430

2531
class 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

Comments
 (0)