|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
60 | 60 |
|
61 | 61 | import org.springframework.cache.Cache;
|
62 | 62 | import org.springframework.cache.concurrent.ConcurrentMapCache;
|
63 |
| -import org.springframework.cache.support.SimpleValueWrapper; |
64 | 63 | import org.springframework.core.ParameterizedTypeReference;
|
65 | 64 | import org.springframework.core.convert.converter.Converter;
|
66 | 65 | import org.springframework.http.HttpStatus;
|
@@ -702,29 +701,25 @@ public void decodeWhenCacheStoredThenAbleToRetrieveJwkSetFromCache() {
|
702 | 701 | @Test
|
703 | 702 | public void decodeWhenCacheThenRetrieveFromCache() throws Exception {
|
704 | 703 | RestOperations restOperations = mock(RestOperations.class);
|
705 |
| - Cache cache = mock(Cache.class); |
706 |
| - given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET); |
707 |
| - given(cache.get(eq(JWK_SET_URI))).willReturn(mock(Cache.ValueWrapper.class)); |
| 704 | + Cache cache = new ConcurrentMapCache("cache"); |
| 705 | + cache.put(JWK_SET_URI, JWK_SET); |
708 | 706 | // @formatter:off
|
709 | 707 | NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
710 | 708 | .cache(cache)
|
711 | 709 | .restOperations(restOperations)
|
712 | 710 | .build();
|
713 | 711 | // @formatter:on
|
714 | 712 | jwtDecoder.decode(SIGNED_JWT);
|
715 |
| - verify(cache).get(eq(JWK_SET_URI), eq(String.class)); |
716 |
| - verify(cache, times(2)).get(eq(JWK_SET_URI)); |
717 |
| - verifyNoMoreInteractions(cache); |
| 713 | + assertThat(cache.get(JWK_SET_URI, String.class)).isSameAs(JWK_SET); |
718 | 714 | verifyNoInteractions(restOperations);
|
719 | 715 | }
|
720 | 716 |
|
721 | 717 | // gh-11621
|
722 | 718 | @Test
|
723 | 719 | public void decodeWhenCacheAndUnknownKidShouldTriggerFetchOfJwkSet() throws JOSEException {
|
724 | 720 | RestOperations restOperations = mock(RestOperations.class);
|
725 |
| - Cache cache = mock(Cache.class); |
726 |
| - given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET); |
727 |
| - given(cache.get(eq(JWK_SET_URI))).willReturn(new SimpleValueWrapper(JWK_SET)); |
| 721 | + Cache cache = new ConcurrentMapCache("cache"); |
| 722 | + cache.put(JWK_SET_URI, JWK_SET); |
728 | 723 | given(restOperations.exchange(any(RequestEntity.class), eq(String.class)))
|
729 | 724 | .willReturn(new ResponseEntity<>(NEW_KID_JWK_SET, HttpStatus.OK));
|
730 | 725 |
|
@@ -794,19 +789,16 @@ public void decodeWhenCacheIsConfiguredAndValueLoaderErrorsThenThrowsJwtExceptio
|
794 | 789 | @Test
|
795 | 790 | public void decodeWhenCacheIsConfiguredAndParseFailsOnCachedValueThenExceptionIgnored() {
|
796 | 791 | RestOperations restOperations = mock(RestOperations.class);
|
797 |
| - Cache cache = mock(Cache.class); |
798 |
| - given(cache.get(eq(JWK_SET_URI), eq(String.class))).willReturn(JWK_SET); |
799 |
| - given(cache.get(eq(JWK_SET_URI))).willReturn(mock(Cache.ValueWrapper.class)); |
| 792 | + Cache cache = new ConcurrentMapCache("cache"); |
| 793 | + cache.put(JWK_SET_URI, JWK_SET); |
800 | 794 | // @formatter:off
|
801 | 795 | NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(JWK_SET_URI)
|
802 | 796 | .cache(cache)
|
803 | 797 | .restOperations(restOperations)
|
804 | 798 | .build();
|
805 | 799 | // @formatter:on
|
806 | 800 | jwtDecoder.decode(SIGNED_JWT);
|
807 |
| - verify(cache).get(eq(JWK_SET_URI), eq(String.class)); |
808 |
| - verify(cache, times(2)).get(eq(JWK_SET_URI)); |
809 |
| - verifyNoMoreInteractions(cache); |
| 801 | + assertThat(cache.get(JWK_SET_URI, String.class)).isSameAs(JWK_SET); |
810 | 802 | verifyNoInteractions(restOperations);
|
811 | 803 |
|
812 | 804 | }
|
|
0 commit comments