generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
91 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
PORT=3007 | ||
INGRESS_URL=http://localhost:3007 | ||
HMPPS_AUTH_URL=http://localhost:9091/auth | ||
TOKEN_VERIFICATION_API_URL=http://localhost:9091/verification | ||
TOKEN_VERIFICATION_ENABLED=true | ||
NODE_ENV=development | ||
API_CLIENT_ID=clientid | ||
API_CLIENT_SECRET=clientsecret | ||
SYSTEM_CLIENT_ID=clientid | ||
SYSTEM_CLIENT_SECRET=clientsecret | ||
|
||
ORCHESTRATION_API_URL=http://localhost:9091/orchestration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
context('Test API call page', () => { | ||
beforeEach(() => { | ||
cy.task('reset') | ||
cy.task('stubSignIn') | ||
cy.signIn() | ||
}) | ||
|
||
it('Test call to Orchestration service', () => { | ||
cy.task('stubHmppsAuthToken') | ||
cy.task('stubSupportedPrisonIds') | ||
cy.visit('/prisons') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import jwt from 'jsonwebtoken' | ||
|
||
import { stubFor } from './wiremock' | ||
|
||
const createToken = () => { | ||
const payload = { | ||
sub: 'system_client_id', | ||
grant_type: 'client_credentials', | ||
scope: ['read', 'write'], | ||
auth_source: 'none', | ||
iss: 'http://localhost:9091/auth/auth/issuer', | ||
authorities: ['ROLE_VISIT_SCHEDULER'], | ||
jti: 'NBmv9IH_xw89YFE_tFoBwI1zo9Y', | ||
client_id: 'system_client_id', | ||
} | ||
return jwt.sign(payload, 'secret', { expiresIn: '1h' }) | ||
} | ||
|
||
const stubHmppsAuthToken = () => | ||
stubFor({ | ||
request: { | ||
method: 'POST', | ||
urlPattern: '/auth/oauth/token', | ||
}, | ||
response: { | ||
status: 200, | ||
headers: { | ||
'Content-Type': 'application/json;charset=UTF-8', | ||
Location: 'http://localhost:3007/sign-in/callback?code=codexxxx&state=stateyyyy', | ||
}, | ||
jsonBody: { | ||
access_token: createToken(), | ||
token_type: 'bearer', | ||
expires_in: 599, | ||
scope: 'read', | ||
sub: 'system_client_id', | ||
auth_source: 'none', | ||
jti: 'NBmv9IH_xw89YFE_tFoBwI1zo9Y', | ||
iss: 'http://localhost:9091/auth/auth/issuer', | ||
}, | ||
}, | ||
}) | ||
|
||
export default { stubHmppsAuthToken } |
18 changes: 10 additions & 8 deletions
18
...ation_tests/mockApis/tokenVerification.ts → integration_tests/mockApis/orchestration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
import { SuperAgentRequest } from 'superagent' | ||
import { stubFor } from './wiremock' | ||
import TestData from '../../server/routes/testutils/testData' | ||
|
||
export default { | ||
stubTokenVerificationPing: (status = 200): SuperAgentRequest => | ||
stubOrchestrationPing: (status = 200): SuperAgentRequest => | ||
stubFor({ | ||
request: { | ||
method: 'GET', | ||
urlPattern: '/verification/health/ping', | ||
urlPattern: '/orchestration/health/ping', | ||
}, | ||
response: { | ||
status, | ||
headers: { 'Content-Type': 'application/json;charset=UTF-8' }, | ||
jsonBody: { status: 'UP' }, | ||
}, | ||
}), | ||
stubVerifyToken: (active = true): SuperAgentRequest => | ||
stubFor({ | ||
stubSupportedPrisonIds: (): SuperAgentRequest => { | ||
return stubFor({ | ||
request: { | ||
method: 'POST', | ||
urlPattern: '/verification/token/verify', | ||
method: 'GET', | ||
url: '/orchestration/config/prisons/supported', | ||
}, | ||
response: { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/json;charset=UTF-8' }, | ||
jsonBody: { active }, | ||
jsonBody: TestData.supportedPrisonIds(), | ||
}, | ||
}), | ||
}) | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
import config from '../config' | ||
|
||
export default function generateOauthClientToken( | ||
clientId: string = config.apis.hmppsAuth.apiClientId, | ||
clientSecret: string = config.apis.hmppsAuth.apiClientSecret, | ||
): string { | ||
export default function generateOauthClientToken(clientId: string, clientSecret: string): string { | ||
const token = Buffer.from(`${clientId}:${clientSecret}`).toString('base64') | ||
return `Basic ${token}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.