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

Example (WIP) config for https Playwright testing #1920

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 11 additions & 2 deletions contrib/playwright/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ networks:
name: fmtm-${GIT_BRANCH:-local}

services:
proxy:
hostname: fmtm.dev.test

api:
hostname: fmtm.dev.test
environment:
# Run via alias fmtm.dev.test
FMTM_DOMAIN: "fmtm.dev.test"
# Do not use dev port, use port 80
FMTM_DEV_PORT: "false"
# Override OSM redirect URL to allow login
OSM_LOGIN_REDIRECT_URI: http://fmtm.dev.test/osmauth
# The ci image has overrides for CMD and ENTRYPOINT, so re-apply
entrypoint: ["/app-entrypoint.sh"]
# API_REPLICAS can be increased via CI env vars
Expand All @@ -36,9 +41,12 @@ services:
hostname: fmtm.dev.test
environment:
VITE_API_URL: "http://fmtm.dev.test:8000"
command: --port 80
volumes:
- ./contrib/playwright/fmtm.dev.test.crt:/cert/cert.crt
- ./contrib/playwright/fmtm.dev.test.key:/cert/cert.key
command: --port 443
healthcheck:
test: timeout 5s bash -c ':> /dev/tcp/127.0.0.1/80' || exit 1
test: timeout 5s bash -c ':> /dev/tcp/127.0.0.1/443' || exit 1
interval: 5s
retries: 3
start_period: 5s
Expand Down Expand Up @@ -75,6 +83,7 @@ services:
volumes:
- ./src/frontend:/app
- /tmp/.X11-unix:/tmp/.X11-unix
# - ./contrib/playwright/rootCA.crt:/usr/local/share/ca-certificates/cert.crt:ro
entrypoint: /bin/sh -c
command:
- |
Expand Down
22 changes: 22 additions & 0 deletions contrib/playwright/fmtm.dev.test.crt
Original file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TebHNX3AC15n+
CuyjtmFP7dHUx7dSz/o90qMfyYseyh5l+nd/60AS/ZJz0DZ6rsdBBnppvqCvqcrO
55XWf+PfBT+okVqefKGFPm5oS3FHCbLT0NDT26hA+LBAc6xSjklSDZLd5zxauxMu
LUfMni5/olxHFq53WpBuzb0MVT547RiUb21fjHFM9bcHMwv84uwhQ0LHRMJBg6tu
mGJQKL7NSpfaD7P8qLsMqQJ6dlA/2EP2pw8Rwg==
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions contrib/playwright/fmtm.dev.test.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC9WL2RDD2LazJi
4UCyAuZPpBfoaTjxsIX3T+jp2rmcw/NXFyf9oHxui7wD48b2rxLkHNvycgIpkP+H
i2M5egNNt/jeh8jNWiOnnmEBBIqjvcQbN3lNl3u1g/1TACTrEstWS+rByXTy32kM
orZGlaDiFej/zX5q5191TnES700KaWr5OOe/EHeSvw5w18CwoFu2fawnjBuUBH/F
h7BQfFLHMhP9zV6d74lvhaTiJ8G45qjWXv2E8LbqdV8b/cyq2VwbM9cP4Xfj3cNW
EYLaV0jo0VOGHmfHhmwmjKKVFE7gdgtb6D318iPZFpnPFKF9GDH/k0Xs/4SzEbCL
ban/JolXAgMBAAECggEADpSDQGSPZqlx/1A2EZ8MigxqNODJXD8KCdGy7zMDAPHL
zqR/VVXizwZei3QiMYOosj0QqLojtXyvWIogsV/WWkk01jnhegKbZUBaWuA1Jsep
jqj2Y8Wq5n7L5nTH4vwXAUWmRZbUNRGD/s+Wtpe2BELIps31kpjPbnKEXX9k0MzM
FJzjRQ+ETw0Wb2bGNvl2LZzuMiG2fBqDHhgnrhvrxhKKpi+nwocGDd+f79EW4mIk
b3CrCm/IlmlHMZzkdz/fPLEw5ECjpEj9elxg8cFaB2LadmdzVF4P3XhQja3XhuvT
xOXFvZJu0LrVcp/99aYsTq2JsuO0cHf/PVH25rrzcQKBgQD7ptZj0uFjCKUNMb1T
iyxxCTVHdAfunVLUa0+XWVd63EinT7LT7zDwwHfGEBl/TALinoYnBt6AEol3QZrR
hJWyfNGebkmiT4zQ1laZ2ldFHiiRbBMbb4kr+cgDAhbE9lanZL1UfOiQ6TFrItGe
OoRAL+T55VdLqEOY4ZoR6oo25wKBgQDAnk0dLNkNQaq7stq7LdbhNlhObasNi/zC
4omUGEOqsZkpRq3B/hGvY9CtKRqggJIpabulDXAi5bn1WjEpdQcx+RBkcBssz3Vo
UqPWtKdT1Ca/20w371ErMndC+FnHDde6Kq4Wk/2bmnYaliw0w385a/T+N2wx1Hp0
1cWu7Hd8EQKBgQCajL8UNXn4cWG0dby5pzqW/Tm8dVU9xV8OWA1cfSENsmXoYzkH
kdmzsfCdMlwGYu9OsF7hbwWNEFVeaWski9HH+YJfU4pjZYms5EXxXTfFmhz+Gqqt
adWLrW6Z8ll7g3J6gZMJZWELRjv0eUDVdUithvyQQLpZG7DQHpWZtTpHNwKBgQCU
Ja0d8W6Huaf9cZS2Po107n2A5OyZIMApjF9QnlD9Kleo3YmrGSS1B0pqxKCMLhc8
7uu6CNnknVgnk1UYk8AS+YNYHLlp/65HrLgC3TONUDD1g0/d/Z0qYkhEJAu5A7aW
o1j+WJjIY0bPMA2UD4D8w0HNfQckVE5TKlA/N/S2YQKBgQC9sQpUr1OgAgSqX11T
AKM2mvgC2Y7GqRzkdNaG/VndodtZXIY4IRV4n0H8UKswdr8Vf5x15JTFhqjVwW2j
ygE+xW/nHXxYwJxkQUZykLTGBJYTfGND1i5cmySu5g/dn95zlMo3AzZSXBIno+LJ
iX23N2haPwNnvmpbmipv5O87vw==
-----END PRIVATE KEY-----
76 changes: 76 additions & 0 deletions contrib/playwright/gen-cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /bin/bash

if [ "$#" -ne 1 ]
then
echo "Error: No domain name argument provided"
echo "Usage: Provide a domain name as an argument"
exit 1
fi

DOMAIN=$1

# Create root CA & Private key

openssl req -x509 \
-sha256 -days 35600 \
-nodes \
-newkey rsa:2048 \
-subj "/CN=${DOMAIN}/C=US/L=San Fransisco" \
-keyout rootCA.key -out rootCA.crt

# Generate Private key

openssl genrsa -out ${DOMAIN}.key 2048

# Create csf conf

cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C = UK
ST = London
L = London
O = HOTOSM
OU = Tech
CN = ${DOMAIN}

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = ${DOMAIN}

EOF

# create CSR request using private key

openssl req -new -key ${DOMAIN}.key -out ${DOMAIN}.csr -config csr.conf

# Create a external config file for the certificate

cat > cert.conf <<EOF

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = ${DOMAIN}

EOF

# Create SSl with self signed CA

openssl x509 -req \
-in ${DOMAIN}.csr \
-CA rootCA.crt -CAkey rootCA.key \
-CAcreateserial -out ${DOMAIN}.crt \
-days 36500 \
-sha256 -extfile cert.conf
21 changes: 21 additions & 0 deletions contrib/playwright/rootCA.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIUav7MlmczRLQ6GnJFAlDSNjaFeNowDQYJKoZIhvcNAQEL
BQAwPTEWMBQGA1UEAwwNZm10bS5kZXYudGVzdDELMAkGA1UEBhMCVVMxFjAUBgNV
BAcMDVNhbiBGcmFuc2lzY28wIBcNMjQxMTI1MTkyNjU1WhgPMjEyMjA1MTYxOTI2
NTVaMD0xFjAUBgNVBAMMDWZtdG0uZGV2LnRlc3QxCzAJBgNVBAYTAlVTMRYwFAYD
VQQHDA1TYW4gRnJhbnNpc2NvMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
AQEAqGL/SLo30OGY+2nyDxCFZVBt7b8S57dmvqlfiexyip96CRrnWCOx1nwVsPzs
p5jdFar1miproWPqXjV4ETd9ekvJq4Z8b15xEpRd4NbkCBH3j8YMJRfE2GvaASRO
qh7xheHPMA3oVqgkA1kiHgpNVMqjq2gABUMfK3GLz03v053qSvoFnVREhVYS0osB
rtlH9uBXEuiE9VxUzRHYxy18HynIzHUh90uBHz1nFcdaA0P4Iu8uWb75WDvlInWL
uDheqeS3M+J5pbS5Om5lwOAmDIfjv7DP+wRZiXgVlgx42az1ccdlrg4Ee+GCakg8
9NxiIgJsFiIMrrdEyBudA46AlQIDAQABo1MwUTAdBgNVHQ4EFgQUqGK//xpvHPO2
3ZH256psxLYqn7MwHwYDVR0jBBgwFoAUqGK//xpvHPO23ZH256psxLYqn7MwDwYD
VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAcnJ64t2QBmeqCgYIiXcE
Qtm8vCdOHmAlUgWOlFbknwgLhdgfHsZ10Jhr3VlpAwqK8sA50B5GeyGImAC8oBuL
AD4Q04f3sdC1sKeVMzpmGs6TkGTZhWqZvokJYtj9/BURtQ9oGmhOKCtueuho8tFj
RdaPEZ2caj6XDFYE9+7sGxESBiOwktTKUWMpvnkAejNZSLCAqNuOs57SCE+cR/Pm
vQvVhdJVf2SF11VvUVS/SzCK2B7wdPXUhQKkQs6rqdyNS+MWU6jXVdF2NTu9EdoT
WpQrsbLCWgGsc5p+sT4t0X6PWB9X6ujRThyaiWV6FUuaCStJlCqSCgfOxl+D+aOy
hg==
-----END CERTIFICATE-----
4 changes: 2 additions & 2 deletions src/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ dist
/playwright-report/
/blob-report/
/playwright/.cache/

playwright/.auth
/e2e/.cache/
e2e/.auth
8 changes: 2 additions & 6 deletions src/frontend/e2e/01-create-new-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

import { test, expect } from '@playwright/test';

import { tempLogin } from './helpers';

test('create new project', async ({ browserName, page }) => {
// Specific for this large test, only run in one browser
// (playwright.config.ts is configured to run all browsers by default)
test.skip(browserName !== 'chromium', 'Test only for chromium!');

// 0. Temp Login
await tempLogin(page);
await page.getByRole('button', { name: '+ Create New Project' }).click();

// 1. Project Details Step
await page.goto('/');
await page.getByRole('button', { name: '+ Create New Project' }).click();
await page.getByRole('button', { name: 'NEXT' }).click();
await expect(page.getByText('Project Name is Required.')).toBeVisible();
await expect(page.getByText('Short Description is Required.', { exact: true })).toBeVisible();
Expand Down
7 changes: 2 additions & 5 deletions src/frontend/e2e/02-mapper-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@

import { test, expect } from '@playwright/test';

import { tempLogin, openTestProject } from './helpers';
import { openTestProject } from './helpers';

test.describe('mapper flow', () => {
test('task actions', async ({ browserName, page }) => {
// Specific for this large test, only run in one browser
// (playwright.config.ts is configured to run all browsers by default)
test.skip(browserName !== 'chromium', 'Test only for chromium!');

// 0. Temp Login
await tempLogin(page);
await openTestProject(page);

// 1. Click on task area on map
await openTestProject(page);
await page.locator('canvas').click({
position: {
x: 445,
Expand Down
25 changes: 25 additions & 0 deletions src/frontend/e2e/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { test as setup, expect } from '@playwright/test';
import path from 'path';

const authFile = path.join(__dirname, './.auth/user.json');

setup('authenticate', async ({ page }) => {
// Navigate to the app's base URL
await page.goto('/');
await page.getByRole('button', { name: 'Sign in' }).click();

// Select OSM login
await page.getByText('Personal OSM Account').click();
await page.waitForSelector('text=Log in to OpenStreetMap');

// OSM Login page
await page.getByLabel('Email Address or Username').fill('FMTM Playwright');
await page.getByLabel('Password').fill('Boondocks County Send6 Slingshot Villain Vocalist');
await page.getByRole('button', { name: 'Log in' }).click();

// Save authentication state
await page.context().storageState({ path: authFile });

// Wait for redirect and valid login (sign out button)
await page.waitForSelector('text=Sign Out');
});
6 changes: 0 additions & 6 deletions src/frontend/e2e/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Page } from '@playwright/test';

export async function tempLogin(page: Page) {
await page.goto('/');
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByText('Temporary Account').click();
}

export async function openTestProject(page: Page) {
// open project card with regex text 'Project Create Playwright xxx'
await page
Expand Down
25 changes: 22 additions & 3 deletions src/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,40 @@ export default defineConfig({
baseURL: 'http://fmtm.dev.test',
// Record a trace for each test, but remove it from successful test runs
trace: 'retain-on-failure',
// Simplify access over HTTPS, ignore errors
// Alternatively rootCA.crt can be installed in the Playwright container
// but specific config to make Chrome work is also required
// as it does not use the system CA store
ignoreHTTPSErrors: true,
},

/* Configure projects for major browsers */
projects: [
// Setup project
{ name: 'setup', testMatch: /.*\.setup\.ts/ },
{
name: 'chromium',
use: { browserName: 'chromium' },
use: {
browserName: 'chromium',
storageState: 'e2e/.auth/user.json',
},
dependencies: ['setup'],
},
{
name: 'firefox',
use: { browserName: 'firefox' },
use: {
browserName: 'firefox',
storageState: 'e2e/.auth/user.json',
},
dependencies: ['setup'],
},
{
name: 'webkit',
use: { browserName: 'webkit' },
use: {
browserName: 'webkit',
storageState: 'playwright/.auth/user.json',
},
dependencies: ['setup'],
},

/* Test against mobile viewports. */
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export default defineConfig(({ mode }) => {
server: {
port: 7051,
host: '0.0.0.0',
https: {
cert: '/cert/cert.crt',
key: '/cert/cert.key',
},
},
build: {
minify: mode === 'development' ? false : 'esbuild',
Expand Down
Loading