2024-12-12 09:11:58 -03:00
|
|
|
// Flags: --permission --allow-fs-read=* --allow-child-process
|
2023-05-07 13:22:32 -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-05-07 13:22:32 -03:00
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
|
|
|
|
const { Session } = require('inspector');
|
|
|
|
const assert = require('assert');
|
2023-07-26 15:32:03 -03:00
|
|
|
const { spawnSync } = require('child_process');
|
2023-05-07 13:22:32 -03:00
|
|
|
|
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('no crypto');
|
|
|
|
|
|
|
|
{
|
|
|
|
assert.throws(() => {
|
|
|
|
const session = new Session();
|
|
|
|
session.connect();
|
|
|
|
}, common.expectsError({
|
2025-04-03 19:24:39 -03:00
|
|
|
message: 'Access to this API has been restricted. ',
|
2023-05-07 13:22:32 -03:00
|
|
|
code: 'ERR_ACCESS_DENIED',
|
|
|
|
permission: 'Inspector',
|
|
|
|
}));
|
|
|
|
}
|
2023-07-26 15:32:03 -03:00
|
|
|
|
|
|
|
{
|
|
|
|
const { status, stderr } = spawnSync(
|
|
|
|
process.execPath,
|
|
|
|
[
|
2024-12-12 09:11:58 -03:00
|
|
|
'--permission',
|
2023-07-26 15:32:03 -03:00
|
|
|
'-e',
|
|
|
|
'(new (require("inspector")).Session()).connect()',
|
|
|
|
],
|
|
|
|
);
|
|
|
|
assert.strictEqual(status, 1);
|
|
|
|
assert.match(stderr.toString(), /Error: Access to this API has been restricted/);
|
|
|
|
}
|