browser-launcher.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const assert = require('assert');
  2. const {
  3. browserLauncherForPlatform
  4. } = require('../../skills/brainstorming/scripts/server.cjs');
  5. let passed = 0;
  6. let failed = 0;
  7. async function test(name, fn) {
  8. try {
  9. await fn();
  10. console.log(` PASS: ${name}`);
  11. passed++;
  12. } catch (e) {
  13. console.log(` FAIL: ${name}`);
  14. console.log(` ${e.message}`);
  15. failed++;
  16. }
  17. }
  18. (async () => {
  19. console.log('\n--- Browser Launcher ---');
  20. await test('Windows launcher does not route URLs through cmd.exe', () => {
  21. const url = 'http://localhost:54122/?key=abc&x=SAFE&echo=INJECTED';
  22. const launcher = browserLauncherForPlatform(url, {
  23. platform: 'win32',
  24. osRelease: '10.0.26200',
  25. env: {}
  26. });
  27. assert.deepStrictEqual(launcher, {
  28. bin: 'rundll32.exe',
  29. args: ['url.dll,FileProtocolHandler', url]
  30. });
  31. assert(!launcher.args.includes('/c'), 'Windows launcher must not pass /c to a command interpreter');
  32. });
  33. await test('WSL launcher does not route URLs through cmd.exe', () => {
  34. const url = 'http://localhost:54122/?key=abc&x=SAFE&echo=INJECTED';
  35. const launcher = browserLauncherForPlatform(url, {
  36. platform: 'linux',
  37. osRelease: '5.15.167.4-microsoft-standard-WSL2',
  38. env: {}
  39. });
  40. assert.deepStrictEqual(launcher, {
  41. bin: 'rundll32.exe',
  42. args: ['url.dll,FileProtocolHandler', url]
  43. });
  44. });
  45. await test('Linux launcher stays headless without a display', () => {
  46. assert.strictEqual(
  47. browserLauncherForPlatform('http://localhost:1/', {
  48. platform: 'linux',
  49. osRelease: '6.0.0',
  50. env: {}
  51. }),
  52. null
  53. );
  54. });
  55. console.log(`\n--- Results: ${passed} passed, ${failed} failed ---`);
  56. if (failed > 0) process.exit(1);
  57. })();