Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: default to verbatim=true in dns.lookup() #20710

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions doc/api/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ changes:
an array. Otherwise, returns a single address. **Default:** `false`.
- `verbatim` {boolean} When `true`, the callback receives IPv4 and IPv6
addresses in the order the DNS resolver returned them. When `false`,
IPv4 addresses are placed before IPv6 addresses.
**Default:** currently `false` (addresses are reordered) but this is
expected to change in the not too distant future.
New code should use `{ verbatim: true }`.
IPv4 addresses are placed before IPv6 addresses. **Default:** `true`
Copy link
Contributor

@vsemozhetbyt vsemozhetbyt May 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: a period after `true` for consistency with the previous option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that can also be done why landing the PR.

* `callback` {Function}
- `err` {Error}
- `address` {string} A string representation of an IPv4 or IPv6 address.
Expand Down
4 changes: 2 additions & 2 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function lookup(hostname, options, callback) {
var hints = 0;
var family = -1;
var all = false;
var verbatim = false;
var verbatim = true;

// Parse arguments
if (hostname && typeof hostname !== 'string') {
Expand All @@ -103,7 +103,7 @@ function lookup(hostname, options, callback) {
hints = options.hints >>> 0;
family = options.family >>> 0;
all = options.all === true;
verbatim = options.verbatim === true;
verbatim = options.verbatim !== false;

validateHints(hints);
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/addons/openssl-client-cert-engine/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ const serverOptions = {
const server = https.createServer(serverOptions, (req, res) => {
res.writeHead(200);
res.end('hello world');
}).listen(0, common.localhostIPv4, () => {
}).listen(0, '127.0.0.1', () => {
const clientOptions = {
method: 'GET',
host: common.localhostIPv4,
host: '127.0.0.1',
port: server.address().port,
path: '/test',
clientCertEngine: engine, // engine will provide key+cert
Expand Down
5 changes: 0 additions & 5 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,6 @@ Platform check for SunOS.

Platform check for Windows.

### localhostIPv4
* [<string>]

IP of `localhost`.

### localIPv6Hosts
* [<Array>]

Expand Down
22 changes: 0 additions & 22 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ if (process.env.NODE_TEST_WITH_ASYNC_HOOKS) {

let opensslCli = null;
let inFreeBSDJail = null;
let localhostIPv4 = null;

const localIPv6Hosts =
isLinux ? [
Expand Down Expand Up @@ -759,27 +758,6 @@ module.exports = {
return inFreeBSDJail;
},

get localhostIPv4() {
if (localhostIPv4 !== null) return localhostIPv4;

if (this.inFreeBSDJail) {
// Jailed network interfaces are a bit special - since we need to jump
// through loops, as well as this being an exception case, assume the
// user will provide this instead.
if (process.env.LOCALHOST) {
localhostIPv4 = process.env.LOCALHOST;
} else {
console.error('Looks like we\'re in a FreeBSD Jail. ' +
'Please provide your default interface address ' +
'as LOCALHOST or expect some tests to fail.');
}
}

if (localhostIPv4 === null) localhostIPv4 = '127.0.0.1';

return localhostIPv4;
},

// opensslCli defined lazily to reduce overhead of spawnSync
get opensslCli() {
if (opensslCli !== null) return opensslCli;
Expand Down
3 changes: 3 additions & 0 deletions test/common/inspector-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ class NodeInstance extends EventEmitter {

httpGet(host, path, hostHeaderValue) {
console.log('[test]', `Testing ${path}`);
// 'localhost' can either resolve to 127.0.0.1 or ::1 but
// the inspector only listens on 127.0.0.1 so be explicit.
if (!host) host = '127.0.0.1';
const headers = hostHeaderValue ? { 'Host': hostHeaderValue } : null;
return this.portPromise.then((port) => new Promise((resolve, reject) => {
const req = http.get({ host, port, path, headers }, (res) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');

// This test should fail because at present `cluster` does not know how to share
// a socket when `worker1` binds with `port: 0`, and others try to bind to the
Expand Down Expand Up @@ -50,7 +50,7 @@ if (cluster.isMaster) {
const socket1 = dgram.createSocket('udp4', () => {});
socket1.on('error', PRT1 === 0 ? () => {} : assert.fail);
socket1.bind(
{ address: common.localhostIPv4, port: PRT1, exclusive: false },
{ address: '127.0.0.1', port: PRT1, exclusive: false },
() => process.send({ message: 'success', port1: socket1.address().port })
);
}
2 changes: 1 addition & 1 deletion test/known_issues/test-inspector-cluster-port-clash.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ if (cluster.isMaster) {

// block one of the ports with a listening socket
const server = net.createServer();
server.listen(clashPort, common.localhostIPv4, common.mustCall(() => {
server.listen(clashPort, '127.0.0.1', common.mustCall(() => {
// try to fork 3 workers No.2 should fail
Promise.all([serialFork(), serialFork(), serialFork()])
.then(common.mustNotCall())
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-send-keep-open.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (process.argv[2] !== 'child') {
});

server.listen(0, () => {
const socket = net.connect(server.address().port, common.localhostIPv4);
const socket = net.connect(server.address().port, '127.0.0.1');
socket.setEncoding('utf8');
socket.on('data', (data) => result += data);
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-cluster-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ if (cluster.isWorker) {
maybeReply();
});

server.listen(0, '127.0.0.1');
server.listen();
} else if (cluster.isMaster) {

const checks = {
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-cluster-worker-wait-server-close.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');
Expand All @@ -12,7 +12,7 @@ if (cluster.isWorker) {
// Wait for any data, then close connection
socket.write('.');
socket.on('data', () => {});
}).listen(0, common.localhostIPv4);
}).listen(0, '127.0.0.1');

server.once('close', function() {
serverClosed = true;
Expand All @@ -34,7 +34,7 @@ if (cluster.isWorker) {

// Disconnect worker when it is ready
worker.once('listening', function(address) {
const socket = net.createConnection(address.port, common.localhostIPv4);
const socket = net.createConnection(address.port, '127.0.0.1');

socket.on('connect', function() {
socket.on('data', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dgram-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const dgram = require('dgram');
socket.on('listening', common.mustCall(() => {
const address = socket.address();

assert.strictEqual(address.address, common.localhostIPv4);
assert.strictEqual(address.address, '127.0.0.1');
assert.strictEqual(typeof address.port, 'number');
assert.ok(isFinite(address.port));
assert.ok(address.port > 0);
Expand All @@ -44,7 +44,7 @@ const dgram = require('dgram');
assert.fail(`Unexpected error on udp4 socket. ${err.toString()}`);
});

socket.bind(0, common.localhostIPv4);
socket.bind(0, '127.0.0.1');
}

if (common.hasIPv6) {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-create-socket-handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const UDP = internalBinding('udp_wrap').UDP;

{
// Create a bound handle.
const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4');
const handle = _createSocketHandle('127.0.0.1', 0, 'udp4');

assert(handle instanceof UDP);
assert.strictEqual(typeof handle.fd, 'number');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-callback-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ const onMessage = common.mustCall(function(err, bytes) {

client.bind(0, () => client.send(buf,
client.address().port,
common.localhostIPv4,
'127.0.0.1',
onMessage));
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-callback-multi-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const buf2 = Buffer.alloc(256, 'y');

client.on('listening', () => {
const port = client.address().port;
client.send([buf1, buf2], port, common.localhostIPv4, messageSent);
client.send([buf1, buf2], port, '127.0.0.1', messageSent);
});

client.on('message', common.mustCall((buf, info) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-callback-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let port;

function onsend() {
if (sent++ < limit) {
client.send(chunk, 0, chunk.length, port, common.localhostIPv4, onsend);
client.send(chunk, 0, chunk.length, port, '127.0.0.1', onsend);
} else {
assert.strictEqual(async, true);
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-empty-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ client.on('message', common.mustCall(function onMessage(buf, info) {

client.on('listening', common.mustCall(function() {
interval = setInterval(function() {
client.send([], client.address().port, common.localhostIPv4);
client.send([], client.address().port, '127.0.0.1');
}, 10);
}));

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dgram-send-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ getSocket((socket) => {
assert.strictEqual(err.code, 'UNKNOWN');
assert.strictEqual(err.errno, 'UNKNOWN');
assert.strictEqual(err.syscall, 'send');
assert.strictEqual(err.address, common.localhostIPv4);
assert.strictEqual(err.address, '127.0.0.1');
assert.strictEqual(err.port, port);
assert.strictEqual(
err.message,
Expand All @@ -64,6 +64,6 @@ getSocket((socket) => {
return UV_UNKNOWN;
};

socket.send('foo', port, common.localhostIPv4, callback);
socket.send('foo', port, '127.0.0.1', callback);
}));
}
2 changes: 1 addition & 1 deletion test/parallel/test-dgram-send-multi-buffer-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const buf2 = Buffer.alloc(256, 'y');

client.on('listening', function() {
const toSend = [buf1, buf2];
client.send(toSend, this.address().port, common.localhostIPv4, onMessage);
client.send(toSend, this.address().port, '127.0.0.1', onMessage);
toSend.splice(0, 2);
});

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-dgram-udp4.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const message_to_send = 'A message to send';

const server = dgram.createSocket('udp4');
server.on('message', common.mustCall((msg, rinfo) => {
assert.strictEqual(rinfo.address, common.localhostIPv4);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(msg.toString(), message_to_send.toString());
server.send(msg, 0, msg.length, rinfo.port, rinfo.address);
}));
server.on('listening', common.mustCall(() => {
const client = dgram.createSocket('udp4');
const port = server.address().port;
client.on('message', common.mustCall((msg, rinfo) => {
assert.strictEqual(rinfo.address, common.localhostIPv4);
assert.strictEqual(rinfo.address, '127.0.0.1');
assert.strictEqual(rinfo.port, port);
assert.strictEqual(msg.toString(), message_to_send.toString());
client.close();
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-domain-abort-on-uncaught.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const tests = [
const server = net.createServer(function(conn) {
conn.pipe(conn);
});
server.listen(0, common.localhostIPv4, function() {
const conn = net.connect(this.address().port, common.localhostIPv4);
server.listen(0, '127.0.0.1', function() {
const conn = net.connect(this.address().port, '127.0.0.1');
conn.once('data', function() {
throw new Error('ok');
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-client-get-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ const server = http.createServer(common.mustCall((req, res) => {
res.end();
}, 3));

server.listen(0, common.localhostIPv4, common.mustCall(() => {
const u = `http://${common.localhostIPv4}:${server.address().port}${testPath}`;
server.listen(0, '127.0.0.1', common.mustCall(() => {
const u = `http://127.0.0.1:${server.address().port}${testPath}`;
http.get(u, common.mustCall(() => {
http.get(url.parse(u), common.mustCall(() => {
http.get(new URL(u), common.mustCall(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-reject-unexpected-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const http = require('http');
const baseOptions = {
method: 'GET',
port: undefined,
host: common.localhostIPv4,
host: '127.0.0.1',
};

const failingAgentOptions = [
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-client-timeout-on-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const server = http.createServer((req, res) => {
// This space is intentionally left blank.
});

server.listen(0, common.localhostIPv4, common.mustCall(() => {
server.listen(0, '127.0.0.1', common.mustCall(() => {
const port = server.address().port;
const req = http.get(`http://${common.localhostIPv4}:${port}`);
const req = http.get(`http://127.0.0.1:${port}`);

req.setTimeout(1);
req.on('socket', common.mustCall((socket) => {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-client-timeout-option-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const options = {
agent,
method: 'GET',
port: undefined,
host: common.localhostIPv4,
host: '127.0.0.1',
path: '/',
timeout: timeout
};
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-http-flush-response-headers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');

Expand All @@ -10,10 +10,10 @@ server.on('request', function(req, res) {
res.flushHeaders();
res.flushHeaders(); // Should be idempotent.
});
server.listen(0, common.localhostIPv4, function() {
server.listen(0, '127.0.0.1', function() {
const req = http.request({
method: 'GET',
host: common.localhostIPv4,
host: '127.0.0.1',
port: this.address().port,
}, onResponse);

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-request-dont-override-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ server.listen(0, function() {
// be mutable / modified
const options = {
host: undefined,
hostname: common.localhostIPv4,
hostname: '127.0.0.1',
port: undefined,
defaultPort: undefined,
path: undefined,
Expand All @@ -31,7 +31,7 @@ server.listen(0, function() {
res.resume();
server.close();
assert.strictEqual(options.host, undefined);
assert.strictEqual(options.hostname, common.localhostIPv4);
assert.strictEqual(options.hostname, '127.0.0.1');
assert.strictEqual(options.port, undefined);
assert.strictEqual(options.defaultPort, undefined);
assert.strictEqual(options.path, undefined);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http-same-map.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Flags: --allow_natives_syntax
'use strict';

const common = require('../common');
require('../common');
const assert = require('assert');
const http = require('http');

const server =
http.createServer(onrequest).listen(0, common.localhostIPv4, () => next(0));
http.createServer(onrequest).listen(0, '127.0.0.1', () => next(0));

function onrequest(req, res) {
res.end('ok');
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http-upgrade-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const srv = net.createServer(function(c) {
});
});

srv.listen(0, '127.0.0.1', common.mustCall(function() {
srv.listen(0, common.mustCall(function() {
const port = this.address().port;
const headers = [
{
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-https-client-get-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const server = https.createServer(options, common.mustCall((req, res) => {
}, 3));

server.listen(0, common.mustCall(() => {
const u = `https://${common.localhostIPv4}:${server.address().port}/foo?bar`;
const u = `https://127.0.0.1:${server.address().port}/foo?bar`;
https.get(u, common.mustCall(() => {
https.get(url.parse(u), common.mustCall(() => {
https.get(new URL(u), common.mustCall(() => {
Expand Down
Loading