0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-repl-history-perm.js
James M Snell 4f2e372716 test: add common.noop, default for common.mustCall()
Export a new common.noop no-operation function for general use.
Allow using common.mustCall() without a fn argument to simplify
test cases.

Replace various non-op functions throughout tests with common.noop

PR-URL: https://github.com/nodejs/node/pull/12027
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-03-26 12:47:15 -07:00

57 lines
1.4 KiB
JavaScript

'use strict';
// Flags: --expose_internals
const common = require('../common');
if (common.isWindows) {
common.skip('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.
const stream = new Duplex();
stream.pause = stream.resume = common.noop;
// 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) {
assert.ifError(err);
// The REPL registers 'module' and 'require' globals
common.allowGlobals(r.context.module, r.context.require);
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
);