Skip to content

Commit 02b3095

Browse files
authored
test: use relative paths in test-cli-permission tests
`process.permission.has("fs")` checks if the process has permission for all files under `cwd`. Granting permission for `/tmp` and running tests with `cwd` containing `/tmp` will make the funtion return `true`, differing from expected results. Using relative paths ensures test paths are not `cwd` itself. Fixes: #54021 PR-URL: #54188 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 880c446 commit 02b3095

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

test/parallel/test-cli-permission-deny-fs.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const path = require('path');
2727
}
2828

2929
{
30-
const tmpPath = path.resolve('/tmp/');
30+
const tmpPath = path.resolve('./tmp/');
3131
const { status, stdout } = spawnSync(
3232
process.execPath,
3333
[
@@ -36,7 +36,7 @@ const path = require('path');
3636
`console.log(process.permission.has("fs"));
3737
console.log(process.permission.has("fs.read"));
3838
console.log(process.permission.has("fs.write"));
39-
console.log(process.permission.has("fs.write", "/tmp/"));`,
39+
console.log(process.permission.has("fs.write", "./tmp/"));`,
4040
]
4141
);
4242
const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n');
@@ -138,6 +138,9 @@ const path = require('path');
138138
if (firstPath.startsWith('/etc')) {
139139
common.skip('/etc as firstPath');
140140
}
141+
if (firstPath.startsWith('/tmp')) {
142+
common.skip('/tmp as firstPath');
143+
}
141144
const file = fixtures.path('permission', 'loader', 'index.js');
142145
const { status, stderr } = spawnSync(
143146
process.execPath,

test/parallel/test-cli-permission-multiple-allow.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const assert = require('assert');
77
const path = require('path');
88

99
{
10-
const tmpPath = path.resolve('/tmp/');
11-
const otherPath = path.resolve('/other-path/');
10+
const tmpPath = path.resolve('./tmp/');
11+
const otherPath = path.resolve('./other-path/');
1212
const { status, stdout } = spawnSync(
1313
process.execPath,
1414
[
@@ -17,8 +17,8 @@ const path = require('path');
1717
`console.log(process.permission.has("fs"));
1818
console.log(process.permission.has("fs.read"));
1919
console.log(process.permission.has("fs.write"));
20-
console.log(process.permission.has("fs.write", "/tmp/"));
21-
console.log(process.permission.has("fs.write", "/other-path/"));`,
20+
console.log(process.permission.has("fs.write", "./tmp/"));
21+
console.log(process.permission.has("fs.write", "./other-path/"));`,
2222
]
2323
);
2424
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
@@ -31,8 +31,8 @@ const path = require('path');
3131
}
3232

3333
{
34-
const tmpPath = path.resolve('/tmp/');
35-
const pathWithComma = path.resolve('/other,path/');
34+
const tmpPath = path.resolve('./tmp/');
35+
const pathWithComma = path.resolve('./other,path/');
3636
const { status, stdout } = spawnSync(
3737
process.execPath,
3838
[
@@ -45,8 +45,8 @@ const path = require('path');
4545
`console.log(process.permission.has("fs"));
4646
console.log(process.permission.has("fs.read"));
4747
console.log(process.permission.has("fs.write"));
48-
console.log(process.permission.has("fs.write", "/tmp/"));
49-
console.log(process.permission.has("fs.write", "/other,path/"));`,
48+
console.log(process.permission.has("fs.write", "./tmp/"));
49+
console.log(process.permission.has("fs.write", "./other,path/"));`,
5050
]
5151
);
5252
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
@@ -59,7 +59,7 @@ const path = require('path');
5959
}
6060

6161
{
62-
const filePath = path.resolve('/tmp/file,with,comma.txt');
62+
const filePath = path.resolve('./tmp/file,with,comma.txt');
6363
const { status, stdout, stderr } = spawnSync(
6464
process.execPath,
6565
[
@@ -70,7 +70,7 @@ const path = require('path');
7070
`console.log(process.permission.has("fs"));
7171
console.log(process.permission.has("fs.read"));
7272
console.log(process.permission.has("fs.write"));
73-
console.log(process.permission.has("fs.write", "/tmp/file,with,comma.txt"));`,
73+
console.log(process.permission.has("fs.write", "./tmp/file,with,comma.txt"));`,
7474
]
7575
);
7676
const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n');

0 commit comments

Comments
 (0)