Skip to content

Commit

Permalink
fix open api handling
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioT90 committed Jan 11, 2025
1 parent 7498a41 commit 77a943e
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 61 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ RUN mkdir -p src/main/java && \

USER ${APP_USER}

RUN gradle openApiGenerateP4PAAUTH dependencies --no-daemon

RUN gradle openApiGenerateOrganization dependencies --no-daemon
RUN gradle dependenciesBuild dependencies --no-daemon

#
# 🏗️ Build Stage
Expand Down
31 changes: 21 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ configurations {
}

tasks.compileJava {
dependsOn("openApiGenerateP4PAAUTH","openApiGenerateOrganization")
dependsOn("dependenciesBuild")
}

tasks.register("dependenciesBuild") {
group = "AutomaticallyGeneratedCode"
description = "grouping all together automatically generate code tasks"

dependsOn(
"openApiGenerateP4PAAUTH",
"openApiGenerateORGANIZATION"
)
}

configure<SourceSetContainer> {
Expand All @@ -133,14 +143,15 @@ tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("ope
apiPackage.set("it.gov.pagopa.payhub.controller.generated")
modelPackage.set("it.gov.pagopa.payhub.dto.generated")
configOptions.set(mapOf(
"dateLibrary" to "java8",
"requestMappingMode" to "api_interface",
"useSpringBoot3" to "true",
"interfaceOnly" to "true",
"useTags" to "true",
"generateConstructorWithAllArgs" to "false",
"generatedConstructorWithRequiredArgs" to "true",
"additionalModelTypeAnnotations" to "@lombok.Data @lombok.Builder @lombok.AllArgsConstructor"
"dateLibrary" to "java8",
"requestMappingMode" to "api_interface",
"useSpringBoot3" to "true",
"interfaceOnly" to "true",
"useTags" to "true",
"useBeanValidation" to "true",
"generateConstructorWithAllArgs" to "true",
"generatedConstructorWithRequiredArgs" to "true",
"additionalModelTypeAnnotations" to "@lombok.Builder"
))
}

Expand All @@ -150,7 +161,7 @@ var targetEnv = when (grgit.branch.current().name) {
else -> "develop"
}

tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerateOrganization") {
tasks.register<org.openapitools.generator.gradle.plugin.tasks.GenerateTask>("openApiGenerateORGANIZATION") {
group = "openapi"
description = "description"

Expand Down
77 changes: 45 additions & 32 deletions postman/p4pa-auth-E2E.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"info": {
"_postman_id": "cc929f09-50c0-4887-bf81-b41f8c297554",
"_postman_id": "13831639-b265-4c57-b4d3-e94d2799ba31",
"name": "p4pa-auth-E2E",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "29647564",
"_collection_link": "https://galactic-eclipse-948669.postman.co/workspace/New-Team-Workspace~be56c5f1-de0c-4252-95d0-ee80f35e2474/collection/29647564-cc929f09-50c0-4887-bf81-b41f8c297554?action=share&source=collection_link&creator=29647564"
"_exporter_id": "15747968",
"_collection_link": "https://warped-astronaut-141685.postman.co/workspace/P4PA~9a8b7dd5-97b6-4dd0-b3f5-95f25fd0b455/collection/15747968-13831639-b265-4c57-b4d3-e94d2799ba31?action=share&source=collection_link&creator=15747968"
},
"item": [
{
Expand Down Expand Up @@ -67,11 +67,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -135,11 +135,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -203,11 +203,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -716,7 +716,7 @@
"listen": "prerequest",
"script": {
"exec": [
""
"pm.collectionVariables.set(\"clientName\", \"testClient\" + pm.variables.get(\"currentdatetime\"));"
],
"type": "text/javascript",
"packages": {}
Expand All @@ -733,9 +733,11 @@
"pm.test(\"Auth - registerClient - Response is correct based on record existence\", function () {\r",
" let jsonResponse = pm.response.json();\r",
"\r",
" let clientName = pm.collectionVariables.get(\"clientName\")\r",
"\r",
" // Verifica il contenuto della risposta quando il record non esiste\r",
" pm.expect(jsonResponse).to.have.property(\"clientId\").to.eq(\"IPA_TESTtestClient\");\r",
" pm.expect(jsonResponse).to.have.property(\"clientName\").to.eq(\"testClient\");\r",
" pm.expect(jsonResponse).to.have.property(\"clientId\").to.eq(\"IPA_TEST\"+clientName);\r",
" pm.expect(jsonResponse).to.have.property(\"clientName\").to.eq(clientName);\r",
" pm.expect(jsonResponse).to.have.property(\"organizationIpaCode\").to.eq(\"IPA_TEST\");\r",
" pm.expect(jsonResponse).to.have.property(\"clientSecret\");\r",
"\r",
Expand Down Expand Up @@ -763,7 +765,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"clientName\" : \"testClient\"\r\n}",
"raw": "{\r\n \"clientName\" : \"{{clientName}}\"\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -826,7 +828,7 @@
"header": [],
"body": {
"mode": "raw",
"raw": "{\r\n \"clientName\" : \"testClient\"\r\n}",
"raw": "{\r\n \"clientName\" : \"{{clientName}}\"\r\n}",
"options": {
"raw": {
"language": "json"
Expand Down Expand Up @@ -913,12 +915,18 @@
"pm.test(\"Auth - getClients - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
"\r",
" let clientId = pm.collectionVariables.get(\"clientId\");\r",
" let clientName = pm.collectionVariables.get(\"clientName\");\r",
"\r",
" pm.expect(jsonResponse).to.be.an(\"array\").that.is.not.empty;\r",
" jsonResponse.forEach(dto => {\r",
" pm.expect(dto).to.have.property(\"clientId\").to.eql(\"IPA_TESTtestClient\");\r",
" pm.expect(dto).to.have.property(\"clientName\").to.eql(\"testClient\");\r",
" pm.expect(dto).to.have.property(\"organizationIpaCode\").to.eql(\"IPA_TEST\");\r",
" });\r",
" let currentClient = jsonResponse.filter(c => c.clientId==clientId)[0]\r",
" console.log(clientId)\r",
" console.log(currentClient)\r",
" pm.expect(currentClient).to.not.null\r",
" \r",
" pm.expect(currentClient).to.have.property(\"clientId\").to.eq(\"IPA_TEST\"+clientName);\r",
" pm.expect(currentClient).to.have.property(\"clientName\").to.eq(clientName);\r",
" pm.expect(currentClient).to.have.property(\"organizationIpaCode\").to.eql(\"IPA_TEST\");\r",
"});\r",
""
],
Expand Down Expand Up @@ -1133,11 +1141,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.variables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.variables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -1199,8 +1207,7 @@
"listen": "prerequest",
"script": {
"exec": [
" pm.environment.get(\"clientId\")\r",
" pm.environment.get(\"organizationIpaCode\")"
""
],
"type": "text/javascript",
"packages": {}
Expand Down Expand Up @@ -1244,7 +1251,9 @@
"type": "text/javascript",
"packages": {},
"exec": [
""
"var moment = require('moment');",
"",
"pm.variables.set('currentdatetime', moment().format((\"YYYY-MM-DDTHH:mm:ss\")));"
]
}
},
Expand Down Expand Up @@ -1279,6 +1288,10 @@
{
"key": "clientSecret",
"value": ""
},
{
"key": "clientName",
"value": ""
}
]
}
44 changes: 29 additions & 15 deletions postman/p4pa-auth-NoAccessModeOrganization.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"info": {
"_postman_id": "4cce1599-b728-41d3-8dab-bfa5f589956c",
"_postman_id": "6a49a33e-71f8-41bf-a00d-29a1d20005b6",
"name": "p4pa-auth-NoAccessModeOrganization",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "29647564",
"_collection_link": "https://galactic-eclipse-948669.postman.co/workspace/New-Team-Workspace~be56c5f1-de0c-4252-95d0-ee80f35e2474/collection/29647564-4cce1599-b728-41d3-8dab-bfa5f589956c?action=share&source=collection_link&creator=29647564"
"_exporter_id": "15747968",
"_collection_link": "https://warped-astronaut-141685.postman.co/workspace/P4PA~9a8b7dd5-97b6-4dd0-b3f5-95f25fd0b455/collection/15747968-6a49a33e-71f8-41bf-a00d-29a1d20005b6?action=share&source=collection_link&creator=15747968"
},
"item": [
{
Expand All @@ -20,11 +20,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.variables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -88,11 +88,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.variables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -156,11 +156,11 @@
"\r",
"pm.test(\"Auth - postToken - Verify response body\", function () {\r",
" let jsonResponse = pm.response.json();\r",
" pm.expect(jsonResponse).have.property(\"tokenType\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expiresIn\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"accessToken\");\r",
" pm.expect(jsonResponse).have.property(\"token_type\").to.eq(\"bearer\");\r",
" pm.expect(jsonResponse).have.property(\"expires_in\").to.eq(14400);\r",
" pm.expect(jsonResponse).have.property(\"access_token\");\r",
"\r",
" pm.variables.set(\"accessToken\", jsonResponse.accessToken)\r",
" pm.collectionVariables.set(\"accessToken\", jsonResponse.access_token)\r",
"});"
],
"type": "text/javascript",
Expand Down Expand Up @@ -460,5 +460,19 @@
]
}
}
],
"variable": [
{
"key": "mappedExternalUserId",
"value": ""
},
{
"key": "organizationIpaCode",
"value": ""
},
{
"key": "accessToken",
"value": ""
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ void givenExpectedAuthTokenWhenPostTokenThenOk() throws Exception {
MvcResult result =
invokePostTokenAndVerify(null, HttpStatus.OK, null);

Mockito.when(accessTokenBuilderServiceMock.getHeaderPrefix()).thenReturn("p4paauthTokenPrefix");

Assertions.assertNotNull(result);
Assertions.assertEquals("{\"accessToken\":\"token\",\"tokenType\":\"bearer\",\"expiresIn\":0}", result.getResponse().getContentAsString());
Assertions.assertEquals("{\"access_token\":\"token\",\"token_type\":\"bearer\",\"expires_in\":0}", result.getResponse().getContentAsString());
}

@Test
Expand Down

0 comments on commit 77a943e

Please sign in to comment.