Skip to content

Commit

Permalink
test: fix flaky test-*-connect-address-family
Browse files Browse the repository at this point in the history
Skip tests if localhost does not resolve to ::1.

Fixes: #7288
PR-URL: #7605
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>

Conflicts:
	test/parallel/test-https-connect-address-family.js
	test/parallel/test-tls-connect-address-family.js
  • Loading branch information
Trott authored and cjihrig committed Aug 10, 2016
1 parent 5f3ab3f commit e56db14
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 35 deletions.
54 changes: 36 additions & 18 deletions test/parallel/test-https-connect-address-family.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const https = require('https');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

if (!common.hasIPv6) {
common.skip('no IPv6 support');
return;
}

const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, function(req, res) {
this.close();
res.end();
}).listen(common.PORT, '::1', function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
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();
const assert = require('assert');
const https = require('https');
const dns = require('dns');

function runTest() {
const ciphers = 'AECDH-NULL-SHA';
https.createServer({ ciphers }, common.mustCall(function(req, res) {
this.close();
res.end();
})).listen(common.PORT, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
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');
});
52 changes: 35 additions & 17 deletions test/parallel/test-tls-connect-address-family.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const tls = require('tls');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

if (!common.hasIPv6) {
common.skip('no IPv6 support');
return;
}

const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, function() {
this.close();
}).listen(common.PORT, '::1', function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
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();
const assert = require('assert');
const tls = require('tls');
const dns = require('dns');

function runTest() {
const ciphers = 'AECDH-NULL-SHA';
tls.createServer({ ciphers }, common.mustCall(function() {
this.close();
})).listen(common.PORT, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
port: common.PORT,
family: 6,
ciphers: ciphers,
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');
});

0 comments on commit e56db14

Please sign in to comment.