Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksimek committed Apr 5, 2021
1 parent d470fd9 commit a1817b4
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions test/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,29 +888,31 @@ describe('VM', () => {
`), /e is not a function/);
});

it('Dynamic import attack', (done) => {
process.once('unhandledRejection', (reason) => {
assert.strictEqual(reason.message, 'process is not defined');
done();
});
if (NODE_VERSION >= 10) {
it('Dynamic import attack', (done) => {
process.once('unhandledRejection', (reason) => {
assert.strictEqual(reason.message, 'process is not defined');
done();
});

const vm2 = new VM();
const vm2 = new VM();

vm2.run(`
(async () => {
try {
await import('oops!');
} catch (ex) {
// ex is an instance of NodeError which is not proxied;
const process = ex.constructor.constructor('return process')();
const require = process.mainModule.require;
const child_process = require('child_process');
const output = child_process.execSync('id');
process.stdout.write(output);
}
})();
`);
});
vm2.run(`
(async () => {
try {
await import('oops!');
} catch (ex) {
// ex is an instance of NodeError which is not proxied;
const process = ex.constructor.constructor('return process')();
const require = process.mainModule.require;
const child_process = require('child_process');
const output = child_process.execSync('id');
process.stdout.write(output);
}
})();
`);
});
};

after(() => {
vm = null;
Expand Down

0 comments on commit a1817b4

Please sign in to comment.