Skip to content

Commit

Permalink
Merge pull request #73 from pagopa/fix-jwt-header
Browse files Browse the repository at this point in the history
fix: add `Bearer` prefix to jwt
  • Loading branch information
masciale89 authored Jun 21, 2023
2 parents c348f55 + 2b73464 commit d852004
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SamlAssertion getAssertion(String jwt, String assertionRef)
LCUserInfo responseAssertion;

try {
responseAssertion = this.defaultApi.getAssertion(ref, jwt);
responseAssertion = this.defaultApi.getAssertion(ref, "Bearer " + jwt);
} catch (ApiException e) {
throw new LollipopAssertionNotFoundException(
"Error retrieving assertion: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public static void createExpectationAssertionFound() {
new Header(
"Ocp-Apim-Subscription-Key", "FakeSubscriptionKey"),
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(RESPONSE_STRING));
}

Expand All @@ -282,7 +282,7 @@ public static void createExpectationAssertionNotFound() {
new Header(
"Ocp-Apim-Subscription-Key", "FakeSubscriptionKey"),
new Header("Accept", "application/json"),
new Header("x-pagopa-lollipop-auth", JWT)))
new Header("x-pagopa-lollipop-auth", "Bearer " + JWT)))
.respond(response().withStatusCode(404).withBody("{}"));
}
}
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-RC3'
version = '1.0.0-RC4'
group = 'it.pagopa.tech.lollipop-consumer-java-sdk'
sourceCompatibility = '11'
targetCompatibility = '11'
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-RC3'
version = '1.0.0-RC4'
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-RC3'
version = '1.0.0-RC4'
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-RC3'
version = '1.0.0-RC4'
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-RC3'
version = '1.0.0-RC4'
sourceCompatibility = '11'

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,14 +54,18 @@ public static void startServer() {
mockServer = startClientAndServer(3000, 3001);
}

@BeforeEach
void setup() {
idpCertSimpleClientConfig.setBaseUri("http://localhost:3001");
}

@Test
void testWithValidRequestReturnsSuccess() throws IOException {
void testWithAValidRequestReturnsSuccess() throws IOException {
SimpleClientsTestUtils.createExpectationAssertionFound();
SimpleClientsTestUtils.createExpectationIdpFound();
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class HttpVerifierHandlerInterceptorIntegrationTest {
public void startServer() {
restTemplate = new TestRestTemplate();
mockServer = startClientAndServer(3000, 3001);
idpCertSimpleClientConfig.setBaseUri("http://localhost:3001");
}

@Test
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit d852004

Please sign in to comment.