Skip to content

Commit

Permalink
tests moved to new test file
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceres6 committed Jul 29, 2023
1 parent 9e7b868 commit e98237e
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 28 deletions.
6 changes: 2 additions & 4 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,9 @@ the [Permission Model][].

Examples can be found in the [File System Permissions][] documentation.

Special shell characters such as `;` must be escaped or quoted:

```bash
node --experimental-permission --permission-fs-path-delimiter=\; \
--allow-fs-read=/path/to/index.js index.js
node --experimental-permission --permission-fs-path-delimiter=";" \
--allow-fs-read="/path/to/index.js;/path/with,comma" index.js
```

### `--policy-integrity=sri`
Expand Down
1 change: 1 addition & 0 deletions src/permission/child_process_permission.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "child_process_permission.h"

#include <string>
#include <unordered_map>
#include <vector>

namespace node {
Expand Down
1 change: 1 addition & 0 deletions src/permission/child_process_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <unordered_map>
#include <vector>
#include "permission/permission_base.h"

Expand Down
1 change: 1 addition & 0 deletions src/permission/fs_permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <filesystem>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

namespace {
Expand Down
1 change: 1 addition & 0 deletions src/permission/inspector_permission.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "inspector_permission.h"

#include <string>
#include <unordered_map>

namespace node {

Expand Down
1 change: 1 addition & 0 deletions src/permission/inspector_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <string>
#include <unordered_map>
#include "permission/permission_base.h"

namespace node {
Expand Down
1 change: 1 addition & 0 deletions src/permission/permission.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

namespace node {
Expand Down
1 change: 1 addition & 0 deletions src/permission/permission_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <map>
#include <string>
#include <string_view>
#include <unordered_map>
#include "v8.h"

namespace node {
Expand Down
1 change: 1 addition & 0 deletions src/permission/worker_permission.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "permission/worker_permission.h"

#include <string>
#include <unordered_map>
#include <vector>

namespace node {
Expand Down
1 change: 1 addition & 0 deletions src/permission/worker_permission.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#include <unordered_map>
#include <vector>
#include "permission/permission_base.h"

Expand Down
24 changes: 0 additions & 24 deletions test/parallel/test-cli-permission-deny-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@ const path = require('path');
assert.strictEqual(status, 0);
}

{
const tmpPath = path.resolve('/tmp/');
const pathWithComma = path.resolve('/other,path/');
const { status, stdout } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-write', `${tmpPath};${pathWithComma}`, '--permission-fs-path-delimiter=;', '-e',
`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/"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
assert.strictEqual(fs, 'false');
assert.strictEqual(fsIn, 'false');
assert.strictEqual(fsOut, 'false');
assert.strictEqual(fsOutAllowed1, 'true');
assert.strictEqual(fsOutAllowed2, 'true');
assert.strictEqual(status, 0);
}

{
const { status, stdout } = spawnSync(
process.execPath,
Expand Down
55 changes: 55 additions & 0 deletions test/parallel/test-cli-permission-fs-path-delimiter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

const { spawnSync } = require('child_process');
const assert = require('assert');
const path = require('path');

{
const tmpPath = path.resolve('/tmp/');
const pathWithComma = path.resolve('/other,path/');
const { status, stdout } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-write',
`${tmpPath};${pathWithComma}`,
'--permission-fs-path-delimiter=;',
'-e',
`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/"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed1, fsOutAllowed2] = stdout.toString().split('\n');
assert.strictEqual(fs, 'false');
assert.strictEqual(fsIn, 'false');
assert.strictEqual(fsOut, 'false');
assert.strictEqual(fsOutAllowed1, 'true');
assert.strictEqual(fsOutAllowed2, 'true');
assert.strictEqual(status, 0);
}

{
const { status, stdout } = spawnSync(
process.execPath,
[
'--experimental-permission',
'--allow-fs-read=*',
'--allow-fs-write=/tmp/file,with,comma.txt',
'--permission-fs-path-delimiter=;',
'-e',
`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"));`,
]
);
const [fs, fsIn, fsOut, fsOutAllowed] = stdout.toString().split('\n');
assert.strictEqual(fs, 'false');
assert.strictEqual(fsIn, 'true');
assert.strictEqual(fsOut, 'false');
assert.strictEqual(fsOutAllowed, 'true');
assert.strictEqual(status, 0);
}

0 comments on commit e98237e

Please sign in to comment.