Skip to content

Commit 53bba2f

Browse files
danbevMylesBorins
authored andcommitted
test: allow for different nsswitch.conf settings
The motivation for this commit is that these two test fail on systems that have different Name Service Switch configuration settings. A concrete example of this is when using Red Hat Enterprise Linux (RHEL) 7. If Name Service Switch is available on the operating system then it might be configured differently (/etc/nsswitch.conf). If the system is configured with no dns the error code will be AI_AGAIN, but if there are more services after the dns entry, for example some linux distributions skip a myhostname service by default which would still produce the ENOTFOUND error. This commit suggests checking for either ENOTFOUND or EAI_AGAIN to accommodate systems like the ones described above. The references below indicate that others have run, or are running, into this aswell. Refs: #12075 Refs: nodejs/help#687 Refs: #15825 PR-URL: #16378 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent fb0c05d commit 53bba2f

4 files changed

+16
-4
lines changed

test/parallel/test-https-connect-address-family.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function runTest() {
3333

3434
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
3535
if (err) {
36-
if (err.code === 'ENOTFOUND')
36+
if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN')
3737
common.skip('localhost does not resolve to ::1');
3838

3939
throw err;

test/parallel/test-net-better-error-messages-port-hostname.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ const c = net.createConnection(0, 'this.hostname.is.invalid');
99
c.on('connect', common.mustNotCall());
1010

1111
c.on('error', common.mustCall(function(e) {
12-
assert.strictEqual(e.code, 'ENOTFOUND');
12+
// If Name Service Switch is available on the operating system then it
13+
// might be configured differently (/etc/nsswitch.conf).
14+
// If the system is configured with no dns the error code will be EAI_AGAIN,
15+
// but if there are more services after the dns entry, for example some
16+
// linux distributions ship a myhostname service by default which would
17+
// still produce the ENOTFOUND error.
18+
assert.ok(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN');
1319
assert.strictEqual(e.port, 0);
1420
assert.strictEqual(e.hostname, 'this.hostname.is.invalid');
1521
}));

test/parallel/test-net-connect-immediate-finish.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ const client = net.connect({
1111
client.once('error', common.mustCall((err) => {
1212
assert(err);
1313
assert.strictEqual(err.code, err.errno);
14-
assert.strictEqual(err.code, 'ENOTFOUND');
14+
// If Name Service Switch is available on the operating system then it
15+
// might be configured differently (/etc/nsswitch.conf).
16+
// If the system is configured with no dns the error code will be EAI_AGAIN,
17+
// but if there are more services after the dns entry, for example some
18+
// linux distributions ship a myhostname service by default which would
19+
// still produce the ENOTFOUND error.
20+
assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN');
1521
assert.strictEqual(err.host, err.hostname);
1622
assert.strictEqual(err.host, 'this.hostname.is.invalid');
1723
assert.strictEqual(err.syscall, 'getaddrinfo');

test/parallel/test-tls-connect-address-family.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function runTest() {
3232

3333
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
3434
if (err) {
35-
if (err.code === 'ENOTFOUND')
35+
if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN')
3636
common.skip('localhost does not resolve to ::1');
3737

3838
throw err;

0 commit comments

Comments
 (0)