diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2017-02-20 06:18:43 -0800 |
---|---|---|
committer | Sam Roberts <vieuxtech@gmail.com> | 2017-04-25 09:59:54 -0700 |
commit | f2282bb812860284035d2a2ed8ac7074bf84cb50 (patch) | |
tree | d3ef613cb3e1e1fb8e1ceb852769cbdc51e64fca /test/parallel/test-cli-node-options.js | |
parent | e522bcd774c6a43d8facc1905b59e53a86f7ae0a (diff) | |
download | android-node-v8-f2282bb812860284035d2a2ed8ac7074bf84cb50.tar.gz android-node-v8-f2282bb812860284035d2a2ed8ac7074bf84cb50.tar.bz2 android-node-v8-f2282bb812860284035d2a2ed8ac7074bf84cb50.zip |
src: allow CLI args in env with NODE_OPTIONS
Not all CLI options are supported, those that are problematic from a
security or implementation point of view are disallowed, as are ones
that are inappropriate (for example, -e, -p, --i), or that only make
sense when changed with code changes (such as options that change the
javascript syntax or add new APIs).
PR-URL: https://github.com/nodejs/node/pull/12028
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Diffstat (limited to 'test/parallel/test-cli-node-options.js')
-rw-r--r-- | test/parallel/test-cli-node-options.js | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/parallel/test-cli-node-options.js b/test/parallel/test-cli-node-options.js new file mode 100644 index 0000000000..08c8f63f79 --- /dev/null +++ b/test/parallel/test-cli-node-options.js @@ -0,0 +1,76 @@ +'use strict'; +const common = require('../common'); +if (process.config.variables.node_without_node_options) + return common.skip('missing NODE_OPTIONS support'); + +// Test options specified by env variable. + +const assert = require('assert'); +const exec = require('child_process').execFile; + +disallow('--version'); +disallow('-v'); +disallow('--help'); +disallow('-h'); +disallow('--eval'); +disallow('-e'); +disallow('--print'); +disallow('-p'); +disallow('-pe'); +disallow('--check'); +disallow('-c'); +disallow('--interactive'); +disallow('-i'); +disallow('--v8-options'); +disallow('--'); + +function disallow(opt) { + const options = {env: {NODE_OPTIONS: opt}}; + exec(process.execPath, options, common.mustCall(function(err) { + const message = err.message.split(/\r?\n/)[1]; + const expect = process.execPath + ': ' + opt + + ' is not allowed in NODE_OPTIONS'; + + assert.strictEqual(err.code, 9); + assert.strictEqual(message, expect); + })); +} + +const printA = require.resolve('../fixtures/printA.js'); + +expect('-r ' + printA, 'A\nB\n'); +expect('--no-deprecation', 'B\n'); +expect('--no-warnings', 'B\n'); +expect('--trace-warnings', 'B\n'); +expect('--redirect-warnings=_', 'B\n'); +expect('--trace-deprecation', 'B\n'); +expect('--trace-sync-io', 'B\n'); +expect('--trace-events-enabled', 'B\n'); +expect('--track-heap-objects', 'B\n'); +expect('--throw-deprecation', 'B\n'); +expect('--zero-fill-buffers', 'B\n'); +expect('--v8-pool-size=10', 'B\n'); +expect('--use-openssl-ca', 'B\n'); +expect('--use-bundled-ca', 'B\n'); +expect('--openssl-config=_ossl_cfg', 'B\n'); +expect('--icu-data-dir=_d', 'B\n'); + + // V8 options +expect('--max_old_space_size=0', 'B\n'); + +function expect(opt, want) { + const printB = require.resolve('../fixtures/printB.js'); + const argv = [printB]; + const opts = { + env: {NODE_OPTIONS: opt}, + maxBuffer: 1000000000, + }; + exec(process.execPath, argv, opts, common.mustCall(function(err, stdout) { + assert.ifError(err); + if (!RegExp(want).test(stdout)) { + console.error('For %j, failed to find %j in: <\n%s\n>', + opt, expect, stdout); + assert(false, 'Expected ' + expect); + } + })); +} |