2020-03-20 20:28:31 +00:00
|
|
|
const ChildProcess = require('child_process');
|
|
|
|
const { expect } = require('chai');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const os = require('os');
|
|
|
|
const { ipcRenderer } = require('electron');
|
2020-06-23 03:32:45 +00:00
|
|
|
const features = process._linkedBinding('electron_common_features');
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const { emittedOnce } = require('./events-helpers');
|
|
|
|
const { ifit } = require('./spec-helpers');
|
2019-04-30 22:44:40 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('node feature', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const fixtures = path.join(__dirname, 'fixtures');
|
2017-10-27 20:45:58 +00:00
|
|
|
|
|
|
|
describe('child_process', () => {
|
2019-01-11 16:02:06 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
if (!features.isRunAsNodeEnabled()) {
|
2020-03-20 20:28:31 +00:00
|
|
|
this.skip();
|
2019-01-11 16:02:06 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-01-11 16:02:06 +00:00
|
|
|
|
2018-06-18 03:09:51 +00:00
|
|
|
describe('child_process.fork', () => {
|
2020-06-30 22:10:36 +00:00
|
|
|
it('works in current process', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'));
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('message');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('preserves args', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const args = ['--expose_gc', '-test', '1'];
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args);
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(args).to.deep.equal(msg.slice(2));
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('works in forked process', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'));
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('message');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('works in forked process when options.env is specifed', async () => {
|
2017-10-27 20:45:58 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
|
2020-03-20 15:12:18 +00:00
|
|
|
path: process.env.PATH
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('message');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('has String::localeCompare working in script', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'));
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.deep.equal([0, -1, 1]);
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('has setImmediate working in script', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'));
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(child, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
child.send('message');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('ok');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-05-31 01:26:19 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('pipes stdio', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), { silent: true });
|
|
|
|
let data = '';
|
2016-05-31 01:26:19 +00:00
|
|
|
child.stdout.on('data', (chunk) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
data += String(chunk);
|
|
|
|
});
|
2020-06-30 22:10:36 +00:00
|
|
|
const [code] = await emittedOnce(child, 'close');
|
|
|
|
expect(code).to.equal(0);
|
|
|
|
expect(data).to.equal('pipes stdio');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-04-06 16:47:33 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('works when sending a message to a process forked with the --eval argument', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const source = "process.on('message', (message) => { process.send(message) })";
|
|
|
|
const forked = ChildProcess.fork('--eval', [source]);
|
2020-06-30 22:10:36 +00:00
|
|
|
const message = emittedOnce(forked, 'message');
|
2020-03-20 20:28:31 +00:00
|
|
|
forked.send('hello');
|
2020-06-30 22:10:36 +00:00
|
|
|
const [msg] = await message;
|
|
|
|
expect(msg).to.equal('hello');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-01-30 06:13:18 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('has the electron version in process.versions', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const source = 'process.send(process.versions)';
|
|
|
|
const forked = ChildProcess.fork('--eval', [source]);
|
2020-06-30 22:10:36 +00:00
|
|
|
const [message] = await emittedOnce(forked, 'message');
|
|
|
|
expect(message)
|
|
|
|
.to.have.own.property('electron')
|
|
|
|
.that.is.a('string')
|
|
|
|
.and.matches(/^\d+\.\d+\.\d+(\S*)?$/);
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-12 20:01:43 +00:00
|
|
|
|
2018-06-18 03:35:49 +00:00
|
|
|
describe('child_process.spawn', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let child;
|
2017-06-12 21:04:57 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
if (child != null) child.kill();
|
|
|
|
});
|
2017-06-12 21:04:57 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', async () => {
|
2017-06-12 21:04:57 +00:00
|
|
|
child = ChildProcess.spawn(process.execPath, [path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
2016-10-12 20:01:43 +00:00
|
|
|
env: {
|
|
|
|
ELECTRON_RUN_AS_NODE: true
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-10-12 20:01:43 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
let output = '';
|
2018-10-24 00:23:12 +00:00
|
|
|
child.stdout.on('data', data => {
|
2020-03-20 20:28:31 +00:00
|
|
|
output += data;
|
|
|
|
});
|
2020-06-30 22:10:36 +00:00
|
|
|
await emittedOnce(child.stdout, 'close');
|
|
|
|
expect(JSON.parse(output)).to.deep.equal({
|
|
|
|
processLog: process.platform === 'win32' ? 'function' : 'undefined',
|
|
|
|
processType: 'undefined',
|
|
|
|
window: 'undefined'
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-08-27 22:35:46 +00:00
|
|
|
|
|
|
|
describe('child_process.exec', () => {
|
|
|
|
(process.platform === 'linux' ? it : it.skip)('allows executing a setuid binary from non-sandboxed renderer', () => {
|
|
|
|
// Chrome uses prctl(2) to set the NO_NEW_PRIVILEGES flag on Linux (see
|
|
|
|
// https://github.com/torvalds/linux/blob/40fde647cc/Documentation/userspace-api/no_new_privs.rst).
|
2019-12-17 02:15:12 +00:00
|
|
|
// We disable this for unsandboxed processes, which the renderer tests
|
2019-08-27 22:35:46 +00:00
|
|
|
// are running in. If this test fails with an error like 'effective uid
|
|
|
|
// is not 0', then it's likely that our patch to prevent the flag from
|
|
|
|
// being set has become ineffective.
|
2020-03-20 20:28:31 +00:00
|
|
|
const stdout = ChildProcess.execSync('sudo --help');
|
|
|
|
expect(stdout).to.not.be.empty();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('contexts', () => {
|
|
|
|
describe('setTimeout in fs callback', () => {
|
|
|
|
it('does not crash', (done) => {
|
|
|
|
fs.readFile(__filename, () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
setTimeout(done, 0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('error thrown in renderer process node context', () => {
|
|
|
|
it('gets emitted as a process uncaughtException event', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const error = new Error('boo!');
|
|
|
|
const listeners = process.listeners('uncaughtException');
|
|
|
|
process.removeAllListeners('uncaughtException');
|
2017-01-25 16:55:38 +00:00
|
|
|
process.on('uncaughtException', (thrown) => {
|
2019-01-12 01:00:43 +00:00
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(thrown).to.equal(error);
|
|
|
|
done();
|
2019-01-12 01:00:43 +00:00
|
|
|
} catch (e) {
|
2020-03-20 20:28:31 +00:00
|
|
|
done(e);
|
2019-01-12 01:00:43 +00:00
|
|
|
} finally {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.removeAllListeners('uncaughtException');
|
|
|
|
listeners.forEach((listener) => process.on('uncaughtException', listener));
|
2019-01-12 01:00:43 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-01-25 16:55:38 +00:00
|
|
|
fs.readFile(__filename, () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2020-08-05 22:05:36 +00:00
|
|
|
describe('URL handling in the renderer process', () => {
|
|
|
|
it('can successfully handle WHATWG URLs constructed by Blink', () => {
|
|
|
|
const url = new URL('file://' + path.resolve(fixtures, 'pages', 'base-page.html'));
|
|
|
|
expect(() => {
|
|
|
|
fs.createReadStream(url);
|
|
|
|
}).to.not.throw();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('error thrown in main process node context', () => {
|
|
|
|
it('gets emitted as a process uncaughtException event', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello');
|
|
|
|
expect(error).to.equal('hello');
|
|
|
|
});
|
|
|
|
});
|
2017-01-25 16:55:38 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('promise rejection in main process node context', () => {
|
|
|
|
it('gets emitted as a process unhandledRejection event', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello');
|
|
|
|
expect(error).to.equal('hello');
|
|
|
|
});
|
|
|
|
});
|
2017-01-25 17:04:25 +00:00
|
|
|
|
2019-06-24 17:18:29 +00:00
|
|
|
describe('setTimeout called under blink env in renderer process', () => {
|
|
|
|
it('can be scheduled in time', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
setTimeout(done, 10);
|
|
|
|
});
|
2019-06-24 17:18:29 +00:00
|
|
|
|
|
|
|
it('works from the timers module', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
require('timers').setTimeout(done, 10);
|
|
|
|
});
|
|
|
|
});
|
2019-06-24 17:18:29 +00:00
|
|
|
|
|
|
|
describe('setInterval called under blink env in renderer process', () => {
|
|
|
|
it('can be scheduled in time', (done) => {
|
2019-10-16 00:10:28 +00:00
|
|
|
const id = setInterval(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
clearInterval(id);
|
|
|
|
done();
|
|
|
|
}, 10);
|
|
|
|
});
|
2019-06-24 17:18:29 +00:00
|
|
|
|
|
|
|
it('can be scheduled in time from timers module', (done) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const { setInterval, clearInterval } = require('timers');
|
2019-10-16 00:10:28 +00:00
|
|
|
const id = setInterval(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
clearInterval(id);
|
|
|
|
done();
|
|
|
|
}, 10);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('message loop', () => {
|
|
|
|
describe('process.nextTick', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
it('emits the callback', (done) => process.nextTick(done));
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in nested calls', (done) => {
|
|
|
|
process.nextTick(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.nextTick(() => process.nextTick(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('setImmediate', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
it('emits the callback', (done) => setImmediate(done));
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in nested calls', (done) => {
|
|
|
|
setImmediate(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
setImmediate(() => setImmediate(done));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('net.connect', () => {
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2019-01-11 16:02:06 +00:00
|
|
|
if (!features.isRunAsNodeEnabled() || process.platform !== 'darwin') {
|
2020-03-20 20:28:31 +00:00
|
|
|
this.skip();
|
2017-11-15 21:05:46 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
it('emit error when connect to a socket path without listeners', async () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const socketPath = path.join(os.tmpdir(), 'atom-shell-test.sock');
|
|
|
|
const script = path.join(fixtures, 'module', 'create_socket.js');
|
|
|
|
const child = ChildProcess.fork(script, [socketPath]);
|
2020-06-30 22:10:36 +00:00
|
|
|
const [code] = await emittedOnce(child, 'exit');
|
|
|
|
expect(code).to.equal(0);
|
|
|
|
const client = require('net').connect(socketPath);
|
|
|
|
const [error] = await emittedOnce(client, 'error');
|
|
|
|
expect(error.code).to.equal('ECONNREFUSED');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('Buffer', () => {
|
|
|
|
it('can be created from WebKit external string', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const p = document.createElement('p');
|
|
|
|
p.innerText = '闲云潭影日悠悠,物换星移几度秋';
|
|
|
|
const b = Buffer.from(p.innerText);
|
|
|
|
expect(b.toString()).to.equal('闲云潭影日悠悠,物换星移几度秋');
|
|
|
|
expect(Buffer.byteLength(p.innerText)).to.equal(45);
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('correctly parses external one-byte UTF8 string', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const p = document.createElement('p');
|
|
|
|
p.innerText = 'Jøhänñéß';
|
|
|
|
const b = Buffer.from(p.innerText);
|
|
|
|
expect(b.toString()).to.equal('Jøhänñéß');
|
|
|
|
expect(Buffer.byteLength(p.innerText)).to.equal(13);
|
|
|
|
});
|
2016-04-05 08:08:27 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('does not crash when creating large Buffers', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
let buffer = Buffer.from(new Array(4096).join(' '));
|
|
|
|
expect(buffer.length).to.equal(4095);
|
|
|
|
buffer = Buffer.from(new Array(4097).join(' '));
|
|
|
|
expect(buffer.length).to.equal(4096);
|
|
|
|
});
|
2017-12-27 11:14:41 +00:00
|
|
|
|
|
|
|
it('does not crash for crypto operations', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const data = 'lG9E+/g4JmRmedDAnihtBD4Dfaha/GFOjd+xUOQI05UtfVX3DjUXvrS98p7kZQwY3LNhdiFo7MY5rGft8yBuDhKuNNag9vRx/44IuClDhdQ=';
|
|
|
|
const key = 'q90K9yBqhWZnAMCMTOJfPQ==';
|
|
|
|
const cipherText = '{"error_code":114,"error_message":"Tham số không hợp lệ","data":null}';
|
2017-12-27 11:14:41 +00:00
|
|
|
for (let i = 0; i < 10000; ++i) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const iv = Buffer.from('0'.repeat(32), 'hex');
|
|
|
|
const input = Buffer.from(data, 'base64');
|
|
|
|
const decipher = crypto.createDecipheriv('aes-128-cbc', Buffer.from(key, 'base64'), iv);
|
|
|
|
const result = Buffer.concat([decipher.update(input), decipher.final()]).toString('utf8');
|
|
|
|
expect(cipherText).to.equal(result);
|
2017-12-27 11:14:41 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('process.stdout', () => {
|
|
|
|
it('does not throw an exception when accessed', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => process.stdout).to.not.throw();
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('does not throw an exception when calling write()', () => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(() => {
|
2020-03-20 20:28:31 +00:00
|
|
|
process.stdout.write('test');
|
|
|
|
}).to.not.throw();
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2019-09-20 14:41:40 +00:00
|
|
|
// TODO: figure out why process.stdout.isTTY is true on Darwin but not Linux/Win.
|
|
|
|
ifit(process.platform !== 'darwin')('isTTY should be undefined in the renderer process', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(process.stdout.isTTY).to.be.undefined();
|
|
|
|
});
|
|
|
|
});
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('process.stdin', () => {
|
|
|
|
it('does not throw an exception when accessed', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => process.stdin).to.not.throw();
|
|
|
|
});
|
2016-09-07 21:40:18 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('returns null when read from', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(process.stdin.read()).to.be.null();
|
|
|
|
});
|
|
|
|
});
|
2016-09-07 21:40:18 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('process.version', () => {
|
|
|
|
it('should not have -pre', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(process.version.endsWith('-pre')).to.be.false();
|
|
|
|
});
|
|
|
|
});
|
2016-04-05 10:53:07 +00:00
|
|
|
|
2018-09-19 10:54:58 +00:00
|
|
|
describe('vm.runInNewContext', () => {
|
2017-10-27 20:45:58 +00:00
|
|
|
it('should not crash', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
require('vm').runInNewContext('');
|
|
|
|
});
|
|
|
|
});
|
2017-01-12 01:51:46 +00:00
|
|
|
|
2019-01-28 21:36:51 +00:00
|
|
|
describe('crypto', () => {
|
|
|
|
it('should list the ripemd160 hash in getHashes', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(require('crypto').getHashes()).to.include('ripemd160');
|
|
|
|
});
|
2019-01-28 21:36:51 +00:00
|
|
|
|
|
|
|
it('should be able to create a ripemd160 hash and use it', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const hash = require('crypto').createHash('ripemd160');
|
|
|
|
hash.update('electron-ripemd160');
|
|
|
|
expect(hash.digest('hex')).to.equal('fa7fec13c624009ab126ebb99eda6525583395fe');
|
|
|
|
});
|
2019-01-30 18:34:14 +00:00
|
|
|
|
|
|
|
it('should list aes-{128,256}-cfb in getCiphers', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(require('crypto').getCiphers()).to.include.members(['aes-128-cfb', 'aes-256-cfb']);
|
|
|
|
});
|
2019-01-30 18:34:14 +00:00
|
|
|
|
|
|
|
it('should be able to create an aes-128-cfb cipher', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
require('crypto').createCipheriv('aes-128-cfb', '0123456789abcdef', '0123456789abcdef');
|
|
|
|
});
|
2019-01-30 18:34:14 +00:00
|
|
|
|
|
|
|
it('should be able to create an aes-256-cfb cipher', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
require('crypto').createCipheriv('aes-256-cfb', '0123456789abcdef0123456789abcdef', '0123456789abcdef');
|
|
|
|
});
|
2019-02-12 19:57:11 +00:00
|
|
|
|
|
|
|
it('should list des-ede-cbc in getCiphers', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(require('crypto').getCiphers()).to.include('des-ede-cbc');
|
|
|
|
});
|
2019-02-12 19:57:11 +00:00
|
|
|
|
|
|
|
it('should be able to create an des-ede-cbc cipher', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const key = Buffer.from('0123456789abcdeff1e0d3c2b5a49786', 'hex');
|
|
|
|
const iv = Buffer.from('fedcba9876543210', 'hex');
|
|
|
|
require('crypto').createCipheriv('des-ede-cbc', key, iv);
|
|
|
|
});
|
2019-03-07 01:59:53 +00:00
|
|
|
|
|
|
|
it('should not crash when getting an ECDH key', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const ecdh = require('crypto').createECDH('prime256v1');
|
|
|
|
expect(ecdh.generateKeys()).to.be.an.instanceof(Buffer);
|
|
|
|
expect(ecdh.getPrivateKey()).to.be.an.instanceof(Buffer);
|
|
|
|
});
|
2019-03-07 01:59:53 +00:00
|
|
|
|
|
|
|
it('should not crash when generating DH keys or fetching DH fields', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const dh = require('crypto').createDiffieHellman('modp15');
|
|
|
|
expect(dh.generateKeys()).to.be.an.instanceof(Buffer);
|
|
|
|
expect(dh.getPublicKey()).to.be.an.instanceof(Buffer);
|
|
|
|
expect(dh.getPrivateKey()).to.be.an.instanceof(Buffer);
|
|
|
|
expect(dh.getPrime()).to.be.an.instanceof(Buffer);
|
|
|
|
expect(dh.getGenerator()).to.be.an.instanceof(Buffer);
|
|
|
|
});
|
2019-03-08 18:50:04 +00:00
|
|
|
|
|
|
|
it('should not crash when creating an ECDH cipher', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const dh = crypto.createECDH('prime256v1');
|
|
|
|
dh.generateKeys();
|
|
|
|
dh.setPrivateKey(dh.getPrivateKey());
|
|
|
|
});
|
|
|
|
});
|
2019-01-28 21:36:51 +00:00
|
|
|
|
2017-01-12 01:51:46 +00:00
|
|
|
it('includes the electron version in process.versions', () => {
|
2018-09-19 10:54:58 +00:00
|
|
|
expect(process.versions)
|
|
|
|
.to.have.own.property('electron')
|
|
|
|
.that.is.a('string')
|
2020-03-20 20:28:31 +00:00
|
|
|
.and.matches(/^\d+\.\d+\.\d+(\S*)?$/);
|
|
|
|
});
|
2017-01-12 01:51:46 +00:00
|
|
|
|
|
|
|
it('includes the chrome version in process.versions', () => {
|
2018-09-19 10:54:58 +00:00
|
|
|
expect(process.versions)
|
|
|
|
.to.have.own.property('chrome')
|
|
|
|
.that.is.a('string')
|
2020-03-20 20:28:31 +00:00
|
|
|
.and.matches(/^\d+\.\d+\.\d+\.\d+$/);
|
|
|
|
});
|
|
|
|
});
|