mirror of
https://github.com/obra/superpowers.git
synced 2026-06-15 23:29:04 +08:00
Harden Windows browser launcher
This commit is contained in:
66
tests/brainstorm-server/browser-launcher.test.js
Normal file
66
tests/brainstorm-server/browser-launcher.test.js
Normal file
@@ -0,0 +1,66 @@
|
||||
const assert = require('assert');
|
||||
const {
|
||||
browserLauncherForPlatform
|
||||
} = require('../../skills/brainstorming/scripts/server.cjs');
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
async function test(name, fn) {
|
||||
try {
|
||||
await fn();
|
||||
console.log(` PASS: ${name}`);
|
||||
passed++;
|
||||
} catch (e) {
|
||||
console.log(` FAIL: ${name}`);
|
||||
console.log(` ${e.message}`);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
console.log('\n--- Browser Launcher ---');
|
||||
|
||||
await test('Windows launcher does not route URLs through cmd.exe', () => {
|
||||
const url = 'http://localhost:54122/?key=abc&x=SAFE&echo=INJECTED';
|
||||
const launcher = browserLauncherForPlatform(url, {
|
||||
platform: 'win32',
|
||||
osRelease: '10.0.26200',
|
||||
env: {}
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(launcher, {
|
||||
bin: 'rundll32.exe',
|
||||
args: ['url.dll,FileProtocolHandler', url]
|
||||
});
|
||||
assert(!launcher.args.includes('/c'), 'Windows launcher must not pass /c to a command interpreter');
|
||||
});
|
||||
|
||||
await test('WSL launcher does not route URLs through cmd.exe', () => {
|
||||
const url = 'http://localhost:54122/?key=abc&x=SAFE&echo=INJECTED';
|
||||
const launcher = browserLauncherForPlatform(url, {
|
||||
platform: 'linux',
|
||||
osRelease: '5.15.167.4-microsoft-standard-WSL2',
|
||||
env: {}
|
||||
});
|
||||
|
||||
assert.deepStrictEqual(launcher, {
|
||||
bin: 'rundll32.exe',
|
||||
args: ['url.dll,FileProtocolHandler', url]
|
||||
});
|
||||
});
|
||||
|
||||
await test('Linux launcher stays headless without a display', () => {
|
||||
assert.strictEqual(
|
||||
browserLauncherForPlatform('http://localhost:1/', {
|
||||
platform: 'linux',
|
||||
osRelease: '6.0.0',
|
||||
env: {}
|
||||
}),
|
||||
null
|
||||
);
|
||||
});
|
||||
|
||||
console.log(`\n--- Results: ${passed} passed, ${failed} failed ---`);
|
||||
if (failed > 0) process.exit(1);
|
||||
})();
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "brainstorm-server-tests",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "node ws-protocol.test.js && node helper.test.js && node auth.test.js && node server.test.js && node lifecycle.test.js && bash start-server.test.sh && bash stop-server.test.sh"
|
||||
"test": "node ws-protocol.test.js && node helper.test.js && node browser-launcher.test.js && node auth.test.js && node server.test.js && node lifecycle.test.js && bash start-server.test.sh && bash stop-server.test.sh"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^8.19.0"
|
||||
|
||||
Reference in New Issue
Block a user