Skip to content

Commit

Permalink
repl: create history file with mode 0600
Browse files Browse the repository at this point in the history
Test code mostly written by Trott
nodejs#3392 (comment).
  • Loading branch information
XeCycle authored and Trott committed Oct 20, 2015
1 parent 1c57845 commit f0d224b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
var writing = false;
var pending = false;
repl.pause();
fs.open(historyPath, 'a+', oninit);
fs.open(historyPath, 'a+', 0o0600, oninit);

function oninit(err, hnd) {
if (err) {
Expand Down
44 changes: 44 additions & 0 deletions test/parallel/test-repl-history-perm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';
// Flags: --expose_internals

const common = require('../common');
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, 'repl_history');

const checkResults = common.mustCall(function(err, r) {
if (err)
throw err;
r.input.end();
const stat = fs.statSync(replHistoryPath);
const mode = '0' + (stat.mode & parseInt('777', 8)).toString(8);
assert.strictEqual(mode, '0600', 'REPL history file should be mode 0600');
});

repl.createInternalRepl(
{NODE_REPL_HISTORY: replHistoryPath},
{
terminal: true,
input: stream,
output: stream
},
checkResults
);

0 comments on commit f0d224b

Please sign in to comment.