@@ -5,29 +5,50 @@ if (!common.hasCrypto) {
55 return ;
66}
77
8- const assert = require ( 'assert' ) ;
9- const https = require ( 'https' ) ;
10-
118if ( ! common . hasIPv6 ) {
129 common . skip ( 'no IPv6 support' ) ;
1310 return ;
1411}
1512
16- const ciphers = 'AECDH-NULL-SHA' ;
17- https . createServer ( { ciphers } , function ( req , res ) {
18- this . close ( ) ;
19- res . end ( ) ;
20- } ) . listen ( common . PORT , '::1' , function ( ) {
21- const options = {
22- host : 'localhost' ,
23- port : common . PORT ,
24- family : 6 ,
25- ciphers : ciphers ,
26- rejectUnauthorized : false ,
27- } ;
28- // Will fail with ECONNREFUSED if the address family is not honored.
29- https . get ( options , common . mustCall ( function ( ) {
30- assert . strictEqual ( '::1' , this . socket . remoteAddress ) ;
31- this . destroy ( ) ;
13+ const assert = require ( 'assert' ) ;
14+ const https = require ( 'https' ) ;
15+ const dns = require ( 'dns' ) ;
16+
17+ // In a more perfect world, we could just use `localhost` for the host.
18+ // Alas, we live in a world where some distributions do not map localhost
19+ // to ::1 by default. See https://github.com/nodejs/node/issues/7288
20+
21+ var index = 0 ;
22+ checkForLocalhost ( common . localIPv6Hosts [ index ] ) ;
23+
24+ function checkForLocalhost ( host ) {
25+ dns . lookup ( host , 6 , ( err , address ) => {
26+ if ( ! err )
27+ return runTest ( host ) ;
28+ index = index + 1 ;
29+ if ( index < common . localIPv6Hosts . length )
30+ return checkForLocalhost ( common . localIPv6Hosts [ index ] ) ;
31+ common . fail ( 'Could not find an IPv6 host for ::1' ) ;
32+ } ) ;
33+ }
34+
35+ const runTest = common . mustCall ( function runTest ( host ) {
36+ const ciphers = 'AECDH-NULL-SHA' ;
37+ https . createServer ( { ciphers } , common . mustCall ( function ( req , res ) {
38+ this . close ( ) ;
39+ res . end ( ) ;
40+ } ) ) . listen ( common . PORT , '::1' , common . mustCall ( function ( ) {
41+ const options = {
42+ host,
43+ port : common . PORT ,
44+ family : 6 ,
45+ ciphers,
46+ rejectUnauthorized : false ,
47+ } ;
48+ // Will fail with ECONNREFUSED if the address family is not honored.
49+ https . get ( options , common . mustCall ( common . mustCall ( function ( ) {
50+ assert . strictEqual ( '::1' , this . socket . remoteAddress ) ;
51+ this . destroy ( ) ;
52+ } ) ) ) ;
3253 } ) ) ;
3354} ) ;
0 commit comments