|
| 1 | +// Flags: --permission --allow-fs-read=* --allow-child-process |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const common = require('../common'); |
| 5 | +const path = require('path'); |
| 6 | +common.skipIfWorker(); |
| 7 | + |
| 8 | +const assert = require('assert'); |
| 9 | +const { spawnSync } = require('child_process'); |
| 10 | + |
| 11 | +{ |
| 12 | + // Relative path as CLI args are supported |
| 13 | + const { status, stdout } = spawnSync( |
| 14 | + process.execPath, |
| 15 | + [ |
| 16 | + '--permission', |
| 17 | + '--allow-fs-write', path.resolve('../fixtures/permission/deny/regular-file.md'), |
| 18 | + '--allow-fs-write', path.resolve('../fixtures/permission/deny/regular-file.md'), |
| 19 | + '--allow-fs-read', path.resolve('../fixtures/permission/deny/regular-file.md'), |
| 20 | + '--allow-fs-read', path.resolve('../fixtures/permission/deny/regular-file.md'), |
| 21 | + '-e', |
| 22 | + ` |
| 23 | + const path = require("path"); |
| 24 | + const absolutePath = path.resolve("../fixtures/permission/deny/regular-file.md"); |
| 25 | + const blockedPath = path.resolve("../fixtures/permission/deny/protected-file.md"); |
| 26 | + console.log(process.permission.has("fs.write", absolutePath)); |
| 27 | + console.log(process.permission.has("fs.read", absolutePath)); |
| 28 | + console.log(process.permission.has("fs.read", blockedPath)); |
| 29 | + console.log(process.permission.has("fs.write", blockedPath)); |
| 30 | + `, |
| 31 | + ] |
| 32 | + ); |
| 33 | + |
| 34 | + const [fsWrite, fsRead, fsBlockedRead, fsBlockedWrite] = stdout.toString().split('\n'); |
| 35 | + assert.strictEqual(status, 0); |
| 36 | + assert.strictEqual(fsWrite, 'true'); |
| 37 | + assert.strictEqual(fsRead, 'true'); |
| 38 | + assert.strictEqual(fsBlockedRead, 'false'); |
| 39 | + assert.strictEqual(fsBlockedWrite, 'false'); |
| 40 | +} |
0 commit comments