Skip to content

Commit 146f0f3

Browse files
committed
test(web): the same-tab sign-in check also runs with the extension host on its own origin
1 parent ddd0e69 commit 146f0f3

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎web/test/e2e-signin-tab.mjs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// - a result left by a callback page whose editor is gone is delivered when the editor next starts,
1717
// and an old one is not.
1818
//
19-
// node web/test/e2e-signin-tab.mjs --static <vscode-web dir> --extensions <built extensions dir>
20-
// node web/test/e2e-signin-tab.mjs --dist <release dir>
19+
// node web/test/e2e-signin-tab.mjs --static <vscode-web dir> --extensions <built extensions dir> [--product <json>]
20+
// node web/test/e2e-signin-tab.mjs --dist <release dir> --stub-port <the account port it was built with>
2121
import { spawn } from 'node:child_process';
2222
import fs from 'node:fs';
2323
import path from 'node:path';
@@ -44,7 +44,12 @@ const check = (name, ok, detail = '') => { results.push(ok); console.log(`${ok ?
4444
const stub = await startStub({ editorOrigin, port: args['stub-port'] ? Number(args['stub-port']) : 0 });
4545
const server = spawn(process.execPath, [path.join(HERE, '..', 'serve.mjs'), '--port', String(PORT), ...(DIST
4646
? ['--dist', DIST]
47-
: ['--static', STATIC, '--extensions', EXTS, '--extension-names', 'levelcode-ai,levelcode-web', '--account', stub.origin])], { stdio: 'inherit' });
47+
: ['--static', STATIC, '--extensions', EXTS, '--extension-names', 'levelcode-ai,levelcode-web', '--account', stub.origin,
48+
...(args.product ? ['--product', args.product] : [])])], { stdio: 'inherit' });
49+
// With the extension host on an origin of its own (--product with webEndpointUrlTemplate, or a release built with
50+
// --ext-host-origin) its fetches carry THAT origin, not the editor's.
51+
let hardened = /webEndpointUrlTemplate/.test(args.product || '');
52+
if (DIST) { try { hardened = !/\(same origin/.test(fs.readFileSync(path.join(DIST, 'build.json'), 'utf8')); } catch { /* keep */ } }
4853
let chrome;
4954
const finish = async (code) => { try { chrome && chrome.close(); } catch {} try { server.kill(); } catch {} try { await stub.close(); } catch {} process.exit(code); };
5055
process.on('SIGINT', () => finish(130));
@@ -66,7 +71,8 @@ try {
6671
await page.waitFor(() => exchanges() >= 1, { ms: 90000, label: 'code exchange' }).catch(() => null);
6772
check('the code was exchanged, with the verifier that was kept across the reload', exchanges() === 1, 'exchanges: ' + exchanges());
6873
const exch = stub.state.log.find((e) => e.path === '/api/levelcode/v1/auth/exchange' && e.method === 'POST') || {};
69-
check('the exchange came from the editor\'s origin (CORS answered)', exch.origin === editorOrigin, 'from ' + exch.origin);
74+
check(hardened ? 'the exchange came from the extension host\'s own origin (CORS answered)' : 'the exchange came from the editor\'s origin (CORS answered)',
75+
hardened ? /^https?:\/\/v--[a-z0-9]+\./.test(exch.origin || '') : exch.origin === editorOrigin, 'from ' + exch.origin);
7076
await workbenchReady(page);
7177
await page.waitFor(() => accountCalls() >= 1, { ms: 30000, label: 'the account API with the new token' }).catch(() => null);
7278
check('the editor then used its session against the account API', accountCalls() >= 1, 'calls: ' + accountCalls());

0 commit comments

Comments
 (0)