2016-06-29 16:37:10 +00:00
|
|
|
const ChildProcess = require('child_process')
|
2018-10-24 00:23:12 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const { expect } = chai
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2016-03-25 20:03:49 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const os = require('os')
|
2018-09-13 16:10:51 +00:00
|
|
|
const { ipcRenderer, remote } = require('electron')
|
2019-01-11 16:02:06 +00:00
|
|
|
const features = process.atomBinding('features')
|
2016-03-25 20:03:49 +00:00
|
|
|
|
2016-06-20 02:16:17 +00:00
|
|
|
const isCI = remote.getGlobal('isCi')
|
2018-10-24 00:23:12 +00:00
|
|
|
chai.use(dirtyChai)
|
2016-06-20 02:16:17 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('node feature', () => {
|
|
|
|
const fixtures = path.join(__dirname, 'fixtures')
|
|
|
|
|
|
|
|
describe('child_process', () => {
|
2019-01-11 16:02:06 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
if (!features.isRunAsNodeEnabled()) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-18 03:09:51 +00:00
|
|
|
describe('child_process.fork', () => {
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in current process', (done) => {
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'ping.js'))
|
2018-10-24 00:23:12 +00:00
|
|
|
child.on('message', msg => {
|
|
|
|
expect(msg).to.equal('message')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('preserves args', (done) => {
|
|
|
|
const args = ['--expose_gc', '-test', '1']
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process_args.js'), args)
|
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(args).to.deep.equal(msg.slice(2))
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in forked process', (done) => {
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'))
|
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(msg).to.equal('message')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in forked process when options.env is specifed', (done) => {
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'fork_ping.js'), [], {
|
2016-01-12 02:40:23 +00:00
|
|
|
path: process.env['PATH']
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(msg).to.equal('message')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works in browser process', (done) => {
|
|
|
|
const fork = remote.require('child_process').fork
|
|
|
|
const child = fork(path.join(fixtures, 'module', 'ping.js'))
|
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(msg).to.equal('message')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('has String::localeCompare working in script', (done) => {
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'locale-compare.js'))
|
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(msg).to.deep.equal([0, -1, 1])
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('has setImmediate working in script', (done) => {
|
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'set-immediate.js'))
|
|
|
|
child.on('message', (msg) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(msg).to.equal('ok')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
child.send('message')
|
|
|
|
})
|
2016-05-31 01:26:19 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('pipes stdio', (done) => {
|
2018-09-13 16:10:51 +00:00
|
|
|
const child = ChildProcess.fork(path.join(fixtures, 'module', 'process-stdout.js'), { silent: true })
|
2016-05-31 01:26:19 +00:00
|
|
|
let data = ''
|
|
|
|
child.stdout.on('data', (chunk) => {
|
|
|
|
data += String(chunk)
|
|
|
|
})
|
2017-04-20 18:40:04 +00:00
|
|
|
child.on('close', (code) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(code).to.equal(0)
|
|
|
|
expect(data).to.equal('pipes stdio')
|
2016-05-31 01:26:19 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2017-04-06 16:47:33 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('works when sending a message to a process forked with the --eval argument', (done) => {
|
2017-04-06 16:52:52 +00:00
|
|
|
const source = "process.on('message', (message) => { process.send(message) })"
|
2017-04-06 16:47:33 +00:00
|
|
|
const forked = ChildProcess.fork('--eval', [source])
|
2017-04-06 16:52:52 +00:00
|
|
|
forked.once('message', (message) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(message).to.equal('hello')
|
2017-04-06 16:47:33 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
forked.send('hello')
|
|
|
|
})
|
2019-01-30 06:13:18 +00:00
|
|
|
|
|
|
|
it('has the electron version in process.versions', (done) => {
|
|
|
|
const source = 'process.send(process.versions)'
|
|
|
|
const forked = ChildProcess.fork('--eval', [source])
|
|
|
|
forked.on('message', (message) => {
|
|
|
|
expect(message)
|
|
|
|
.to.have.own.property('electron')
|
|
|
|
.that.is.a('string')
|
|
|
|
.and.matches(/^\d+\.\d+\.\d+(\S*)?$/)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-10-12 20:01:43 +00:00
|
|
|
|
2018-06-18 03:35:49 +00:00
|
|
|
describe('child_process.spawn', () => {
|
2017-06-12 21:04:57 +00:00
|
|
|
let child
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
afterEach(() => {
|
|
|
|
if (child != null) child.kill()
|
2017-06-12 21:04:57 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('supports spawning Electron as a node process via the ELECTRON_RUN_AS_NODE env var', (done) => {
|
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
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let output = ''
|
2018-10-24 00:23:12 +00:00
|
|
|
child.stdout.on('data', data => {
|
2016-10-12 20:01:43 +00:00
|
|
|
output += data
|
|
|
|
})
|
2017-10-27 20:45:58 +00:00
|
|
|
child.stdout.on('close', () => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(JSON.parse(output)).to.deep.equal({
|
2016-10-12 20:01:43 +00:00
|
|
|
processLog: process.platform === 'win32' ? 'function' : 'undefined',
|
|
|
|
processType: 'undefined',
|
|
|
|
window: 'undefined'
|
|
|
|
})
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
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, () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
setTimeout(done, 0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
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) => {
|
2017-01-25 16:55:38 +00:00
|
|
|
const error = new Error('boo!')
|
|
|
|
const listeners = process.listeners('uncaughtException')
|
2016-03-25 20:03:49 +00:00
|
|
|
process.removeAllListeners('uncaughtException')
|
2017-01-25 16:55:38 +00:00
|
|
|
process.on('uncaughtException', (thrown) => {
|
2019-01-12 01:00:43 +00:00
|
|
|
try {
|
|
|
|
expect(thrown).to.equal(error)
|
|
|
|
done()
|
|
|
|
} catch (e) {
|
|
|
|
done(e)
|
|
|
|
} finally {
|
|
|
|
process.removeAllListeners('uncaughtException')
|
|
|
|
listeners.forEach((listener) => process.on('uncaughtException', listener))
|
|
|
|
}
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2017-01-25 16:55:38 +00:00
|
|
|
fs.readFile(__filename, () => {
|
2016-03-25 20:03:49 +00:00
|
|
|
throw error
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('error thrown in main process node context', () => {
|
|
|
|
it('gets emitted as a process uncaughtException event', () => {
|
2017-01-25 16:55:38 +00:00
|
|
|
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
|
2018-10-24 00:23:12 +00:00
|
|
|
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', () => {
|
2017-01-25 17:04:25 +00:00
|
|
|
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(error).to.equal('hello')
|
2017-01-25 17:04:25 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('setTimeout called under Chromium event loop in browser process', () => {
|
|
|
|
it('can be scheduled in time', (done) => {
|
2016-03-25 20:03:49 +00:00
|
|
|
remote.getGlobal('setTimeout')(done, 0)
|
|
|
|
})
|
2018-07-30 01:14:04 +00:00
|
|
|
|
|
|
|
it('can be promisified', (done) => {
|
|
|
|
remote.getGlobal('setTimeoutPromisified')(0).then(done)
|
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('setInterval called under Chromium event loop in browser process', () => {
|
|
|
|
it('can be scheduled in time', (done) => {
|
2018-03-07 05:40:27 +00:00
|
|
|
let interval = null
|
2018-03-14 05:51:47 +00:00
|
|
|
let clearing = false
|
2018-03-07 05:40:27 +00:00
|
|
|
const clear = () => {
|
2018-10-24 00:23:12 +00:00
|
|
|
if (interval === null || clearing) return
|
|
|
|
|
2018-03-14 05:51:47 +00:00
|
|
|
// interval might trigger while clearing (remote is slow sometimes)
|
|
|
|
clearing = true
|
2016-03-25 20:03:49 +00:00
|
|
|
remote.getGlobal('clearInterval')(interval)
|
2018-03-14 05:51:47 +00:00
|
|
|
clearing = false
|
2018-03-07 05:40:27 +00:00
|
|
|
interval = null
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
interval = remote.getGlobal('setInterval')(clear, 10)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2018-06-18 03:29:46 +00:00
|
|
|
describe('inspector', () => {
|
2018-09-19 10:54:58 +00:00
|
|
|
let child = null
|
2017-11-06 14:25:48 +00:00
|
|
|
|
2019-01-11 16:02:06 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
if (!features.isRunAsNodeEnabled()) {
|
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-11-06 14:25:48 +00:00
|
|
|
afterEach(() => {
|
2018-09-19 10:54:58 +00:00
|
|
|
if (child !== null) child.kill()
|
2017-11-06 14:25:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('supports starting the v8 inspector with --inspect/--inspect-brk', (done) => {
|
|
|
|
child = ChildProcess.spawn(process.execPath, ['--inspect-brk', path.join(__dirname, 'fixtures', 'module', 'run-as-node.js')], {
|
|
|
|
env: {
|
|
|
|
ELECTRON_RUN_AS_NODE: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let output = ''
|
2018-10-02 06:36:22 +00:00
|
|
|
function cleanup () {
|
|
|
|
child.stderr.removeListener('data', errorDataListener)
|
|
|
|
child.stdout.removeListener('data', outDataHandler)
|
|
|
|
}
|
|
|
|
function errorDataListener (data) {
|
2017-11-06 14:25:48 +00:00
|
|
|
output += data
|
2018-10-02 06:36:22 +00:00
|
|
|
if (output.trim().startsWith('Debugger listening on ws://')) {
|
|
|
|
cleanup()
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function outDataHandler (data) {
|
|
|
|
cleanup()
|
2017-11-06 14:25:48 +00:00
|
|
|
done(new Error(`Unexpected output: ${data.toString()}`))
|
2018-10-02 06:36:22 +00:00
|
|
|
}
|
|
|
|
child.stderr.on('data', errorDataListener)
|
|
|
|
child.stdout.on('data', outDataHandler)
|
2017-11-06 14:25:48 +00:00
|
|
|
})
|
|
|
|
|
2018-11-20 21:23:50 +00:00
|
|
|
it('does not start the v8 inspector when --inspect is after a -- argument', (done) => {
|
|
|
|
child = ChildProcess.spawn(remote.process.execPath, [path.join(__dirname, 'fixtures', 'module', 'noop.js'), '--', '--inspect'])
|
|
|
|
|
|
|
|
let output = ''
|
|
|
|
function dataListener (data) {
|
|
|
|
output += data
|
|
|
|
}
|
|
|
|
child.stderr.on('data', dataListener)
|
|
|
|
child.stdout.on('data', dataListener)
|
|
|
|
child.on('exit', () => {
|
|
|
|
if (output.trim().startsWith('Debugger listening on ws://')) {
|
|
|
|
done(new Error('Inspector was started when it should not have been'))
|
|
|
|
} else {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-06 14:25:48 +00:00
|
|
|
it('supports js binding', (done) => {
|
|
|
|
child = ChildProcess.spawn(process.execPath, ['--inspect', path.join(__dirname, 'fixtures', 'module', 'inspector-binding.js')], {
|
|
|
|
env: {
|
|
|
|
ELECTRON_RUN_AS_NODE: true
|
|
|
|
},
|
|
|
|
stdio: ['ipc']
|
|
|
|
})
|
|
|
|
|
2018-10-30 05:13:33 +00:00
|
|
|
child.on('message', ({ cmd, debuggerEnabled, success }) => {
|
2017-11-06 14:25:48 +00:00
|
|
|
if (cmd === 'assert') {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(debuggerEnabled).to.be.true()
|
|
|
|
expect(success).to.be.true()
|
2017-11-06 14:25:48 +00:00
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('message loop', () => {
|
|
|
|
describe('process.nextTick', () => {
|
2018-10-24 00:23:12 +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(() => {
|
2018-10-24 00:23:12 +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', () => {
|
2018-10-24 00:23:12 +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(() => {
|
2018-10-24 00:23:12 +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') {
|
2017-11-15 21:05:46 +00:00
|
|
|
this.skip()
|
|
|
|
}
|
|
|
|
})
|
2016-02-17 01:09:41 +00:00
|
|
|
|
2018-06-18 14:24:26 +00:00
|
|
|
it('emit error when connect to a socket path without listeners', (done) => {
|
2017-10-27 20:45:58 +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])
|
|
|
|
child.on('exit', (code) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(code).to.equal(0)
|
2017-10-27 20:45:58 +00:00
|
|
|
const client = require('net').connect(socketPath)
|
|
|
|
client.on('error', (error) => {
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(error.code).to.equal('ECONNREFUSED')
|
2016-03-25 20:03:49 +00:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
describe('Buffer', () => {
|
|
|
|
it('can be created from WebKit external string', () => {
|
|
|
|
const p = document.createElement('p')
|
2016-03-25 20:03:49 +00:00
|
|
|
p.innerText = '闲云潭影日悠悠,物换星移几度秋'
|
2017-11-23 22:22:31 +00:00
|
|
|
const b = Buffer.from(p.innerText)
|
2018-10-24 00:23:12 +00:00
|
|
|
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', () => {
|
|
|
|
const p = document.createElement('p')
|
2016-03-25 20:03:49 +00:00
|
|
|
p.innerText = 'Jøhänñéß'
|
2017-11-23 22:22:31 +00:00
|
|
|
const b = Buffer.from(p.innerText)
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(b.toString()).to.equal('Jøhänñéß')
|
|
|
|
expect(Buffer.byteLength(p.innerText)).to.equal(13)
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
2016-04-05 08:08:27 +00:00
|
|
|
|
2017-10-27 20:45:58 +00:00
|
|
|
it('does not crash when creating large Buffers', () => {
|
2017-11-23 22:22:31 +00:00
|
|
|
let buffer = Buffer.from(new Array(4096).join(' '))
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(buffer.length).to.equal(4095)
|
2017-11-23 22:22:31 +00:00
|
|
|
buffer = Buffer.from(new Array(4097).join(' '))
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(buffer.length).to.equal(4096)
|
2016-04-05 08:08:27 +00:00
|
|
|
})
|
2017-12-27 11:14:41 +00:00
|
|
|
|
|
|
|
it('does not crash for crypto operations', () => {
|
|
|
|
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}'
|
|
|
|
for (let i = 0; i < 10000; ++i) {
|
2018-10-02 01:56: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')
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(cipherText).to.equal(result)
|
2017-12-27 11:14:41 +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', () => {
|
2018-10-24 00:23:12 +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(() => {
|
2016-09-07 21:40:18 +00:00
|
|
|
process.stdout.write('test')
|
2018-10-24 00:23:12 +00:00
|
|
|
}).to.not.throw()
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('should have isTTY defined on Mac and Linux', function () {
|
|
|
|
if (isCI || process.platform === 'win32') {
|
2018-09-19 10:54:58 +00:00
|
|
|
this.skip()
|
2017-11-15 21:05:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-10-24 00:23:12 +00:00
|
|
|
expect(process.stdout.isTTY).to.be.a('boolean')
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-06-20 02:16:17 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('should have isTTY undefined on Windows', function () {
|
|
|
|
if (isCI || process.platform !== 'win32') {
|
2018-09-19 10:54:58 +00:00
|
|
|
this.skip()
|
2017-11-15 21:05:46 +00:00
|
|
|
return
|
2016-09-08 20:12:00 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
|
2018-10-24 00:23:12 +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', () => {
|
2018-10-24 00:23:12 +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', () => {
|
2018-10-24 00:23:12 +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', () => {
|
2018-10-24 00:23:12 +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', () => {
|
2016-03-25 20:03:49 +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', () => {
|
|
|
|
expect(require('crypto').getHashes()).to.include('ripemd160')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to create a ripemd160 hash and use it', () => {
|
|
|
|
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', () => {
|
|
|
|
expect(require('crypto').getCiphers()).to.include.members(['aes-128-cfb', 'aes-256-cfb'])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to create an aes-128-cfb cipher', () => {
|
|
|
|
require('crypto').createCipheriv('aes-128-cfb', '0123456789abcdef', '0123456789abcdef')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to create an aes-256-cfb cipher', () => {
|
|
|
|
require('crypto').createCipheriv('aes-256-cfb', '0123456789abcdef0123456789abcdef', '0123456789abcdef')
|
|
|
|
})
|
2019-02-12 19:57:11 +00:00
|
|
|
|
|
|
|
it('should list des-ede-cbc in getCiphers', () => {
|
|
|
|
expect(require('crypto').getCiphers()).to.include('des-ede-cbc')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should be able to create an des-ede-cbc cipher', () => {
|
|
|
|
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', () => {
|
|
|
|
const ecdh = require('crypto').createECDH('prime256v1')
|
|
|
|
expect(ecdh.generateKeys()).to.be.an.instanceof(Buffer)
|
|
|
|
expect(ecdh.getPrivateKey()).to.be.an.instanceof(Buffer)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not crash when generating DH keys or fetching DH fields', () => {
|
|
|
|
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-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')
|
|
|
|
.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')
|
|
|
|
.and.matches(/^\d+\.\d+\.\d+\.\d+$/)
|
2017-01-12 01:51:46 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|