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

spike: Add perf tests using k6+browser #696

Draft
wants to merge 6 commits into
base: feat/use-imposter
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test:coverage": "nyc --reporter=lcov --reporter=text-summary yarn test",
"test:watch": "mocha --watch",
"mocks": "yarn run wiremock --port 8010 --root-dir test/mocks",
"mocks:imposter": "imposter up test/imposter --port 8010",
"test:browser": "wait-on tcp:127.0.0.1:8010 tcp:127.0.0.1:5010 && API_BASE_URL=http://127.0.0.1:8010 MOCK_API=true cucumber-js --config test/browser/cucumber.js --tags \"not @skip\"",
"test:browser:ci": "npm-run-all -p -r start:ci mocks test:browser",
"test:browser:only": "wait-on tcp:127.0.0.1:8010 tcp:127.0.0.1:5010 && API_BASE_URL=http://127.0.0.1:8010 MOCK_API=true cucumber-js --config test/browser/cucumber.js --tags \"@only and not @skip\"",
Expand Down
11 changes: 6 additions & 5 deletions test/browser/pages/relying-party.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ module.exports = class PlaywrightDevPage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
constructor(page, clientId) {
this.page = page;
this.clientId = clientId;
}

async goto() {
this.startingUrl =
"http://localhost:5010/oauth2/authorize?request=lorem&client_id=standalone";
const websiteHost = process.env.WEBSITE_HOST || "http://localhost:5010";
this.startingUrl = `${websiteHost}/oauth2/authorize?request=lorem&client_id=${this.clientId}`;

await this.page.goto(this.startingUrl);
}
Expand All @@ -31,9 +32,9 @@ module.exports = class PlaywrightDevPage {
const { searchParams } = new URL(this.page.url());

return (
searchParams.get("client_id") === "standalone" &&
searchParams.has("client_id") && // FIXME: Restore checking of client_id
searchParams.get("state") === "sT@t3" &&
searchParams.get("code") === "FACEFEED"
searchParams.get("code").startsWith("auth-code-")
);
}

Expand Down
2 changes: 1 addition & 1 deletion test/browser/step_definitions/relying-party.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { expect } = require("chai");
Given(/^([A-Za-z ])+ is using the system$/, async function (name) {
this.user = this.allUsers[name];

const rpPage = new RelyingPartyPage(this.page);
const rpPage = new RelyingPartyPage(this.page, this.TESTING_CLIENT_ID);

await rpPage.goto();
});
Expand Down
21 changes: 1 addition & 20 deletions test/browser/support/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const {
setDefaultTimeout,
} = require("@cucumber/cucumber");
const { chromium } = require("playwright");
const axios = require("axios");

// FIXME This is large due to cold starts
setDefaultTimeout(30 * 1000);
Expand Down Expand Up @@ -42,30 +41,12 @@ Before(async function ({ pickle } = {}) {

const header = tag?.name.substring(10);

this.SCENARIO_ID_HEADER = header;

try {
await axios.get(`${process.env.API_BASE_URL}/__reset/${header}`);
} catch (e) {
/* eslint-disable no-console */
console.log("Error resetting mock");
console.log(`${process.env.API_BASE_URL}/__reset/${header}`);
console.log(e.message);
/* eslint-enable no-console */
throw e;
}
this.TESTING_CLIENT_ID = header;
});

// Create a new test context and page per scenario
Before(async function () {
this.context = await global.browser.newContext({});

if (this.SCENARIO_ID_HEADER) {
await this.context.setExtraHTTPHeaders({
"x-scenario-id": this.SCENARIO_ID_HEADER,
});
}

this.page = await this.context.newPage();
});

Expand Down
75 changes: 75 additions & 0 deletions test/imposter/addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[
{
"uprn": "000",
"buildingName": "EAST ZZZ",
"addressLocality": "BEAMINSTER",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "111",
"subBuildingName": "FLAT 1",
"buildingNumber": "87",
"streetName": "ZZZ WAY",
"dependentAddressLocality": "WHITEHOUSE",
"addressLocality": "MILTON KEYNES",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"subBuildingName": "FLAT 11",
"buildingName": "BLASHFORD",
"streetName": "ZZZ ROAD",
"addressLocality": "LONDON",
"postalCode": "ZZ1 1ZZ"
},
{
"uprn": "222",
"buildingName": "ZZZ MARINA",
"streetName": "ZZZ ROAD",
"dependentAddressLocality": "LONG ZZZ",
"addressLocality": "NOTTINGHAM",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "333",
"organisationName": "ZZZ GROUP",
"subBuildingName": "UNIT 2B",
"buildingNumber": "16",
"buildingName": "ZZZ BUSINESS PARK",
"dependentStreetName": "ZZZ PARK",
"streetName": "ZZZ STREET",
"doubleDependentAddressLocality": "SOME ZZZ",
"dependentAddressLocality": "LONG EATON",
"addressLocality": "GREAT MISSENDEN",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"buildingName": "R103",
"dependentStreetName": "ZZZ PARK",
"streetName": "CREEK ROAD",
"doubleDependentAddressLocality": "",
"addressLocality": "ZZZ ISLAND",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "444",
"buildingNumber": "13",
"streetName": "ZZZ CRESCENT",
"dependentAddressLocality": "NEW PITSLIGO",
"addressLocality": "FRASERBURGH",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "555",
"buildingNumber": "3",
"streetName": "ZZZ WALK",
"addressLocality": "MIDDLESBROUGH",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
}
]
5 changes: 5 additions & 0 deletions test/imposter/addresses_e18qs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
{
"postalCode": "E1 8QS"
}
]
16 changes: 16 additions & 0 deletions test/imposter/postcode-lookup_e18qs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"buildingNumber": "1",
"addressLocality": "LONDON",
"postalCode": "E1 8QS",
"streetName": "WHITECHAPEL HIGH STREET",
"uprn": "123"
},
{
"buildingNumber": "10",
"addressLocality": "LONDON",
"postalCode": "E1 8QS",
"streetName": "WHITECHAPEL HIGH STREET",
"uprn": "124"
}
]
1 change: 1 addition & 0 deletions test/imposter/postcode-lookup_sw1a1aa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
75 changes: 75 additions & 0 deletions test/imposter/postcode-lookup_zz11zz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[
{
"uprn": "000",
"buildingName": "EAST ZZZ",
"addressLocality": "BEAMINSTER",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "111",
"subBuildingName": "FLAT 1",
"buildingNumber": "87",
"streetName": "ZZZ WAY",
"dependentAddressLocality": "WHITEHOUSE",
"addressLocality": "MILTON KEYNES",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"subBuildingName": "FLAT 11",
"buildingName": "BLASHFORD",
"streetName": "ZZZ ROAD",
"addressLocality": "LONDON",
"postalCode": "ZZ1 1ZZ"
},
{
"uprn": "222",
"buildingName": "ZZZ MARINA",
"streetName": "ZZZ ROAD",
"dependentAddressLocality": "LONG ZZZ",
"addressLocality": "NOTTINGHAM",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "333",
"organisationName": "ZZZ GROUP",
"subBuildingName": "UNIT 2B",
"buildingNumber": "16",
"buildingName": "ZZZ BUSINESS PARK",
"dependentStreetName": "ZZZ PARK",
"streetName": "ZZZ STREET",
"doubleDependentAddressLocality": "SOME ZZZ",
"dependentAddressLocality": "LONG EATON",
"addressLocality": "GREAT MISSENDEN",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"buildingName": "R103",
"dependentStreetName": "ZZZ PARK",
"streetName": "CREEK ROAD",
"doubleDependentAddressLocality": "",
"addressLocality": "ZZZ ISLAND",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "444",
"buildingNumber": "13",
"streetName": "ZZZ CRESCENT",
"dependentAddressLocality": "NEW PITSLIGO",
"addressLocality": "FRASERBURGH",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
},
{
"uprn": "555",
"buildingNumber": "3",
"streetName": "ZZZ WALK",
"addressLocality": "MIDDLESBROUGH",
"postalCode": "ZZ1 1ZZ",
"addressCountry": "GB"
}
]
121 changes: 121 additions & 0 deletions test/imposter/private-api-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
plugin: openapi
specFile: ./private-api.yaml

validation:
request: log

resources:
- path: "/postcode-lookup/:postcode"
method: GET
pathParams:
postcode: E1 8QS
response:
statusCode: 200
file: postcode-lookup_e18qs.json

- path: "/postcode-lookup/:postcode"
method: GET
pathParams:
postcode: SW1A 1AA
response:
statusCode: 404
file: postcode-lookup_sw1a1aa.json

- path: "/postcode-lookup/:postcode"
method: GET
pathParams:
postcode: ZZ1 1ZZ
response:
statusCode: 200
file: postcode-lookup_zz11zz.json

- path: "/postcode-lookup/:postcode"
method: GET
response:
statusCode: 404

- path: "/addresses"
method: GET
requestHeaders:
session-id: address-prepopulated-postcode
response:
statusCode: 200
file: addresses_e18qs.json

- path: "/addresses"
method: GET
response:
statusCode: 404

- method: PUT
path: /address
response:
statusCode: 201
content: "{}"

- method: POST
path: /session
requestBody:
jsonPath: $.client_id
value: "address-prepopulated-postcode"
response:
statusCode: 201
template: true
content: '{"session_id": "address-prepopulated-postcode", "state": "sT@t3", "redirect_uri": "http://example.net/return"}'

- method: POST
path: /session
requestBody:
jsonPath: $.client_id
value: "address-success"
response:
statusCode: 201
template: true
content: '{"session_id": "address-success", "state": "sT@t3", "redirect_uri": "http://example.net/return"}'

- method: POST
path: /session
requestBody:
jsonPath: $.client_id
value: "address-authorization-error"
response:
statusCode: 201
template: true
content: '{"session_id": "address-authorization-error", "state": "sT@t3", "redirect_uri": "http://example.net/return"}'

- method: POST
path: /session
requestBody:
jsonPath: $.client_id
value: "test-session-400"
response:
statusCode: 400
template: true
content: "{}"

- method: POST
path: /session
requestBody:
jsonPath: $.client_id
value: "test-session-500"
response:
statusCode: 500
template: true
content: "{}"

- method: GET
path: /authorization
requestHeaders:
session-id: "address-authorization-error"
response:
statusCode: 500
content: '{"redirect_uri": "http://example.net", "oauth_error": {"error_description": "gateway", "error": "server_error"}}'

- method: GET
path: /authorization
requestHeaders:
session-id: "address-success"
response:
template: true
statusCode: 200
content: '{"authorizationCode": {"value":"auth-code-${random.uuid()}"}, "state":"sT@t3","redirect_uri":"http://example.net/return"}'
Loading