fuses-spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. import { BrowserWindow } from 'electron';
  2. import { expect } from 'chai';
  3. import { spawn } 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 fetching file:// URLs when grant_file_protocol_extra_privileges is 0', async () => {
  19. const rc = await startRemoteControlApp(['--set-fuse-grant_file_protocol_extra_privileges=0']);
  20. await expect(rc.remotely(async (fixture: string) => {
  21. const bw = new BrowserWindow({ show: false });
  22. await bw.loadFile(fixture);
  23. return await bw.webContents.executeJavaScript("ajax('file:///etc/passwd')");
  24. }, path.join(__dirname, 'fixtures', 'pages', 'fetch.html'))).to.eventually.be.rejectedWith('Failed to fetch');
  25. });
  26. });