11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (!common.hasCrypto)
61cb0ef41Sopenharmony_ci  common.skip('missing crypto');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cicommon.requireNoPackageJSONAbove();
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst assert = require('assert');
111cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process');
121cb0ef41Sopenharmony_ciconst { cpSync, rmSync } = require('fs');
131cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures.js');
141cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir.js');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci{
171cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'invalid.json');
181cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
191cb0ef41Sopenharmony_ci    '--experimental-policy',
201cb0ef41Sopenharmony_ci    policyFilepath,
211cb0ef41Sopenharmony_ci    './fhqwhgads.js',
221cb0ef41Sopenharmony_ci  ]);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
251cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
261cb0ef41Sopenharmony_ci  assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/);
271cb0ef41Sopenharmony_ci  assert.match(stderr, /pattern needs to have a single trailing "\*"/);
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  tmpdir.refresh();
321cb0ef41Sopenharmony_ci  const policyFilepath = tmpdir.resolve('file with % in its name.json');
331cb0ef41Sopenharmony_ci  cpSync(fixtures.path('policy-manifest', 'invalid.json'), policyFilepath);
341cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
351cb0ef41Sopenharmony_ci    '--experimental-policy',
361cb0ef41Sopenharmony_ci    policyFilepath,
371cb0ef41Sopenharmony_ci    './fhqwhgads.js',
381cb0ef41Sopenharmony_ci  ]);
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
411cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
421cb0ef41Sopenharmony_ci  assert.match(stderr, /ERR_MANIFEST_INVALID_SPECIFIER/);
431cb0ef41Sopenharmony_ci  assert.match(stderr, /pattern needs to have a single trailing "\*"/);
441cb0ef41Sopenharmony_ci  rmSync(policyFilepath);
451cb0ef41Sopenharmony_ci}
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci{
481cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
491cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
501cb0ef41Sopenharmony_ci    '--experimental-policy',
511cb0ef41Sopenharmony_ci    policyFilepath,
521cb0ef41Sopenharmony_ci    '-e',
531cb0ef41Sopenharmony_ci    'require("os").cpus()',
541cb0ef41Sopenharmony_ci  ]);
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
571cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
581cb0ef41Sopenharmony_ci  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
591cb0ef41Sopenharmony_ci  assert.match(stderr, /does not list module as a dependency specifier for conditions: require, node, node-addons/);
601cb0ef41Sopenharmony_ci}
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci{
631cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
641cb0ef41Sopenharmony_ci  const mainModuleBypass = fixtures.path('policy-manifest', 'main-module-bypass.js');
651cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
661cb0ef41Sopenharmony_ci    '--experimental-policy',
671cb0ef41Sopenharmony_ci    policyFilepath,
681cb0ef41Sopenharmony_ci    mainModuleBypass,
691cb0ef41Sopenharmony_ci  ]);
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
721cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
731cb0ef41Sopenharmony_ci  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
741cb0ef41Sopenharmony_ci  assert.match(stderr, /does not list os as a dependency specifier for conditions: require, node, node-addons/);
751cb0ef41Sopenharmony_ci}
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci{
781cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-resource-exit.json');
791cb0ef41Sopenharmony_ci  const objectDefinePropertyBypass = fixtures.path('policy-manifest', 'object-define-property-bypass.js');
801cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
811cb0ef41Sopenharmony_ci    '--experimental-policy',
821cb0ef41Sopenharmony_ci    policyFilepath,
831cb0ef41Sopenharmony_ci    objectDefinePropertyBypass,
841cb0ef41Sopenharmony_ci  ]);
851cb0ef41Sopenharmony_ci
861cb0ef41Sopenharmony_ci  assert.strictEqual(result.status, 0);
871cb0ef41Sopenharmony_ci}
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci{
901cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
911cb0ef41Sopenharmony_ci  const mainModuleBypass = fixtures.path('policy-manifest', 'main-module-proto-bypass.js');
921cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
931cb0ef41Sopenharmony_ci    '--experimental-policy',
941cb0ef41Sopenharmony_ci    policyFilepath,
951cb0ef41Sopenharmony_ci    mainModuleBypass,
961cb0ef41Sopenharmony_ci  ]);
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
991cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
1001cb0ef41Sopenharmony_ci  assert.match(stderr, /ERR_MANIFEST_DEPENDENCY_MISSING/);
1011cb0ef41Sopenharmony_ci  assert.match(stderr, /does not list os as a dependency specifier for conditions: require, node, node-addons/);
1021cb0ef41Sopenharmony_ci}
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci{
1051cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
1061cb0ef41Sopenharmony_ci  const mainModuleBypass = fixtures.path('policy-manifest', 'module-constructor-bypass.js');
1071cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
1081cb0ef41Sopenharmony_ci    '--experimental-policy',
1091cb0ef41Sopenharmony_ci    policyFilepath,
1101cb0ef41Sopenharmony_ci    mainModuleBypass,
1111cb0ef41Sopenharmony_ci  ]);
1121cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
1131cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
1141cb0ef41Sopenharmony_ci  assert.match(stderr, /TypeError/);
1151cb0ef41Sopenharmony_ci}
1161cb0ef41Sopenharmony_ci
1171cb0ef41Sopenharmony_ci{
1181cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'manifest-impersonate.json');
1191cb0ef41Sopenharmony_ci  const createRequireBypass = fixtures.path('policy-manifest', 'createRequire-bypass.js');
1201cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
1211cb0ef41Sopenharmony_ci    '--experimental-policy',
1221cb0ef41Sopenharmony_ci    policyFilepath,
1231cb0ef41Sopenharmony_ci    createRequireBypass,
1241cb0ef41Sopenharmony_ci  ]);
1251cb0ef41Sopenharmony_ci
1261cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
1271cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
1281cb0ef41Sopenharmony_ci  assert.match(stderr, /TypeError/);
1291cb0ef41Sopenharmony_ci}
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ci{
1321cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
1331cb0ef41Sopenharmony_ci  const mainModuleBypass = fixtures.path('policy-manifest', 'main-constructor-bypass.js');
1341cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
1351cb0ef41Sopenharmony_ci    '--experimental-policy',
1361cb0ef41Sopenharmony_ci    policyFilepath,
1371cb0ef41Sopenharmony_ci    mainModuleBypass,
1381cb0ef41Sopenharmony_ci  ]);
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
1411cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
1421cb0ef41Sopenharmony_ci  assert.match(stderr, /TypeError/);
1431cb0ef41Sopenharmony_ci}
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci{
1461cb0ef41Sopenharmony_ci  const policyFilepath = fixtures.path('policy-manifest', 'onerror-exit.json');
1471cb0ef41Sopenharmony_ci  const mainModuleBypass = fixtures.path('policy-manifest', 'main-constructor-extensions-bypass.js');
1481cb0ef41Sopenharmony_ci  const result = spawnSync(process.execPath, [
1491cb0ef41Sopenharmony_ci    '--experimental-policy',
1501cb0ef41Sopenharmony_ci    policyFilepath,
1511cb0ef41Sopenharmony_ci    mainModuleBypass,
1521cb0ef41Sopenharmony_ci  ]);
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci  assert.notStrictEqual(result.status, 0);
1551cb0ef41Sopenharmony_ci  const stderr = result.stderr.toString();
1561cb0ef41Sopenharmony_ci  assert.match(stderr, /TypeError/);
1571cb0ef41Sopenharmony_ci}
158