test: --force-context-aware cli flag

PR-URL: https://github.com/nodejs/node/pull/29631
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Shelley Vohr 2019-09-20 21:01:43 -07:00 committed by Rich Trott
parent 3c17f160e3
commit f120e6d817
6 changed files with 36 additions and 1 deletions

View File

@ -416,7 +416,7 @@ Silence all process warnings (including deprecations).
added: REPLACEME
-->
Disable loading non-context-aware native addons.
Disable loading native addons that are not [context-aware][].
### `--openssl-config=file`
<!-- YAML
@ -1264,3 +1264,4 @@ greater than `4` (its current default value). For more information, see the
[experimental ECMAScript Module]: esm.html#esm_resolve_hook
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
[context-aware]: addons.html#addons_context_aware_addons

View File

@ -0,0 +1,6 @@
#include <node.h>
#include <v8.h>
void init(v8::Local<v8::Object> exports) {}
NODE_MODULE(NODE_GYP_MODULE_NAME, init)

View File

@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}

View File

@ -0,0 +1,4 @@
'use strict';
const common = require('../../common');
require(`./build/${common.buildType}/binding`);

View File

@ -0,0 +1,13 @@
'use strict';
const common = require('../../common');
const childProcess = require('child_process');
const assert = require('assert');
const path = require('path');
const mod = path.join('test', 'addons', 'force-context-aware', 'index.js');
const execString = `"${process.execPath}" --force-context-aware ./${mod}`;
childProcess.exec(execString, common.mustCall((err) => {
const errMsg = 'Loading non context-aware native modules has been disabled';
assert.strictEqual(err.message.includes(errMsg), true);
}));

View File

@ -1,3 +1,5 @@
// Flags: --force-context-aware
'use strict';
const common = require('../../common');