File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
src/test/java/fi/hsl/common/redis Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 8
8
import org .testcontainers .utility .DockerImageName ;
9
9
import redis .clients .jedis .Jedis ;
10
10
11
+ import java .util .Base64 ;
12
+
11
13
import static org .junit .Assert .assertEquals ;
12
14
import static org .junit .Assert .assertFalse ;
13
15
@@ -51,4 +53,20 @@ public void testSetGetExpiringValue() throws InterruptedException {
51
53
52
54
assertFalse (redisUtils .getValue ("test" ).isPresent ());
53
55
}
56
+
57
+ @ Test
58
+ public void extractUsernameFromTokenBase64PaddingWorks () {
59
+ // Payload with length not a multiple of 4 (e.g., 2 or 3 mod 4)
60
+ String header = Base64 .getUrlEncoder ().withoutPadding ().encodeToString ("{\" alg\" :\" none\" }" .getBytes ());
61
+
62
+ // 2 mod 4 length
63
+ String payload2 = Base64 .getUrlEncoder ().withoutPadding ().encodeToString ("{\" oid\" :\" ab\" }" .getBytes ());
64
+ String token2 = header + "." + payload2 + ".sig" ;
65
+ assertEquals ("ab" , RedisUtils .extractUsernameFromToken (token2 ));
66
+
67
+ // 3 mod 4 length
68
+ String payload3 = Base64 .getUrlEncoder ().withoutPadding ().encodeToString ("{\" oid\" :\" abc\" }" .getBytes ());
69
+ String token3 = header + "." + payload3 + ".sig" ;
70
+ assertEquals ("abc" , RedisUtils .extractUsernameFromToken (token3 ));
71
+ }
54
72
}
You can’t perform that action at this time.
0 commit comments