From 77a943ed3c6bf01481710faace1737bd186c17a1 Mon Sep 17 00:00:00 2001 From: "antonio.torre" Date: Sat, 11 Jan 2025 15:18:51 +0100 Subject: [PATCH] fix open api handling --- Dockerfile | 4 +- build.gradle.kts | 31 +++++--- postman/p4pa-auth-E2E.postman_collection.json | 77 +++++++++++-------- ...ssModeOrganization.postman_collection.json | 44 +++++++---- .../auth/controller/AuthnControllerTest.java | 4 +- 5 files changed, 99 insertions(+), 61 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5ef892..ec0ec8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/build.gradle.kts b/build.gradle.kts index e37ae11..24c670f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { @@ -133,14 +143,15 @@ tasks.register("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" )) } @@ -150,7 +161,7 @@ var targetEnv = when (grgit.branch.current().name) { else -> "develop" } -tasks.register("openApiGenerateOrganization") { +tasks.register("openApiGenerateORGANIZATION") { group = "openapi" description = "description" diff --git a/postman/p4pa-auth-E2E.postman_collection.json b/postman/p4pa-auth-E2E.postman_collection.json index 9a934f8..a88b4f8 100644 --- a/postman/p4pa-auth-E2E.postman_collection.json +++ b/postman/p4pa-auth-E2E.postman_collection.json @@ -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": [ { @@ -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", @@ -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", @@ -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", @@ -716,7 +716,7 @@ "listen": "prerequest", "script": { "exec": [ - "" + "pm.collectionVariables.set(\"clientName\", \"testClient\" + pm.variables.get(\"currentdatetime\"));" ], "type": "text/javascript", "packages": {} @@ -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", @@ -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" @@ -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" @@ -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", "" ], @@ -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", @@ -1199,8 +1207,7 @@ "listen": "prerequest", "script": { "exec": [ - " pm.environment.get(\"clientId\")\r", - " pm.environment.get(\"organizationIpaCode\")" + "" ], "type": "text/javascript", "packages": {} @@ -1244,7 +1251,9 @@ "type": "text/javascript", "packages": {}, "exec": [ - "" + "var moment = require('moment');", + "", + "pm.variables.set('currentdatetime', moment().format((\"YYYY-MM-DDTHH:mm:ss\")));" ] } }, @@ -1279,6 +1288,10 @@ { "key": "clientSecret", "value": "" + }, + { + "key": "clientName", + "value": "" } ] } \ No newline at end of file diff --git a/postman/p4pa-auth-NoAccessModeOrganization.postman_collection.json b/postman/p4pa-auth-NoAccessModeOrganization.postman_collection.json index bc21fd2..dbb398a 100644 --- a/postman/p4pa-auth-NoAccessModeOrganization.postman_collection.json +++ b/postman/p4pa-auth-NoAccessModeOrganization.postman_collection.json @@ -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": [ { @@ -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", @@ -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", @@ -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", @@ -460,5 +460,19 @@ ] } } + ], + "variable": [ + { + "key": "mappedExternalUserId", + "value": "" + }, + { + "key": "organizationIpaCode", + "value": "" + }, + { + "key": "accessToken", + "value": "" + } ] } \ No newline at end of file diff --git a/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthnControllerTest.java b/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthnControllerTest.java index 1b030c0..620c192 100644 --- a/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthnControllerTest.java +++ b/src/test/java/it/gov/pagopa/payhub/auth/controller/AuthnControllerTest.java @@ -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