mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
Add --permission-audit flag that enables the permission model in warning-only mode. Instead of throwing ERR_ACCESS_DENIED, it emits a message via diagnostics channel and allows the operation to continue. Publish permission check results to per-scope diagnostics channels (e.g., node:permission-model:fs) so users can observe permission decisions at runtime via diagnostics_channel. Refs: https://github.com/nodejs/node/issues/59935 PR-URL: https://github.com/nodejs/node/pull/61869 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
30 lines
831 B
JavaScript
30 lines
831 B
JavaScript
// Flags: --permission --allow-fs-read=*
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
if (!isMainThread) {
|
|
common.skip('This test only works on a main thread');
|
|
}
|
|
|
|
const assert = require('node:assert');
|
|
const dc = require('node:diagnostics_channel');
|
|
const fs = require('node:fs');
|
|
|
|
const messages = [];
|
|
dc.subscribe('node:permission-model:fs', (msg) => {
|
|
messages.push(msg);
|
|
});
|
|
|
|
// Granted permission should not publish
|
|
fs.readFileSync(__filename);
|
|
assert.strictEqual(messages.length, 0);
|
|
|
|
// Denied permission should publish
|
|
const hasWrite = process.permission.has('fs.write', '/tmp/test');
|
|
assert.strictEqual(hasWrite, false);
|
|
|
|
assert.ok(messages.length > 0, 'Expected at least one denied message');
|
|
assert.strictEqual(messages[0].permission, 'FileSystemWrite');
|