Skip to content

Commit a58b8dd

Browse files
joyeecheungaddaleax
authored andcommitted
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: #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>
1 parent 36c56db commit a58b8dd

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

test/internet/test-dns-lookup.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
require('../common');
4+
const dnsPromises = require('dns').promises;
5+
const { addresses } = require('../common/internet');
6+
const assert = require('assert');
7+
8+
assert.rejects(
9+
dnsPromises.lookup(addresses.INVALID_HOST, {
10+
hints: 0,
11+
family: 0,
12+
all: false
13+
}),
14+
{
15+
code: 'ENOTFOUND',
16+
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
17+
}
18+
);
19+
20+
assert.rejects(
21+
dnsPromises.lookup(addresses.INVALID_HOST, {
22+
hints: 0,
23+
family: 0,
24+
all: true
25+
}),
26+
{
27+
code: 'ENOTFOUND',
28+
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
29+
}
30+
);

test/parallel/test-dns-lookup.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Flags: --expose-internals
22
'use strict';
33
const common = require('../common');
4-
const { addresses } = require('../common/internet');
54
const assert = require('assert');
65
const { internalBinding } = require('internal/test/binding');
76
const cares = internalBinding('cares_wrap');
@@ -95,30 +94,6 @@ common.expectsError(() => {
9594
all: false
9695
});
9796
assert.deepStrictEqual(res, { address: '127.0.0.1', family: 4 });
98-
99-
assert.rejects(
100-
dnsPromises.lookup(addresses.INVALID_HOST, {
101-
hints: 0,
102-
family: 0,
103-
all: false
104-
}),
105-
{
106-
code: 'ENOTFOUND',
107-
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
108-
}
109-
);
110-
111-
assert.rejects(
112-
dnsPromises.lookup(addresses.INVALID_HOST, {
113-
hints: 0,
114-
family: 0,
115-
all: true
116-
}),
117-
{
118-
code: 'ENOTFOUND',
119-
message: `getaddrinfo ENOTFOUND ${addresses.INVALID_HOST}`
120-
}
121-
);
12297
})();
12398

12499
dns.lookup(false, {

0 commit comments

Comments
 (0)