-
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 NODE_DNS_VERBATIM to change default verbatim
Allow the NODE_DNS_VERBATIM environment variable to change the default value of `verbatim` in `dns.lookup()`.
- Loading branch information
Showing
6 changed files
with
78 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Flags: --expose-internals | ||
'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 NODE_DNS_VERBATIM works as expected. | ||
|
||
const originalGetaddrinfo = cares.getaddrinfo; | ||
const calls = []; | ||
cares.getaddrinfo = (...args) => { | ||
calls.push(args); | ||
originalGetaddrinfo(...args); | ||
}; | ||
|
||
const dns = require('dns'); | ||
const dnsPromises = dns.promises; | ||
|
||
(async () => { | ||
{ | ||
process.env.NODE_DNS_VERBATIM = '1'; | ||
let verbatim; | ||
|
||
await promisify(dns.lookup)('example.org'); | ||
|
||
assert.strictEqual(calls.length, 1); | ||
verbatim = calls[0][4]; | ||
assert.strictEqual(verbatim, true); | ||
|
||
await dnsPromises.lookup('example.org'); | ||
assert.strictEqual(calls.length, 2); | ||
verbatim = calls[1][4]; | ||
assert.strictEqual(verbatim, true); | ||
|
||
process.env.NODE_DNS_VERBATIM = '0'; | ||
|
||
await promisify(dns.lookup)('example.org'); | ||
|
||
assert.strictEqual(calls.length, 3); | ||
verbatim = calls[2][4]; | ||
assert.strictEqual(verbatim, false); | ||
|
||
await dnsPromises.lookup('example.org'); | ||
assert.strictEqual(calls.length, 4); | ||
verbatim = calls[3][4]; | ||
assert.strictEqual(verbatim, false); | ||
} | ||
})(); |