From cf68f15ae34576e5a1f8d46ca89931906232b7bf Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 20 Oct 2017 08:35:54 +0200 Subject: [PATCH 1/2] 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: https://github.com/nodejs/node/issues/12075 Refs: https://github.com/nodejs/help/issues/687 --- .../test-net-better-error-messages-port-hostname.js | 8 +++++++- test/parallel/test-net-connect-immediate-finish.js | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-net-better-error-messages-port-hostname.js b/test/parallel/test-net-better-error-messages-port-hostname.js index dac17141677dcb..818ea4bfff41f6 100644 --- a/test/parallel/test-net-better-error-messages-port-hostname.js +++ b/test/parallel/test-net-better-error-messages-port-hostname.js @@ -9,7 +9,13 @@ const c = net.createConnection(0, 'this.hostname.is.invalid'); c.on('connect', common.mustNotCall()); c.on('error', common.mustCall(function(e) { - assert.strictEqual(e.code, 'ENOTFOUND'); + // 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 EAI_AGAIN, + // but if there are more services after the dns entry, for example some + // linux distributions ship a myhostname service by default which would + // still produce the ENOTFOUND error. + assert.ok(e.code === 'ENOTFOUND' || e.code === 'EAI_AGAIN'); assert.strictEqual(e.port, 0); assert.strictEqual(e.hostname, 'this.hostname.is.invalid'); })); diff --git a/test/parallel/test-net-connect-immediate-finish.js b/test/parallel/test-net-connect-immediate-finish.js index 1b65ce15ab8a1c..e2e5e1c6715b9a 100644 --- a/test/parallel/test-net-connect-immediate-finish.js +++ b/test/parallel/test-net-connect-immediate-finish.js @@ -32,7 +32,13 @@ const client = net.connect({ client.once('error', common.mustCall((err) => { assert(err); assert.strictEqual(err.code, err.errno); - assert.strictEqual(err.code, 'ENOTFOUND'); + // 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 EAI_AGAIN, + // but if there are more services after the dns entry, for example some + // linux distributions ship a myhostname service by default which would + // still produce the ENOTFOUND error. + assert.ok(err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN'); assert.strictEqual(err.host, err.hostname); assert.strictEqual(err.host, 'this.hostname.is.invalid'); assert.strictEqual(err.syscall, 'getaddrinfo'); From 4c61f4807101c193cd7c5594bb910499040f10df Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 24 Oct 2017 14:02:39 +0200 Subject: [PATCH 2/2] test: allow for differences in hosts config The hosts configuration on a system can affect how dns look up works and different error can occur with different setups. This commit adds a check for EAI_AGAIN to avoid the issue reported in the issue referred to below. Refs: https://github.com/nodejs/node/issues/15825 --- test/parallel/test-https-connect-address-family.js | 2 +- test/parallel/test-tls-connect-address-family.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-https-connect-address-family.js b/test/parallel/test-https-connect-address-family.js index fa9baa528efa00..a345a70a57074b 100644 --- a/test/parallel/test-https-connect-address-family.js +++ b/test/parallel/test-https-connect-address-family.js @@ -33,7 +33,7 @@ function runTest() { dns.lookup('localhost', { family: 6, all: true }, (err, addresses) => { if (err) { - if (err.code === 'ENOTFOUND') + if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') common.skip('localhost does not resolve to ::1'); throw err; diff --git a/test/parallel/test-tls-connect-address-family.js b/test/parallel/test-tls-connect-address-family.js index 663e9399b610ce..b0623c6cf603ec 100644 --- a/test/parallel/test-tls-connect-address-family.js +++ b/test/parallel/test-tls-connect-address-family.js @@ -32,7 +32,7 @@ function runTest() { dns.lookup('localhost', { family: 6, all: true }, (err, addresses) => { if (err) { - if (err.code === 'ENOTFOUND') + if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') common.skip('localhost does not resolve to ::1'); throw err;