use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.
the class ECDSAAlgorithmTest method invalidECDSA256SignatureShouldFailTokenVerification.
@Test
public void invalidECDSA256SignatureShouldFailTokenVerification() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectCause(isA(SignatureException.class));
String jwtWithInvalidSig = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0._____wAAAAD__________7zm-q2nF56E87nKwvxjJVH_____AAAAAP__________vOb6racXnoTzucrC_GMlUQ";
ECKey key256 = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
ECKey key384 = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
ECKey key512 = (ECKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_512, "EC");
JWTVerifier verifier256 = JWT.require(Algorithm.ECDSA256(key256)).build();
JWTVerifier verifier384 = JWT.require(Algorithm.ECDSA256(key384)).build();
JWTVerifier verifier512 = JWT.require(Algorithm.ECDSA256(key512)).build();
verifier256.verify(jwtWithInvalidSig);
verifier384.verify(jwtWithInvalidSig);
verifier512.verify(jwtWithInvalidSig);
}
use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideDefaultNotBeforeLeeway.
@Test
public void shouldOverrideDefaultNotBeforeLeeway() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).acceptNotBefore(9999L).build();
assertThat(verifier.expectedChecks, is(notNullValue()));
assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(9999L));
}
use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.
the class JWTVerifierTest method shouldVerifyBooleanClaimPresence.
@Test
public void shouldVerifyBooleanClaimPresence() {
String jwt = JWTCreator.init().withClaim("custom", true).sign(Algorithm.HMAC256("secret"));
JWTVerifier verifier = JWTVerifier.init(Algorithm.HMAC256("secret")).withClaimPresence("custom").build();
DecodedJWT decodedJWT = verifier.verify(jwt);
assertThat(decodedJWT, is(notNullValue()));
}
use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.
the class JWTVerifierTest method shouldSuccessfullyVerifyClaimWithPredicate.
@Test
public void shouldSuccessfullyVerifyClaimWithPredicate() {
String jwt = JWTCreator.init().withClaim("claimName", "claimValue").sign(Algorithm.HMAC256("secret"));
JWTVerifier verifier = JWTVerifier.init(Algorithm.HMAC256("secret")).withClaim("claimName", (claim, decodedJWT) -> "claimValue".equals(claim.asString())).build();
DecodedJWT decodedJWT = verifier.verify(jwt);
assertThat(decodedJWT, is(notNullValue()));
}
use of com.auth0.jwt.JWTVerifier in project java-jwt by auth0.
the class JWTVerifierTest method shouldOverrideDefaultExpiresAtLeeway.
@Test
public void shouldOverrideDefaultExpiresAtLeeway() {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(algorithm);
JWTVerifier verifier = verification.acceptLeeway(1234L).acceptExpiresAt(9999L).build();
assertThat(verifier.expectedChecks, is(notNullValue()));
assertThat(verification.getLeewayFor(RegisteredClaims.ISSUED_AT), is(1234L));
assertThat(verification.getLeewayFor(RegisteredClaims.EXPIRES_AT), is(9999L));
assertThat(verification.getLeewayFor(RegisteredClaims.NOT_BEFORE), is(1234L));
}
Aggregations