test: move test that depends on dns query to internet

These test cases in `test/parallel/test-dns-lookup.js` send
dns requests and depend on the results, which could fail
if the DNS service for invalid hosts is hijacked by the ISP.

PR-URL: https://github.com/nodejs/node/pull/22516
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Joyee Cheung 2018-08-25 09:03:09 +08:00 committed by Anna Henningsen
parent 36c56db0b1
commit a58b8dd545
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 30 additions and 25 deletions

View File

@ -0,0 +1,30 @@
'use strict';
require('../common');
const dnsPromises = require('dns').promises;
const { addresses } = require('../common/internet');
const assert = require('assert');
assert.rejects(
dnsPromises.lookup(addresses.INVALID_HOST, {
hints: 0,
family: 0,
all: false
}),
{
code: 'ENOTFOUND',
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
}
);
assert.rejects(
dnsPromises.lookup(addresses.INVALID_HOST, {
hints: 0,
family: 0,
all: true
}),
{
code: 'ENOTFOUND',
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
}
);

View File

@ -1,7 +1,6 @@
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { addresses } = require('../common/internet');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const cares = internalBinding('cares_wrap');
@ -95,30 +94,6 @@ common.expectsError(() => {
all: false
});
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
assert.rejects(
dnsPromises.lookup(addresses.INVALID_HOST, {
hints: 0,
family: 0,
all: false
}),
{
code: 'ENOTFOUND',
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
}
);
assert.rejects(
dnsPromises.lookup(addresses.INVALID_HOST, {
hints: 0,
family: 0,
all: true
}),
{
code: 'ENOTFOUND',
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
}
);
})();
dns.lookup(false, {