@Test public void processWhenUsingPublicKeyWithRs512ThenSuccessfullyDecodes() throws Exception { JWTProcessor<SecurityContext> processor = JwtProcessors .withPublicKey(key()).jwsAlgorithm(JwsAlgorithms.RS512).build(); assertThat(processor.process(RS512_SIGNED_JWT, null)) .extracting(JWTClaimsSet::getSubject) .isEqualTo("test-subject"); }
@Test public void buildWhenSignatureAlgorithmMismatchesKeyTypeThenThrowsException() { assertThatCode(() -> JwtProcessors.withPublicKey(key()) .jwsAlgorithm(JwsAlgorithms.ES256) .build()) .isInstanceOf(IllegalStateException.class); }
@Test public void processWhenSignatureMismatchesAlgorithmThenThrowsException() throws Exception { JWTProcessor<SecurityContext> processor = JwtProcessors .withPublicKey(key()).jwsAlgorithm(JwsAlgorithms.RS512).build(); assertThatCode(() -> processor.process(RS256_SIGNED_JWT, null)) .isInstanceOf(BadJOSEException.class); }