Skip to content

Commit

Permalink
test(ses): add a smoke test for SES lockdown in chrome canary
Browse files Browse the repository at this point in the history
  • Loading branch information
naugtur committed Jan 17, 2024
1 parent 5792949 commit c8ff7b4
Show file tree
Hide file tree
Showing 5 changed files with 690 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/lockdown-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Lockdown Canary
## detects lockdown issues on latest chrome

on:
push:
branches:
- lockdown-canary
schedule:
- cron: '0 0 * * *' # Runs every day at midnight

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js stable
uses: actions/setup-node@v3

- name: Setup Chrome
uses: browser-actions/setup-chrome@latest
with:
chrome-version: 'canary'

- name: install dependencies
run: |
cd ./packages/ses/smoke-test/
yarn install
- name: Run tests
run: |
CHROME_BIN=$(which google-chrome-unstable) node ./packages/ses/smoke-test/index.js
11 changes: 11 additions & 0 deletions packages/ses/smoke-test/fixture/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="../../dist/lockdown.umd.js"></script>
</body>
</html>
47 changes: 47 additions & 0 deletions packages/ses/smoke-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable @endo/no-polymorphic-call */
import puppeteer from 'puppeteer-core';
import assert from 'assert';

const chromePath = process.env.CHROME_BIN;
let browser;

async function runTests() {
// Launch the browser
browser = await puppeteer.launch({
executablePath: chromePath,
});

// Open a new page
const page = await browser.newPage();
page.on('pageerror', async err => {
console.error(`Page error: ${err.toString()}`);
});

const pathToIndex = new URL('./fixture/index.html', import.meta.url).href;

await page.goto(pathToIndex);

assert.equal(
await page.evaluate(`typeof lockdown;`),
'function',
'lockdown is not a function',
);
const result = await page.evaluate(`
try {
lockdown();
'success';
}
catch (e) {
e;
}
`);
assert.equal(result, 'success', 'lockdown failed');

await browser.close();
}

runTests().catch(error => {
console.error(error);
browser.close();
process.exit(1);
});
11 changes: 11 additions & 0 deletions packages/ses/smoke-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "ses-smoke-test",
"version": "1.0.1",
"description": "Browser smoke test for SES lockdown",
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"puppeteer-core": "^21.7.0"
},
"private": true
}
Loading

0 comments on commit c8ff7b4

Please sign in to comment.