mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-22 20:12:14 +00:00
Polish Tests
Issue gh-16251
This commit is contained in:
parent
f7e0f7fa8a
commit
f9824fd688
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -60,7 +60,6 @@ import org.mockito.ArgumentCaptor;
|
|||||||
|
|
||||||
import org.springframework.cache.Cache;
|
import org.springframework.cache.Cache;
|
||||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||||
import org.springframework.cache.support.SimpleValueWrapper;
|
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -702,9 +701,8 @@ public class NimbusJwtDecoderTests {
|
|||||||
@Test
|
@Test
|
||||||
public void decodeWhenCacheThenRetrieveFromCache() throws Exception {
|
public void decodeWhenCacheThenRetrieveFromCache() throws Exception {
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = new ConcurrentMapCache("cache");
|
||||||
given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET);
|
cache.put(JWK_SET_URI, JWK_SET);
|
||||||
given(cache.get(eq(JWK_SET_URI))).willReturn(mock(Cache.ValueWrapper.class));
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
||||||
.cache(cache)
|
.cache(cache)
|
||||||
@ -712,9 +710,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
jwtDecoder.decode(SIGNED_JWT);
|
jwtDecoder.decode(SIGNED_JWT);
|
||||||
verify(cache).get(eq(JWK_SET_URI), eq(String.class));
|
assertThat(cache.get(JWK_SET_URI, String.class)).isSameAs(JWK_SET);
|
||||||
verify(cache, times(2)).get(eq(JWK_SET_URI));
|
|
||||||
verifyNoMoreInteractions(cache);
|
|
||||||
verifyNoInteractions(restOperations);
|
verifyNoInteractions(restOperations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -722,9 +718,8 @@ public class NimbusJwtDecoderTests {
|
|||||||
@Test
|
@Test
|
||||||
public void decodeWhenCacheAndUnknownKidShouldTriggerFetchOfJwkSet() throws JOSEException {
|
public void decodeWhenCacheAndUnknownKidShouldTriggerFetchOfJwkSet() throws JOSEException {
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = new ConcurrentMapCache("cache");
|
||||||
given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET);
|
cache.put(JWK_SET_URI, JWK_SET);
|
||||||
given(cache.get(eq(JWK_SET_URI))).willReturn(new SimpleValueWrapper(JWK_SET));
|
|
||||||
given(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
given(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
||||||
.willReturn(new ResponseEntity<>(NEW_KID_JWK_SET, HttpStatus.OK));
|
.willReturn(new ResponseEntity<>(NEW_KID_JWK_SET, HttpStatus.OK));
|
||||||
|
|
||||||
@ -794,9 +789,8 @@ public class NimbusJwtDecoderTests {
|
|||||||
@Test
|
@Test
|
||||||
public void decodeWhenCacheIsConfiguredAndParseFailsOnCachedValueThenExceptionIgnored() {
|
public void decodeWhenCacheIsConfiguredAndParseFailsOnCachedValueThenExceptionIgnored() {
|
||||||
RestOperations restOperations = mock(RestOperations.class);
|
RestOperations restOperations = mock(RestOperations.class);
|
||||||
Cache cache = mock(Cache.class);
|
Cache cache = new ConcurrentMapCache("cache");
|
||||||
given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET);
|
cache.put(JWK_SET_URI, JWK_SET);
|
||||||
given(cache.get(eq(JWK_SET_URI))).willReturn(mock(Cache.ValueWrapper.class));
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
||||||
.cache(cache)
|
.cache(cache)
|
||||||
@ -804,9 +798,7 @@ public class NimbusJwtDecoderTests {
|
|||||||
.build();
|
.build();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
jwtDecoder.decode(SIGNED_JWT);
|
jwtDecoder.decode(SIGNED_JWT);
|
||||||
verify(cache).get(eq(JWK_SET_URI), eq(String.class));
|
assertThat(cache.get(JWK_SET_URI, String.class)).isSameAs(JWK_SET);
|
||||||
verify(cache, times(2)).get(eq(JWK_SET_URI));
|
|
||||||
verifyNoMoreInteractions(cache);
|
|
||||||
verifyNoInteractions(restOperations);
|
verifyNoInteractions(restOperations);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user