nodejs/test/parallel/test-permission-fs-read.js
Rafael Gonzaga f58613a64c
src,permission: implicit allow-fs-read to app entrypoint
This commit automatically includes in the allow-fs-read
list all the app's entrypoints.

`--require` and user entry point

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs/node/pull/58579
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2025-06-07 13:33:25 +00:00

56 lines
1.3 KiB
JavaScript

// Flags: --permission --allow-fs-read=* --allow-fs-write=* --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');
}
if (!common.hasCrypto) {
common.skip('no crypto');
}
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { spawnSync } = require('child_process');
const path = require('path');
const blockedFile = fixtures.path('permission', 'deny', 'protected-file.md');
const blockedFolder = tmpdir.path;
const file = fixtures.path('permission', 'fs-read.js');
const commonPathWildcard = path.join(__filename, '../../common*');
const commonPath = path.join(__filename, '../../common');
{
tmpdir.refresh();
}
{
const { status, stderr } = spawnSync(
process.execPath,
[
'--permission',
// Do not uncomment this line
// `--allow-fs-read=${file}`,
`--allow-fs-read=${commonPathWildcard}`,
file,
],
{
env: {
...process.env,
BLOCKEDFILE: blockedFile,
BLOCKEDFOLDER: blockedFolder,
ALLOWEDFOLDER: commonPath,
},
}
);
assert.strictEqual(status, 0, stderr.toString());
}
{
tmpdir.refresh();
}