mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-07-07 03:02:23 +00:00
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 {
|
public Resource retrieveResource(URL url) throws IOException {
|
||||||
String jwkSet;
|
String jwkSet;
|
||||||
try {
|
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) {
|
} catch (Exception ex) {
|
||||||
throw new IOException(ex);
|
throw new IOException(ex);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowJwtExceptionWhenJwkSetEndpointHasNotRespondedAndCacheIsConfigured() throws Exception {
|
public void decodeWhenJwkEndpointIsUnresponsiveAndCacheIsConfiguredThenReturnsJwtException() throws Exception {
|
||||||
try ( MockWebServer server = new MockWebServer() ) {
|
try ( MockWebServer server = new MockWebServer() ) {
|
||||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||||
String jwkSetUri = server.url("/.well-known/jwks.json").toString();
|
String jwkSetUri = server.url("/.well-known/jwks.json").toString();
|
||||||
@ -287,7 +287,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowIllegalArgumentExceptionWhenJwkSetCacheIsNull() {
|
public void cacheWhenNullThenThrowsException() {
|
||||||
NimbusJwtDecoder.JwkSetUriJwtDecoderBuilder builder = withJwkSetUri(JWK_SET_URI);
|
NimbusJwtDecoder.JwkSetUriJwtDecoderBuilder builder = withJwkSetUri(JWK_SET_URI);
|
||||||
Assertions.assertThatCode(() -> builder.cache(null)).isInstanceOf(IllegalArgumentException.class);
|
Assertions.assertThatCode(() -> builder.cache(null)).isInstanceOf(IllegalArgumentException.class);
|
||||||
}
|
}
|
||||||
@ -465,7 +465,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldStoreRetrievedJwkSetToCache() {
|
public void decodeWhenCacheThenStoreRetrievedJwkSetToCache() {
|
||||||
// given
|
// given
|
||||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
@ -487,7 +487,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDecodeJwtUsingJwkSetCache() {
|
public void decodeWhenCacheThenRetrieveFromCache() {
|
||||||
// given
|
// given
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = mock(Cache.class);
|
||||||
@ -505,7 +505,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowJwtExceptionWhenExceptionOccurredWhileRetrievingJwkSetInsideCachingRetriever() {
|
public void decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtException() {
|
||||||
// given
|
// given
|
||||||
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
Cache cache = new ConcurrentMapCache("test-jwk-set-cache");
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user