From 9bf8978e087e922c88bf44700d4dcc00bd77aff0 Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 11:28:30 +0100 Subject: [PATCH 1/6] [#171703313] SAML certs and Startup IDP metadata from ENV --- README.md | 2 + package.json | 2 +- src/__tests__/app.test.ts | 26 ---- src/app.ts | 20 +-- src/config.ts | 38 +++-- src/types/commons.ts | 3 + yarn.lock | 291 +++++--------------------------------- 7 files changed, 85 insertions(+), 297 deletions(-) diff --git a/README.md b/README.md index 93ec689dc..b0baa0aba 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,8 @@ Those are all Environment variables needed by the application: | SAML_CALLBACK_URL | The absolute URL of the assertion consumer service endpoint | string | | SAML_ISSUER | The issuer id for this Service Provider | string | | SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX | The index in the attribute consumer list | int | +| SAML_KEY | Private Key used by SAML protocol | string | +| SAML_CERT | Certificate used by SAML protocol | string | | PRE_SHARED_KEY | The key shared with the API backend to authenticate the webhook notifications | string | | ALLOW_NOTIFY_IP_SOURCE_RANGE | The range in CIDR form of allowed IPs for the webhook notifications | string | | AZURE_NH_HUB_NAME | The hub name configured in the Azure Notification HUB | string | diff --git a/package.json b/package.json index 180077f44..baa65f4d4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ }, "homepage": "https://github.com/pagopa/io-backend#readme", "dependencies": { - "@pagopa/io-spid-commons": "^2.7.0", + "@pagopa/io-spid-commons": "^2.9.0", "apicache": "^1.4.0", "applicationinsights": "^1.4.2", "azure-sb": "^0.10.6", diff --git a/src/__tests__/app.test.ts b/src/__tests__/app.test.ts index 8bde63b63..dbb1b0184 100644 --- a/src/__tests__/app.test.ts +++ b/src/__tests__/app.test.ts @@ -1,8 +1,5 @@ -import * as spid from "@pagopa/io-spid-commons"; import { Express } from "express"; import { isRight } from "fp-ts/lib/Either"; -import { Task } from "fp-ts/lib/Task"; -import * as TE from "fp-ts/lib/TaskEither"; import { NodeEnvironmentEnum } from "italia-ts-commons/lib/environment"; import { ResponseSuccessJson } from "italia-ts-commons/lib/responses"; import { CIDR } from "italia-ts-commons/lib/strings"; @@ -122,26 +119,3 @@ describe("Success app start", () => { }); }); }); - -describe("Failure app start", () => { - it("Close app if download IDP metadata fails on startup", async () => { - // Override return value of generateSpidStrategy with a rejected promise. - jest.spyOn(spid, "withSpid").mockImplementation(() => { - return TE.left( - new Task(async () => new Error("Error download metadata")) - ); - }); - const mockExit = jest - .spyOn(process, "exit") - .mockImplementation(() => true as never); - await appModule.newApp( - NodeEnvironmentEnum.PRODUCTION, - aValidCIDR, - aValidCIDR, - "", - "/api/v1", - "/pagopa/api/v1" - ); - expect(mockExit).toBeCalledWith(1); - }); -}); diff --git a/src/app.ts b/src/app.ts index 9c1458c0b..65d23d625 100644 --- a/src/app.ts +++ b/src/app.ts @@ -223,14 +223,18 @@ export function newApp( return { app, acsController }; }, toError) .chain(_ => - withSpid( - appConfig, - samlConfig, - serviceProviderConfig, - REDIS_CLIENT, - _.app, - _.acsController.acs.bind(_.acsController), - _.acsController.slo.bind(_.acsController) + tryCatch( + async () => + withSpid( + appConfig, + samlConfig, + serviceProviderConfig, + REDIS_CLIENT, + _.app, + _.acsController.acs.bind(_.acsController), + _.acsController.slo.bind(_.acsController) + ).run(), + toError ) ) .map(_ => { diff --git a/src/config.ts b/src/config.ts index ec19ba563..12aca47eb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,13 +2,16 @@ * Defines services and register them to the Service Container. */ import * as dotenv from "dotenv"; -import { isLeft } from "fp-ts/lib/Either"; +import { isLeft, parseJSON, toError } from "fp-ts/lib/Either"; import { fromNullable, isSome } from "fp-ts/lib/Option"; import { getNodeEnvironmentFromProcessEnv, NodeEnvironmentEnum } from "italia-ts-commons/lib/environment"; -import { ReadableReporter } from "italia-ts-commons/lib/reporters"; +import { + errorsToReadableMessages, + ReadableReporter +} from "italia-ts-commons/lib/reporters"; import { CIDR } from "italia-ts-commons/lib/strings"; import { UrlFromString } from "italia-ts-commons/lib/url"; @@ -28,6 +31,7 @@ import { } from "@pagopa/io-spid-commons"; import RedisSessionStorage from "./services/redisSessionStorage"; +import { STRINGS_RECORD } from "./types/commons"; import { createClusterRedisClient, createSimpleRedisClient @@ -57,18 +61,19 @@ export const CACHE_MAX_AGE_SECONDS: number = parseInt( // Private key used in SAML authentication to a SPID IDP. const samlKey = () => { - return readFile( - process.env.SAML_KEY_PATH || "./certs/key.pem", - "SAML private key" + return fromNullable(process.env.SAML_KEY).getOrElse( + readFile(process.env.SAML_KEY_PATH || "./certs/key.pem", "SAML private key") ); }; export const SAML_KEY = samlKey(); // Public certificate used in SAML authentication to a SPID IDP. const samlCert = () => { - return readFile( - process.env.SAML_CERT_PATH || "./certs/cert.pem", - "SAML certificate" + return fromNullable(process.env.SAML_CERT).getOrElse( + readFile( + process.env.SAML_CERT_PATH || "./certs/cert.pem", + "SAML certificate" + ) ); }; @@ -104,6 +109,20 @@ const SPID_TESTENV_URL = export const IDP_METADATA_URL = getRequiredENVVar("IDP_METADATA_URL"); const CIE_METADATA_URL = getRequiredENVVar("CIE_METADATA_URL"); +export const STARTUP_IDPS_METADATA: + | Record + | undefined = fromNullable(process.env.STARTUP_IDPS_METADATA) + .map(_ => + parseJSON(_, toError) + .chain | undefined>(_1 => + STRINGS_RECORD.decode(_1).mapLeft( + err => new Error(errorsToReadableMessages(err).join(" / ")) + ) + ) + .getOrElse(undefined) + ) + .getOrElse(undefined); + export const CLIENT_ERROR_REDIRECTION_URL = process.env.CLIENT_ERROR_REDIRECTION_URL || "/error.html"; @@ -116,7 +135,8 @@ export const appConfig: IApplicationConfig = { clientLoginRedirectionUrl: CLIENT_REDIRECTION_URL, loginPath: "/login", metadataPath: "/metadata", - sloPath: "/slo" + sloPath: "/slo", + startupIdpsMetadata: STARTUP_IDPS_METADATA }; const maybeSpidValidatorUrlOption = fromNullable( diff --git a/src/types/commons.ts b/src/types/commons.ts index c5d9b69c3..ff022194f 100644 --- a/src/types/commons.ts +++ b/src/types/commons.ts @@ -9,3 +9,6 @@ export const SuccessResponse = t.interface({ }); export type SuccessResponse = t.TypeOf; + +export const STRINGS_RECORD = t.record(t.string, t.string); +export type STRINGS_RECORD = t.TypeOf; diff --git a/yarn.lock b/yarn.lock index 1b6f49c64..7f6f1424a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,67 +52,6 @@ "@nodelib/fs.scandir" "2.1.3" fastq "^1.6.0" -"@oclif/command@^1.4.35", "@oclif/command@^1.5.13": - version "1.5.19" - resolved "https://registry.yarnpkg.com/@oclif/command/-/command-1.5.19.tgz#13f472450eb83bd6c6871a164c03eadb5e1a07ed" - integrity sha512-6+iaCMh/JXJaB2QWikqvGE9//wLEVYYwZd5sud8aLoLKog1Q75naZh2vlGVtg5Mq/NqpqGQvdIjJb3Bm+64AUQ== - dependencies: - "@oclif/config" "^1" - "@oclif/errors" "^1.2.2" - "@oclif/parser" "^3.8.3" - "@oclif/plugin-help" "^2" - debug "^4.1.1" - semver "^5.6.0" - -"@oclif/config@^1", "@oclif/config@^1.6.33": - version "1.14.0" - resolved "https://registry.yarnpkg.com/@oclif/config/-/config-1.14.0.tgz#0af93facd5c5087f804489f1603c4f3bc0c45014" - integrity sha512-KsOP/mx9lzTah+EtGqLUXN3PDL0J3zb9/dTneFyiUK2K6T7vFEGhV6OasmqTh4uMZHGYTGrNPV8x/Yw6qZNL6A== - dependencies: - "@oclif/errors" "^1.0.0" - "@oclif/parser" "^3.8.0" - debug "^4.1.1" - tslib "^1.9.3" - -"@oclif/errors@^1.0.0", "@oclif/errors@^1.2.2": - version "1.2.2" - resolved "https://registry.yarnpkg.com/@oclif/errors/-/errors-1.2.2.tgz#9d8f269b15f13d70aa93316fed7bebc24688edc2" - integrity sha512-Eq8BFuJUQcbAPVofDxwdE0bL14inIiwt5EaKRVY9ZDIG11jwdXZqiQEECJx0VfnLyUZdYfRd/znDI/MytdJoKg== - dependencies: - clean-stack "^1.3.0" - fs-extra "^7.0.0" - indent-string "^3.2.0" - strip-ansi "^5.0.0" - wrap-ansi "^4.0.0" - -"@oclif/linewrap@^1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@oclif/linewrap/-/linewrap-1.0.0.tgz#aedcb64b479d4db7be24196384897b5000901d91" - integrity sha512-Ups2dShK52xXa8w6iBWLgcjPJWjais6KPJQq3gQ/88AY6BXoTX+MIGFPrWQO1KLMiQfoTpcLnUwloN4brrVUHw== - -"@oclif/parser@^3.8.0", "@oclif/parser@^3.8.3": - version "3.8.4" - resolved "https://registry.yarnpkg.com/@oclif/parser/-/parser-3.8.4.tgz#1a90fc770a42792e574fb896325618aebbe8c9e4" - integrity sha512-cyP1at3l42kQHZtqDS3KfTeyMvxITGwXwH1qk9ktBYvqgMp5h4vHT+cOD74ld3RqJUOZY/+Zi9lb4Tbza3BtuA== - dependencies: - "@oclif/linewrap" "^1.0.0" - chalk "^2.4.2" - tslib "^1.9.3" - -"@oclif/plugin-help@^2", "@oclif/plugin-help@^2.0.5": - version "2.2.3" - resolved "https://registry.yarnpkg.com/@oclif/plugin-help/-/plugin-help-2.2.3.tgz#b993041e92047f0e1762668aab04d6738ac06767" - integrity sha512-bGHUdo5e7DjPJ0vTeRBMIrfqTRDBfyR5w0MP41u0n3r7YG5p14lvMmiCXxi6WDaP2Hw5nqx3PnkAIntCKZZN7g== - dependencies: - "@oclif/command" "^1.5.13" - chalk "^2.4.1" - indent-string "^4.0.0" - lodash.template "^4.4.0" - string-width "^3.0.0" - strip-ansi "^5.0.0" - widest-line "^2.0.1" - wrap-ansi "^4.0.0" - "@octokit/auth-token@^2.4.0": version "2.4.0" resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.4.0.tgz#b64178975218b99e4dfe948253f0673cbbb59d9f" @@ -216,10 +155,10 @@ dependencies: "@types/node" ">= 8" -"@pagopa/io-spid-commons@^2.7.0": - version "2.7.0" - resolved "https://npm.pkg.github.com/download/@pagopa/io-spid-commons/2.7.0/0047e9feda6d126b054b14c5252dfddee4c8b45e55187911c0141554d63857d6#6d2924755e082ed86515269e4f36a73deea1c55a" - integrity sha512-Qfk2wTYI3a6Z+2XP2Hfgh9+A6FUOq93IOGj3P4nthB3Xz1943k7CO92/8g1z51MkrzmVsxvNekjaFgOkSmNGmg== +"@pagopa/io-spid-commons@^2.9.0": + version "2.9.0" + resolved "https://npm.pkg.github.com/download/@pagopa/io-spid-commons/2.9.0/15f1cb9049dc3c5070b31d9dd33ce5e3482997da9d0c320d85731e5fb9b38ee9#67144724563b088b5b2cf80d3b45097e92d6d8e1" + integrity sha512-SHBpjHTym/YSXrAsGaMtyDn6gy2yiOtnvvepSZKp8zcnn7SuEUQV7CSlG8lXaQ/xwLqNxMBqhOvUii8gMeHKbw== dependencies: "@types/redis" "^2.8.14" date-fns "^1.30.1" @@ -236,6 +175,7 @@ xml-crypto "^1.4.0" xml2js "^0.4.23" xmldom "^0.1.27" + yargs "^15.3.0" "@sindresorhus/is@^0.14.0": version "0.14.0" @@ -1373,11 +1313,6 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" -clean-stack@^1.3.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31" - integrity sha1-noIVAa6XmYbEax1m0tQy2y/UrjE= - cli-boxes@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-1.0.0.tgz#4fa917c3e59c94a004cd61f8ee509da651687143" @@ -1558,11 +1493,6 @@ commander@^2.12.1, commander@^2.18.0, commander@^2.7.1, commander@^2.9.0, comman resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@~4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068" - integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA== - component-emitter@^1.2.0, component-emitter@^1.2.1: version "1.3.0" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0" @@ -2084,11 +2014,6 @@ double-ended-queue@^2.1.0-0: resolved "https://registry.yarnpkg.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c" integrity sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw= -drange@^1.0.2: - version "1.1.1" - resolved "https://registry.yarnpkg.com/drange/-/drange-1.1.1.tgz#b2aecec2aab82fcef11dbbd7b9e32b83f8f6c0b8" - integrity sha512-pYxfDYpued//QpnLIm4Avk7rsNtAtQkUES2cwAYSvD/wd2pKD71gN2Ebj3e7klzXwjocvE8c5vx/1fxwpqmSxA== - duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" @@ -2487,11 +2412,6 @@ extsprintf@^1.2.0: resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f" integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8= -faker@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f" - integrity sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8= - fast-deep-equal@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4" @@ -2744,15 +2664,6 @@ fs-extra@^6.0.0: jsonfile "^4.0.0" universalify "^0.1.0" -fs-extra@^7.0.0: - version "7.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-7.0.1.tgz#4f189c44aa123b895f722804f55ea23eadc348e9" - integrity sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw== - dependencies: - graceful-fs "^4.1.2" - jsonfile "^4.0.0" - universalify "^0.1.0" - fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -2955,13 +2866,6 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423" integrity sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ== -graphlib@^2.1.8: - version "2.1.8" - resolved "https://registry.yarnpkg.com/graphlib/-/graphlib-2.1.8.tgz#5761d414737870084c92ec7b5dbcb0592c9d35da" - integrity sha512-jcLLfkpoVGmH7/InMC/1hIvOPSUh38oJtGhvrOFGzioE1DZ+0YW16RgmOJhHiuWTvGiJQ9Z1Ik43JvkRPRvE+A== - dependencies: - lodash "^4.17.15" - growly@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" @@ -3277,16 +3181,6 @@ imurmurhash@^0.1.4: resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= -indent-string@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289" - integrity sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok= - -indent-string@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-4.0.0.tgz#624f8f4497d619b2d9768531d58f4122854d7251" - integrity sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg== - inflight@^1.0.4: version "1.0.6" resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" @@ -4203,11 +4097,6 @@ jest@^23.6.0: import-local "^1.0.0" jest-cli "^23.6.0" -js-base64@^2.4.5: - version "2.5.2" - resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.2.tgz#313b6274dda718f714d00b3330bbae6e38e90209" - integrity sha512-Vg8czh0Q7sFBSUMWWArX/miJeBWYBPpdU/3M/DKSaekLMqrqVPaedp+5mZhie/r0lgrcaYBfwXatEew6gwgiQQ== - "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -4218,7 +4107,7 @@ js-tokens@^3.0.2: resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls= -js-yaml@^3.12.0, js-yaml@^3.12.1, js-yaml@^3.13.1, js-yaml@^3.7.0: +js-yaml@^3.12.0, js-yaml@^3.13.1, js-yaml@^3.7.0: version "3.13.1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== @@ -4287,29 +4176,6 @@ json-parse-better-errors@^1.0.1: resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw== -json-refs@^3.0.13, json-refs@^3.0.6: - version "3.0.15" - resolved "https://registry.yarnpkg.com/json-refs/-/json-refs-3.0.15.tgz#1089f4acf263a3152c790479485195cd6449e855" - integrity sha512-0vOQd9eLNBL18EGl5yYaO44GhixmImes2wiYn9Z3sag3QnehWrYWlB9AFtMxCL2Bj3fyxgDYkxGFEU/chlYssw== - dependencies: - commander "~4.1.1" - graphlib "^2.1.8" - js-yaml "^3.13.1" - lodash "^4.17.15" - native-promise-only "^0.8.1" - path-loader "^1.0.10" - slash "^3.0.0" - uri-js "^4.2.2" - -json-schema-faker@^0.5.0-rc16: - version "0.5.0-rc23" - resolved "https://registry.yarnpkg.com/json-schema-faker/-/json-schema-faker-0.5.0-rc23.tgz#f6cfab390e429b1f57ac83199480439db60962fa" - integrity sha512-lRzFEnp55TihRzMvUBrtvTlM/aHGhCwfes0/T9bN9OiB2n36/SUFxtMn7anYoES+f95eU3viJ/foXKosCwsiJw== - dependencies: - json-schema-ref-parser "^6.1.0" - jsonpath-plus "^1.0.0" - randexp "^0.5.3" - json-schema-ref-parser@^5.1.3: version "5.1.3" resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-5.1.3.tgz#f86c5868f40898e69169e1bbc854725a4fd0e1ad" @@ -4320,15 +4186,6 @@ json-schema-ref-parser@^5.1.3: js-yaml "^3.12.0" ono "^4.0.6" -json-schema-ref-parser@^6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-6.1.0.tgz#30af34aeab5bee0431da805dac0eb21b574bf63d" - integrity sha512-pXe9H1m6IgIpXmE5JSb8epilNTGsmTb2iPohAXpOdhqGFbQjNeHHsZxU+C8w6T81GZxSPFLeUoqDJmzxx5IGuw== - dependencies: - call-me-maybe "^1.0.1" - js-yaml "^3.12.1" - ono "^4.0.11" - json-schema-ref-parser@^7.1.0, json-schema-ref-parser@^7.1.3: version "7.1.3" resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-7.1.3.tgz#21468cd180b2f1939ce93fe291f743b441e97d49" @@ -4377,11 +4234,6 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -jsonpath-plus@^1.0.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/jsonpath-plus/-/jsonpath-plus-1.1.0.tgz#7caaea4db88b761a0a3b55d715cb01eaa469dfa5" - integrity sha512-ydqTBOuLcFCUr9e7AxJlKCFgxzEQ03HjnIim0hJSdk2NxD8MOsaMOrRgP6XWEm5q3VuDY5+cRT1DM9vLlGo/qA== - jsonpointer@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/jsonpointer/-/jsonpointer-4.0.1.tgz#4fd92cb34e0e9db3c89c8622ecf51f9b978c6cb9" @@ -4570,11 +4422,6 @@ locate-path@^5.0.0: dependencies: p-locate "^4.1.0" -lodash._reinterpolate@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" - integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0= - lodash.find@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1" @@ -4650,27 +4497,12 @@ lodash.sortby@^4.7.0: resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= -lodash.template@^4.4.0: - version "4.5.0" - resolved "https://registry.yarnpkg.com/lodash.template/-/lodash.template-4.5.0.tgz#f976195cf3f347d0d5f52483569fe8031ccce8ab" - integrity sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A== - dependencies: - lodash._reinterpolate "^3.0.0" - lodash.templatesettings "^4.0.0" - -lodash.templatesettings@^4.0.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz#e481310f049d3cf6d47e912ad09313b154f0fb33" - integrity sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ== - dependencies: - lodash._reinterpolate "^3.0.0" - lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@4.17.15, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.5.0: +lodash@4.17.15, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.5.0: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== @@ -5041,11 +4873,6 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" -native-promise-only@^0.8.1: - version "0.8.1" - resolved "https://registry.yarnpkg.com/native-promise-only/-/native-promise-only-0.8.1.tgz#20a318c30cb45f71fe7adfbf7b21c99c1472ef11" - integrity sha1-IKMYwwy0X3H+et+/eyHJnBRy7xE= - natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -5330,7 +5157,7 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -ono@^4.0.11, ono@^4.0.6: +ono@^4.0.6: version "4.0.11" resolved "https://registry.yarnpkg.com/ono/-/ono-4.0.11.tgz#c7f4209b3e396e8a44ef43b9cedc7f5d791d221d" integrity sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g== @@ -5446,18 +5273,6 @@ os-tmpdir@^1.0.1, os-tmpdir@~1.0.2: resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= -oval@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/oval/-/oval-1.0.0.tgz#37036f82ec2b0a7be91ed8bd8d8016be4586b59e" - integrity sha512-HbGSm0yZ4nTliQnsTzIxM7cnrOJl6bjEVFF0Pwb8aKlcd7GDJIQAk+mxXheh93LGkBx4EuLW9JB67AGNLip4ZQ== - dependencies: - "@oclif/command" "^1.4.35" - "@oclif/config" "^1.6.33" - "@oclif/plugin-help" "^2.0.5" - chalk "^2.4.1" - json-refs "^3.0.6" - sway "^2.0.0" - p-cancelable@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc" @@ -5708,14 +5523,6 @@ path-key@^3.1.0: resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375" integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== -path-loader@^1.0.10: - version "1.0.10" - resolved "https://registry.yarnpkg.com/path-loader/-/path-loader-1.0.10.tgz#dd3d1bd54cb6f2e6423af2ad334a41cc0bce4cf6" - integrity sha512-CMP0v6S6z8PHeJ6NFVyVJm6WyJjIwFvyz2b0n2/4bKdS/0uZa/9sKUlYZzubrn3zuDRU0zIuEDX9DZYQ2ZI8TA== - dependencies: - native-promise-only "^0.8.1" - superagent "^3.8.3" - path-parse@^1.0.5, path-parse@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" @@ -5726,13 +5533,6 @@ path-to-regexp@0.1.7: resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w= -path-to-regexp@^1.7.0: - version "1.8.0" - resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.8.0.tgz#887b3ba9d84393e87a0a0b9f4cb756198b53548a" - integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA== - dependencies: - isarray "0.0.1" - path-type@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" @@ -5950,14 +5750,6 @@ qs@~6.5.2: resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== -randexp@^0.5.3: - version "0.5.3" - resolved "https://registry.yarnpkg.com/randexp/-/randexp-0.5.3.tgz#f31c2de3148b30bdeb84b7c3f59b0ebb9fec3738" - integrity sha512-U+5l2KrcMNOUPYvazA3h5ekF80FHTUG+87SEAmHZmolh1M+i/WyTCxVzmi+tidIa1tM4BSe8g2Y/D3loWDjj+w== - dependencies: - drange "^1.0.2" - ret "^0.2.0" - randomatic@^3.0.0: version "3.1.1" resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" @@ -6346,11 +6138,6 @@ restore-cursor@^3.1.0: onetime "^5.1.0" signal-exit "^3.0.2" -ret@^0.2.0: - version "0.2.2" - resolved "https://registry.yarnpkg.com/ret/-/ret-0.2.2.tgz#b6861782a1f4762dce43402a71eb7a283f44573c" - integrity sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ== - ret@~0.1.10: version "0.1.15" resolved "https://registry.yarnpkg.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" @@ -6859,7 +6646,7 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" -strip-ansi@^5.0.0, strip-ansi@^5.1.0: +strip-ansi@^5.1.0: version "5.2.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-5.2.0.tgz#8c9a536feb6afc962bdfa5b104a5091c1ad9c0ae" integrity sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA== @@ -6971,7 +6758,7 @@ swagger-cli@^2.3.1: swagger-parser "^8.0.4" yargs "^15.0.2" -swagger-methods@^1.0.0, swagger-methods@^1.0.4: +swagger-methods@^1.0.4: version "1.0.8" resolved "https://registry.yarnpkg.com/swagger-methods/-/swagger-methods-1.0.8.tgz#8baf37ee861d3c72ff7b2faad6d74c60b336e2ed" integrity sha512-G6baCwuHA+C5jf4FNOrosE4XlmGsdjbOjdBK4yuiDDj/ro9uR4Srj3OR84oQMT8F3qKp00tYNv0YN730oTHPZA== @@ -7027,24 +6814,6 @@ swagger-schema-official@2.0.0-bab6bed: resolved "https://registry.yarnpkg.com/swagger-schema-official/-/swagger-schema-official-2.0.0-bab6bed.tgz#70070468d6d2977ca5237b2e519ca7d06a2ea3fd" integrity sha1-cAcEaNbSl3ylI3suUZyn0Gouo/0= -sway@^2.0.0: - version "2.0.6" - resolved "https://registry.yarnpkg.com/sway/-/sway-2.0.6.tgz#57e730c7289c4d58a294481f63c8ad0c686155bc" - integrity sha512-0HRT2WuU44XIdq+eCiMx67Bl/kiEKORP+4j+Wt89rFjoR5Dwx2hmU4PkMA6hnd48XLfS50olIac3pQGrV/wv7w== - dependencies: - debug "^3.1.0" - faker "^4.1.0" - js-base64 "^2.4.5" - js-yaml "^3.13.1" - json-refs "^3.0.13" - json-schema-faker "^0.5.0-rc16" - lodash "^4.17.10" - native-promise-only "^0.8.1" - path-to-regexp "^1.7.0" - swagger-methods "^1.0.0" - swagger-schema-official "2.0.0-bab6bed" - z-schema "^3.22.0" - symbol-tree@^3.2.2: version "3.2.4" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" @@ -7218,7 +6987,7 @@ tslib@1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.0.tgz#e37a86fda8cbbaf23a057f473c9f4dc64e5fc2e8" integrity sha512-f/qGG2tUkrISBlQZEjEqoZ3B2+npJjIf04H1wuAv9iA8i04Icp+61KRXxFdha22670NJopsZCIjhC3SnjPRKrQ== -tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.11.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.11.1.tgz#eb15d128827fbee2841549e171f45ed338ac7e35" integrity sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA== @@ -7715,7 +7484,7 @@ which@^2.0.1: dependencies: isexe "^2.0.0" -widest-line@^2.0.0, widest-line@^2.0.1: +widest-line@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/widest-line/-/widest-line-2.0.1.tgz#7438764730ec7ef4381ce4df82fb98a53142a3fc" integrity sha512-Ba5m9/Fa4Xt9eb2ELXt77JxVDV8w7qQrH0zS/TWSJdLyAwQjWoOzpzj5lwVftDz6n/EOu3tNACS84v509qwnJA== @@ -7795,15 +7564,6 @@ wrap-ansi@^2.0.0: string-width "^1.0.1" strip-ansi "^3.0.1" -wrap-ansi@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-4.0.0.tgz#b3570d7c70156159a2d42be5cc942e957f7b1131" - integrity sha512-uMTsj9rDb0/7kk1PbcbCcwvHUxp60fGDB/NNXpVa0Q+ic/e7y5+BwTxKfQ33VYgDppSwi/FBzpetYzo8s6tfbg== - dependencies: - ansi-styles "^3.2.0" - string-width "^2.1.1" - strip-ansi "^4.0.0" - wrap-ansi@^6.2.0: version "6.2.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" @@ -7959,6 +7719,14 @@ yargs-parser@^16.1.0: camelcase "^5.0.0" decamelize "^1.2.0" +yargs-parser@^18.1.0: + version "18.1.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.0.tgz#1b0ab1118ebd41f68bb30e729f4c83df36ae84c3" + integrity sha512-o/Jr6JBOv6Yx3pL+5naWSoIA2jJ+ZkMYQG/ie9qFbukBe4uzmBatlXFOiu/tNKRWEtyf+n5w7jc/O16ufqOTdQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + yargs-parser@^9.0.2: version "9.0.2" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-9.0.2.tgz#9ccf6a43460fe4ed40a9bb68f48d43b8a68cc077" @@ -8001,6 +7769,23 @@ yargs@^15.0.2: y18n "^4.0.0" yargs-parser "^16.1.0" +yargs@^15.3.0: + version "15.3.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.3.0.tgz#403af6edc75b3ae04bf66c94202228ba119f0976" + integrity sha512-g/QCnmjgOl1YJjGsnUg2SatC7NUYEiLXJqxNOQU9qSpjzGtGXda9b+OKccr1kLTy8BN9yqEyqfq5lxlwdc13TA== + dependencies: + cliui "^6.0.0" + decamelize "^1.2.0" + find-up "^4.1.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^4.2.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^18.1.0" + yargs@^3.32.0: version "3.32.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.32.0.tgz#03088e9ebf9e756b69751611d2a5ef591482c995" @@ -8019,7 +7804,7 @@ yn@^2.0.0: resolved "https://registry.yarnpkg.com/yn/-/yn-2.0.0.tgz#e5adabc8acf408f6385fc76495684c88e6af689a" integrity sha1-5a2ryKz0CPY4X8dklWhMiOavaJo= -z-schema@^3.22.0, z-schema@^3.23.0: +z-schema@^3.23.0: version "3.25.1" resolved "https://registry.yarnpkg.com/z-schema/-/z-schema-3.25.1.tgz#7e14663be2b96003d938a56f644fb8561643fb7e" integrity sha512-7tDlwhrBG+oYFdXNOjILSurpfQyuVgkRe3hB2q8TEssamDHB7BbLWYkYO98nTn0FibfdFroFKDjndbgufAgS/Q== From 1da4e942bd7ccd2847ae7ee19a7f614c27c93280 Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 13:29:55 +0100 Subject: [PATCH 2/6] [#171703313] Shutdown the program if no one idp is configured --- src/__tests__/app.test.ts | 35 ++++++++++++++++++++++++++++++ src/app.ts | 45 ++++++++++++++++++++++----------------- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/__tests__/app.test.ts b/src/__tests__/app.test.ts index dbb1b0184..c3ffba93e 100644 --- a/src/__tests__/app.test.ts +++ b/src/__tests__/app.test.ts @@ -1,5 +1,8 @@ +import * as spid from "@pagopa/io-spid-commons/dist/utils/metadata"; import { Express } from "express"; import { isRight } from "fp-ts/lib/Either"; +import { Task } from "fp-ts/lib/Task"; +import * as TE from "fp-ts/lib/TaskEither"; import { NodeEnvironmentEnum } from "italia-ts-commons/lib/environment"; import { ResponseSuccessJson } from "italia-ts-commons/lib/responses"; import { CIDR } from "italia-ts-commons/lib/strings"; @@ -119,3 +122,35 @@ describe("Success app start", () => { }); }); }); + +describe("Failure app start", () => { + let app: Express | undefined; + afterAll(() => { + jest.restoreAllMocks(); + app?.emit("server:stop"); + }); + + it("Close app if download IDP metadata fails on startup", async () => { + // Override return value of generateSpidStrategy with a rejected promise. + const mockFetchIdpsMetadata = jest + .spyOn(spid, "fetchIdpsMetadata") + .mockImplementation(() => { + return TE.left( + new Task(async () => new Error("Error download metadata")) + ); + }); + const mockExit = jest + .spyOn(process, "exit") + .mockImplementation(() => true as never); + app = await appModule.newApp( + NodeEnvironmentEnum.PRODUCTION, + aValidCIDR, + aValidCIDR, + "", + "/api/v1", + "/pagopa/api/v1" + ); + expect(mockFetchIdpsMetadata).toBeCalledTimes(3); + expect(mockExit).toBeCalledWith(1); + }); +}); diff --git a/src/app.ts b/src/app.ts index 65d23d625..1965830ae 100644 --- a/src/app.ts +++ b/src/app.ts @@ -56,8 +56,9 @@ import { } from "./utils/package"; import { withSpid } from "@pagopa/io-spid-commons"; -import { toError } from "fp-ts/lib/Either"; -import { tryCatch } from "fp-ts/lib/TaskEither"; +import { getSpidStrategyOption } from "@pagopa/io-spid-commons/dist/utils/middleware"; +import { StrMap } from "fp-ts/lib/StrMap"; +import { Task } from "fp-ts/lib/Task"; import { VersionPerPlatform } from "../generated/public/VersionPerPlatform"; import UserDataProcessingController from "./controllers/userDataProcessingController"; import MessagesService from "./services/messagesService"; @@ -170,7 +171,7 @@ export function newApp( // Setup routes // - return tryCatch(async () => { + return new Task(async () => { // Ceate the Token Service const TOKEN_SERVICE = new TokenService(); @@ -221,20 +222,16 @@ export function newApp( PROFILE_SERVICE ); return { app, acsController }; - }, toError) + }) .chain(_ => - tryCatch( - async () => - withSpid( - appConfig, - samlConfig, - serviceProviderConfig, - REDIS_CLIENT, - _.app, - _.acsController.acs.bind(_.acsController), - _.acsController.slo.bind(_.acsController) - ).run(), - toError + withSpid( + appConfig, + samlConfig, + serviceProviderConfig, + REDIS_CLIENT, + _.app, + _.acsController.acs.bind(_.acsController), + _.acsController.slo.bind(_.acsController) ) ) .map(_ => { @@ -242,9 +239,19 @@ export function newApp( _.app.on("server:stop", () => clearInterval(idpMetadataRefreshTimer)); return _.app; }) - .getOrElseL(err => { - log.error("Fatal error during Express initialization: %s", err); - process.exit(1); + .map(_ => { + const spidStrategyOption = getSpidStrategyOption(_); + // If no one idp is configured the program execution will be stopped + if ( + !spidStrategyOption?.idp || + new StrMap(spidStrategyOption?.idp).reduce(true, () => false) + ) { + log.error( + "Fatal error during Express configuation. No one IDP available." + ); + process.exit(1); + } + return _; }) .run(); } From b8e835b6338e08765b70965335a5d07290c5a21e Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 13:58:18 +0100 Subject: [PATCH 3/6] Fix comment text Co-Authored-By: Danilo Spinelli --- src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 1965830ae..0b04e78f0 100644 --- a/src/app.ts +++ b/src/app.ts @@ -241,7 +241,7 @@ export function newApp( }) .map(_ => { const spidStrategyOption = getSpidStrategyOption(_); - // If no one idp is configured the program execution will be stopped + // Process ends in case no IDP is configured if ( !spidStrategyOption?.idp || new StrMap(spidStrategyOption?.idp).reduce(true, () => false) From d875c26fb319c644d8ffbf862a10000668eb58a7 Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 13:58:44 +0100 Subject: [PATCH 4/6] Fix error log text Co-Authored-By: Danilo Spinelli --- src/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 0b04e78f0..832edebf4 100644 --- a/src/app.ts +++ b/src/app.ts @@ -247,7 +247,7 @@ export function newApp( new StrMap(spidStrategyOption?.idp).reduce(true, () => false) ) { log.error( - "Fatal error during Express configuation. No one IDP available." + "Fatal error during application start. Cannot get IDPs metadata." ); process.exit(1); } From 53626f287569b72eaa514a1707453e170bd7de1c Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 14:03:51 +0100 Subject: [PATCH 5/6] [#171703313] Add README info for new ENV --- README.md | 1 + src/app.ts | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b0baa0aba..b9835e4eb 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,7 @@ Those are all Environment variables needed by the application: | PAGOPA_API_URL_TEST | The url for the PagoPA api endpoints in test mode | string | | PAGOPA_BASE_PATH | The root path for the PagoPA endpoints | string | | SPID_AUTOLOGIN | The user used in the autologin feature, omit this to disable autologin | string | +| STARTUP_IDPS_METADATA | Stringified JSON containing idps metadata `Record` | string | | CIE_METADATA_URL | Url to download CIE metadata from | string | | IDP_METADATA_URL | Url to download IDP metadata from | string | | IDP_METADATA_REFRESH_INTERVAL_SECONDS | The number of seconds when the IDPs Metadata are refreshed | int | diff --git a/src/app.ts b/src/app.ts index 1965830ae..2a07db4be 100644 --- a/src/app.ts +++ b/src/app.ts @@ -242,10 +242,7 @@ export function newApp( .map(_ => { const spidStrategyOption = getSpidStrategyOption(_); // If no one idp is configured the program execution will be stopped - if ( - !spidStrategyOption?.idp || - new StrMap(spidStrategyOption?.idp).reduce(true, () => false) - ) { + if (new StrMap(spidStrategyOption?.idp || {}).reduce(true, () => false)) { log.error( "Fatal error during Express configuation. No one IDP available." ); From ee660bf1b47fedcff5b366e88afdab58cec79ffa Mon Sep 17 00:00:00 2001 From: Daniele Manni Date: Tue, 10 Mar 2020 14:16:06 +0100 Subject: [PATCH 6/6] [#171703313] More readable condition for empty object check --- src/app.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index 75c01ea83..3a559728f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -57,7 +57,7 @@ import { import { withSpid } from "@pagopa/io-spid-commons"; import { getSpidStrategyOption } from "@pagopa/io-spid-commons/dist/utils/middleware"; -import { StrMap } from "fp-ts/lib/StrMap"; +import { isEmpty, StrMap } from "fp-ts/lib/StrMap"; import { Task } from "fp-ts/lib/Task"; import { VersionPerPlatform } from "../generated/public/VersionPerPlatform"; import UserDataProcessingController from "./controllers/userDataProcessingController"; @@ -242,7 +242,7 @@ export function newApp( .map(_ => { const spidStrategyOption = getSpidStrategyOption(_); // Process ends in case no IDP is configured - if (new StrMap(spidStrategyOption?.idp || {}).reduce(true, () => false)) { + if (isEmpty(new StrMap(spidStrategyOption?.idp || {}))) { log.error( "Fatal error during application start. Cannot get IDPs metadata." );