generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* NFDIV-4298 starting * NFDIV-4298 starting * NFDIV-4298 starting * NFDIV-4298 try mocking token * NFDIV-4298 system user fix * NFDIV-4298 prettier fix * NFDIV-4298 fortify label ability for pr * NFDIV-4298 import * NFDIV-4298 fortify fixes will need to test the updated redirect with token works * NFDIV-4298 healthcheck failing so removing that last user hmcts to try * NFDIV-4298 healthcheck failing * NFDIV-4298 fixing my buggy changes * NFDIV-4298 fixing my buggy changes * NFDIV-4298 merge master * NFDIV-4298 errors missing gradle wrapper * NFDIV-4298 errors missing gradle wrapper * NFDIV-4298 * Delete src/test/java/.gitignore * NFDIV-4298 try to update uppy version to see if this one behaves with fortify * NFDIV-4298 try to update uppy version to see if this one behaves with fortify * NFDIV-4298 new errors after upgrading uppy, needed to add pluralise and result can be undefined so needed to add a check for that * NFDIV-4298 * NFDIV-4298 pluralize fix * NFDIV-4298 think wdio/sauce-service latest might be to blame for fortify issue so downgrading * NFDIV-4559 * NFDIV-4298 update from master * NFDIV-4298 lock file * NFDIV-4298 fix bad merge * NFDIV-4298 fix fortify issue after merge --------- Co-authored-by: adamg-hmcts <[email protected]>
- Loading branch information
1 parent
7c9cd25
commit ab06db0
Showing
23 changed files
with
360 additions
and
257 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,7 +1,7 @@ | ||
import axios, { AxiosRequestHeaders, AxiosResponse, AxiosStatic } from 'axios'; | ||
import jwt from 'jsonwebtoken'; | ||
|
||
import { APPLICANT_2_SIGN_IN_URL, CALLBACK_URL, SIGN_IN_URL } from '../../../steps/urls'; | ||
import { UserDetails } from '../../controller/AppRequest'; | ||
|
||
import { OidcResponse, getRedirectUrl, getSystemUser, getUserDetails } from './oidc'; | ||
|
||
|
@@ -13,8 +13,25 @@ jest.mock('config'); | |
const mockedConfig = config as jest.Mocked<typeof config>; | ||
const mockedAxios = axios as jest.Mocked<AxiosStatic>; | ||
|
||
const token = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwiZ2l2ZW5fbmFtZSI6IkpvaG4iLCJmYW1pbHlfbmFtZSI6IkRvcmlhbiIsInVpZCI6IjEyMyIsInJvbGVzIjpbImNpdGl6ZW4iXX0.rxjx6XsSNNYavVppwKAqWiNWT_GxN4vjVzdLRe6q14I'; | ||
const mockSecret = 'mock-secret'; | ||
const mockPayload = { | ||
uid: '123', | ||
id: '123', | ||
sub: '[email protected]', | ||
email: '[email protected]', | ||
given_name: 'John', | ||
family_name: 'Dorian', | ||
roles: ['citizen'], | ||
}; | ||
const mockSystemPayload = { | ||
uid: '456', | ||
sub: 'user-email', | ||
name: 'System', | ||
roles: ['caseworker-divorce-systemupdate', 'caseworker-caa', 'caseworker', 'caseworker-divorce'], | ||
}; | ||
// Generate a mock JWT for testing | ||
const mockToken = jwt.sign(mockPayload, mockSecret, { expiresIn: '1h' }); | ||
const mockSystemToken = jwt.sign(mockSystemPayload, mockSecret, { expiresIn: '1h' }); | ||
|
||
describe('getRedirectUrl', () => { | ||
test('should create a valid URL to redirect to the login screen', () => { | ||
|
@@ -36,16 +53,16 @@ describe('getRedirectUrl', () => { | |
|
||
describe('getUserDetails', () => { | ||
test('should exchange a code for a token and decode a JWT to get the user details', async () => { | ||
mockedAxios.post.mockResolvedValue({ | ||
mockedAxios.post.mockResolvedValueOnce({ | ||
data: { | ||
access_token: token, | ||
id_token: token, | ||
id_token: mockToken, | ||
access_token: 'token', | ||
}, | ||
}); | ||
} as AxiosResponse); | ||
|
||
const result = await getUserDetails('http://localhost', '123', CALLBACK_URL); | ||
expect(result).toStrictEqual({ | ||
accessToken: token, | ||
accessToken: 'token', | ||
email: '[email protected]', | ||
givenName: 'John', | ||
familyName: 'Dorian', | ||
|
@@ -62,26 +79,30 @@ describe('getUserDetails', () => { | |
}); | ||
|
||
describe('getSystemUser', () => { | ||
const getSystemUserTestToken = | ||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0QHRlc3QuY29tIiwiZ2l2ZW5fbmFtZSI6IkpvaG4iLCJmYW1pbHlfbmFtZSI6IkRvcmlhbiIsInVpZCI6IjEyMyIsInJvbGVzIjpbImNhc2V3b3JrZXItZGl2b3JjZS1zeXN0ZW11cGRhdGUiLCJjYXNld29ya2VyLWNhYSIsImNhc2V3b3JrZXIiLCJjYXNld29ya2VyLWRpdm9yY2UiXX0.NDab3XAV8NWQTuuxBQ9mpwTIdw4KMWWiJ37Dp3EHG7s'; | ||
|
||
const accessTokenResponse: AxiosResponse<OidcResponse> = { | ||
status: 200, | ||
data: { | ||
id_token: getSystemUserTestToken, | ||
access_token: getSystemUserTestToken, | ||
id_token: mockSystemToken, | ||
access_token: 'systemUserTestToken', | ||
}, | ||
statusText: 'wsssw', | ||
headers: { test: 'now' }, | ||
config: { headers: [] as unknown as AxiosRequestHeaders }, | ||
}; | ||
|
||
const expectedGetSystemUserResponse: UserDetails = { | ||
accessToken: getSystemUserTestToken, | ||
email: '[email protected]', | ||
givenName: 'John', | ||
familyName: 'Dorian', | ||
id: '123', | ||
const expectedGetSystemUserResponse: { | ||
givenName: undefined; | ||
familyName: undefined; | ||
roles: string[]; | ||
id: string; | ||
accessToken: string; | ||
email: string; | ||
} = { | ||
email: 'user-email', | ||
accessToken: 'systemUserTestToken', | ||
id: '456', | ||
givenName: undefined, | ||
familyName: undefined, | ||
roles: ['caseworker-divorce-systemupdate', 'caseworker-caa', 'caseworker', 'caseworker-divorce'], | ||
}; | ||
|
||
|
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
Oops, something went wrong.