-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-fs-glob-permission.js
More file actions
71 lines (61 loc) · 1.36 KB
/
test-fs-glob-permission.js
File metadata and controls
71 lines (61 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
require('../common');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');
const { spawnSyncAndAssert } = require('../common/child_process');
const tmpdir = require('../common/tmpdir');
// This test verifies that fs.globSync() works correctly udner permission model
// when --allow-fs-read is granted only to the certain directory
// Example:
// Directory structure:
// somedir/
// file1.js
// sample.js
//
// Command:
// node --permission --allow-fs-read=somedir/ sample.js
//
// Code:
// fs.globSync('somedir/*') <- sould find file1.js
tmpdir.refresh();
const someDir = tmpdir.resolve('somedir');
const script = tmpdir.resolve('sample.js');
fs.mkdirSync(someDir);
fs.writeFileSync(
path.join(someDir, 'file1.js'),
'console.log("test");'
);
fs.writeFileSync(
script,
`
'use strict';
const fs = require('fs');
const matches = fs.globSync('somedir/*');
console.log(JSON.stringify(matches));
`
);
spawnSyncAndAssert(
process.execPath,
[
'--permission',
`--allow-fs-read=${someDir}`,
script,
],
{
cwd: tmpdir.path,
},
{
stdout(output) {
assert.deepStrictEqual(
JSON.parse(output),
['somedir/file1.js']
);
return true;
},
stderr(output) {
assert.doesNotMatch(output, /ERR_ACCESS_DENIED/);
return true;
},
}
);