Skip to content

Commit

Permalink
test: --force-context-aware cli flag
Browse files Browse the repository at this point in the history
PR-URL: #29631
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
codebytere authored and BridgeAR committed Oct 9, 2019
1 parent 6bfe8f4 commit 54ef0fd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/api/cli.md
Expand Up @@ -444,7 +444,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
Expand Down Expand Up @@ -1293,3 +1293,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
6 changes: 6 additions & 0 deletions test/addons/force-context-aware/binding.cc
@@ -0,0 +1,6 @@
#include <node.h>
#include <v8.h>

void init(v8::Local<v8::Object> exports) {}

NODE_MODULE(NODE_GYP_MODULE_NAME, init)
9 changes: 9 additions & 0 deletions test/addons/force-context-aware/binding.gyp
@@ -0,0 +1,9 @@
{
'targets': [
{
'target_name': 'binding',
'sources': [ 'binding.cc' ],
'includes': ['../common.gypi'],
}
]
}
4 changes: 4 additions & 0 deletions test/addons/force-context-aware/index.js
@@ -0,0 +1,4 @@
'use strict';
const common = require('../../common');

require(`./build/${common.buildType}/binding`);
13 changes: 13 additions & 0 deletions test/addons/force-context-aware/test.js
@@ -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);
}));
2 changes: 2 additions & 0 deletions test/addons/zlib-binding/test.js
@@ -1,3 +1,5 @@
// Flags: --force-context-aware

'use strict';

const common = require('../../common');
Expand Down

0 comments on commit 54ef0fd

Please sign in to comment.