Skip to content

Commit

Permalink
VB-3191 Switch to hmpps-manage-users-api (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmcgowan authored Dec 12, 2023
1 parent 7c8833f commit 248a468
Show file tree
Hide file tree
Showing 43 changed files with 241 additions and 130 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ REDIS_HOST=localhost
HMPPS_AUTH_URL=https://sign-in-dev.hmpps.service.justice.gov.uk/auth
HMPPS_AUTH_EXTERNAL_URL=https://sign-in-dev.hmpps.service.justice.gov.uk/auth
NOMIS_AUTH_URL=https://sign-in-dev.hmpps.service.justice.gov.uk/auth
MANAGE_USERS_API_URL=https://manage-users-api-dev.hmpps.service.justice.gov.uk
NODE_ENV=development

# Use credentials from the dev namespace for API and SYSTEM client
Expand Down
2 changes: 2 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig } from 'cypress'
import { resetStubs } from './integration_tests/mockApis/wiremock'
import auth from './integration_tests/mockApis/auth'
import manageUsersApi from './integration_tests/mockApis/manageUsersApi'
import tokenVerification from './integration_tests/mockApis/tokenVerification'
import prisonRegister from './integration_tests/mockApis/prisonRegister'
import categoryGroups from './integration_tests/mockApis/visitScheduler/categoryGroups'
Expand Down Expand Up @@ -29,6 +30,7 @@ export default defineConfig({
on('task', {
reset: resetStubs,
...auth,
...manageUsersApi,
...tokenVerification,

...prisonRegister,
Expand Down
1 change: 1 addition & 0 deletions feature.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
PORT=3007
HMPPS_AUTH_URL=http://localhost:9091/auth
MANAGE_USERS_API_URL=http://localhost:9091/manage-users-api
TOKEN_VERIFICATION_API_URL=http://localhost:9091/verification
TOKEN_VERIFICATION_ENABLED=true
NODE_ENV=development
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ generic-service:
env:
INGRESS_URL: "https://visits-internal-admin-dev.prison.service.justice.gov.uk"
HMPPS_AUTH_URL: "https://sign-in-dev.hmpps.service.justice.gov.uk/auth"
MANAGE_USERS_API_URL: "https://manage-users-api-dev.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-dev.prison.service.justice.gov.uk"
PRISON_REGISTER_API_URL: "https://prison-register-dev.hmpps.service.justice.gov.uk"
VISIT_SCHEDULER_API_URL: "https://visit-scheduler-dev.prison.service.justice.gov.uk"
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ generic-service:
env:
INGRESS_URL: "https://visits-internal-admin-preprod.prison.service.justice.gov.uk"
HMPPS_AUTH_URL: "https://sign-in-preprod.hmpps.service.justice.gov.uk/auth"
MANAGE_USERS_API_URL: "https://manage-users-api-preprod.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-preprod.prison.service.justice.gov.uk"
PRISON_REGISTER_API_URL: "https://prison-register-preprod.hmpps.service.justice.gov.uk"
VISIT_SCHEDULER_API_URL: "https://visit-scheduler-preprod.prison.service.justice.gov.uk"
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ generic-service:
env:
INGRESS_URL: "https://visits-internal-admin.prison.service.justice.gov.uk"
HMPPS_AUTH_URL: "https://sign-in.hmpps.service.justice.gov.uk/auth"
MANAGE_USERS_API_URL: "https://manage-users-api.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api.prison.service.justice.gov.uk"
PRISON_REGISTER_API_URL: "https://prison-register.hmpps.service.justice.gov.uk"
VISIT_SCHEDULER_API_URL: "https://visit-scheduler.prison.service.justice.gov.uk"
Expand Down
1 change: 1 addition & 0 deletions helm_deploy/values-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ generic-service:
env:
INGRESS_URL: "https://visits-internal-admin-staging.prison.service.justice.gov.uk"
HMPPS_AUTH_URL: "https://sign-in-dev.hmpps.service.justice.gov.uk/auth"
MANAGE_USERS_API_URL: "https://manage-users-api-dev.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-dev.prison.service.justice.gov.uk"
PRISON_REGISTER_API_URL: "https://prison-register-dev.hmpps.service.justice.gov.uk"
VISIT_SCHEDULER_API_URL: "https://visit-scheduler-staging.prison.service.justice.gov.uk"
Expand Down
1 change: 1 addition & 0 deletions integration_tests/e2e/health.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ context('Healthcheck', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubAuthPing')
cy.task('stubManageUsersPing')
cy.task('stubTokenVerificationPing')
})

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ context('Home page', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.signIn()
})

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/e2e/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ context('SignIn', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
})

it('Unauthenticated user directed to auth', () => {
Expand Down Expand Up @@ -61,7 +61,7 @@ context('SignIn', () => {
cy.request('/').its('body').should('contain', 'Sign in')

cy.task('stubVerifyToken', true)
cy.task('stubAuthUser', 'bobby brown')
cy.task('stubManageUser', 'bobby brown')
cy.signIn()

indexPage.headerUserName().contains('B. Brown')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ context('Category groups - add', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ context('Category groups - list', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Category groups - single', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ context('Prison configuration', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ context('Excluded dates', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Incentive groups - add', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ context('Incentive groups - list', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Incentive groups - single', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ context('Location groups - add', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Location groups - list', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ context('Location groups - single', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ context('Session templates - add', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Session templates - update', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ context('Session templates - list', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.task('stubGetAllPrisons')
cy.signIn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ context('Session templates - single', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Session templates - delete', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ context('Session templates - status', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/e2e/prisons/supportedPrisons.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('Supported prisons', () => {
beforeEach(() => {
cy.task('reset')
cy.task('stubSignIn')
cy.task('stubAuthUser')
cy.task('stubManageUser')
cy.task('stubPrisonNames')
cy.signIn()
})
Expand Down
36 changes: 0 additions & 36 deletions integration_tests/mockApis/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,45 +118,9 @@ const token = (role: string) =>
},
})

const stubUser = (name: string) =>
stubFor({
request: {
method: 'GET',
urlPattern: '/auth/api/user/me',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
staffId: 231232,
username: 'USER1',
active: true,
name,
},
},
})

const stubUserRoles = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/auth/api/user/me/roles',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: [{ roleCode: 'ROLE_PRISON_VISITS_ADMIN' }],
},
})

export default {
getSignInUrl,
stubAuthPing: ping,
stubSignIn: (role: string): Promise<[Response, Response, Response, Response, Response, Response]> =>
Promise.all([favicon(), redirect(), signOut(), manageDetails(), token(role), tokenVerification.stubVerifyToken()]),
stubAuthUser: (name = 'john smith'): Promise<[Response, Response]> => Promise.all([stubUser(name), stubUserRoles()]),
}
55 changes: 55 additions & 0 deletions integration_tests/mockApis/manageUsersApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Response } from 'superagent'

import { stubFor } from './wiremock'

const stubUser = (name: string) =>
stubFor({
request: {
method: 'GET',
urlPattern: '/manage-users-api/users/me',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: {
staffId: 231232,
username: 'USER1',
active: true,
name,
},
},
})

const stubUserRoles = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/manage-users-api/users/me/roles',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: [{ roleCode: 'SOME_USER_ROLE' }],
},
})

const ping = () =>
stubFor({
request: {
method: 'GET',
urlPattern: '/manage-users-api/health/ping',
},
response: {
status: 200,
},
})

export default {
stubManageUser: (name = 'john smith'): Promise<[Response, Response]> =>
Promise.all([stubUser(name), stubUserRoles()]),
stubManageUsersPing: ping,
}
8 changes: 8 additions & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export default {
systemClientId: get('SYSTEM_CLIENT_ID', 'clientid', requiredInProduction),
systemClientSecret: get('SYSTEM_CLIENT_SECRET', 'clientsecret', requiredInProduction),
},
manageUsersApi: {
url: get('MANAGE_USERS_API_URL', 'http://localhost:9091', requiredInProduction),
timeout: {
response: Number(get('MANAGE_USERS_API_TIMEOUT_RESPONSE', 10000)),
deadline: Number(get('MANAGE_USERS_API_TIMEOUT_DEADLINE', 10000)),
},
agent: new AgentConfig(Number(get('MANAGE_USERS_API_TIMEOUT_RESPONSE', 10000))),
},
tokenVerification: {
url: get('TOKEN_VERIFICATION_API_URL', 'http://localhost:8100', requiredInProduction),
timeout: {
Expand Down
Loading

0 comments on commit 248a468

Please sign in to comment.