Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#IP-339] Migrate fp-ts version from 1.x to 2.x #91

Merged
merged 31 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4d83d41
update saml.ts
fabriziopapi Sep 10, 2021
8082643
update example.ts
fabriziopapi Sep 10, 2021
e6928a9
update IDPEntityDescriptor.ts
fabriziopapi Sep 10, 2021
794622a
update index.ts
fabriziopapi Sep 10, 2021
45bf42b
update metadata.ts
fabriziopapi Sep 10, 2021
2101e7d
update middleware.ts
fabriziopapi Sep 10, 2021
995a90a
update package.json
fabriziopapi Sep 10, 2021
6b4dd83
update redis_cache_provider.ts
fabriziopapi Sep 10, 2021
8a58ca7
update response.ts
fabriziopapi Sep 10, 2021
28269de
update saml_client.ts
fabriziopapi Sep 10, 2021
acfe249
update spid.ts
fabriziopapi Sep 10, 2021
ca27802
update startup-idps-metadata.ts
fabriziopapi Sep 10, 2021
66924fb
fixed wrong "not reachable" left test case
fabriziopapi Sep 10, 2021
4ed4e18
fixed duplicated import
fabriziopapi Sep 10, 2021
3b6cb69
add "do notation" to remove boilerplate
fabriziopapi Sep 10, 2021
f0c39f4
fixed duplicated Task import
fabriziopapi Sep 10, 2021
dc67a68
fixed deprecated task use
fabriziopapi Sep 10, 2021
82ae91f
fixed step-functions naming convetion
fabriziopapi Sep 10, 2021
dae51d1
fixed step-functions naming convetion
fabriziopapi Sep 10, 2021
622afc1
fixed wrong error message
fabriziopapi Sep 10, 2021
51db11a
Merge branch 'IP-339--migrate-fp-ts-version' of https://github.com/pa…
fabriziopapi Sep 10, 2021
6f9690c
fixed depracated predicate
fabriziopapi Sep 10, 2021
990efcc
fixed lint issues
fabriziopapi Sep 10, 2021
c679b64
fixed duplicated import
fabriziopapi Sep 16, 2021
ea43292
revert 'update saml.ts'
fabriziopapi Sep 16, 2021
4554cb4
duplicate saml.ts to samlUtils.ts
fabriziopapi Sep 16, 2021
fa566ca
restore saml.ts post duplicate
fabriziopapi Sep 16, 2021
c41beac
Merge branch 'IP-339-migrate-fp-ts-version-for-duplicate' into HEAD
fabriziopapi Sep 16, 2021
7e83fd9
update saml.ts (with history)
fabriziopapi Sep 16, 2021
545f9e5
fixed legacy "enumarted" type for validation chain
fabriziopapi Sep 16, 2021
a8547c1
refactored 'trim' call in chain to better readibility
fabriziopapi Sep 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
"typescript": "^3.7.0"
},
"dependencies": {
"@pagopa/ts-commons": "^10.0.0",
"@types/redis": "^2.8.14",
"date-fns": "^1.30.1",
"fp-ts": "1.17.0",
"io-ts": "1.8.5",
"io-ts-types": "^0.4.7",
"italia-ts-commons": "^5.1.4",
"fp-ts": "^2.11.1",
"io-ts": "^2.2.16",
"io-ts-types": "^0.5.16",
"node-fetch": "^2.2.0",
"node-forge": "^0.10.0",
"passport": "^0.4.1",
Expand All @@ -85,9 +85,6 @@
"preset": "ts-jest",
"testMatch": null
},
"resolutions": {
"fp-ts": "1.17.0"
},
"bugs": {
"url": "https://github.com/pagopa/io-spid-commons/issues"
},
Expand Down
3 changes: 2 additions & 1 deletion src/__mocks__/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { IDPEntityDescriptor } from "../types/IDPEntityDescriptor";

import { NonEmptyArray } from "fp-ts/lib/NonEmptyArray";

import { NonEmptyString } from "italia-ts-commons/lib/strings";
// tslint:disable-next-line: no-submodule-imports
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";

export const mockIdpMetadata: Record<string, IDPEntityDescriptor> = {
intesaid: {
Expand Down
9 changes: 5 additions & 4 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// tslint:disable-next-line: no-submodule-imports
import { ResponsePermanentRedirect } from "@pagopa/ts-commons/lib/responses";
import * as express from "express";
import { left, right } from "fp-ts/lib/Either";
import { fromEither } from "fp-ts/lib/TaskEither";
import { ResponsePermanentRedirect } from "italia-ts-commons/lib/responses";
import { createMockRedis } from "mock-redis-client";
import { RedisClient } from "redis";
import * as request from "supertest";
Expand Down Expand Up @@ -178,15 +179,15 @@ describe("io-spid-commons withSpid", () => {
app,
acs: async () => ResponsePermanentRedirect({ href: "/success?acs" }),
logout: async () => ResponsePermanentRedirect({ href: "/success?logout" })
}).run();
})();
expect(mockFetchIdpsMetadata).toBeCalledTimes(3);
const emptySpidStrategyOption = getSpidStrategyOption(spid.app);
expect(emptySpidStrategyOption).toHaveProperty("idp", {});

jest.resetAllMocks();

initMockFetchIDPMetadata();
await spid.idpMetadataRefresher().run();
await spid.idpMetadataRefresher()();
expect(mockFetchIdpsMetadata).toHaveBeenNthCalledWith(
1,
IDPMetadataUrl,
Expand Down Expand Up @@ -221,7 +222,7 @@ describe("io-spid-commons withSpid", () => {
app,
acs: async () => ResponsePermanentRedirect({ href: "/success?acs" }),
logout: async () => ResponsePermanentRedirect({ href: "/success?logout" })
}).run();
})();
return request(spid.app)
.get(`${appConfig.loginPath}?authLevel=SpidL1`)
.expect(400);
Expand Down
86 changes: 48 additions & 38 deletions src/bin/startup-idps-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env node

import { array } from "fp-ts/lib/Array";
import { fromNullable } from "fp-ts/lib/Option";
import { task } from "fp-ts/lib/Task";
import * as AP from "fp-ts/lib/Apply";
import * as A from "fp-ts/lib/Array";
import { pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import * as T from "fp-ts/lib/Task";
import * as TE from "fp-ts/lib/TaskEither";
import * as yargs from "yargs";
import { logger } from "../utils/logger";
import { fetchMetadataXML } from "../utils/metadata";
Expand Down Expand Up @@ -44,44 +47,51 @@ function printIdpsMetadata(
): Promise<IIDPSMetadataXML> {
// tslint:disable: no-object-mutation no-any no-empty
logger.info = (): any => {};
const maybeIdpsMetadataURL = fromNullable(idpsMetadataENV)
.mapNullable(_ => process.env[_])
.map((_: string) =>
fetchMetadataXML(_)
.map<{ idps?: string }>(_1 => ({
idps: _1
}))
.getOrElse({})
)
.getOrElse(task.of({}));
const maybeTestEnvMetadataURL = fromNullable(testEnv2MetadataENV)
.mapNullable(_ => process.env[_])
.map((_: string) =>
fetchMetadataXML(`${_}/metadata`)
.map<{ xx_testenv2?: string }>(_1 => ({
xx_testenv2: _1
}))
.getOrElse({})
)
.getOrElse(task.of({}));
const maybeCIEMetadataURL = fromNullable(cieMetadataENV)
.mapNullable(_ => process.env[_])
.map((_: string) =>
fetchMetadataXML(_)
.map<{ xx_servizicie?: string }>(_1 => ({
xx_servizicie: _1
}))
.getOrElse({})
)
.getOrElse(task.of({}));
return array
.sequence(task)<IIDPSMetadataXML>([
const maybeIdpsMetadataURL = pipe(
O.fromNullable(idpsMetadataENV),
O.chainNullableK(_ => process.env[_]),
O.map((_: string) =>
pipe(
TE.Do,
TE.bind("idps", () => fetchMetadataXML(_)),
TE.getOrElseW(() => T.of({}))
)
),
O.getOrElseW(() => T.of({}))
);
const maybeTestEnvMetadataURL = pipe(
O.fromNullable(testEnv2MetadataENV),
O.chainNullableK(_ => process.env[_]),
O.map((_: string) =>
pipe(
TE.Do,
TE.bind("xx_testenv2", () => fetchMetadataXML(`${_}/metadata`)),
TE.getOrElseW(() => T.of({}))
)
),
O.getOrElseW(() => T.of({}))
);
const maybeCIEMetadataURL = pipe(
O.fromNullable(cieMetadataENV),
O.chainNullableK(_ => process.env[_]),
O.map((_: string) =>
pipe(
TE.Do,
TE.bind("xx_servizicie", () => fetchMetadataXML(_)),
TE.getOrElseW(() => T.of({}))
)
),
O.getOrElseW(() => T.of({}))
);
return pipe(
AP.sequenceT(T.ApplicativePar)(
maybeIdpsMetadataURL,
maybeTestEnvMetadataURL,
maybeCIEMetadataURL
])
.map(_ => _.reduce((prev, current) => ({ ...prev, ...current }), {}))
.run();
),
// tslint:disable-next-line: no-inferred-empty-object-type
T.map(A.reduce({}, (prev, current) => ({ ...prev, ...current })))
)();
}

printIdpsMetadata(
Expand Down
43 changes: 24 additions & 19 deletions src/example.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import * as bodyParser from "body-parser";
import * as express from "express";
import * as fs from "fs";
import * as t from "io-ts";
import { ResponsePermanentRedirect } from "italia-ts-commons/lib/responses";
// tslint:disable-next-line: no-submodule-imports
import { ResponsePermanentRedirect } from "@pagopa/ts-commons/lib/responses";
import {
EmailString,
FiscalCode,
NonEmptyString
} from "italia-ts-commons/lib/strings";
// tslint:disable-next-line: no-submodule-imports
} from "@pagopa/ts-commons/lib/strings";
import * as bodyParser from "body-parser";
import * as express from "express";
import { pipe } from "fp-ts/lib/function";
import * as T from "fp-ts/lib/Task";
import * as fs from "fs";
import * as t from "io-ts";
import passport = require("passport");
import { SamlConfig } from "passport-saml";
import * as redis from "redis";
Expand Down Expand Up @@ -152,17 +156,18 @@ const doneCb = (ip: string | null, request: string, response: string) => {
console.log(response);
};

withSpid({
acs,
app,
appConfig,
doneCb,
logout,
redisClient,
samlConfig,
serviceProviderConfig
})
.map(({ app: withSpidApp, idpMetadataRefresher }) => {
pipe(
withSpid({
acs,
app,
appConfig,
doneCb,
logout,
redisClient,
samlConfig,
serviceProviderConfig
}),
T.map(({ app: withSpidApp, idpMetadataRefresher }) => {
withSpidApp.get("/success", (_, res) =>
res.json({
success: "success"
Expand All @@ -176,7 +181,7 @@ withSpid({
.status(400)
);
withSpidApp.get("/refresh", async (_, res) => {
await idpMetadataRefresher().run();
await idpMetadataRefresher()();
res.json({
metadataUpdate: "completed"
});
Expand All @@ -194,6 +199,6 @@ withSpid({
);
withSpidApp.listen(3000);
})
.run()
)()
// tslint:disable-next-line: no-console
.catch(e => console.error("Application error: ", e));
Loading