use of com.auth0.jwt.Algorithm in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldPassECDSA256KVerificationWithProvidedPublicKey.
@Test
public void shouldPassECDSA256KVerificationWithProvidedPublicKey() throws Exception {
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_256K, "EC");
when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
Algorithm algorithm = Algorithm.ECDSA256K(provider);
algorithm.verify(JWT.decode(ES256K_JWT));
}
use of com.auth0.jwt.Algorithm in project java-jwt by auth0.
the class JWTVerifierTest method shouldRemoveAudienceWhenPassingNullReference.
@Test
public void shouldRemoveAudienceWhenPassingNullReference() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm).withAudience((String) null).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey(JWTVerifier.AUDIENCE_EXACT)));
verifier = JWTVerifier.init(algorithm).withAudience((String[]) null).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey(JWTVerifier.AUDIENCE_EXACT)));
verifier = JWTVerifier.init(algorithm).withAudience().build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey(JWTVerifier.AUDIENCE_EXACT)));
String emptyAud = " ";
verifier = JWTVerifier.init(algorithm).withAudience(emptyAud).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry(JWTVerifier.AUDIENCE_EXACT, Collections.singletonList(emptyAud)));
}
use of com.auth0.jwt.Algorithm in project java-jwt by auth0.
the class JWTVerifierTest method shouldRemoveIssuerWhenPassingNullReference.
@Test
public void shouldRemoveIssuerWhenPassingNullReference() throws Exception {
Algorithm algorithm = mock(Algorithm.class);
JWTVerifier verifier = JWTVerifier.init(algorithm).withIssuer((String) null).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey("iss")));
verifier = JWTVerifier.init(algorithm).withIssuer((String[]) null).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey("iss")));
verifier = JWTVerifier.init(algorithm).withIssuer().build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, not(hasKey("iss")));
String emptyIss = " ";
verifier = JWTVerifier.init(algorithm).withIssuer(emptyIss).build();
assertThat(verifier.claims, is(notNullValue()));
assertThat(verifier.claims, hasEntry("iss", Collections.singletonList(emptyIss)));
}
use of com.auth0.jwt.Algorithm in project java-jwt by auth0.
the class ECDSABouncyCastleProviderTests method shouldFailECDSA256KVerificationOnInvalidJOSESignatureLength.
@Test
public void shouldFailECDSA256KVerificationOnInvalidJOSESignatureLength() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(IllegalArgumentException.class));
exception.expectCause(hasMessage(is("Last unit does not have enough valid bits")));
String jwt = ES256K_JWT.substring(0, ES256K_JWT.length() - 1);
Algorithm algorithm = Algorithm.ECDSA256K((ECPublicKey) readPublicKeyFromFile(INVALID_PUBLIC_KEY_FILE_256K, "EC"), null);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.jwt.Algorithm in project java-jwt by auth0.
the class ECDSABouncyCastleProviderTests method shouldThrowOnECDSA256KVerificationWithDERSignature.
@Test
public void shouldThrowOnECDSA256KVerificationWithDERSignature() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(SignatureException.class));
exception.expectCause(hasMessage(is("Invalid JOSE signature format.")));
String jwt = "eyJraWQiOiJteS1rZXktaWQiLCJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.e30.MEUCIQDaCA-xzjHBCFhyAm56je5DXgylpUncBsQTxQT7AD19zwIgEjIm3lueII2W4pC_iQR6oRMHNtgqfAzTrWnV7DPNURk";
ECPublicKey key = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256K, "EC");
Algorithm algorithm = Algorithm.ECDSA256K(key, null);
algorithm.verify(JWT.decode(jwt));
}
Aggregations