ImmutableJsonWebToken extends AbstractJsonWebToken { public static JsonWebToken fromAuthorization(final String authorization) { final String token = getTokenFromAuthorizationString(authorization); return fromToken(token); } private  ImmutableJsonWebToken(final String token); static JsonWebToken fromAuthorization(final String authorization); static JsonWebToken fromToken(final String token); @Override List<String> getSubjects(); @Override boolean equals(@Nullable final Object o); @Override int hashCode(); @Override String toString();  }
@Test public void tryToCreateInstanceFromEmptyTokenString() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> ImmutableJsonWebToken.fromAuthorization("")) .withNoCause(); }
@Test public void tryToParseTokenFromMissingAuthorization() { assertThatExceptionOfType(JwtInvalidException.class) .isThrownBy(() -> ImmutableJsonWebToken.fromAuthorization("Authorization")) .withNoCause(); }
@Test public void tryToParseTokenFromInvalidAuthorization() { assertThatExceptionOfType(JwtInvalidException.class) .isThrownBy(() -> ImmutableJsonWebToken.fromAuthorization("Authorization foo")); }
@Test public void tryToParseTokenWithMissingSignature() { final String header = "{\"header\":\"value\"}"; final String payload = "{\"payload\":\"foo\"}"; final String authorizationHeader = "Bearer " + base64(header) + "." + base64(payload); assertThatExceptionOfType(JwtInvalidException.class) .isThrownBy(() -> ImmutableJsonWebToken.fromAuthorization(authorizationHeader)); }
@Test public void checkTokenExpiration() { final String header = "{\"header\":\"value\"}"; final String payload = String.format("{\"exp\":%d}", Instant.now().getEpochSecond()); final String signature = "{\"signature\":\"foo\"}"; final String authorizationHeader = "Bearer " + base64(header) + "." + base64(payload) + "." + base64(signature); final JsonWebToken expiredJsonWebToken = ImmutableJsonWebToken.fromAuthorization(authorizationHeader); assertThat(expiredJsonWebToken.isExpired()).isEqualTo(true); }