0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/parallel/test-debug-port-cluster.js
Ben Noordhuis 8e7cbe2546 src: make debugger listen on 127.0.0.1 by default
Commit 2272052 ("net: bind to `::` TCP address by default") from
April 2014 seems to have accidentally changed the default listen
address from 127.0.0.1 to 0.0.0.0, a.k.a. the "any" address.

From a security viewpoint it's undesirable to accept debug agent
connections from anywhere so let's change that back.  Users can
override the default with the `--debug=<host>:<port>` switch.

Fixes: https://github.com/nodejs/node/issues/8081
PR-URL: https://github.com/nodejs/node/pull/8106
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-23 21:10:34 +02:00

32 lines
829 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const spawn = require('child_process').spawn;
const PORT_MIN = common.PORT + 1; // The fixture uses common.PORT.
const PORT_MAX = PORT_MIN + 2;
const args = [
'--debug=' + PORT_MIN,
common.fixturesDir + '/clustered-server/app.js'
];
const child = spawn(process.execPath, args);
child.stderr.setEncoding('utf8');
const checkMessages = common.mustCall(() => {
for (let port = PORT_MIN; port <= PORT_MAX; port += 1) {
assert(stderr.includes(`Debugger listening on 127.0.0.1:${port}`));
}
});
let stderr = '';
child.stderr.on('data', (data) => {
process.stderr.write(`[DATA] ${data}`);
stderr += data;
if (child.killed !== true && stderr.includes('all workers are running')) {
child.kill();
checkMessages();
}
});