spec: add missing checks to "validates process APIs access in sandboxed renderer" (#17129)
This commit is contained in:
parent
67f04c0370
commit
676c02611d
2 changed files with 46 additions and 9 deletions
|
@ -10,7 +10,6 @@ const qs = require('querystring')
|
||||||
const http = require('http')
|
const http = require('http')
|
||||||
const { closeWindow } = require('./window-helpers')
|
const { closeWindow } = require('./window-helpers')
|
||||||
const { emittedOnce } = require('./events-helpers')
|
const { emittedOnce } = require('./events-helpers')
|
||||||
const { resolveGetters } = require('./assert-helpers')
|
|
||||||
const { ipcRenderer, remote } = require('electron')
|
const { ipcRenderer, remote } = require('electron')
|
||||||
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
|
const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote
|
||||||
|
|
||||||
|
@ -1923,14 +1922,30 @@ describe('BrowserWindow module', () => {
|
||||||
|
|
||||||
it('validates process APIs access in sandboxed renderer', (done) => {
|
it('validates process APIs access in sandboxed renderer', (done) => {
|
||||||
ipcMain.once('answer', function (event, test) {
|
ipcMain.once('answer', function (event, test) {
|
||||||
assert.strictEqual(test.arch, remote.process.arch)
|
expect(test.hasCrash).to.be.true()
|
||||||
assert.strictEqual(test.platform, remote.process.platform)
|
expect(test.hasHang).to.be.true()
|
||||||
assert.deepStrictEqual(...resolveGetters(test.env, remote.process.env))
|
expect(test.heapStatistics).to.be.an('object')
|
||||||
assert.strictEqual(test.execPath, remote.process.helperExecPath)
|
expect(test.processMemoryInfo).to.be.an('object')
|
||||||
assert.strictEqual(test.sandboxed, true)
|
expect(test.systemVersion).to.be.a('string')
|
||||||
assert.strictEqual(test.type, 'renderer')
|
expect(test.cpuUsage).to.be.an('object')
|
||||||
assert.strictEqual(test.version, remote.process.version)
|
expect(test.ioCounters).to.be.an('object')
|
||||||
assert.deepStrictEqual(test.versions, remote.process.versions)
|
expect(test.arch).to.equal(remote.process.arch)
|
||||||
|
expect(test.platform).to.equal(remote.process.platform)
|
||||||
|
expect(test.env).to.deep.equal(remote.process.env)
|
||||||
|
expect(test.execPath).to.equal(remote.process.helperExecPath)
|
||||||
|
expect(test.sandboxed).to.be.true()
|
||||||
|
expect(test.type).to.equal('renderer')
|
||||||
|
expect(test.version).to.equal(remote.process.version)
|
||||||
|
expect(test.versions).to.deep.equal(remote.process.versions)
|
||||||
|
|
||||||
|
if (process.platform === 'linux' && test.osSandbox) {
|
||||||
|
expect(test.creationTime).to.be.null()
|
||||||
|
expect(test.systemMemoryInfo).to.be.null()
|
||||||
|
} else {
|
||||||
|
expect(test.creationTime).to.be.a('number')
|
||||||
|
expect(test.systemMemoryInfo).to.be.an('object')
|
||||||
|
}
|
||||||
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
remote.process.env.sandboxmain = 'foo'
|
remote.process.env.sandboxmain = 'foo'
|
||||||
|
@ -1942,6 +1957,9 @@ describe('BrowserWindow module', () => {
|
||||||
preload
|
preload
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
w.webContents.once('preload-error', (event, preloadPath, error) => {
|
||||||
|
done(error)
|
||||||
|
})
|
||||||
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
|
w.loadFile(path.join(fixtures, 'api', 'preload.html'))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
19
spec/fixtures/module/preload-sandbox.js
vendored
19
spec/fixtures/module/preload-sandbox.js
vendored
|
@ -4,11 +4,30 @@
|
||||||
window.ipcRenderer = ipcRenderer
|
window.ipcRenderer = ipcRenderer
|
||||||
window.setImmediate = setImmediate
|
window.setImmediate = setImmediate
|
||||||
window.require = require
|
window.require = require
|
||||||
|
|
||||||
|
function invoke (code) {
|
||||||
|
try {
|
||||||
|
return code()
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (location.protocol === 'file:') {
|
if (location.protocol === 'file:') {
|
||||||
window.test = 'preload'
|
window.test = 'preload'
|
||||||
window.process = process
|
window.process = process
|
||||||
if (process.env.sandboxmain) {
|
if (process.env.sandboxmain) {
|
||||||
window.test = {
|
window.test = {
|
||||||
|
osSandbox: !process.argv.includes('--no-sandbox'),
|
||||||
|
hasCrash: typeof process.crash === 'function',
|
||||||
|
hasHang: typeof process.hang === 'function',
|
||||||
|
creationTime: invoke(() => process.getCreationTime()),
|
||||||
|
heapStatistics: invoke(() => process.getHeapStatistics()),
|
||||||
|
processMemoryInfo: invoke(() => process.getProcessMemoryInfo()),
|
||||||
|
systemMemoryInfo: invoke(() => process.getSystemMemoryInfo()),
|
||||||
|
systemVersion: invoke(() => process.getSystemVersion()),
|
||||||
|
cpuUsage: invoke(() => process.getCPUUsage()),
|
||||||
|
ioCounters: invoke(() => process.getIOCounters()),
|
||||||
env: process.env,
|
env: process.env,
|
||||||
execPath: process.execPath,
|
execPath: process.execPath,
|
||||||
pid: process.pid,
|
pid: process.pid,
|
||||||
|
|
Loading…
Reference in a new issue