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