fix: capture the promise global to avoid userland mutation (#20925) (#20947)

This commit is contained in:
Samuel Attard
2019-11-04 15:58:55 -08:00
committed by GitHub
parent 976c7d122a
commit 49009236d9
6 changed files with 40 additions and 2 deletions

View File

@@ -508,4 +508,22 @@ describe('remote module', () => {
w.loadURL('about:blank')
})
})
describe('with an overriden global Promise constrctor', () => {
let original
before(() => {
original = Promise
})
it('using a promise based method resolves correctly', async () => {
expect(await remote.getGlobal('returnAPromise')(123)).to.equal(123)
global.Promise = { resolve: () => ({}) }
expect(await remote.getGlobal('returnAPromise')(456)).to.equal(456)
})
after(() => {
global.Promise = original
})
})
})

View File

@@ -72,6 +72,7 @@ ipcMain.on('echo', function (event, msg) {
})
global.setTimeoutPromisified = util.promisify(setTimeout)
global.returnAPromise = (value) => new Promise((resolve) => setTimeout(() => resolve(value), 100))
global.permissionChecks = {
allow: () => electron.session.defaultSession.setPermissionCheckHandler(null),