1'use strict'; 2const common = require('../common'); 3if (!common.hasCrypto) 4 common.skip('missing crypto'); 5 6if (!common.hasIPv6) 7 common.skip('no IPv6 support'); 8 9const assert = require('assert'); 10const fixtures = require('../common/fixtures'); 11const tls = require('tls'); 12const dns = require('dns'); 13 14function runTest() { 15 tls.createServer({ 16 cert: fixtures.readKey('agent1-cert.pem'), 17 key: fixtures.readKey('agent1-key.pem'), 18 }).on('connection', common.mustCall(function() { 19 this.close(); 20 })).listen(0, '::1', common.mustCall(function() { 21 const options = { 22 host: 'localhost', 23 port: this.address().port, 24 family: 6, 25 rejectUnauthorized: false, 26 }; 27 // Will fail with ECONNREFUSED if the address family is not honored. 28 tls.connect(options).once('secureConnect', common.mustCall(function() { 29 assert.strictEqual(this.remoteAddress, '::1'); 30 this.destroy(); 31 })); 32 })); 33} 34 35dns.lookup('localhost', { 36 family: 6, all: true 37}, common.mustCall((err, addresses) => { 38 if (err) { 39 if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') 40 common.skip('localhost does not resolve to ::1'); 41 42 throw err; 43 } 44 45 if (addresses.some((val) => val.address === '::1')) 46 runTest(); 47 else 48 common.skip('localhost does not resolve to ::1'); 49})); 50