-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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-verbatim to change default dns verbatim
Allow the "--dns-verbatim" 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.
- Loading branch information
Showing
8 changed files
with
165 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Flags: --expose-internals --dns-verbatim=0 | ||
'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-verbatim=0 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; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org')); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, false); | ||
callsLength += 1; | ||
|
||
await allowFailed(dnsPromises.lookup('example.org')); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, false); | ||
callsLength += 1; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org', {})); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, false); | ||
callsLength += 1; | ||
|
||
await allowFailed(dnsPromises.lookup('example.org', {})); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, false); | ||
callsLength += 1; | ||
})().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,57 @@ | ||
// Flags: --expose-internals --dns-verbatim=1 | ||
'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-verbatim=1 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; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org')); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, true); | ||
callsLength += 1; | ||
|
||
await allowFailed(dnsPromises.lookup('example.org')); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, true); | ||
callsLength += 1; | ||
|
||
await allowFailed(promisify(dns.lookup)('example.org', {})); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, true); | ||
callsLength += 1; | ||
|
||
await allowFailed(dnsPromises.lookup('example.org', {})); | ||
assert.strictEqual(calls.length, callsLength + 1); | ||
verbatim = calls[callsLength][4]; | ||
assert.strictEqual(verbatim, true); | ||
callsLength += 1; | ||
})().then(common.mustCall()); |