|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('../common'); |
| 4 | + |
| 5 | +const { spawnSync } = require('child_process'); |
| 6 | +const assert = require('assert'); |
| 7 | +const path = require('path'); |
| 8 | + |
| 9 | +{ |
| 10 | + const tmpPath = path.resolve('/tmp/'); |
| 11 | + const otherPath = path.resolve('/other-path/'); |
| 12 | + const { status, stdout } = spawnSync( |
| 13 | + process.execPath, |
| 14 | + [ |
| 15 | + '--experimental-permission', |
| 16 | + '--allow-fs-write', tmpPath, '--allow-fs-write', otherPath, '-e', |
| 17 | + `console.log(process.permission.has("fs")); |
| 18 | + console.log(process.permission.has("fs.read")); |
| 19 | + console.log(process.permission.has("fs.write")); |
| 20 | + console.log(process.permission.has("fs.write", "/tmp/")); |
| 21 | + console.log(process.permission.has("fs.write", "/other-path/"));`, |
| 22 | + ] |
| 23 | + ); |
| 24 | + const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n'); |
| 25 | + assert.strictEqual(fs, 'false'); |
| 26 | + assert.strictEqual(fsIn, 'false'); |
| 27 | + assert.strictEqual(fsOut, 'false'); |
| 28 | + assert.strictEqual(fsOutAllowed1, 'true'); |
| 29 | + assert.strictEqual(fsOutAllowed2, 'true'); |
| 30 | + assert.strictEqual(status, 0); |
| 31 | +} |
| 32 | + |
| 33 | +{ |
| 34 | + const tmpPath = path.resolve('/tmp/'); |
| 35 | + const pathWithComma = path.resolve('/other,path/'); |
| 36 | + const { status, stdout } = spawnSync( |
| 37 | + process.execPath, |
| 38 | + [ |
| 39 | + '--experimental-permission', |
| 40 | + '--allow-fs-write', |
| 41 | + tmpPath, |
| 42 | + '--allow-fs-write', |
| 43 | + pathWithComma, |
| 44 | + '-e', |
| 45 | + `console.log(process.permission.has("fs")); |
| 46 | + console.log(process.permission.has("fs.read")); |
| 47 | + console.log(process.permission.has("fs.write")); |
| 48 | + console.log(process.permission.has("fs.write", "/tmp/")); |
| 49 | + console.log(process.permission.has("fs.write", "/other,path/"));`, |
| 50 | + ] |
| 51 | + ); |
| 52 | + const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n'); |
| 53 | + assert.strictEqual(fs, 'false'); |
| 54 | + assert.strictEqual(fsIn, 'false'); |
| 55 | + assert.strictEqual(fsOut, 'false'); |
| 56 | + assert.strictEqual(fsOutAllowed1, 'true'); |
| 57 | + assert.strictEqual(fsOutAllowed2, 'true'); |
| 58 | + assert.strictEqual(status, 0); |
| 59 | +} |
| 60 | + |
| 61 | +{ |
| 62 | + const filePath = path.resolve('/tmp/file,with,comma.txt'); |
| 63 | + const { status, stdout, stderr } = spawnSync( |
| 64 | + process.execPath, |
| 65 | + [ |
| 66 | + '--experimental-permission', |
| 67 | + '--allow-fs-read=*', |
| 68 | + `--allow-fs-write=${filePath}`, |
| 69 | + '-e', |
| 70 | + `console.log(process.permission.has("fs")); |
| 71 | + console.log(process.permission.has("fs.read")); |
| 72 | + console.log(process.permission.has("fs.write")); |
| 73 | + console.log(process.permission.has("fs.write", "/tmp/file,with,comma.txt"));`, |
| 74 | + ] |
| 75 | + ); |
| 76 | + const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n'); |
| 77 | + assert.strictEqual(fs, 'false'); |
| 78 | + assert.strictEqual(fsIn, 'true'); |
| 79 | + assert.strictEqual(fsOut, 'false'); |
| 80 | + assert.strictEqual(fsOutAllowed, 'true'); |
| 81 | + assert.strictEqual(status, 0); |
| 82 | + assert.ok(stderr.toString().includes('Warning: The --allow-fs-write CLI flag has changed.')); |
| 83 | +} |
0 commit comments