Polish NimbusJwtDecoder
- Follow convention to prefix member variable references with "this." - Reduce stack trace when IOException is thrown - Name tests to follow conventions Issue gh-8332
This commit is contained in:
parent
9133cc24e4
commit
10aa9743ed
|
@ -365,7 +365,14 @@ public final class NimbusJwtDecoder implements JwtDecoder {
|
|||
public Resource retrieveResource(URL url) throws IOException {
|
||||
String jwkSet;
|
||||
try {
|
||||
jwkSet = cache.get(url.toString(), () -> resourceRetriever.retrieveResource(url).getContent());
|
||||
jwkSet = this.cache.get(url.toString(),
|
||||
() -> this.resourceRetriever.retrieveResource(url).getContent());
|
||||
} catch (Cache.ValueRetrievalException ex) {
|
||||
Throwable thrownByValueLoader = ex.getCause();
|
||||
if (thrownByValueLoader instanceof IOException) {
|
||||
throw (IOException) thrownByValueLoader;
|
||||
}
|
||||
throw new IOException(thrownByValueLoader);
|
||||
} catch (Exception ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
|
|
|
@ -255,7 +255,7 @@ public class NimbusJwtDecoderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowJwtExceptionWhenJwkSetEndpointHasNotRespondedAndCacheIsConfigured() throws Exception {
|
||||
public void decodeWhenJwkEndpointIsUnresponsiveAndCacheIsConfiguredThenReturnsJwtException() throws Exception {
|
||||
try ( MockWebServer server = new MockWebServer() ) {
|
||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||
String jwkSetUri = server.url("/.well-known/jwks.json").toString();
|
||||
|
@ -287,7 +287,7 @@ public class NimbusJwtDecoderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowIllegalArgumentExceptionWhenJwkSetCacheIsNull() {
|
||||
public void cacheWhenNullThenThrowsException() {
|
||||
NimbusJwtDecoder.JwkSetUriJwtDecoderBuilder builder = withJwkSetUri(JWK_SET_URI);
|
||||
Assertions.assertThatCode(() -> builder.cache(null)).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
@ -465,7 +465,7 @@ public class NimbusJwtDecoderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStoreRetrievedJwkSetToCache() {
|
||||
public void decodeWhenCacheThenStoreRetrievedJwkSetToCache() {
|
||||
// given
|
||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||
RestOperations restOperations = mock(RestOperations.class);
|
||||
|
@ -487,7 +487,7 @@ public class NimbusJwtDecoderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDecodeJwtUsingJwkSetCache() {
|
||||
public void decodeWhenCacheThenRetrieveFromCache() {
|
||||
// given
|
||||
RestOperations restOperations = mock(RestOperations.class);
|
||||
Cache cache = mock(Cache.class);
|
||||
|
@ -505,7 +505,7 @@ public class NimbusJwtDecoderTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowJwtExceptionWhenExceptionOccurredWhileRetrievingJwkSetInsideCachingRetriever() {
|
||||
public void decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtException() {
|
||||
// given
|
||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||
RestOperations restOperations = mock(RestOperations.class);
|
||||
|
|
Loading…
Reference in New Issue