1'use strict'; 2 3// Verifies that the REPL history file is created with mode 0600 4 5// Flags: --expose-internals 6 7const common = require('../common'); 8 9if (common.isWindows) { 10 common.skip('Win32 uses ACLs for file permissions, ' + 11 'modes are always 0666 and says nothing about group/other ' + 12 'read access.'); 13} 14 15const assert = require('assert'); 16const path = require('path'); 17const fs = require('fs'); 18const repl = require('internal/repl'); 19const Duplex = require('stream').Duplex; 20// Invoking the REPL should create a repl history file at the specified path 21// and mode 600. 22 23const stream = new Duplex(); 24stream.pause = stream.resume = () => {}; 25// ends immediately 26stream._read = function() { 27 this.push(null); 28}; 29stream._write = function(c, e, cb) { 30 cb(); 31}; 32stream.readable = stream.writable = true; 33 34const tmpdir = require('../common/tmpdir'); 35tmpdir.refresh(); 36const replHistoryPath = path.join(tmpdir.path, '.node_repl_history'); 37 38const checkResults = common.mustSucceed((r) => { 39 const stat = fs.statSync(replHistoryPath); 40 const fileMode = stat.mode & 0o777; 41 assert.strictEqual( 42 fileMode, 0o600, 43 `REPL history file should be mode 0600 but was 0${fileMode.toString(8)}`); 44 45 // Close the REPL 46 r.input.emit('keypress', '', { ctrl: true, name: 'd' }); 47 r.input.end(); 48}); 49 50repl.createInternalRepl( 51 { NODE_REPL_HISTORY: replHistoryPath }, 52 { 53 terminal: true, 54 input: stream, 55 output: stream 56 }, 57 checkResults 58); 59