@Test public void issuerWhenResponseIsNonCompliantThenThrowsRuntimeException() { prepareOpenIdConfigurationResponse("{ \"missing_required_keys\" : \"and_values\" }"); assertThatCode(() -> JwtDecoders.fromOidcIssuerLocation(this.issuer)) .isInstanceOf(RuntimeException.class); }
@Test public void issuerWhenResponseIsMalformedThenThrowsRuntimeException() { prepareOpenIdConfigurationResponse("malformed"); assertThatCode(() -> JwtDecoders.fromOidcIssuerLocation(this.issuer)) .isInstanceOf(RuntimeException.class); }
@Test public void issuerWhenRespondingIssuerMismatchesRequestedIssuerThenThrowsIllegalStateException() { prepareOpenIdConfigurationResponse(); assertThatCode(() -> JwtDecoders.fromOidcIssuerLocation(this.issuer + "/wrong")) .isInstanceOf(IllegalStateException.class); }
@Test public void issuerWhenRequestedIssuerIsUnresponsiveThenThrowsIllegalArgumentException() throws Exception { this.server.shutdown(); assertThatCode(() -> JwtDecoders.fromOidcIssuerLocation("https://issuer")) .isInstanceOf(IllegalArgumentException.class); }
@Test public void issuerWhenContainsTrailingSlashThenSuccess() { prepareOpenIdConfigurationResponse(); this.server.enqueue(new MockResponse().setBody(JWK_SET)); assertThat(JwtDecoders.fromOidcIssuerLocation(this.issuer)).isNotNull(); assertThat(this.issuer).endsWith("/"); }
@Test public void issuerWhenResponseIsTypicalThenReturnedDecoderValidatesIssuer() { prepareOpenIdConfigurationResponse(); this.server.enqueue(new MockResponse().setBody(JWK_SET)); JwtDecoder decoder = JwtDecoders.fromOidcIssuerLocation(this.issuer); assertThatCode(() -> decoder.decode(ISSUER_MISMATCH)) .isInstanceOf(JwtValidationException.class) .hasMessageContaining("This iss claim is not equal to the configured issuer"); }