2023-04-04 17:14:04 +00:00
|
|
|
// 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',
|
2023-08-17 18:39:04 +00:00
|
|
|
...allowList.flatMap((path) => ['--allow-fs-read', path]),
|
2023-04-04 17:14:04 +00:00
|
|
|
'-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/*',
|
2023-06-25 19:11:22 +00:00
|
|
|
'/files/index.js',
|
|
|
|
'/files/index.json',
|
|
|
|
'/files/i',
|
2023-04-04 17:14:04 +00:00
|
|
|
];
|
|
|
|
const { status, stderr } = spawnSync(
|
|
|
|
process.execPath,
|
|
|
|
[
|
|
|
|
'--experimental-permission',
|
2023-08-17 18:39:04 +00:00
|
|
|
...allowList.flatMap((path) => ['--allow-fs-read', path]),
|
2023-04-04 17:14:04 +00:00
|
|
|
'-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'));
|
2023-06-25 19:11:22 +00:00
|
|
|
assert.ok(process.permission.has('fs.read', '/files/index.js'));
|
|
|
|
assert.ok(process.permission.has('fs.read', '/files/index.json'));
|
|
|
|
assert.ok(!process.permission.has('fs.read', '/files/index.j'));
|
|
|
|
assert.ok(process.permission.has('fs.read', '/files/i'));
|
2023-04-04 17:14:04 +00:00
|
|
|
`,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { status, stderr } = spawnSync(
|
|
|
|
process.execPath,
|
|
|
|
[
|
|
|
|
'--experimental-permission',
|
2023-08-17 18:39:04 +00:00
|
|
|
`--allow-fs-read=${file}`, `--allow-fs-read=${commonPathWildcard}`, ...allowList.flatMap((path) => ['--allow-fs-read', path]),
|
2023-04-04 17:14:04 +00:00
|
|
|
file,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
|
|
}
|
2023-12-21 17:36:05 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
if (!common.isWindows) {
|
|
|
|
const { status, stderr } = spawnSync(
|
|
|
|
process.execPath,
|
|
|
|
[
|
|
|
|
'--experimental-permission',
|
|
|
|
'--allow-fs-read=/a/b/*',
|
|
|
|
'--allow-fs-read=/a/b/d',
|
|
|
|
'-e',
|
|
|
|
`
|
|
|
|
const assert = require('assert')
|
|
|
|
assert.ok(process.permission.has('fs.read', '/a/b/c'));
|
|
|
|
assert.ok(!process.permission.has('fs.read', '/a/c/c'));
|
|
|
|
`,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
|
|
}
|
|
|
|
}
|