diff --git a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java index d80a5a16..f484a285 100644 --- a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java +++ b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/DefaultOidcConfigurationFetcher.java @@ -35,6 +35,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; +import com.nimbusds.jose.KeySourceException; import com.nimbusds.jose.RemoteKeySourceException; @Service @@ -55,8 +56,8 @@ public class DefaultOidcConfigurationFetcher implements OidcConfigurationFetcher public DefaultOidcConfigurationFetcher(RestTemplateBuilder restBuilder, OAuthProperties oAuthProperties) { - final Duration TIMEOUT = Duration.ofSeconds(oAuthProperties.getRefreshTimeoutSeconds()); - this.restTemplate = restBuilder.setConnectTimeout(TIMEOUT).setReadTimeout(TIMEOUT).build(); + final Duration timeout = Duration.ofSeconds(oAuthProperties.getRefreshTimeoutSeconds()); + this.restTemplate = restBuilder.setConnectTimeout(timeout).setReadTimeout(timeout).build(); } private void metadataChecks(String issuer, Map oidcConfiguration) { @@ -86,15 +87,7 @@ public Map loadConfigurationForIssuer(String issuer) { URI uri = UriComponentsBuilder.fromUriString(issuer + WELL_KNOWN_FRAGMENT).build().toUri(); ResponseEntity> response = null; try { - - RequestEntity request = RequestEntity.get(uri).build(); - response = restTemplate.exchange(request, typeReference); - if (response.getStatusCodeValue() != 200) { - throw new RuntimeException( - format("Received status code: %s", response.getStatusCodeValue())); - } - metadataChecks(issuer, response.getBody()); - return response.getBody(); + response = restTemplate.exchange(RequestEntity.get(uri).build(), typeReference); } catch (RuntimeException e) { final String errorMsg = format("Unable to resolve OpenID configuration from '%s'", uri); if (LOG.isDebugEnabled()) { @@ -102,10 +95,16 @@ public Map loadConfigurationForIssuer(String issuer) { } throw new OidcConfigurationResolutionError(errorMsg, e); } + if (response.getStatusCodeValue() != 200) { + throw new OidcConfigurationResolutionError( + format("Received status code: %s", response.getStatusCodeValue())); + } + metadataChecks(issuer, response.getBody()); + return response.getBody(); } @Override - public String loadJWKSourceForURL(URI uri) throws RemoteKeySourceException { + public String loadJWKSourceForURL(URI uri) throws KeySourceException { LOG.debug("Fetching JWK from {}", uri); @@ -115,10 +114,6 @@ public String loadJWKSourceForURL(URI uri) throws RemoteKeySourceException { try { RequestEntity request = RequestEntity.get(uri).headers(headers).build(); response = restTemplate.exchange(request, String.class); - if (response.getStatusCodeValue() != 200) { - throw new RuntimeException( - format("Received status code: %s", response.getStatusCodeValue())); - } } catch (RuntimeException e) { final String errorMsg = format("Unable to get JWK from '%s'", uri); if (LOG.isDebugEnabled()) { @@ -126,7 +121,10 @@ public String loadJWKSourceForURL(URI uri) throws RemoteKeySourceException { } throw new RemoteKeySourceException(errorMsg, e); } - + if (response.getStatusCodeValue() != 200) { + throw new KeySourceException(format("Unable to get JWK from '%s': received status code %s", + uri, response.getStatusCodeValue())); + } return response.getBody(); } } diff --git a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/NoExpirationStringCache.java b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/NoExpirationStringCache.java index 2fb17297..7f7a70ee 100644 --- a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/NoExpirationStringCache.java +++ b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/NoExpirationStringCache.java @@ -48,17 +48,14 @@ protected Object lookup(Object key) { @Override public void put(Object key, Object value) { - return; } @Override public void evict(Object key) { - return; } @Override public void clear() { - return; } @SuppressWarnings("unchecked") diff --git a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/OidcConfigurationFetcher.java b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/OidcConfigurationFetcher.java index f1632e65..7aa30179 100644 --- a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/OidcConfigurationFetcher.java +++ b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/OidcConfigurationFetcher.java @@ -18,12 +18,12 @@ import java.net.URI; import java.util.Map; -import com.nimbusds.jose.RemoteKeySourceException; +import com.nimbusds.jose.KeySourceException; public interface OidcConfigurationFetcher { Map loadConfigurationForIssuer(String issuer); - String loadJWKSourceForURL(URI uri) throws RemoteKeySourceException; + String loadJWKSourceForURL(URI uri) throws KeySourceException; } diff --git a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/TrustedJwtDecoderCacheLoader.java b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/TrustedJwtDecoderCacheLoader.java index 68d18d10..f9e19765 100644 --- a/src/main/java/org/italiangrid/storm/webdav/oauth/utils/TrustedJwtDecoderCacheLoader.java +++ b/src/main/java/org/italiangrid/storm/webdav/oauth/utils/TrustedJwtDecoderCacheLoader.java @@ -78,7 +78,7 @@ public JwtDecoder load(String issuer) throws Exception { Map oidcConfiguration = fetcher.loadConfigurationForIssuer(issuer); URI jwksUri = URI.create(oidcConfiguration.get("jwks_uri").toString()); Cache noExpirationCache = - new NoExpirationStringCache(fetcher.loadJWKSourceForURL(jwksUri).toString()); + new NoExpirationStringCache(fetcher.loadJWKSourceForURL(jwksUri)); NimbusJwtDecoder decoder = NimbusJwtDecoder.withJwkSetUri((oidcConfiguration.get("jwks_uri").toString())) diff --git a/src/main/java/org/italiangrid/storm/webdav/server/DefaultWebServerFactory.java b/src/main/java/org/italiangrid/storm/webdav/server/DefaultWebServerFactory.java index 24c00606..56d286cf 100644 --- a/src/main/java/org/italiangrid/storm/webdav/server/DefaultWebServerFactory.java +++ b/src/main/java/org/italiangrid/storm/webdav/server/DefaultWebServerFactory.java @@ -45,9 +45,10 @@ public DefaultWebServerFactory(ServiceConfiguration configuration, } private InstrumentedQueuedThreadPool getInstrumentedThreadPool() { - InstrumentedQueuedThreadPool tPool = new InstrumentedQueuedThreadPool(metricRegistry, configuration.getMaxConnections(), - configuration.getMinConnections(), configuration.getThreadPoolMaxIdleTimeInMsec(), - new ArrayBlockingQueue(configuration.getMaxQueueSize()), "storm.http"); + InstrumentedQueuedThreadPool tPool = + new InstrumentedQueuedThreadPool(metricRegistry, configuration.getMaxConnections(), + configuration.getMinConnections(), configuration.getThreadPoolMaxIdleTimeInMsec(), + new ArrayBlockingQueue<>(configuration.getMaxQueueSize()), "storm.http"); tPool.setName("thread-pool"); return tPool; } diff --git a/src/test/java/org/italiangrid/storm/webdav/server/TLSConnectorBuilderTest.java b/src/test/java/org/italiangrid/storm/webdav/server/TLSConnectorBuilderTest.java index 003dd1b1..70bbcb27 100644 --- a/src/test/java/org/italiangrid/storm/webdav/server/TLSConnectorBuilderTest.java +++ b/src/test/java/org/italiangrid/storm/webdav/server/TLSConnectorBuilderTest.java @@ -15,6 +15,9 @@ */ package org.italiangrid.storm.webdav.server; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertThrows; import java.util.concurrent.TimeUnit; @@ -24,6 +27,7 @@ import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; import org.italiangrid.storm.webdav.server.util.CANLListener; import org.italiangrid.voms.util.CertificateValidatorBuilder; import org.junit.jupiter.api.Test; @@ -40,15 +44,19 @@ public class TLSConnectorBuilderTest { @Test - public void tlsConnectorBuilderErrorTests() { - - new TLSConnectorBuilderError("This is an error!"); - new TLSConnectorBuilderError("This is an error!", new RuntimeException()); - new TLSConnectorBuilderError(new RuntimeException()); + void tlsConnectorBuilderErrorTests() { + + TLSConnectorBuilderError e = new TLSConnectorBuilderError("This is an error!"); + assertThat(e.getMessage(), is("This is an error!")); + e = new TLSConnectorBuilderError("This is an error!", new RuntimeException()); + assertThat(e.getMessage(), is("This is an error!")); + e = new TLSConnectorBuilderError(new RuntimeException("This is an error!")); + assertThat(e.getCause() instanceof RuntimeException, is(true)); + assertThat(e.getMessage(), containsString("This is an error!")); } @Test - public void illegalArgumentExceptionThrown() { + void illegalArgumentExceptionThrown() { Server server = Mockito.mock(Server.class); X509CertChainValidatorExt validator = Mockito.mock(X509CertChainValidatorExt.class); @@ -83,7 +91,7 @@ private X509CertChainValidatorExt getValidator() { } @Test - public void tlsConnectorBuilderTests() { + void tlsConnectorBuilderTests() { Server server = new Server(); X509CertChainValidatorExt validator = getValidator(); @@ -103,6 +111,7 @@ public void tlsConnectorBuilderTests() { .withHostnameVerifier(new NoopHostnameVerifier()) .withConscrypt(false); - builder.build(); + ServerConnector c = builder.build(); + assertThat(c.getPort(), is(1234)); } } \ No newline at end of file diff --git a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/OidcConfigurationFetcherTest.java b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/OidcConfigurationFetcherTest.java index 0bd16b59..5b8162ea 100644 --- a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/OidcConfigurationFetcherTest.java +++ b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/OidcConfigurationFetcherTest.java @@ -15,8 +15,11 @@ */ package org.italiangrid.storm.webdav.test.oauth.jwk; +import static java.lang.String.format; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.italiangrid.storm.webdav.oauth.utils.DefaultOidcConfigurationFetcher.ISSUER_MISMATCH_ERROR_TEMPLATE; +import static org.italiangrid.storm.webdav.oauth.utils.DefaultOidcConfigurationFetcher.NO_JWKS_URI_ERROR_TEMPLATE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; @@ -51,21 +54,21 @@ import org.springframework.web.client.RestTemplate; import com.google.common.collect.Maps; -import com.nimbusds.jose.RemoteKeySourceException; +import com.nimbusds.jose.KeySourceException; import com.nimbusds.jose.jwk.JWKSet; import com.nimbusds.jose.jwk.KeyType; @ExtendWith(MockitoExtension.class) -public class OidcConfigurationFetcherTest { +class OidcConfigurationFetcherTest { - final static String ISSUER = "https://iam-dev.cloud.cnaf.infn.it/"; + static final String ISSUER = "https://iam-dev.cloud.cnaf.infn.it/"; final static String JWK_URI = ISSUER + "jwk"; - final static String ANOTHER_ISSUER = "https://iam.cloud.infn.it/"; - final static String ANOTHER_JWK_URI = ANOTHER_ISSUER + "jwk"; + static final String ANOTHER_ISSUER = "https://iam.cloud.infn.it/"; + static final String ANOTHER_JWK_URI = ANOTHER_ISSUER + "jwk"; + + static final String KID = "rsa1"; - final static String KID = "rsa1"; - final ParameterizedTypeReference> typeReference = new ParameterizedTypeReference>() {}; @@ -85,9 +88,11 @@ private Map getMapWithIssuerAndJwkUri(String issuer, String jwkU } @SuppressWarnings("unchecked") - private ResponseEntity> getWellKnownResponse(HttpStatus status, Map map) { + private ResponseEntity> getWellKnownResponse(HttpStatus status, + Map map) { - ResponseEntity> mockedEntity = (ResponseEntity>) Mockito.mock(ResponseEntity.class); + ResponseEntity> mockedEntity = + (ResponseEntity>) Mockito.mock(ResponseEntity.class); lenient().when(mockedEntity.getStatusCode()).thenReturn(status); lenient().when(mockedEntity.getStatusCodeValue()).thenReturn(status.value()); lenient().when(mockedEntity.getBody()).thenReturn(map); @@ -102,16 +107,18 @@ private String loadJwkFromFile() throws IOException { } @SuppressWarnings("unchecked") - private ResponseEntity getJWKURIResponse(HttpStatus status, String data) throws IOException { + private ResponseEntity getJWKURIResponse(HttpStatus status, String data) { - ResponseEntity mockedEntity = (ResponseEntity) Mockito.mock(ResponseEntity.class); + ResponseEntity mockedEntity = + (ResponseEntity) Mockito.mock(ResponseEntity.class); lenient().when(mockedEntity.getBody()).thenReturn(data); lenient().when(mockedEntity.getStatusCode()).thenReturn(status); lenient().when(mockedEntity.getStatusCodeValue()).thenReturn(status.value()); return mockedEntity; } - private OidcConfigurationFetcher getFetcher(ResponseEntity> wellKnownResponse, ResponseEntity jwkResponse) { + private OidcConfigurationFetcher getFetcher(ResponseEntity> wellKnownResponse, + ResponseEntity jwkResponse) { lenient().when(restTemplate.exchange(any(), eq(typeReference))).thenReturn(wellKnownResponse); lenient().when(restTemplate.exchange(any(), eq(String.class))).thenReturn(jwkResponse); @@ -125,19 +132,23 @@ private OidcConfigurationFetcher getFetcher(ResponseEntity> private OidcConfigurationFetcher getSuccessfulFetcher() throws RestClientException, IOException { - ResponseEntity> mockedResponseMapEntity = getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ISSUER, JWK_URI)); + ResponseEntity> mockedResponseMapEntity = + getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ISSUER, JWK_URI)); ResponseEntity mockedResponseStringEntity = getJWKURIResponse(OK, loadJwkFromFile()); return getFetcher(mockedResponseMapEntity, mockedResponseStringEntity); } - private OidcConfigurationFetcher getSuccessfulFetcherWithWrongIssuer() throws RestClientException, IOException { + private OidcConfigurationFetcher getSuccessfulFetcherWithWrongIssuer() + throws RestClientException, IOException { - ResponseEntity> mockedResponseMapEntity = getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ANOTHER_ISSUER, ANOTHER_JWK_URI)); + ResponseEntity> mockedResponseMapEntity = + getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ANOTHER_ISSUER, ANOTHER_JWK_URI)); ResponseEntity mockedResponseStringEntity = getJWKURIResponse(OK, loadJwkFromFile()); return getFetcher(mockedResponseMapEntity, mockedResponseStringEntity); } - private OidcConfigurationFetcher getSuccessfulFetcherWithNoIssuer() throws RestClientException, IOException { + private OidcConfigurationFetcher getSuccessfulFetcherWithNoIssuer() + throws RestClientException, IOException { Map map = getMapWithIssuerAndJwkUri(ANOTHER_ISSUER, ANOTHER_JWK_URI); map.remove("issuer"); @@ -146,7 +157,8 @@ private OidcConfigurationFetcher getSuccessfulFetcherWithNoIssuer() throws RestC return getFetcher(mockedResponseMapEntity, mockedResponseStringEntity); } - private OidcConfigurationFetcher getSuccessfulFetcherWithNoJwk() throws RestClientException, IOException { + private OidcConfigurationFetcher getSuccessfulFetcherWithNoJwk() + throws RestClientException, IOException { Map map = getMapWithIssuerAndJwkUri(ISSUER, JWK_URI); map.remove("jwks_uri"); @@ -155,15 +167,18 @@ private OidcConfigurationFetcher getSuccessfulFetcherWithNoJwk() throws RestClie return getFetcher(mockedResponseMapEntity, mockedResponseStringEntity); } - private OidcConfigurationFetcher getFetcherWithErrorOnFetch() throws RestClientException, IOException { + private OidcConfigurationFetcher getFetcherWithErrorOnFetch() throws RestClientException { - ResponseEntity> mockedResponseMapEntity = getWellKnownResponse(NOT_FOUND, null); + ResponseEntity> mockedResponseMapEntity = + getWellKnownResponse(NOT_FOUND, null); return getFetcher(mockedResponseMapEntity, null); } - private OidcConfigurationFetcher getFetcherWithErrorOnGetJwk() throws RestClientException, IOException { + private OidcConfigurationFetcher getFetcherWithErrorOnGetJwk() + throws RestClientException, IOException { - ResponseEntity> mockedResponseMapEntity = getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ISSUER, JWK_URI)); + ResponseEntity> mockedResponseMapEntity = + getWellKnownResponse(OK, getMapWithIssuerAndJwkUri(ISSUER, JWK_URI)); ResponseEntity mockedResponseStringEntity = getJWKURIResponse(NOT_FOUND, null); return getFetcher(mockedResponseMapEntity, mockedResponseStringEntity); } @@ -174,7 +189,7 @@ public void setDebugLevel() { } @Test - public void fetchWellKnownEndpointWithSuccessTests() throws RestClientException, IOException { + void fetchWellKnownEndpointWithSuccessTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getSuccessfulFetcher(); Map conf = fetcher.loadConfigurationForIssuer(ISSUER); @@ -184,60 +199,56 @@ public void fetchWellKnownEndpointWithSuccessTests() throws RestClientException, } @Test - public void fetchWellKnownEndpointWithErrorTests() throws RestClientException, IOException { + void fetchWellKnownEndpointWithErrorTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getFetcherWithErrorOnFetch(); RuntimeException exception = assertThrows(RuntimeException.class, () -> { fetcher.loadConfigurationForIssuer(ISSUER); }); - String expectedMessage = "Unable to resolve OpenID configuration from '" + ISSUER + ".well-known/openid-configuration'"; + String expectedMessage = "Received status code: 404"; String actualMessage = exception.getMessage(); assertEquals(expectedMessage, actualMessage); } @Test - public void fetchWellKnownEndpointWrongIssuerTests() throws RestClientException, IOException { + void fetchWellKnownEndpointWrongIssuerTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getSuccessfulFetcherWithWrongIssuer(); - OidcConfigurationResolutionError exception = assertThrows(OidcConfigurationResolutionError.class, () -> { - fetcher.loadConfigurationForIssuer(ISSUER); - }); - String expectedMessage = "Unable to resolve OpenID configuration from '" + ISSUER + ".well-known/openid-configuration'"; - String actualMessage = exception.getMessage(); - - assertEquals(expectedMessage, actualMessage); - + OidcConfigurationResolutionError exception = + assertThrows(OidcConfigurationResolutionError.class, () -> { + fetcher.loadConfigurationForIssuer(ISSUER); + }); + assertEquals(format(ISSUER_MISMATCH_ERROR_TEMPLATE, ANOTHER_ISSUER, ISSUER), + exception.getMessage()); } @Test - public void fetchWellKnownEndpointNoIssuerTests() throws RestClientException, IOException { + void fetchWellKnownEndpointNoIssuerTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getSuccessfulFetcherWithNoIssuer(); - OidcConfigurationResolutionError exception = assertThrows(OidcConfigurationResolutionError.class, () -> { - fetcher.loadConfigurationForIssuer(ISSUER); - }); - String expectedMessage = "Unable to resolve OpenID configuration from '" + ISSUER + ".well-known/openid-configuration'"; - String actualMessage = exception.getMessage(); - - assertEquals(expectedMessage, actualMessage); + OidcConfigurationResolutionError exception = + assertThrows(OidcConfigurationResolutionError.class, () -> { + fetcher.loadConfigurationForIssuer(ISSUER); + }); + assertEquals(format(ISSUER_MISMATCH_ERROR_TEMPLATE, "(unavailable)", ISSUER), + exception.getMessage()); } @Test - public void fetchWellKnownEndpointNoJwkTests() throws RestClientException, IOException { + void fetchWellKnownEndpointNoJwkTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getSuccessfulFetcherWithNoJwk(); - OidcConfigurationResolutionError exception = assertThrows(OidcConfigurationResolutionError.class, () -> { - fetcher.loadConfigurationForIssuer(ISSUER); - }); - String expectedMessage = "Unable to resolve OpenID configuration from '" + ISSUER + ".well-known/openid-configuration'"; - String actualMessage = exception.getMessage(); - - assertEquals(expectedMessage, actualMessage); + OidcConfigurationResolutionError exception = + assertThrows(OidcConfigurationResolutionError.class, () -> { + fetcher.loadConfigurationForIssuer(ISSUER); + }); + assertEquals(format(NO_JWKS_URI_ERROR_TEMPLATE, ISSUER), exception.getMessage()); } @Test - public void fetchJWKEndpointTests() throws RestClientException, IOException, RemoteKeySourceException, ParseException { + void fetchJWKEndpointTests() + throws RestClientException, IOException, ParseException, KeySourceException { OidcConfigurationFetcher fetcher = getSuccessfulFetcher(); JWKSet key = JWKSet.parse(fetcher.loadJWKSourceForURL(URI.create(JWK_URI))); @@ -247,16 +258,17 @@ public void fetchJWKEndpointTests() throws RestClientException, IOException, Rem } @Test - public void fetcJWKEndpointWithErrorTests() throws RestClientException, IOException { + void fetchJWKEndpointWithErrorTests() throws RestClientException, IOException { OidcConfigurationFetcher fetcher = getFetcherWithErrorOnGetJwk(); final URI jwkUri = URI.create(JWK_URI); - RemoteKeySourceException exception = assertThrows(RemoteKeySourceException.class, () -> { + KeySourceException exception = assertThrows(KeySourceException.class, () -> { fetcher.loadJWKSourceForURL(jwkUri); }); - String expectedMessage = "Unable to get JWK from '" + jwkUri + "'"; + String expectedMessage = + "Unable to get JWK from '" + jwkUri + "': received status code " + NOT_FOUND.value(); String actualMessage = exception.getMessage(); assertEquals(expectedMessage, actualMessage); } -} \ No newline at end of file +} diff --git a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/TrustedJwtDecoderCacheLoaderTest.java b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/TrustedJwtDecoderCacheLoaderTest.java index 99857006..62af0313 100644 --- a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/TrustedJwtDecoderCacheLoaderTest.java +++ b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwk/TrustedJwtDecoderCacheLoaderTest.java @@ -28,9 +28,9 @@ import org.apache.commons.io.FileUtils; import org.italiangrid.storm.webdav.config.OAuthProperties; +import org.italiangrid.storm.webdav.config.OAuthProperties.AuthorizationServer; import org.italiangrid.storm.webdav.config.ServiceConfigurationProperties; import org.italiangrid.storm.webdav.config.ServiceConfigurationProperties.AuthorizationServerProperties; -import org.italiangrid.storm.webdav.config.OAuthProperties.AuthorizationServer; import org.italiangrid.storm.webdav.oauth.utils.OidcConfigurationFetcher; import org.italiangrid.storm.webdav.oauth.utils.TrustedJwtDecoderCacheLoader; import org.junit.jupiter.api.BeforeEach; @@ -45,13 +45,13 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.util.concurrent.ListenableFuture; -import com.nimbusds.jose.RemoteKeySourceException; +import com.nimbusds.jose.KeySourceException; @ExtendWith(MockitoExtension.class) -public class TrustedJwtDecoderCacheLoaderTest { +class TrustedJwtDecoderCacheLoaderTest { - private final String ISSUER = "https://wlcg.cloud.cnaf.infn.it/"; - private final String JWK_URI = "https://wlcg.cloud.cnaf.infn.it/jwks"; + private static final String ISSUER = "https://wlcg.cloud.cnaf.infn.it/"; + private static final String JWK_URI = "https://wlcg.cloud.cnaf.infn.it/jwks"; @Mock ServiceConfigurationProperties properties; @@ -66,7 +66,7 @@ public class TrustedJwtDecoderCacheLoaderTest { private TrustedJwtDecoderCacheLoader jwtLoader; @BeforeEach - public void setup() throws IOException, RemoteKeySourceException { + public void setup() throws IOException, KeySourceException { AuthorizationServer as = new AuthorizationServer(); as.setIssuer(ISSUER); @@ -98,7 +98,7 @@ public void setup() throws IOException, RemoteKeySourceException { } @Test - public void testLoadRemoteIssuerConfiguration() throws Exception { + void testLoadRemoteIssuerConfiguration() throws Exception { JwtDecoder decoder = jwtLoader.load(ISSUER); assertTrue(decoder instanceof NimbusJwtDecoder); diff --git a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwt/NoExpirationStringCacheTest.java b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwt/NoExpirationStringCacheTest.java index 4482e101..a5c8653c 100644 --- a/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwt/NoExpirationStringCacheTest.java +++ b/src/test/java/org/italiangrid/storm/webdav/test/oauth/jwt/NoExpirationStringCacheTest.java @@ -23,13 +23,13 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -public class NoExpirationStringCacheTest { +class NoExpirationStringCacheTest { - final String CACHED_VALUE = "this-is-my-cached-value"; - final String FAKE_ISSUER = "http://localhost"; + private static final String CACHED_VALUE = "this-is-my-cached-value"; + private static final String FAKE_ISSUER = "http://localhost"; @Test - public void noExpirationCacheWorks() { + void noExpirationCacheWorks() { NoExpirationStringCache cache = new NoExpirationStringCache(CACHED_VALUE);