|
|
|
@ -243,19 +243,25 @@ public class NimbusJwtDecoderJwkSupportTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void decodeWhenReadingErrorPickTheFirstErrorMessage() { |
|
|
|
public void decodeWhenReadingErrorPickTheFirstErrorMessage() throws Exception { |
|
|
|
OAuth2TokenValidator<Jwt> jwtValidator = mock(OAuth2TokenValidator.class); |
|
|
|
try ( MockWebServer server = new MockWebServer() ) { |
|
|
|
this.jwtDecoder.setJwtValidator(jwtValidator); |
|
|
|
server.enqueue(new MockResponse().setBody(JWK_SET)); |
|
|
|
|
|
|
|
String jwkSetUrl = server.url("/.well-known/jwks.json").toString(); |
|
|
|
OAuth2Error errorEmpty = new OAuth2Error("mock-error", "", "mock-uri"); |
|
|
|
|
|
|
|
OAuth2Error error = new OAuth2Error("mock-error", "mock-description", "mock-uri"); |
|
|
|
NimbusJwtDecoderJwkSupport decoder = new NimbusJwtDecoderJwkSupport(jwkSetUrl); |
|
|
|
OAuth2Error error2 = new OAuth2Error("mock-error-second", "mock-description-second", "mock-uri-second"); |
|
|
|
OAuth2TokenValidator<Jwt> jwtValidator = mock(OAuth2TokenValidator.class); |
|
|
|
OAuth2TokenValidatorResult result = OAuth2TokenValidatorResult.failure(errorEmpty, error, error2); |
|
|
|
decoder.setJwtValidator(jwtValidator); |
|
|
|
Mockito.when(jwtValidator.validate(any(Jwt.class))).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
OAuth2Error errorEmpty = new OAuth2Error("mock-error", "", "mock-uri"); |
|
|
|
Assertions.assertThatCode(() -> this.jwtDecoder.decode(SIGNED_JWT)) |
|
|
|
OAuth2Error error = new OAuth2Error("mock-error", "mock-description", "mock-uri"); |
|
|
|
.isInstanceOf(JwtValidationException.class) |
|
|
|
OAuth2Error error2 = new OAuth2Error("mock-error-second", "mock-description-second", "mock-uri-second"); |
|
|
|
.hasMessageContaining("mock-description"); |
|
|
|
OAuth2TokenValidatorResult result = OAuth2TokenValidatorResult.failure(errorEmpty, error, error2); |
|
|
|
|
|
|
|
Mockito.when(jwtValidator.validate(any(Jwt.class))).thenReturn(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertions.assertThatCode(() -> decoder.decode(SIGNED_JWT)) |
|
|
|
|
|
|
|
.isInstanceOf(JwtValidationException.class) |
|
|
|
|
|
|
|
.hasMessageContaining("mock-description"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
|