Browse Source

test: fix flaky test-*-connect-address-family

Skip tests if localhost does not resolve to ::1.

Fixes: https://github.com/nodejs/node/issues/7288
PR-URL: https://github.com/nodejs/node/pull/7605
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
v7.x
Rich Trott 8 years ago
parent
commit
2d77cba7e7
  1. 51
      test/parallel/test-https-connect-address-family.js
  2. 49
      test/parallel/test-tls-connect-address-family.js

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

@ -5,29 +5,42 @@ if (!common.hasCrypto) {
return; return;
} }
const assert = require('assert');
const https = require('https');
if (!common.hasIPv6) { if (!common.hasIPv6) {
common.skip('no IPv6 support'); common.skip('no IPv6 support');
return; return;
} }
const ciphers = 'AECDH-NULL-SHA'; const assert = require('assert');
https.createServer({ ciphers }, function(req, res) { const https = require('https');
this.close(); const dns = require('dns');
res.end();
}).listen(common.PORT, '::1', function() { function runTest() {
const options = { const ciphers = 'AECDH-NULL-SHA';
host: 'localhost', https.createServer({ ciphers }, common.mustCall(function(req, res) {
port: common.PORT, this.close();
family: 6, res.end();
ciphers: ciphers, })).listen(common.PORT, '::1', common.mustCall(function() {
rejectUnauthorized: false, const options = {
}; host: 'localhost',
// Will fail with ECONNREFUSED if the address family is not honored. port: common.PORT,
https.get(options, common.mustCall(function() { family: 6,
assert.strictEqual('::1', this.socket.remoteAddress); ciphers: ciphers,
this.destroy(); rejectUnauthorized: false,
};
// Will fail with ECONNREFUSED if the address family is not honored.
https.get(options, common.mustCall(function() {
assert.strictEqual('::1', this.socket.remoteAddress);
this.destroy();
}));
})); }));
}
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
if (err)
throw err;
if (addresses.some((val) => val.address === '::1'))
runTest();
else
common.skip('localhost does not resolve to ::1');
}); });

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

@ -5,28 +5,41 @@ if (!common.hasCrypto) {
return; return;
} }
const assert = require('assert');
const tls = require('tls');
if (!common.hasIPv6) { if (!common.hasIPv6) {
common.skip('no IPv6 support'); common.skip('no IPv6 support');
return; return;
} }
const ciphers = 'AECDH-NULL-SHA'; const assert = require('assert');
tls.createServer({ ciphers }, function() { const tls = require('tls');
this.close(); const dns = require('dns');
}).listen(common.PORT, '::1', function() {
const options = { function runTest() {
host: 'localhost', const ciphers = 'AECDH-NULL-SHA';
port: common.PORT, tls.createServer({ ciphers }, common.mustCall(function() {
family: 6, this.close();
ciphers: ciphers, })).listen(common.PORT, '::1', common.mustCall(function() {
rejectUnauthorized: false, const options = {
}; host: 'localhost',
// Will fail with ECONNREFUSED if the address family is not honored. port: common.PORT,
tls.connect(options).once('secureConnect', common.mustCall(function() { family: 6,
assert.strictEqual('::1', this.remoteAddress); ciphers: ciphers,
this.destroy(); rejectUnauthorized: false,
};
// Will fail with ECONNREFUSED if the address family is not honored.
tls.connect(options).once('secureConnect', common.mustCall(function() {
assert.strictEqual('::1', this.remoteAddress);
this.destroy();
}));
})); }));
}
dns.lookup('localhost', {family: 6, all: true}, (err, addresses) => {
if (err)
throw err;
if (addresses.some((val) => val.address === '::1'))
runTest();
else
common.skip('localhost does not resolve to ::1');
}); });

Loading…
Cancel
Save