• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7
8common.requireNoPackageJSONAbove();
9
10const assert = require('assert');
11const { spawnSync } = require('child_process');
12const { cpSync, rmSync } = require('fs');
13const fixtures = require('../common/fixtures.js');
14const tmpdir = require('../common/tmpdir.js');
15
16{
17  const policyFilepath = fixtures.path('policy-manifest', 'invalid.json');
18  const result = spawnSync(process.execPath, [
19    '--experimental-policy',
20    policyFilepath,
21    './fhqwhgads.js',
22  ]);
23
24  assert.notStrictEqual(result.status, 0);
25  const stderr = result.stderr.toString();
26  assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/);
27  assert.match(stderr, /pattern needs to have a single trailing "\*"/);
28}
29
30{
31  tmpdir.refresh();
32  const policyFilepath = tmpdir.resolve('file with % in its name.json');
33  cpSync(fixtures.path('policy-manifest', 'invalid.json'), policyFilepath);
34  const result = spawnSync(process.execPath, [
35    '--experimental-policy',
36    policyFilepath,
37    './fhqwhgads.js',
38  ]);
39
40  assert.notStrictEqual(result.status, 0);
41  const stderr = result.stderr.toString();
42  assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/);
43  assert.match(stderr, /pattern needs to have a single trailing "\*"/);
44  rmSync(policyFilepath);
45}
46
47{
48  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
49  const result = spawnSync(process.execPath, [
50    '--experimental-policy',
51    policyFilepath,
52    '-e',
53    'require("os").cpus()',
54  ]);
55
56  assert.notStrictEqual(result.status, 0);
57  const stderr = result.stderr.toString();
58  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
59  assert.match(stderr, /does not list module as a dependency specifier for conditions: require, node, node-addons/);
60}
61
62{
63  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
64  const mainModuleBypass = fixtures.path('policy-manifest', 'main-module-bypass.js');
65  const result = spawnSync(process.execPath, [
66    '--experimental-policy',
67    policyFilepath,
68    mainModuleBypass,
69  ]);
70
71  assert.notStrictEqual(result.status, 0);
72  const stderr = result.stderr.toString();
73  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
74  assert.match(stderr, /does not list os as a dependency specifier for conditions: require, node, node-addons/);
75}
76
77{
78  const policyFilepath = fixtures.path('policy-manifest', 'onerror-resource-exit.json');
79  const objectDefinePropertyBypass = fixtures.path('policy-manifest', 'object-define-property-bypass.js');
80  const result = spawnSync(process.execPath, [
81    '--experimental-policy',
82    policyFilepath,
83    objectDefinePropertyBypass,
84  ]);
85
86  assert.strictEqual(result.status, 0);
87}
88
89{
90  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
91  const mainModuleBypass = fixtures.path('policy-manifest', 'main-module-proto-bypass.js');
92  const result = spawnSync(process.execPath, [
93    '--experimental-policy',
94    policyFilepath,
95    mainModuleBypass,
96  ]);
97
98  assert.notStrictEqual(result.status, 0);
99  const stderr = result.stderr.toString();
100  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
101  assert.match(stderr, /does not list os as a dependency specifier for conditions: require, node, node-addons/);
102}
103
104{
105  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
106  const mainModuleBypass = fixtures.path('policy-manifest', 'module-constructor-bypass.js');
107  const result = spawnSync(process.execPath, [
108    '--experimental-policy',
109    policyFilepath,
110    mainModuleBypass,
111  ]);
112  assert.notStrictEqual(result.status, 0);
113  const stderr = result.stderr.toString();
114  assert.match(stderr, /TypeError/);
115}
116
117{
118  const policyFilepath = fixtures.path('policy-manifest', 'manifest-impersonate.json');
119  const createRequireBypass = fixtures.path('policy-manifest', 'createRequire-bypass.js');
120  const result = spawnSync(process.execPath, [
121    '--experimental-policy',
122    policyFilepath,
123    createRequireBypass,
124  ]);
125
126  assert.notStrictEqual(result.status, 0);
127  const stderr = result.stderr.toString();
128  assert.match(stderr, /TypeError/);
129}
130
131{
132  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
133  const mainModuleBypass = fixtures.path('policy-manifest', 'main-constructor-bypass.js');
134  const result = spawnSync(process.execPath, [
135    '--experimental-policy',
136    policyFilepath,
137    mainModuleBypass,
138  ]);
139
140  assert.notStrictEqual(result.status, 0);
141  const stderr = result.stderr.toString();
142  assert.match(stderr, /TypeError/);
143}
144
145{
146  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
147  const mainModuleBypass = fixtures.path('policy-manifest', 'main-constructor-extensions-bypass.js');
148  const result = spawnSync(process.execPath, [
149    '--experimental-policy',
150    policyFilepath,
151    mainModuleBypass,
152  ]);
153
154  assert.notStrictEqual(result.status, 0);
155  const stderr = result.stderr.toString();
156  assert.match(stderr, /TypeError/);
157}
158