Skip to content

Commit

Permalink
test: use relative paths in test-cli-permission tests
Browse files Browse the repository at this point in the history
`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 <[email protected]>
  • Loading branch information
sendoru authored and targos committed Aug 14, 2024
1 parent f87aa27 commit 3e25be7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 5 additions & 2 deletions test/parallel/test-cli-permission-deny-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const path = require('path');
}

{
const tmpPath = path.resolve('/tmp/');
const tmpPath = path.resolve('./tmp/');
const { status, stdout } = spawnSync(
process.execPath,
[
Expand All @@ -36,7 +36,7 @@ const path = require('path');
`console.log(process.permission.has("fs"));
console.log(process.permission.has("fs.read"));
console.log(process.permission.has("fs.write"));
console.log(process.permission.has("fs.write", "/tmp/"));`,
console.log(process.permission.has("fs.write", "./tmp/"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n');
Expand Down Expand Up @@ -138,6 +138,9 @@ const path = require('path');
if (firstPath.startsWith('/etc')) {
common.skip('/etc as firstPath');
}
if (firstPath.startsWith('/tmp')) {
common.skip('/tmp as firstPath');
}
const file = fixtures.path('permission', 'loader', 'index.js');
const { status, stderr } = spawnSync(
process.execPath,
Expand Down
20 changes: 10 additions & 10 deletions test/parallel/test-cli-permission-multiple-allow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const assert = require('assert');
const path = require('path');

{
const tmpPath = path.resolve('/tmp/');
const otherPath = path.resolve('/other-path/');
const tmpPath = path.resolve('./tmp/');
const otherPath = path.resolve('./other-path/');
const { status, stdout } = spawnSync(
process.execPath,
[
Expand All @@ -17,8 +17,8 @@ const path = require('path');
`console.log(process.permission.has("fs"));
console.log(process.permission.has("fs.read"));
console.log(process.permission.has("fs.write"));
console.log(process.permission.has("fs.write", "/tmp/"));
console.log(process.permission.has("fs.write", "/other-path/"));`,
console.log(process.permission.has("fs.write", "./tmp/"));
console.log(process.permission.has("fs.write", "./other-path/"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
Expand All @@ -31,8 +31,8 @@ const path = require('path');
}

{
const tmpPath = path.resolve('/tmp/');
const pathWithComma = path.resolve('/other,path/');
const tmpPath = path.resolve('./tmp/');
const pathWithComma = path.resolve('./other,path/');
const { status, stdout } = spawnSync(
process.execPath,
[
Expand All @@ -45,8 +45,8 @@ const path = require('path');
`console.log(process.permission.has("fs"));
console.log(process.permission.has("fs.read"));
console.log(process.permission.has("fs.write"));
console.log(process.permission.has("fs.write", "/tmp/"));
console.log(process.permission.has("fs.write", "/other,path/"));`,
console.log(process.permission.has("fs.write", "./tmp/"));
console.log(process.permission.has("fs.write", "./other,path/"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
Expand All @@ -59,7 +59,7 @@ const path = require('path');
}

{
const filePath = path.resolve('/tmp/file,with,comma.txt');
const filePath = path.resolve('./tmp/file,with,comma.txt');
const { status, stdout, stderr } = spawnSync(
process.execPath,
[
Expand All @@ -70,7 +70,7 @@ const path = require('path');
`console.log(process.permission.has("fs"));
console.log(process.permission.has("fs.read"));
console.log(process.permission.has("fs.write"));
console.log(process.permission.has("fs.write", "/tmp/file,with,comma.txt"));`,
console.log(process.permission.has("fs.write", "./tmp/file,with,comma.txt"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n');
Expand Down

0 comments on commit 3e25be7

Please sign in to comment.