Skip to content

Commit

Permalink
test: --force-context-aware cli flag
Browse files Browse the repository at this point in the history
PR-URL: nodejs#29631
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
codebytere authored and Trott committed Sep 25, 2019
1 parent 3c17f16 commit f120e6d
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions test/addons/force-context-aware/binding.cc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Flags: --force-context-aware

'use strict';

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

0 comments on commit f120e6d

Please sign in to comment.