From 02b30954a8a5b1f93b5e50d005c7a01b122a86ef Mon Sep 17 00:00:00 2001 From: sendoru Date: Wed, 14 Aug 2024 12:49:39 +0900 Subject: [PATCH] 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 --- test/parallel/test-cli-permission-deny-fs.js | 7 +++++-- .../test-cli-permission-multiple-allow.js | 20 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-cli-permission-deny-fs.js b/test/parallel/test-cli-permission-deny-fs.js index 964a0ad0a0e..d38c4a61adb 100644 --- a/test/parallel/test-cli-permission-deny-fs.js +++ b/test/parallel/test-cli-permission-deny-fs.js @@ -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, diff --git a/test/parallel/test-cli-permission-multiple-allow.js b/test/parallel/test-cli-permission-multiple-allow.js index 68e9029b1dd..57ce1553530 100644 --- a/test/parallel/test-cli-permission-multiple-allow.js +++ b/test/parallel/test-cli-permission-multiple-allow.js @@ -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');