@@ -5,28 +5,41 @@ if (!common.hasCrypto) {
5
5
return ;
6
6
}
7
7
8
- const assert = require ( 'assert' ) ;
9
- const tls = require ( 'tls' ) ;
10
-
11
8
if ( ! common . hasIPv6 ) {
12
9
common . skip ( 'no IPv6 support' ) ;
13
10
return ;
14
11
}
15
12
16
- const ciphers = 'AECDH-NULL-SHA' ;
17
- tls . createServer ( { ciphers } , function ( ) {
18
- this . close ( ) ;
19
- } ) . listen ( common . PORT , '::1' , function ( ) {
20
- const options = {
21
- host : 'localhost' ,
22
- port : common . PORT ,
23
- family : 6 ,
24
- ciphers : ciphers ,
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 ( '::1' , this . remoteAddress ) ;
30
- this . destroy ( ) ;
13
+ const assert = require ( 'assert' ) ;
14
+ const tls = require ( 'tls' ) ;
15
+ const dns = require ( 'dns' ) ;
16
+
17
+ function runTest ( ) {
18
+ const ciphers = 'AECDH-NULL-SHA' ;
19
+ tls . createServer ( { ciphers } , common . mustCall ( function ( ) {
20
+ this . close ( ) ;
21
+ } ) ) . listen ( common . PORT , '::1' , common . mustCall ( function ( ) {
22
+ const options = {
23
+ host : 'localhost' ,
24
+ port : common . PORT ,
25
+ family : 6 ,
26
+ ciphers : ciphers ,
27
+ rejectUnauthorized : false ,
28
+ } ;
29
+ // Will fail with ECONNREFUSED if the address family is not honored.
30
+ tls . connect ( options ) . once ( 'secureConnect' , common . mustCall ( function ( ) {
31
+ assert . strictEqual ( '::1' , this . remoteAddress ) ;
32
+ this . destroy ( ) ;
33
+ } ) ) ;
31
34
} ) ) ;
35
+ }
36
+
37
+ dns . lookup ( 'localhost' , { family : 6 , all : true } , ( err , addresses ) => {
38
+ if ( err )
39
+ throw err ;
40
+
41
+ if ( addresses . some ( ( val ) => { return val . address === '::1' ; } ) )
42
+ runTest ( ) ;
43
+ else
44
+ common . skip ( 'localhost does not resolve to ::1' ) ;
32
45
} ) ;
0 commit comments