Files
node/test/parallel/test-permission-diagnostics-channel.js
RafaelGSS a8eb690e0a src,permission: add --permission-audit
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>
2026-02-26 00:48:26 +00:00

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');