0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00

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: https://github.com/nodejs/node/issues/54021
PR-URL: https://github.com/nodejs/node/pull/54188
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
sendoru 2024-08-14 12:49:39 +09:00 committed by GitHub
parent 880c446d95
commit 02b30954a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View File

@ -27,7 +27,7 @@ const path = require('path');
}
{
const tmpPath = path.resolve('/tmp/');
const tmpPath = path.resolve('./tmp/');
const { status, stdout } = spawnSync(
process.execPath,
[
@ -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');
@ -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,

View File

@ -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,
[
@ -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');
@ -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,
[
@ -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');
@ -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,
[
@ -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');