-
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
1 parent
817a86f
commit 4cb79a5
Showing
7 changed files
with
197 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Testing |
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,89 @@ | ||
import { DynamoDBClient, GetItemCommand, GetItemCommandOutput, ServiceInputTypes, ServiceOutputTypes } from "@aws-sdk/client-dynamodb"; | ||
import { AwsStub } from "aws-sdk-client-mock"; | ||
import { DigidLoa } from "../../src/app/code/DigiDLoa"; | ||
|
||
|
||
export class TestUtils { | ||
|
||
static getSessionStoreMock( | ||
ddMock: AwsStub<ServiceInputTypes, ServiceOutputTypes>, | ||
loggedin: boolean = true, | ||
bsn: string = '900026236', | ||
state: string = '12345', | ||
loa: DigidLoa = DigidLoa.Midden | ||
) { | ||
const dynamoDBClient = new DynamoDBClient({ region: 'us-east-1' }); | ||
|
||
const getItemOutput: Partial<GetItemCommandOutput> = { | ||
Item: { | ||
data: { | ||
M: { | ||
loggedin: { BOOL: loggedin }, | ||
bsn: { S: bsn }, | ||
state: { S: state }, | ||
loa: { S: loa }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
ddMock.on(GetItemCommand).resolves(getItemOutput); | ||
return dynamoDBClient; | ||
} | ||
|
||
static getYiviSessionExampleResponse() { | ||
|
||
const sessionResponse = { | ||
sessionPtr: { | ||
u: 'https://gw-test.nijmegen.nl/yivi/session/anothertoken', | ||
yiviqr: 'issuing' | ||
}, | ||
token: 'sometoken', | ||
frontendRequest: { | ||
authorization: 'blabla', | ||
pairingHint: true, | ||
minProtocolVersion: '1.0', | ||
maxProtocolVersion: '1.1' | ||
} | ||
} | ||
return sessionResponse; | ||
} | ||
|
||
static getBrpExampleData() { | ||
const brpData = { | ||
"Persoon": { | ||
"BSN": { | ||
"BSN": "900026236" | ||
}, | ||
"Persoonsgegevens": { | ||
"Voorletters": "H.", | ||
"Voornamen": "Hans", | ||
"Voorvoegsel": "de", | ||
"Geslachtsnaam": "Jong", | ||
"Achternaam": "de Jong", | ||
"Naam": "H. de Jong", | ||
"Geboortedatum": "01-01-1956", | ||
"Geslacht": "M", | ||
"NederlandseNationaliteit": "Ja", | ||
"Geboorteplaats": "Nijmegen", | ||
"Geboorteland": "Nederland" | ||
}, | ||
"Adres": { | ||
"Straat": "Kelfkensbos", | ||
"Huisnummer": "80", | ||
"Gemeente": "Nijmegen", | ||
"Postcode": "6511 RN", | ||
"Woonplaats": "Nijmegen" | ||
}, | ||
"ageLimits": { | ||
"over12": "Yes", | ||
"over16": "Yes", | ||
"over18": "Yes", | ||
"over21": "Yes", | ||
"over65": "Yes" | ||
} | ||
} | ||
} | ||
return brpData; | ||
} | ||
|
||
} |
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,92 @@ | ||
import axios from 'axios'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { BrpApi } from '../../src/app/issue/BrpApi'; | ||
import { issueRequestHandler } from '../../src/app/issue/issueRequestHandler'; | ||
import { ApiClient } from '@gemeentenijmegen/apiclient'; | ||
import { YiviApi } from '../../src/app/code/YiviApi'; | ||
import { DynamoDBClient } from '@aws-sdk/client-dynamodb'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import { DigidLoa } from '../../src/app/code/DigiDLoa'; | ||
import { TestUtils } from './TestUtils'; | ||
|
||
const ddbMock = mockClient(DynamoDBClient); | ||
const axiosMock = new MockAdapter(axios); | ||
|
||
const brpApi = new BrpApi(new ApiClient('cert', 'key', 'ca')); | ||
const yiviApi = new YiviApi(); | ||
|
||
// Mock SSM and Secrets manager utility (cannot be moved to TestUtils) | ||
jest.mock('@gemeentenijmegen/utils/lib/AWS', () => ({ | ||
AWS: { | ||
getParameter: jest.fn().mockImplementation((name) => `${name}`), | ||
getSecret: jest.fn().mockImplementation((arn) => `${arn}`), | ||
} | ||
})); | ||
|
||
beforeAll(async () => { | ||
// Mock the logging functions (can be used to check for precense of logging) | ||
console.log = jest.fn(); | ||
console.info = jest.fn(); | ||
console.debug = jest.fn(); | ||
console.error = jest.fn(); | ||
console.time = jest.fn(); | ||
|
||
// Setup BRP and Yivi client | ||
process.env.BRP_API_URL = 'https://example.com/brp/api/test'; | ||
await brpApi.init(); | ||
yiviApi.manualInit('yivi-server-test.nijmegen.nl', true, 'someid', 'somesecretkey', 'irma-autharizaiton-header'); | ||
}); | ||
|
||
beforeEach(() => { | ||
axiosMock.reset(); | ||
ddbMock.reset(); | ||
}); | ||
|
||
test('Issue page loads successfull', async () => { | ||
|
||
// Mocks | ||
const dynamoDBClient = TestUtils.getSessionStoreMock(ddbMock); | ||
axiosMock.onPost('https://yivi-server-test.nijmegen.nl/session').reply(200, TestUtils.getYiviSessionExampleResponse()); | ||
axiosMock.onPost('https://example.com/brp/api/test').reply(200, TestUtils.getBrpExampleData()); | ||
|
||
// Call issue request handler | ||
const response = await issueRequestHandler('session=12345', brpApi, yiviApi, dynamoDBClient); | ||
|
||
// Check if the session resonse is encoded in the html | ||
const data = await brpApi.getBrpData('900026236'); | ||
const manuallyObtainedSessionResponse = await yiviApi.startSession(data, DigidLoa.Midden); | ||
const base64SessionResponse = Buffer.from(JSON.stringify(manuallyObtainedSessionResponse), 'utf-8').toString('base64'); | ||
expect(response.body).toContain(base64SessionResponse) | ||
}); | ||
|
||
test('Issue page not logged in', async () => { | ||
// Session store not logged in | ||
const dynamoDBClient = TestUtils.getSessionStoreMock(ddbMock, false); | ||
|
||
const response = await issueRequestHandler('session=12345', brpApi, yiviApi, dynamoDBClient); | ||
expect(response.statusCode).toBe(302); | ||
expect(response.headers?.Location).toBe('/login'); | ||
expect(response.body).toBe(''); | ||
}); | ||
|
||
test('Yivi API timeout', async () => { | ||
// Mocks | ||
const dynamoDBClient = TestUtils.getSessionStoreMock(ddbMock); | ||
axiosMock.onPost('https://yivi-server-test.nijmegen.nl/session').timeout(); | ||
axiosMock.onPost('https://example.com/brp/api/test').reply(200, TestUtils.getBrpExampleData()); | ||
|
||
// Call issue request handler | ||
await issueRequestHandler('session=12345', brpApi, yiviApi, dynamoDBClient); | ||
expect(console.error).toHaveBeenCalledWith('timeout of 2000ms exceeded'); | ||
}); | ||
|
||
|
||
test('BRP API timeout', async () => { | ||
// Mocks | ||
const dynamoDBClient = TestUtils.getSessionStoreMock(ddbMock); | ||
axiosMock.onPost('https://example.com/brp/api/test').timeout(); | ||
|
||
// Call issue request handler | ||
await issueRequestHandler('session=12345', brpApi, yiviApi, dynamoDBClient); | ||
expect(console.error).toHaveBeenCalledWith('timeout of 2000ms exceeded'); | ||
}); |