lib,permission: drop repl autocomplete when pm enabled
PR-URL: https://github.com/nodejs/node/pull/48920 Fixes: https://github.com/nodejs/node/issues/48884 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
0da3f61a19
commit
b907815fbc
@ -12,6 +12,7 @@ const {
|
|||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
const { validatePort } = require('internal/validators');
|
const { validatePort } = require('internal/validators');
|
||||||
|
const permission = require('internal/process/permission');
|
||||||
|
|
||||||
const kMinPort = 1024;
|
const kMinPort = 1024;
|
||||||
const kMaxPort = 65535;
|
const kMaxPort = 65535;
|
||||||
@ -47,6 +48,10 @@ let session;
|
|||||||
function sendInspectorCommand(cb, onError) {
|
function sendInspectorCommand(cb, onError) {
|
||||||
const { hasInspector } = internalBinding('config');
|
const { hasInspector } = internalBinding('config');
|
||||||
if (!hasInspector) return onError();
|
if (!hasInspector) return onError();
|
||||||
|
// Do not preview when the permission model is enabled
|
||||||
|
// because this feature require access to the inspector,
|
||||||
|
// which is unavailable in this case.
|
||||||
|
if (permission.isEnabled()) return onError();
|
||||||
const inspector = require('inspector');
|
const inspector = require('inspector');
|
||||||
if (session === undefined) session = new inspector.Session();
|
if (session === undefined) session = new inspector.Session();
|
||||||
session.connect();
|
session.connect();
|
||||||
|
135
test/parallel/test-repl-permission-model.js
Normal file
135
test/parallel/test-repl-permission-model.js
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// Flags: --expose-internals --experimental-permission --allow-fs-read=*
|
||||||
|
|
||||||
|
const common = require('../common');
|
||||||
|
const stream = require('stream');
|
||||||
|
const REPL = require('internal/repl');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { inspect } = require('util');
|
||||||
|
|
||||||
|
common.skipIfDumbTerminal();
|
||||||
|
|
||||||
|
// Create an input stream specialized for testing an array of actions
|
||||||
|
class ActionStream extends stream.Stream {
|
||||||
|
run(data) {
|
||||||
|
const _iter = data[Symbol.iterator]();
|
||||||
|
const doAction = () => {
|
||||||
|
const next = _iter.next();
|
||||||
|
if (next.done) {
|
||||||
|
// Close the repl. Note that it must have a clean prompt to do so.
|
||||||
|
this.emit('keypress', '', { ctrl: true, name: 'd' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const action = next.value;
|
||||||
|
|
||||||
|
if (typeof action === 'object') {
|
||||||
|
this.emit('keypress', '', action);
|
||||||
|
} else {
|
||||||
|
this.emit('data', `${action}`);
|
||||||
|
}
|
||||||
|
setImmediate(doAction);
|
||||||
|
};
|
||||||
|
doAction();
|
||||||
|
}
|
||||||
|
resume() {}
|
||||||
|
pause() {}
|
||||||
|
}
|
||||||
|
ActionStream.prototype.readable = true;
|
||||||
|
|
||||||
|
// Mock keys
|
||||||
|
const ENTER = { name: 'enter' };
|
||||||
|
const TABULATION = { name: 'tab' };
|
||||||
|
|
||||||
|
const prompt = '> ';
|
||||||
|
|
||||||
|
const tests = [
|
||||||
|
{
|
||||||
|
test: (function*() {
|
||||||
|
yield 'f';
|
||||||
|
yield TABULATION;
|
||||||
|
yield ENTER;
|
||||||
|
})(),
|
||||||
|
expected: [],
|
||||||
|
env: {}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const numtests = tests.length;
|
||||||
|
|
||||||
|
const runTestWrap = common.mustCall(runTest, numtests);
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
const opts = tests.shift();
|
||||||
|
if (!opts) return; // All done
|
||||||
|
|
||||||
|
const { expected, skip } = opts;
|
||||||
|
|
||||||
|
// Test unsupported on platform.
|
||||||
|
if (skip) {
|
||||||
|
setImmediate(runTestWrap, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const lastChunks = [];
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
REPL.createInternalRepl(opts.env, {
|
||||||
|
input: new ActionStream(),
|
||||||
|
output: new stream.Writable({
|
||||||
|
write(chunk, _, next) {
|
||||||
|
const output = chunk.toString();
|
||||||
|
|
||||||
|
if (!opts.showEscapeCodes &&
|
||||||
|
(output[0] === '\x1B' || /^[\r\n]+$/.test(output))) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
lastChunks.push(output);
|
||||||
|
|
||||||
|
if (expected.length && !opts.checkTotal) {
|
||||||
|
try {
|
||||||
|
assert.strictEqual(output, expected[i]);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed test # ${numtests - tests.length}`);
|
||||||
|
console.error('Last outputs: ' + inspect(lastChunks, {
|
||||||
|
breakLength: 5, colors: true
|
||||||
|
}));
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
// TODO(BridgeAR): Auto close on last chunk!
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
allowBlockingCompletions: true,
|
||||||
|
completer: opts.completer,
|
||||||
|
prompt,
|
||||||
|
useColors: false,
|
||||||
|
preview: opts.preview,
|
||||||
|
terminal: true
|
||||||
|
}, function(err, repl) {
|
||||||
|
if (err) {
|
||||||
|
console.error(`Failed test # ${numtests - tests.length}`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
repl.once('close', () => {
|
||||||
|
|
||||||
|
if (opts.checkTotal) {
|
||||||
|
assert.deepStrictEqual(lastChunks, expected);
|
||||||
|
} else if (expected.length !== i) {
|
||||||
|
console.error(tests[numtests - tests.length - 1]);
|
||||||
|
throw new Error(`Failed test # ${numtests - tests.length}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
setImmediate(runTestWrap, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
repl.input.run(opts.test);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the tests
|
||||||
|
runTest();
|
Loading…
x
Reference in New Issue
Block a user