From 2b73464168799c26f7859d1f55302978005ae29e Mon Sep 17 00:00:00 2001 From: Alessandro Masci Date: Wed, 21 Jun 2023 10:48:09 +0200 Subject: [PATCH] fix test --- .../consumer/servlet/ServletIntegrationTest.java | 11 ++++++----- .../servlet/utils/SimpleClientsTestUtils.java | 5 ++++- ...HttpVerifierHandlerInterceptorIntegrationTest.java | 2 +- .../consumer/spring/SimpleClientsTestUtils.java | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/ServletIntegrationTest.java b/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/ServletIntegrationTest.java index 80ffca84..ce3dadda 100644 --- a/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/ServletIntegrationTest.java +++ b/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/ServletIntegrationTest.java @@ -9,10 +9,7 @@ import it.pagopa.tech.lollipop.consumer.servlet.config.HttpVerifierConfiguration; import it.pagopa.tech.lollipop.consumer.servlet.utils.SimpleClientsTestUtils; import java.io.IOException; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; import org.junit.jupiter.api.extension.ExtendWith; import org.mockserver.integration.ClientAndServer; import org.springframework.beans.factory.annotation.Autowired; @@ -57,6 +54,11 @@ public static void startServer() { mockServer = startClientAndServer(3000, 3001); } + @BeforeEach + void setup() { + idpCertSimpleClientConfig.setBaseUri("http://localhost:3001"); + } + @Test void testWithAValidRequestReturnsSuccess() throws IOException { SimpleClientsTestUtils.createExpectationAssertionFound(); @@ -64,7 +66,6 @@ void testWithAValidRequestReturnsSuccess() throws IOException { lollipopConsumerRequestConfig.setAssertionExpireInDays(365); lollipopConsumerRequestConfig.setAssertionNotBeforeDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); lollipopConsumerRequestConfig.setAssertionInstantDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - idpCertSimpleClientConfig.setBaseUri("http://localhost:3001"); RestTemplate exec = restTemplate.getRestTemplate(); exec.getClientHttpRequestInitializers() diff --git a/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/utils/SimpleClientsTestUtils.java b/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/utils/SimpleClientsTestUtils.java index 94ff3420..e4661c9f 100644 --- a/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/utils/SimpleClientsTestUtils.java +++ b/servlet-impl/src/test/java/it/pagopa/tech/lollipop/consumer/servlet/utils/SimpleClientsTestUtils.java @@ -240,6 +240,8 @@ public class SimpleClientsTestUtils { "eyJrdHkiOiJFQyIsIngiOiJTaHlZa0ZyN1F3eE9rOE5BRXF6aklkTnc4dEVKODlZOVBlWFF1eVVOWDVjIiwieSI6InlULVJxNWc2VlVadENUd0ZnRExDM2RneGNuM2RsSmNGRjhnWGdxYWgyS0UiLCJjcnYiOiJQLTI1NiJ9"; private static final String IDP_TAG = "latest"; + private static final String SUBSCRIPTION_KEY = "FakeSubscriptionKey"; + public static void createExpectationAssertionFound() { new MockServerClient("localhost", 3000) .when( @@ -249,7 +251,8 @@ public static void createExpectationAssertionFound() { .withPathParameter("assertion", ASSERTION_REF) .withHeaders( new Header("Accept", "application/json"), - new Header("x-pagopa-lollipop-auth", JWT))) + new Header("x-pagopa-lollipop-auth", "Bearer " + JWT), + new Header("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY))) .respond(response().withStatusCode(200).withBody(VALID_ASSERTION_XML)); } diff --git a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java index d1405ce0..7e1d3cbe 100644 --- a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java +++ b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/HttpVerifierHandlerInterceptorIntegrationTest.java @@ -53,6 +53,7 @@ public class HttpVerifierHandlerInterceptorIntegrationTest { public void startServer() { restTemplate = new TestRestTemplate(); mockServer = startClientAndServer(3000, 3001); + idpCertSimpleClientConfig.setBaseUri("http://localhost:3001"); } @Test @@ -63,7 +64,6 @@ void testWithValidRequestReturnsSuccess() throws IOException { "yyyy-MM-dd'T'HH:mm:ss'Z'"); springLollipopConsumerRequestConfig.setAssertionInstantDateFormat( "yyyy-MM-dd'T'HH:mm:ss'Z'"); - idpCertSimpleClientConfig.setBaseUri("http://localhost:3001"); RestTemplate exec = restTemplate.getRestTemplate(); exec.getClientHttpRequestInitializers() diff --git a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/SimpleClientsTestUtils.java b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/SimpleClientsTestUtils.java index 42b69912..802beaeb 100644 --- a/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/SimpleClientsTestUtils.java +++ b/spring-impl/src/test/java/it/pagopa/tech/lollipop/consumer/spring/SimpleClientsTestUtils.java @@ -249,7 +249,7 @@ public static void createExpectationAssertionFound() { .withPathParameter("assertion", ASSERTION_REF) .withHeaders( new Header("Accept", "application/json"), - new Header("x-pagopa-lollipop-auth", JWT))) + new Header("x-pagopa-lollipop-auth", "Bearer " + JWT))) .respond(response().withStatusCode(200).withBody(VALID_ASSERTION_XML)); }