From 67372016bbbd352a573923f2396ea2c2d6c31101 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 25 Aug 2018 09:03:09 +0800 Subject: [PATCH] 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 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Refael Ackermann Reviewed-By: Trivikram Kamat Reviewed-By: Ruben Bridgewater --- test/internet/test-dns-lookup.js | 30 ++++++++++++++++++++++++++++++ test/parallel/test-dns-lookup.js | 25 ------------------------- 2 files changed, 30 insertions(+), 25 deletions(-) create mode 100644 test/internet/test-dns-lookup.js diff --git a/test/internet/test-dns-lookup.js b/test/internet/test-dns-lookup.js new file mode 100644 index 00000000000000..b84f80735fb866 --- /dev/null +++ b/test/internet/test-dns-lookup.js @@ -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}` + } +); diff --git a/test/parallel/test-dns-lookup.js b/test/parallel/test-dns-lookup.js index 244d2356d9e902..3413bcffd8abe9 100644 --- a/test/parallel/test-dns-lookup.js +++ b/test/parallel/test-dns-lookup.js @@ -1,6 +1,5 @@ 'use strict'; const common = require('../common'); -const { addresses } = require('../common/internet'); const assert = require('assert'); const cares = process.binding('cares_wrap'); const dns = require('dns'); @@ -93,30 +92,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, {