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

VB-807: updates from template app #184

Merged
merged 5 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ feature_branch: &feature_branch
version: 2.1

orbs:
hmpps: ministryofjustice/hmpps@3.14
hmpps: ministryofjustice/hmpps@5.1
slack: circleci/[email protected]

parameters:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/book-a-prison-visit-staff-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised this doesn't seem to be used anywhere? All the files are still using APPINSIGHTS_INSTRUMENTATIONKEY? Not sure if that's right or not.


# Pre-existing kubernetes secrets to load as environment variables in the deployment.
# namespace_secrets:
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/mockApis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]),
}
14 changes: 6 additions & 8 deletions integration_tests/mockApis/tokenVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -26,6 +25,5 @@ export default {
headers: { 'Content-Type': 'application/json;charset=UTF-8' },
jsonBody: { active: 'true' },
},
})
},
}),
}
10 changes: 2 additions & 8 deletions integration_tests/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
33 changes: 0 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 11 additions & 12 deletions server/data/hmppsAuthClient.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -16,19 +16,18 @@ function getSystemClientTokenFromHmppsAuth(username?: string): Promise<superagen
config.apis.hmppsAuth.systemClientSecret
)

const authRequest = username
? querystring.stringify({ grant_type: 'client_credentials', username })
: querystring.stringify({ grant_type: 'client_credentials' })
const grantRequest = new URLSearchParams({
grant_type: 'client_credentials',
...(username && { username }),
}).toString()

logger.info(
`HMPPS Auth request '${authRequest}' for client id '${config.apis.hmppsAuth.systemClientId}' and user '${username}'`
)
logger.info(`${grantRequest} HMPPS Auth request for client id '${config.apis.hmppsAuth.systemClientId}''`)

return superagent
.post(`${hmppsAuthUrl}/oauth/token`)
.set('Authorization', clientToken)
.set('content-type', 'application/x-www-form-urlencoded')
.send(authRequest)
.send(grantRequest)
.timeout(timeoutSpec)
}

Expand All @@ -44,17 +43,17 @@ export interface UserRole {
export default class HmppsAuthClient {
constructor(private readonly tokenStore: TokenStore) {}

private restClient(token: string): RestClient {
private static restClient(token: string): RestClient {
return new RestClient('HMPPS Auth Client', config.apis.hmppsAuth, token)
}

getUser(token: string): Promise<User> {
logger.info(`Getting user details: calling HMPPS Auth`)
return this.restClient(token).get({ path: '/api/user/me' }) as Promise<User>
return HmppsAuthClient.restClient(token).get({ path: '/api/user/me' }) as Promise<User>
}

getUserRoles(token: string): Promise<string[]> {
return this.restClient(token)
return HmppsAuthClient.restClient(token)
.get({ path: '/api/user/me/roles' })
.then(roles => (<UserRole[]>roles).map(role => role.roleCode)) as Promise<string[]>
}
Expand Down
2 changes: 1 addition & 1 deletion server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down