11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciif (!common.hasIPv6) 71cb0ef41Sopenharmony_ci common.skip('no IPv6 support'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst assert = require('assert'); 101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 111cb0ef41Sopenharmony_ciconst tls = require('tls'); 121cb0ef41Sopenharmony_ciconst dns = require('dns'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cifunction runTest() { 151cb0ef41Sopenharmony_ci tls.createServer({ 161cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem'), 171cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 181cb0ef41Sopenharmony_ci }).on('connection', common.mustCall(function() { 191cb0ef41Sopenharmony_ci this.close(); 201cb0ef41Sopenharmony_ci })).listen(0, '::1', common.mustCall(function() { 211cb0ef41Sopenharmony_ci const options = { 221cb0ef41Sopenharmony_ci host: 'localhost', 231cb0ef41Sopenharmony_ci port: this.address().port, 241cb0ef41Sopenharmony_ci family: 6, 251cb0ef41Sopenharmony_ci rejectUnauthorized: false, 261cb0ef41Sopenharmony_ci }; 271cb0ef41Sopenharmony_ci // Will fail with ECONNREFUSED if the address family is not honored. 281cb0ef41Sopenharmony_ci tls.connect(options).once('secureConnect', common.mustCall(function() { 291cb0ef41Sopenharmony_ci assert.strictEqual(this.remoteAddress, '::1'); 301cb0ef41Sopenharmony_ci this.destroy(); 311cb0ef41Sopenharmony_ci })); 321cb0ef41Sopenharmony_ci })); 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cidns.lookup('localhost', { 361cb0ef41Sopenharmony_ci family: 6, all: true 371cb0ef41Sopenharmony_ci}, common.mustCall((err, addresses) => { 381cb0ef41Sopenharmony_ci if (err) { 391cb0ef41Sopenharmony_ci if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN') 401cb0ef41Sopenharmony_ci common.skip('localhost does not resolve to ::1'); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci throw err; 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci if (addresses.some((val) => val.address === '::1')) 461cb0ef41Sopenharmony_ci runTest(); 471cb0ef41Sopenharmony_ci else 481cb0ef41Sopenharmony_ci common.skip('localhost does not resolve to ::1'); 491cb0ef41Sopenharmony_ci})); 50