[PATCH] test: use relative paths in test-cli-permission tests
authorsendoru <sendol39@gmail.com>
Wed, 14 Aug 2024 03:49:39 +0000 (12:49 +0900)
committerJérémy Lal <kapouer@melix.org>
Thu, 29 Aug 2024 08:25:23 +0000 (10:25 +0200)
`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>
Gbp-Pq: Topic build
Gbp-Pq: Name fix_permission_test_env.patch

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

index 964a0ad0a0e0c26ff5cff5478c48b53a6a9ccbfd..d38c4a61adbcfc59f63d8d6a49ab8501e5e32b7c 100644 (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,
index 68e9029b1ddb4554e99b283b05cfc7a974bb6bb5..57ce15535300d51d5c11aae5ecb251b350ccabca 100644 (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');