forked from auth0/java-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenUtilsTest.java
More file actions
55 lines (45 loc) · 2.01 KB
/
TokenUtilsTest.java
File metadata and controls
55 lines (45 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.auth0.jwt;
import com.auth0.jwt.exceptions.JWTDecodeException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
public class TokenUtilsTest {
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void shouldSplitToken() throws Exception {
String token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJhdXRoMCJ9.W1mx_Y0hbAMbPmfW9whT605AAcxB7REFuJiDAHk2Sdc";
String[] parts = TokenUtils.splitToken(token);
assertThat(parts, is(notNullValue()));
assertThat(parts, is(arrayWithSize(3)));
assertThat(parts[0], is("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0"));
assertThat(parts[1], is("eyJpc3MiOiJhdXRoMCJ9"));
assertThat(parts[2], is("W1mx_Y0hbAMbPmfW9whT605AAcxB7REFuJiDAHk2Sdc"));
}
@Test
public void shouldSplitTokenWithEmptySignature() throws Exception {
String token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpc3MiOiJhdXRoMCJ9.";
String[] parts = TokenUtils.splitToken(token);
assertThat(parts, is(notNullValue()));
assertThat(parts, is(arrayWithSize(3)));
assertThat(parts[0], is("eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0"));
assertThat(parts[1], is("eyJpc3MiOiJhdXRoMCJ9"));
assertThat(parts[2], is(isEmptyString()));
}
@Test
public void shouldThrowOnSplitTokenWithMoreThan3Parts() throws Exception {
exception.expect(JWTDecodeException.class);
exception.expectMessage("The token was expected to have 3 parts, but got 4.");
String token = "this.has.four.parts";
TokenUtils.splitToken(token);
}
@Test
public void shouldThrowOnSplitTokenWithLessThan3Parts() throws Exception {
exception.expect(JWTDecodeException.class);
exception.expectMessage("The token was expected to have 3 parts, but got 2.");
String token = "two.parts";
TokenUtils.splitToken(token);
}
}