0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-permission-fs-read.js
Carlos Espa 413c16e490
src,permission: add multiple allow-fs-* flags
Support for a single comma separates list for allow-fs-* flags is
removed. Instead now multiple flags can be passed to allow multiple
paths.

Fixes: https://github.com/nodejs/security-wg/issues/1039
PR-URL: https://github.com/nodejs/node/pull/49047
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2023-08-17 18:39:04 +00:00

48 lines
1.2 KiB
JavaScript

// Flags: --experimental-permission --allow-fs-read=* --allow-fs-write=* --allow-child-process
'use strict';
const common = require('../common');
common.skipIfWorker();
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,
[
'--experimental-permission', `--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();
}