Skip to content

Commit 251f90b

Browse files
🐛 Fixing bug in packaging
1 parent 9a8fec0 commit 251f90b

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2022 Rajesh Rajagopalan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.rrajesh1979.tool;
18+
19+
import org.junit.jupiter.api.DisplayName;
20+
import org.junit.jupiter.api.Test;
21+
import picocli.CommandLine;
22+
23+
import static org.junit.jupiter.api.Assertions.*;
24+
25+
class JWTCTest {
26+
27+
@Test
28+
@DisplayName("Test JWTC Main - encode")
29+
void mainEncodeTest() {
30+
String[] args = {"encode"};
31+
CommandLine jwtcCommandLine = new CommandLine(new JWTC());
32+
int exitCode = jwtcCommandLine
33+
.setColorScheme(JWTC.getColorScheme())
34+
.execute(args);
35+
assertEquals(0, exitCode);
36+
}
37+
38+
@Test
39+
@DisplayName("Test JWTC Main - decode")
40+
void mainDecodeTest() {
41+
String[] args = {"decode -j=\"\" -k=\"\""};
42+
CommandLine jwtcCommandLine = new CommandLine(new JWTC());
43+
int exitCode = jwtcCommandLine
44+
.setColorScheme(JWTC.getColorScheme())
45+
.execute(args);
46+
assertEquals(0, exitCode);
47+
}
48+
}

src/test/java/org/rrajesh1979/utils/JWTUtilTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)