Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test-cli-permission tests when cwd contains /tmp #54188

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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
  • Loading branch information
sendoru committed Aug 3, 2024
commit effea4b4211805ac2b03f781bee42bf852d61cff
4 changes: 2 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
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