mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 03:34:30 +00:00

PR-URL: https://github.com/nodejs/node/pull/47335 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Beth Griggs <bethanyngriggs@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
// Flags: --experimental-permission --allow-fs-read=* --allow-child-process
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
common.skipIfWorker();
|
|
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const { spawnSync } = require('child_process');
|
|
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const commonPathWildcard = path.join(__filename, '../../common*');
|
|
const file = fixtures.path('permission', 'fs-wildcard.js');
|
|
|
|
let allowList = [];
|
|
|
|
if (common.isWindows) {
|
|
const { root } = path.parse(process.cwd());
|
|
const abs = (p) => path.join(root, p);
|
|
allowList = [
|
|
'tmp\\*',
|
|
'example\\foo*',
|
|
'example\\bar*',
|
|
'folder\\*',
|
|
'show',
|
|
'slower',
|
|
'slown',
|
|
'home\\foo\\*',
|
|
].map(abs);
|
|
const { status, stderr } = spawnSync(
|
|
process.execPath,
|
|
[
|
|
'--experimental-permission',
|
|
`--allow-fs-read=${allowList.join(',')}`,
|
|
'-e',
|
|
`
|
|
const path = require('path');
|
|
const assert = require('assert');
|
|
const { root } = path.parse(process.cwd());
|
|
const abs = (p) => path.join(root, p);
|
|
assert.ok(!process.permission.has('fs.read', abs('slow')));
|
|
assert.ok(!process.permission.has('fs.read', abs('slows')));
|
|
assert.ok(process.permission.has('fs.read', abs('slown')));
|
|
assert.ok(process.permission.has('fs.read', abs('home\\\\foo')));
|
|
assert.ok(process.permission.has('fs.read', abs('home\\\\foo\\\\')));
|
|
assert.ok(!process.permission.has('fs.read', abs('home\\\\fo')));
|
|
`,
|
|
]
|
|
);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
} else {
|
|
allowList = [
|
|
'/tmp/*',
|
|
'/example/foo*',
|
|
'/example/bar*',
|
|
'/folder/*',
|
|
'/show',
|
|
'/slower',
|
|
'/slown',
|
|
'/home/foo/*',
|
|
];
|
|
const { status, stderr } = spawnSync(
|
|
process.execPath,
|
|
[
|
|
'--experimental-permission',
|
|
`--allow-fs-read=${allowList.join(',')}`,
|
|
'-e',
|
|
`
|
|
const assert = require('assert')
|
|
assert.ok(!process.permission.has('fs.read', '/slow'));
|
|
assert.ok(!process.permission.has('fs.read', '/slows'));
|
|
assert.ok(process.permission.has('fs.read', '/slown'));
|
|
assert.ok(process.permission.has('fs.read', '/home/foo'));
|
|
assert.ok(process.permission.has('fs.read', '/home/foo/'));
|
|
assert.ok(!process.permission.has('fs.read', '/home/fo'));
|
|
`,
|
|
]
|
|
);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
}
|
|
|
|
{
|
|
const { status, stderr } = spawnSync(
|
|
process.execPath,
|
|
[
|
|
'--experimental-permission',
|
|
`--allow-fs-read=${file},${commonPathWildcard},${allowList.join(',')}`,
|
|
file,
|
|
],
|
|
);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
}
|