Verifier { public Rfc7519Claims verify(String jwt) throws TokenException, GeneralSecurityException { return verify(jwt, Rfc7519Claims.class); } Verifier(byte[] secret);  Verifier(byte[] secret, Gson gson); Rfc7519Claims verify(String jwt); T verify(String jwt, Class<T> klass);  }
@Test public void testRfc7515A1() throws Throwable { Verifier verifier = new Verifier(rfc7515A1key); Rfc7515A1Claims claims = verifier.verify(rfc7515A1jwt, Rfc7515A1Claims.class); assertEquals("joe", claims.getIssuer()); assertEquals(new Long(1300819380), claims.getExpirationTime()); assertEquals(true, claims.getIsRoot()); }
@Test(expected = InvalidTokenException.class) public void invalidSeparators() throws Exception { this.verifier.verify("....."); }
@Test(expected = InvalidTokenException.class) public void invalidHeader() throws Exception { this.verifier.verify("header.payload.signature"); }
@Test(expected = InvalidTokenException.class) public void nullHeader() throws Exception { String header = b64e("null"); this.verifier.verify(String.format("%s.payload.signature", header)); }
@Test(expected = InvalidTokenException.class) public void emptyObjectHeader() throws Exception { String header = b64e("{}"); this.verifier.verify(String.format("%s.payload.signature", header)); }
@Test(expected = InvalidTokenException.class) public void invalidTypeHeader() throws Exception { String header = b64e("{\"typ\": 123}"); this.verifier.verify(String.format("%s.payload.signature", header)); }
@Test(expected = InvalidTokenException.class) public void invalidAlgorithmHeader() throws Exception { String header = b64e("{\"typ\": \"JWT\", \"alg\": \"rot13\"}"); this.verifier.verify(String.format("%s.payload.signature", header)); }
@Test(expected = InvalidSignatureException.class) public void invalidSignature() throws Exception { String header = b64e("{\"typ\": \"JWT\", \"alg\": \"HS256\"}"); String payload = b64e("f00dcafe"); this.verifier.verify(String.format("%s.%s.deadbeef", header, payload)); }
@Test(expected = InvalidTokenException.class) public void invalidPayload() throws Exception { String header = b64e("{\"typ\": \"JWT\", \"alg\": \"HS256\"}"); String payload = b64e("f00dcafe"); String jwt = String.format("%s.%s.%s", header, payload, sign(header, payload)); this.verifier.verify(jwt); }
@Test(expected = InvalidTokenException.class) public void nullPayload() throws Exception { String header = b64e("{\"typ\": \"JWT\", \"alg\": \"HS256\"}"); String payload = b64e("null"); String jwt = String.format("%s.%s.%s", header, payload, sign(header, payload)); this.verifier.verify(jwt); }
@Test public void emptyPayload() throws Exception { String header = b64e("{\"typ\": \"JWT\", \"alg\": \"HS256\"}"); String payload = b64e("{}"); String jwt = String.format("%s.%s.%s", header, payload, sign(header, payload)); Rfc7519Claims claims = this.verifier.verify(jwt); assertNotNull(claims); }