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

feat: Use Docker with Imposter #695

Draft
wants to merge 9 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 .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.log
node_modules
test
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
43 changes: 0 additions & 43 deletions test/browser/compose.yml

This file was deleted.

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
2 changes: 2 additions & 0 deletions test/docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.log
node_modules
11 changes: 11 additions & 0 deletions test/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mcr.microsoft.com/playwright:v1.34.3-jammy as playwright

WORKDIR /

COPY docker/package.json docker/package-lock.json ./

RUN npm install

COPY browser /test/browser

CMD ["npm", "run", "test:browser"]
50 changes: 50 additions & 0 deletions test/docker/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "3.9"
services:
mocks:
image: outofcoffee/imposter
volumes:
- "../imposter:/opt/imposter/config"
ports:
- "8010:8080"
# core-stub:
# image: ghcr.io/alphagov/di/di-ipv-core-stub:latest
# environment:
# CORE_STUB_CONFIG_FILE: "/app/di-ipv-config.yaml"
# CORE_STUB_KEYSTORE_ALIAS: ipv-core-stub
# CORE_STUB_KEYSTORE_PASSWORD: "puppet"
# CORE_STUB_KEYSTORE_FILE: "/app/keystore.jks"
# CORE_STUB_USER_DATA_PATH: "/app/experian-uat-users-large.zip"
# volumes:
# - "./di-ipv-config.yaml:/app/di-ipv-config.yaml"
# - "${CORE_STUB_CONFIG_DIRECTORY}/keystore.jks:/app/keystore.jks"
# - "${CORE_STUB_CONFIG_DIRECTORY}/experian-uat-users-large.zip:/app/experian-uat-users-large.zip"
# ports:
# - "8085:8085"
web:
build:
context: ../..
dockerfile: local.Dockerfile
environment:
REDIS_SESSION_URL: db
API_BASE_URL: http://172.17.0.1:8010
# API_BASE_URL: http://mocks:8010
PORT: 5010
NODE_ENV: development
ports:
- "5010:5010"
depends_on:
- mocks
# - core-stub
links:
- mocks
cucumber:
build:
context: ../
dockerfile: docker/Dockerfile
environment:
WEBSITE_HOST: http://172.17.0.1:8010
depends_on:
- web
# volumes:
# - ../browser:/cucumber/test/browser

Loading