2024-12-12 09:11:58 -03:00
|
|
|
// Flags: --permission --allow-fs-read=*
|
2023-02-23 15:11:51 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2025-01-22 14:19:38 -08:00
|
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
|
|
|
|
if (!isMainThread) {
|
|
|
|
common.skip('This test only works on a main thread');
|
|
|
|
}
|
|
|
|
|
2023-02-23 15:11:51 -03:00
|
|
|
const assert = require('assert');
|
|
|
|
const childProcess = require('child_process');
|
|
|
|
|
|
|
|
if (process.argv[2] === 'child') {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Guarantee the initial state
|
|
|
|
{
|
|
|
|
assert.ok(!process.permission.has('child'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// When a permission is set by cli, the process shouldn't be able
|
|
|
|
// to spawn
|
|
|
|
{
|
|
|
|
assert.throws(() => {
|
|
|
|
childProcess.spawn(process.execPath, ['--version']);
|
|
|
|
}, common.expectsError({
|
2025-04-03 19:24:39 -03:00
|
|
|
message: 'Access to this API has been restricted. Use --allow-child-process to manage permissions.',
|
2023-02-23 15:11:51 -03:00
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-03-06 13:45:07 -03:00
|
|
|
assert.throws(() => {
|
|
|
|
childProcess.spawnSync(process.execPath, ['--version']);
|
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-02-23 15:11:51 -03:00
|
|
|
assert.throws(() => {
|
2024-09-29 22:44:52 +02:00
|
|
|
childProcess.exec(...common.escapePOSIXShell`"${process.execPath}" --version`);
|
2023-02-23 15:11:51 -03:00
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-03-06 13:45:07 -03:00
|
|
|
assert.throws(() => {
|
2024-09-29 22:44:52 +02:00
|
|
|
childProcess.execSync(...common.escapePOSIXShell`"${process.execPath}" --version`);
|
2023-03-06 13:45:07 -03:00
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-02-23 15:11:51 -03:00
|
|
|
assert.throws(() => {
|
|
|
|
childProcess.fork(__filename, ['child']);
|
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
|
|
|
assert.throws(() => {
|
2024-09-29 22:44:52 +02:00
|
|
|
childProcess.execFile(...common.escapePOSIXShell`"${process.execPath}" --version`);
|
2023-02-23 15:11:51 -03:00
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-03-06 13:45:07 -03:00
|
|
|
assert.throws(() => {
|
2024-09-29 22:44:52 +02:00
|
|
|
childProcess.execFileSync(...common.escapePOSIXShell`"${process.execPath}" --version`);
|
2023-03-06 13:45:07 -03:00
|
|
|
}, common.expectsError({
|
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'ChildProcess',
|
|
|
|
}));
|
2023-02-23 15:11:51 -03:00
|
|
|
}
|