diff --git a/assertion-rest-client-native/build.gradle b/assertion-rest-client-native/build.gradle index 7bb20a06..45745e29 100644 --- a/assertion-rest-client-native/build.gradle +++ b/assertion-rest-client-native/build.gradle @@ -70,6 +70,16 @@ tasks.named('test') { useJUnitPlatform() } /* +!! WARNING: +Generated client do not handle `Ocp-Apim-Subscription-Key` header. +We added it to `ApiClient` class, by defining the interceptor as + +`interceptor = t -> t.header("Ocp-Apim-Subscription-Key", config.getSubscriptionKey());` + +If we need to regenerate the client, please copy/paste this piece of code again to `ApiClient class construction`. + +---------------- + compileJava.dependsOn tasks.openApiGenerate openApiGenerate { diff --git a/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientConfig.java b/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientConfig.java index a0b40182..2b823d2b 100644 --- a/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientConfig.java +++ b/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientConfig.java @@ -15,4 +15,6 @@ public class AssertionSimpleClientConfig { @Builder.Default private String baseUri = "http://localhost:3000"; @Builder.Default private String assertionRequestEndpoint = "/assertions"; + + @Builder.Default private String subscriptionKey = "FakeSubscriptionKey"; } diff --git a/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/internal/ApiClient.java b/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/internal/ApiClient.java index 64d1e2f1..610d7804 100644 --- a/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/internal/ApiClient.java +++ b/assertion-rest-client-native/src/main/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/internal/ApiClient.java @@ -67,7 +67,7 @@ public ApiClient(AssertionSimpleClientConfig config) { this.builder = createDefaultHttpClientBuilder(); this.mapper = createDefaultObjectMapper(); updateBaseUri(config.getBaseUri()); - interceptor = null; + interceptor = t -> t.header("Ocp-Apim-Subscription-Key", config.getSubscriptionKey()); readTimeout = null; connectTimeout = null; responseInterceptor = null; diff --git a/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTest.java b/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTest.java index 14e8f951..197d3635 100644 --- a/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTest.java +++ b/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTest.java @@ -3,6 +3,7 @@ import static it.pagopa.tech.lollipop.consumer.assertion.client.simple.AssertionSimpleClientTestUtils.*; import static org.mockserver.integration.ClientAndServer.startClientAndServer; +import static org.mockserver.model.HttpRequest.request; import it.pagopa.tech.lollipop.consumer.assertion.client.simple.internal.ApiClient; import it.pagopa.tech.lollipop.consumer.exception.LollipopAssertionNotFoundException; @@ -14,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockserver.integration.ClientAndServer; +import org.mockserver.verify.VerificationTimes; class AssertionSimpleClientTest { @@ -40,6 +42,10 @@ void samlAssertionFound() throws LollipopAssertionNotFoundException, OidcAsserti Assertions.assertNotNull(response.getAssertionData()); Assertions.assertEquals(ASSERTION_REF, response.getAssertionRef()); Assertions.assertEquals(XML_STRING, response.getAssertionData()); + + mockServer.verify( + request().withHeader("Ocp-Apim-Subscription-Key", "FakeSubscriptionKey"), + VerificationTimes.exactly(1)); } @Test diff --git a/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTestUtils.java b/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTestUtils.java index 48b2ef3d..1f93160a 100644 --- a/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTestUtils.java +++ b/assertion-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/client/simple/AssertionSimpleClientTestUtils.java @@ -264,6 +264,8 @@ public static void createExpectationAssertionFound() { .withPath("/assertions/{assertion}") .withPathParameter("assertion", ASSERTION_REF) .withHeaders( + new Header( + "Ocp-Apim-Subscription-Key", "FakeSubscriptionKey"), new Header("Accept", "application/json"), new Header("x-pagopa-lollipop-auth", JWT))) .respond(response().withStatusCode(200).withBody(RESPONSE_STRING)); @@ -277,6 +279,8 @@ public static void createExpectationAssertionNotFound() { .withPath("/assertions/{assertion}") .withPathParameter("assertion", WRONG_ASSERTION_REF) .withHeaders( + new Header( + "Ocp-Apim-Subscription-Key", "FakeSubscriptionKey"), new Header("Accept", "application/json"), new Header("x-pagopa-lollipop-auth", JWT))) .respond(response().withStatusCode(404).withBody("{}")); diff --git a/build.gradle b/build.gradle index 7a5b75a6..e0a86de7 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ repositories { } allprojects { - version = '1.0.0-RC2' + version = '1.0.0-RC3' group = 'it.pagopa.tech.lollipop-consumer-java-sdk' sourceCompatibility = '11' targetCompatibility = '11' diff --git a/core/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/storage/SimpleAssertionStorageTest.java b/core/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/storage/SimpleAssertionStorageTest.java index 819971bb..ca9edabd 100644 --- a/core/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/storage/SimpleAssertionStorageTest.java +++ b/core/src/test/java/it/pagopa/tech/lollipop/consumer/assertion/storage/SimpleAssertionStorageTest.java @@ -28,7 +28,7 @@ void setUp() { @Test void getExistingAssertionAndResetScheduleEvictionWithStorageEnabled() - throws InterruptedException, ExecutionException { + throws InterruptedException { doReturn(true).when(storageConfigMock).isAssertionStorageEnabled(); doReturn(1000L).when(storageConfigMock).getStorageEvictionDelay(); doReturn(TimeUnit.MILLISECONDS).when(storageConfigMock).getStorageEvictionDelayTimeUnit(); @@ -72,10 +72,10 @@ void getNotExistingAssertionWithStorageEnabled() { } @Test - void saveAssertionAndScheduleEvictionWithStorageEnabled() - throws InterruptedException, ExecutionException { + void saveAssertionAndScheduleEvictionWithStorageEnabled() throws InterruptedException { doReturn(true).when(storageConfigMock).isAssertionStorageEnabled(); doReturn(1000L).when(storageConfigMock).getStorageEvictionDelay(); + doReturn(TimeUnit.MILLISECONDS).when(storageConfigMock).getStorageEvictionDelayTimeUnit(); doReturn(100L).when(storageConfigMock).getMaxNumberOfElements(); diff --git a/identity-service-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/idp/client/simple/storage/SimpleIdpCertStorageTest.java b/identity-service-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/idp/client/simple/storage/SimpleIdpCertStorageTest.java index e189d7eb..8c715be7 100644 --- a/identity-service-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/idp/client/simple/storage/SimpleIdpCertStorageTest.java +++ b/identity-service-rest-client-native/src/test/java/it/pagopa/tech/lollipop/consumer/idp/client/simple/storage/SimpleIdpCertStorageTest.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.*; -import lombok.SneakyThrows; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -67,7 +66,7 @@ void getNotExistingAssertionWithStorageEnabled() { } @Test - void saveAssertionAndScheduleEvictionWithStorageEnabled() + void saveIdpCertAndScheduleEvictionWithStorageEnabled() throws InterruptedException, ExecutionException { doReturn(true).when(storageConfigMock).isIdpCertDataStorageEnabled(); @@ -120,15 +119,14 @@ private CompletableFuture waitEvictionEnd( CompletableFuture future = new CompletableFuture<>(); ExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); executorService.submit( - new Runnable() { - @SneakyThrows - @Override - public void run() { - ScheduledFuture scheduledFuture = - scheduledEvictionsMap.get(IDPCERTDATA_1); + () -> { + ScheduledFuture scheduledFuture = scheduledEvictionsMap.get(IDPCERTDATA_1); + try { scheduledFuture.get(); - future.complete(true); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); } + future.complete(true); }); return future; } diff --git a/samples/servlet/build.gradle b/samples/servlet/build.gradle index 2dcce4b9..d2be0dde 100644 --- a/samples/servlet/build.gradle +++ b/samples/servlet/build.gradle @@ -13,7 +13,7 @@ plugins { group = 'it.pagopa.tech.lollipop.consumer.samples' -version = '1.0.0-RC2' +version = '1.0.0-RC3' sourceCompatibility = '11' application { diff --git a/samples/simple/build.gradle b/samples/simple/build.gradle index 5de1ab46..4e8f0956 100644 --- a/samples/simple/build.gradle +++ b/samples/simple/build.gradle @@ -13,7 +13,7 @@ plugins { group = 'it.pagopa.tech.lollipop.consumer.samples' -version = '1.0.0-RC2' +version = '1.0.0-RC3' sourceCompatibility = '11' application { diff --git a/samples/simpleTypesafe/build.gradle b/samples/simpleTypesafe/build.gradle index 5ba10d65..74c1580c 100644 --- a/samples/simpleTypesafe/build.gradle +++ b/samples/simpleTypesafe/build.gradle @@ -13,7 +13,7 @@ plugins { group = 'it.pagopa.tech.lollipop.consumer.samples' -version = '1.0.0-RC2' +version = '1.0.0-RC3' sourceCompatibility = '11' application { diff --git a/samples/spring/build.gradle b/samples/spring/build.gradle index d6150f82..bb634c7e 100644 --- a/samples/spring/build.gradle +++ b/samples/spring/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'it.pagopa.tech.lollipop.consumer.samples' -version = '1.0.0-RC2' +version = '1.0.0-RC3' sourceCompatibility = '11' configurations { diff --git a/samples/spring/src/main/resources/application.properties b/samples/spring/src/main/resources/application.properties index 091162b0..f0cef817 100644 --- a/samples/spring/src/main/resources/application.properties +++ b/samples/spring/src/main/resources/application.properties @@ -26,6 +26,7 @@ lollipop.idp.storage.config.storageEvictionDelay=${IDP_STORAGE_EVICTION_DELAY:1} ##Assertion Client Configs lollipop.assertion.rest.config.baseUri=${ASSERTION_REST_URI:http://localhost:3000} lollipop.assertion.rest.config.assertionRequestEndpoint=${ASSERTION_REST_ENDPOINT:/assertions} +lollipop.assertion.rest.config.subscriptionKey=${ASSERTION_REST_SUBSCRIPTION_KEY:FakeSubscriptionKey} ##Assertion Storage Configs lollipop.assertion.rest.config.assertionStorageEnabled=${ASSERTION_STORAGE_ENABLED:true}