mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00

This commit also adds a suggestion flag (if exists) when ERR_ACCESS_DENIED is thrown, so users don't need to jump into the documentation to see how to manage that permission error. PR-URL: https://github.com/nodejs/node/pull/57585 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
43 lines
991 B
JavaScript
43 lines
991 B
JavaScript
// Flags: --permission --allow-fs-read=* --allow-child-process
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
if (!isMainThread) {
|
|
common.skip('This test only works on a main thread');
|
|
}
|
|
|
|
common.skipIfInspectorDisabled();
|
|
|
|
const { Session } = require('inspector');
|
|
const assert = require('assert');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('no crypto');
|
|
|
|
{
|
|
assert.throws(() => {
|
|
const session = new Session();
|
|
session.connect();
|
|
}, common.expectsError({
|
|
message: 'Access to this API has been restricted. ',
|
|
code: 'ERR_ACCESS_DENIED',
|
|
permission: 'Inspector',
|
|
}));
|
|
}
|
|
|
|
{
|
|
const { status, stderr } = spawnSync(
|
|
process.execPath,
|
|
[
|
|
'--permission',
|
|
'-e',
|
|
'(new (require("inspector")).Session()).connect()',
|
|
],
|
|
);
|
|
assert.strictEqual(status, 1);
|
|
assert.match(stderr.toString(), /Error: Access to this API has been restricted/);
|
|
}
|