-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dns: allow
--dns-result-order
to change default dns verbatim
Allow the `--dns-result-order` option to change the default value of verbatim in `dns.lookup()`. This is useful when running Node.js in ipv6-only environments to avoid possible ENETUNREACH errors. PR-URL: #38099 Refs: #31566 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- Loading branch information
Showing
10 changed files
with
298 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Flags: --expose-internals --dns-result-order=ipv4first | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { internalBinding } = require('internal/test/binding'); | ||
const cares = internalBinding('cares_wrap'); | ||
const { promisify } = require('util'); | ||
|
||
// Test that --dns-result-order=ipv4first works as expected. | ||
|
||
const originalGetaddrinfo = cares.getaddrinfo; | ||
const calls = []; | ||
cares.getaddrinfo = common.mustCallAtLeast((...args) => { | ||
calls.push(args); | ||
originalGetaddrinfo(...args); | ||
}, 1); | ||
|
||
const dns = require('dns'); | ||
const dnsPromises = dns.promises; | ||
|
||
let verbatim; | ||
|
||
// We want to test the parameter of verbatim only so that we | ||
// ignore possible errors here. | ||
function allowFailed(fn) { | ||
return fn.catch((_err) => { | ||
// | ||
}); | ||
} | ||
|
||
(async () => { | ||
let callsLength = 0; | ||
const checkParameter = (expected) => { | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, expected); | ||
callsLength += 1; | ||
}; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org')); | ||
checkParameter(false); | ||
|
||
await allowFailed(dnsPromises.lookup('example.org')); | ||
checkParameter(false); | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org', {})); | ||
checkParameter(false); | ||
|
||
await allowFailed(dnsPromises.lookup('example.org', {})); | ||
checkParameter(false); | ||
})().then(common.mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Flags: --expose-internals --dns-result-order=verbatim | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { internalBinding } = require('internal/test/binding'); | ||
const cares = internalBinding('cares_wrap'); | ||
const { promisify } = require('util'); | ||
|
||
// Test that --dns-result-order=verbatim works as expected. | ||
|
||
const originalGetaddrinfo = cares.getaddrinfo; | ||
const calls = []; | ||
cares.getaddrinfo = common.mustCallAtLeast((...args) => { | ||
calls.push(args); | ||
originalGetaddrinfo(...args); | ||
}, 1); | ||
|
||
const dns = require('dns'); | ||
const dnsPromises = dns.promises; | ||
|
||
let verbatim; | ||
|
||
// We want to test the parameter of verbatim only so that we | ||
// ignore possible errors here. | ||
function allowFailed(fn) { | ||
return fn.catch((_err) => { | ||
// | ||
}); | ||
} | ||
|
||
(async () => { | ||
let callsLength = 0; | ||
const checkParameter = (expected) => { | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, expected); | ||
callsLength += 1; | ||
}; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org')); | ||
checkParameter(true); | ||
|
||
await allowFailed(dnsPromises.lookup('example.org')); | ||
checkParameter(true); | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org', {})); | ||
checkParameter(true); | ||
|
||
await allowFailed(dnsPromises.lookup('example.org', {})); | ||
checkParameter(true); | ||
})().then(common.mustCall()); |
Oops, something went wrong.