From e53a0934d3e6326c08a06d5ff44788cb8481f260 Mon Sep 17 00:00:00 2001 From: Thomas McGowan Date: Wed, 18 May 2022 07:45:15 +0100 Subject: [PATCH] VB-807: updates from template app (#184) * Fix query string warning From https://github.com/ministryofjustice/hmpps-template-typescript/pull/87 * Remove stray @types/cookie-session dev dependency * Tidy up mocks and switch to multiplatform builds From https://github.com/ministryofjustice/hmpps-template-typescript/pull/89 * Allow async get to take an array of path strings From https://github.com/ministryofjustice/hmpps-template-typescript/pull/90 * Switch to using AppInsights connection string From https://github.com/ministryofjustice/hmpps-template-typescript/pull/91 --- .circleci/config.yml | 6 ++-- docker-compose-test.yml | 6 ++-- .../book-a-prison-visit-staff-ui/values.yaml | 1 + integration_tests/mockApis/auth.ts | 4 +-- .../mockApis/tokenVerification.ts | 14 ++++---- integration_tests/plugins/index.ts | 10 ++---- package-lock.json | 33 ------------------- package.json | 1 - server/data/hmppsAuthClient.ts | 23 +++++++------ server/routes/index.ts | 2 +- 10 files changed, 28 insertions(+), 72 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7132f765..f3706d42 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,7 @@ feature_branch: &feature_branch version: 2.1 orbs: - hmpps: ministryofjustice/hmpps@3.14 + hmpps: ministryofjustice/hmpps@5.1 slack: circleci/slack@4.4.2 parameters: @@ -105,7 +105,7 @@ jobs: integration_test: executor: - name: hmpps/node_redis_cimg + name: hmpps/node_redis node_tag: << pipeline.parameters.node-version >> redis_tag: "6.2" steps: @@ -157,7 +157,7 @@ workflows: - build - hmpps/helm_lint: name: helm_lint - - hmpps/build_docker: + - hmpps/build_multiplatform_docker: name: build_docker - request_dev_approval: <<: *feature_branch diff --git a/docker-compose-test.yml b/docker-compose-test.yml index 16192a00..7a9c5dad 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -2,16 +2,14 @@ version: '3.1' services: redis: - image: 'bitnami/redis:5.0' + image: 'redis:6.2' networks: - hmpps_int - environment: - - ALLOW_EMPTY_PASSWORD=yes ports: - '6379:6379' wiremock: - image: rodolpheche/wiremock + image: wiremock/wiremock networks: - hmpps_int container_name: wiremock diff --git a/helm_deploy/book-a-prison-visit-staff-ui/values.yaml b/helm_deploy/book-a-prison-visit-staff-ui/values.yaml index 19c89090..ffd5034b 100644 --- a/helm_deploy/book-a-prison-visit-staff-ui/values.yaml +++ b/helm_deploy/book-a-prison-visit-staff-ui/values.yaml @@ -27,6 +27,7 @@ generic-service: NODE_ENV: "production" REDIS_TLS_ENABLED: "true" TOKEN_VERIFICATION_ENABLED: "true" + APPLICATIONINSIGHTS_CONNECTION_STRING: "InstrumentationKey=$(APPINSIGHTS_INSTRUMENTATIONKEY);IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/;LiveEndpoint=https://northeurope.livediagnostics.monitor.azure.com/" # Pre-existing kubernetes secrets to load as environment variables in the deployment. # namespace_secrets: diff --git a/integration_tests/mockApis/auth.ts b/integration_tests/mockApis/auth.ts index cb5fdf9b..bbf81eb1 100644 --- a/integration_tests/mockApis/auth.ts +++ b/integration_tests/mockApis/auth.ts @@ -157,8 +157,8 @@ const stubUserRoles = () => export default { getSignInUrl, - stubPing: (): Promise<[Response, Response]> => Promise.all([ping(), tokenVerification.stubPing()]), + stubAuthPing: ping, stubSignIn: (): Promise<[Response, Response, Response, Response, Response, Response]> => Promise.all([favicon(), redirect(), signOut(), manageDetails(), token(), tokenVerification.stubVerifyToken()]), - stubUser: (): Promise<[Response, Response]> => Promise.all([stubUser(), stubUserRoles()]), + stubAuthUser: (): Promise<[Response, Response]> => Promise.all([stubUser(), stubUserRoles()]), } diff --git a/integration_tests/mockApis/tokenVerification.ts b/integration_tests/mockApis/tokenVerification.ts index 192a17c1..1b23fcaa 100644 --- a/integration_tests/mockApis/tokenVerification.ts +++ b/integration_tests/mockApis/tokenVerification.ts @@ -2,8 +2,8 @@ import { SuperAgentRequest } from 'superagent' import { stubFor } from './wiremock' export default { - stubPing: (): SuperAgentRequest => { - return stubFor({ + stubTokenVerificationPing: (): SuperAgentRequest => + stubFor({ request: { method: 'GET', urlPattern: '/verification/health/ping', @@ -13,10 +13,9 @@ export default { headers: { 'Content-Type': 'application/json;charset=UTF-8' }, jsonBody: { status: 'UP' }, }, - }) - }, - stubVerifyToken: (): SuperAgentRequest => { - return stubFor({ + }), + stubVerifyToken: (): SuperAgentRequest => + stubFor({ request: { method: 'POST', urlPattern: '/verification/token/verify', @@ -26,6 +25,5 @@ export default { headers: { 'Content-Type': 'application/json;charset=UTF-8' }, jsonBody: { active: 'true' }, }, - }) - }, + }), } diff --git a/integration_tests/plugins/index.ts b/integration_tests/plugins/index.ts index 061d2874..6d4b7ef2 100644 --- a/integration_tests/plugins/index.ts +++ b/integration_tests/plugins/index.ts @@ -14,14 +14,8 @@ import { Visit } from '../../server/data/visitSchedulerApiTypes' export default (on: (string, Record) => void): void => { on('task', { reset: resetStubs, - - getSignInUrl: auth.getSignInUrl, - stubSignIn: auth.stubSignIn, - - stubAuthUser: auth.stubUser, - stubAuthPing: auth.stubPing, - - stubTokenVerificationPing: tokenVerification.stubPing, + ...auth, + ...tokenVerification, stubGetPrisonerSocialContacts: (offenderNo: string) => prisonerContactRegistry.getPrisonerSocialContacts(offenderNo), diff --git a/package-lock.json b/package-lock.json index 15560f54..3dceeebf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,6 @@ "@types/compression": "^1.7.2", "@types/connect-flash": "0.0.37", "@types/connect-redis": "^0.0.18", - "@types/cookie-session": "^2.0.44", "@types/csurf": "^1.11.2", "@types/express-session": "^1.17.4", "@types/http-errors": "^1.8.2", @@ -2805,16 +2804,6 @@ "@types/redis": "^2.8.0" } }, - "node_modules/@types/cookie-session": { - "version": "2.0.44", - "resolved": "https://registry.npmjs.org/@types/cookie-session/-/cookie-session-2.0.44.tgz", - "integrity": "sha512-3DheOZ41pql6raSIkqEPphJdhA2dX2bkS+s2Qacv8YMKkoCbAIEXbsDil7351ARzMqvfyDUGNeHGiRZveIzhqQ==", - "dev": true, - "dependencies": { - "@types/express": "*", - "@types/keygrip": "*" - } - }, "node_modules/@types/cookiejar": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", @@ -2941,12 +2930,6 @@ "@types/node": "*" } }, - "node_modules/@types/keygrip": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.2.tgz", - "integrity": "sha512-GJhpTepz2udxGexqos8wgaBx4I/zWIDPh/KOGEwAqtuGDkOUJu5eFvwmdBX4AmB8Odsr+9pHCQqiAqDL/yKMKw==", - "dev": true - }, "node_modules/@types/mime": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", @@ -15250,16 +15233,6 @@ "@types/redis": "^2.8.0" } }, - "@types/cookie-session": { - "version": "2.0.44", - "resolved": "https://registry.npmjs.org/@types/cookie-session/-/cookie-session-2.0.44.tgz", - "integrity": "sha512-3DheOZ41pql6raSIkqEPphJdhA2dX2bkS+s2Qacv8YMKkoCbAIEXbsDil7351ARzMqvfyDUGNeHGiRZveIzhqQ==", - "dev": true, - "requires": { - "@types/express": "*", - "@types/keygrip": "*" - } - }, "@types/cookiejar": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@types/cookiejar/-/cookiejar-2.1.2.tgz", @@ -15386,12 +15359,6 @@ "@types/node": "*" } }, - "@types/keygrip": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.2.tgz", - "integrity": "sha512-GJhpTepz2udxGexqos8wgaBx4I/zWIDPh/KOGEwAqtuGDkOUJu5eFvwmdBX4AmB8Odsr+9pHCQqiAqDL/yKMKw==", - "dev": true - }, "@types/mime": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", diff --git a/package.json b/package.json index 4fb6c377..047b80f1 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,6 @@ "@types/compression": "^1.7.2", "@types/connect-flash": "0.0.37", "@types/connect-redis": "^0.0.18", - "@types/cookie-session": "^2.0.44", "@types/csurf": "^1.11.2", "@types/express-session": "^1.17.4", "@types/http-errors": "^1.8.2", diff --git a/server/data/hmppsAuthClient.ts b/server/data/hmppsAuthClient.ts index b11f5453..2b90ea2e 100644 --- a/server/data/hmppsAuthClient.ts +++ b/server/data/hmppsAuthClient.ts @@ -1,7 +1,7 @@ import superagent from 'superagent' -import querystring from 'querystring' -import type TokenStore from './tokenStore' +import { URLSearchParams } from 'url' +import type TokenStore from './tokenStore' import logger from '../../logger' import config from '../config' import generateOauthClientToken from '../authentication/clientCredentials' @@ -16,19 +16,18 @@ function getSystemClientTokenFromHmppsAuth(username?: string): Promise { logger.info(`Getting user details: calling HMPPS Auth`) - return this.restClient(token).get({ path: '/api/user/me' }) as Promise + return HmppsAuthClient.restClient(token).get({ path: '/api/user/me' }) as Promise } getUserRoles(token: string): Promise { - return this.restClient(token) + return HmppsAuthClient.restClient(token) .get({ path: '/api/user/me/roles' }) .then(roles => (roles).map(role => role.roleCode)) as Promise } diff --git a/server/routes/index.ts b/server/routes/index.ts index 467d6c60..b30a2783 100644 --- a/server/routes/index.ts +++ b/server/routes/index.ts @@ -3,7 +3,7 @@ import type { RequestHandler, Router } from 'express' import asyncMiddleware from '../middleware/asyncMiddleware' export default function routes(router: Router): Router { - const get = (path: string, handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) + const get = (path: string | string[], handler: RequestHandler) => router.get(path, asyncMiddleware(handler)) get('/', (req, res, next) => { res.render('pages/index')