fuses-spec.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { BrowserWindow } from 'electron';
  2. import { expect } from 'chai';
  3. import { spawn, spawnSync } from 'node:child_process';
  4. import { once } from 'node:events';
  5. import path = require('node:path');
  6. import { startRemoteControlApp } from './lib/spec-helpers';
  7. describe('fuses', () => {
  8. it('can be enabled by command-line argument during testing', async () => {
  9. const child0 = spawn(process.execPath, ['-v'], { env: { NODE_OPTIONS: '-e 0' } });
  10. const [code0] = await once(child0, 'exit');
  11. // Should exit with 9 because -e is not allowed in NODE_OPTIONS
  12. expect(code0).to.equal(9);
  13. const child1 = spawn(process.execPath, ['--set-fuse-node_options=0', '-v'], { env: { NODE_OPTIONS: '-e 0' } });
  14. const [code1] = await once(child1, 'exit');
  15. // Should print the version and exit with 0
  16. expect(code1).to.equal(0);
  17. });
  18. it('disables --inspect flag when node_cli_inspect is 0', () => {
  19. const { status, stderr } = spawnSync(process.execPath, ['--set-fuse-node_cli_inspect=0', '--inspect', '-v'], { encoding: 'utf-8' });
  20. expect(stderr).to.not.include('Debugger listening on ws://');
  21. // Should print the version and exit with 0
  22. expect(status).to.equal(0);
  23. });
  24. it('disables fetching file:// URLs when grant_file_protocol_extra_privileges is 0', async () => {
  25. const rc = await startRemoteControlApp(['--set-fuse-grant_file_protocol_extra_privileges=0']);
  26. await expect(rc.remotely(async (fixture: string) => {
  27. const bw = new BrowserWindow({ show: false });
  28. await bw.loadFile(fixture);
  29. return await bw.webContents.executeJavaScript("ajax('file:///etc/passwd')");
  30. }, path.join(__dirname, 'fixtures', 'pages', 'fetch.html'))).to.eventually.be.rejectedWith('Failed to fetch');
  31. });
  32. });