Skip to content

Commit

Permalink
Merge pull request #70 from pagopa/addSubcriptionKeyHeader
Browse files Browse the repository at this point in the history
fix: Add Ocp-Apim-Subscription-Key header to `GetAssertion` request
  • Loading branch information
masciale89 authored Jun 19, 2023
2 parents 2662bfa + 4fe0104 commit c348f55
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 18 deletions.
10 changes: 10 additions & 0 deletions assertion-rest-client-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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("{}"));
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -67,7 +66,7 @@ void getNotExistingAssertionWithStorageEnabled() {
}

@Test
void saveAssertionAndScheduleEvictionWithStorageEnabled()
void saveIdpCertAndScheduleEvictionWithStorageEnabled()
throws InterruptedException, ExecutionException {
doReturn(true).when(storageConfigMock).isIdpCertDataStorageEnabled();

Expand Down Expand Up @@ -120,15 +119,14 @@ private CompletableFuture<Boolean> waitEvictionEnd(
CompletableFuture<Boolean> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion samples/simple/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion samples/simpleTypesafe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion samples/spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions samples/spring/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit c348f55

Please sign in to comment.