diff options
| author | Doan Luu Duc Tai <doan@luuduct.ai> | 2026-10-30 17:04:10 -0500 |
|---|---|---|
| committer | Doan Luu Duc Tai <doan@luuduct.ai> | 2026-10-30 17:04:10 -0500 |
| commit | f196c27faf265cd14d8d7accf58e87b4df3c8a91 (patch) | |
| tree | f01a57dbee2c6583458c496a366bc06bc82d5fb7 /crates/chat-crypto/tests/browser.mjs | |
| parent | b46ece18a424eaea3f396ddae7e45e91d1c0e742 (diff) | |
Add experimental PQ browser probe and document blocking timing review
Diffstat (limited to 'crates/chat-crypto/tests/browser.mjs')
| -rw-r--r-- | crates/chat-crypto/tests/browser.mjs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/crates/chat-crypto/tests/browser.mjs b/crates/chat-crypto/tests/browser.mjs new file mode 100644 index 0000000..c6aae93 --- /dev/null +++ b/crates/chat-crypto/tests/browser.mjs @@ -0,0 +1,66 @@ +// Copyright (C) 2026 Doan Luu Duc Tai <doan@luuduct.ai> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +import { createServer } from 'node:http'; +import { readFile } from 'node:fs/promises'; +import { resolve } from 'node:path'; +import assert from 'node:assert/strict'; +import { chromium } from '../../../.tools/browser/node_modules/playwright/index.mjs'; + +const assets = new Map([ + ['/crypto.js', ['stack_chat_crypto.js', 'text/javascript']], + ['/stack_chat_crypto_bg.wasm', ['stack_chat_crypto_bg.wasm', 'application/wasm']], +]); +const server = createServer(async (request, response) => { + response.setHeader('Cache-Control', 'no-store'); + if (request.url === '/') { + response.setHeader('Content-Type', 'text/html'); + response.end('<!doctype html><title>Local cryptographic compatibility test</title>'); + return; + } + const asset = assets.get(request.url); + if (!asset) { response.writeHead(404); response.end(); return; } + response.setHeader('Content-Type', asset[1]); + response.end(await readFile(resolve('.tools/chat-proof', asset[0]))); +}); +await new Promise(resolveReady => server.listen(0, '127.0.0.1', resolveReady)); +const origin = `http://127.0.0.1:${server.address().port}`; +const browser = await chromium.launch({headless: true, channel: "chromium"}); +const deadline = setTimeout(() => browser.close(), 120000); +try { + const page = await browser.newPage(); + const external = []; + page.on('request', request => { + if (!request.url().startsWith(origin + '/')) external.push(request.url()); + }); + await page.goto(origin); + const result = await page.evaluate(async () => { + const module = await import('/crypto.js'); + await module.default(); + return module.compatibility_probe(); + }); + assert.match(result, /^PASS:/); + assert.deepEqual(external, []); + assert.deepEqual(await page.context().cookies(), []); + assert.equal(await page.evaluate(() => localStorage.length + sessionStorage.length), 0); + assert.deepEqual(await page.evaluate(async () => indexedDB.databases()), []); + assert.equal(await page.evaluate(async () => (await navigator.serviceWorker.getRegistrations()).length), 0); + console.log(result); + console.log('PASS: actual Chromium WASM execution; no external requests, cookies, web storage, or IndexedDB.'); +} finally { + clearTimeout(deadline); + await browser.close(); + await new Promise(resolveClosed => server.close(resolveClosed)); +} |
