11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Test that the family option of https.get is honored. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciif (!common.hasCrypto) 71cb0ef41Sopenharmony_ci common.skip('missing crypto'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciif (!common.hasIPv6) 101cb0ef41Sopenharmony_ci common.skip('no IPv6 support'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst assert = require('assert'); 131cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 141cb0ef41Sopenharmony_ciconst https = require('https'); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci{ 171cb0ef41Sopenharmony_ci // Test that `https` machinery passes host name, and receives IP. 181cb0ef41Sopenharmony_ci const hostAddrIPv6 = '::1'; 191cb0ef41Sopenharmony_ci const HOSTNAME = 'dummy'; 201cb0ef41Sopenharmony_ci https.createServer({ 211cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem'), 221cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 231cb0ef41Sopenharmony_ci }, common.mustCall(function(req, res) { 241cb0ef41Sopenharmony_ci this.close(); 251cb0ef41Sopenharmony_ci res.end(); 261cb0ef41Sopenharmony_ci })).listen(0, hostAddrIPv6, common.mustCall(function() { 271cb0ef41Sopenharmony_ci const options = { 281cb0ef41Sopenharmony_ci host: HOSTNAME, 291cb0ef41Sopenharmony_ci port: this.address().port, 301cb0ef41Sopenharmony_ci family: 6, 311cb0ef41Sopenharmony_ci rejectUnauthorized: false, 321cb0ef41Sopenharmony_ci lookup: common.mustCall((addr, opt, cb) => { 331cb0ef41Sopenharmony_ci assert.strictEqual(addr, HOSTNAME); 341cb0ef41Sopenharmony_ci assert.strictEqual(opt.family, 6); 351cb0ef41Sopenharmony_ci cb(null, hostAddrIPv6, opt.family); 361cb0ef41Sopenharmony_ci }) 371cb0ef41Sopenharmony_ci }; 381cb0ef41Sopenharmony_ci // Will fail with ECONNREFUSED if the address family is not honored. 391cb0ef41Sopenharmony_ci https.get(options, common.mustCall(function() { 401cb0ef41Sopenharmony_ci assert.strictEqual(this.socket.remoteAddress, hostAddrIPv6); 411cb0ef41Sopenharmony_ci this.destroy(); 421cb0ef41Sopenharmony_ci })); 431cb0ef41Sopenharmony_ci })); 441cb0ef41Sopenharmony_ci} 45