diff options
author | Carl Lei <xecycle@gmail.com> | 2015-10-16 16:29:34 +0800 |
---|---|---|
committer | silverwind <me@silverwind.io> | 2016-05-04 19:06:02 +0200 |
commit | b72d048a743dc7dbe8a1c6d9843d358cb55a1c46 (patch) | |
tree | b5009fd5a2ed7fd628426f8d56ce775e48e82467 /test/parallel/test-repl-history-perm.js | |
parent | be480b14996153e93326cdf17ea86f85c0b43fa6 (diff) | |
download | android-node-v8-b72d048a743dc7dbe8a1c6d9843d358cb55a1c46.tar.gz android-node-v8-b72d048a743dc7dbe8a1c6d9843d358cb55a1c46.tar.bz2 android-node-v8-b72d048a743dc7dbe8a1c6d9843d358cb55a1c46.zip |
repl: create history file with mode 0600
Set the mode bits on the history file to 0o600 instead of leaving it
unspecified, which resulted in 0o755 on Unices.
Test code mostly written by Trott:
https://github.com/nodejs/node/issues/3392#issuecomment-148634126.
PR-URL: https://github.com/nodejs/node/pull/3394
Fixes: https://github.com/nodejs/node/issues/3392
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-repl-history-perm.js')
-rw-r--r-- | test/parallel/test-repl-history-perm.js | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/test/parallel/test-repl-history-perm.js b/test/parallel/test-repl-history-perm.js new file mode 100644 index 0000000000..717728bc4f --- /dev/null +++ b/test/parallel/test-repl-history-perm.js @@ -0,0 +1,53 @@ +'use strict'; +// Flags: --expose_internals + +const common = require('../common'); + +if (common.isWindows) { + console.log('1..0 # Skipped: Win32 uses ACLs for file permissions, ' + + 'modes are always 0666 and says nothing about group/other ' + + 'read access.'); + return; +} + +const assert = require('assert'); +const path = require('path'); +const fs = require('fs'); +const repl = require('internal/repl'); +const Duplex = require('stream').Duplex; +// Invoking the REPL should create a repl history file at the specified path +// and mode 600. + +var stream = new Duplex(); +stream.pause = stream.resume = function() {}; +// ends immediately +stream._read = function() { + this.push(null); +}; +stream._write = function(c, e, cb) { + cb(); +}; +stream.readable = stream.writable = true; + +common.refreshTmpDir(); +const replHistoryPath = path.join(common.tmpDir, '.node_repl_history'); + +const checkResults = common.mustCall(function(err, r) { + if (err) + throw err; + r.input.end(); + const stat = fs.statSync(replHistoryPath); + assert.strictEqual( + stat.mode & 0o777, 0o600, + 'REPL history file should be mode 0600'); +}); + +repl.createInternalRepl( + {NODE_REPL_HISTORY: replHistoryPath}, + { + terminal: true, + input: stream, + output: stream + }, + checkResults +); |