Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: make the https connect test more robust
Use common.skipIfNoIpv6Localhost
  • Loading branch information
joyeecheung committed Nov 12, 2017
commit c3c65402387ea512763f3f25f1475fc38d99fb6c
31 changes: 8 additions & 23 deletions test/parallel/test-https-connect-address-family.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
'use strict';

// This test that the family option of https.get is honored.

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

if (!common.hasIPv6)
common.skip('no IPv6 support');

const assert = require('assert');
const fixtures = require('../common/fixtures');
const https = require('https');
const dns = require('dns');
common.skipIfNoIpv6Localhost((ipv6Host) => {
const assert = require('assert');
const https = require('https');
const fixtures = require('../common/fixtures');

function runTest() {
https.createServer({
cert: fixtures.readKey('agent1-cert.pem'),
key: fixtures.readKey('agent1-key.pem'),
Expand All @@ -20,7 +19,7 @@ function runTest() {
res.end();
})).listen(0, '::1', common.mustCall(function() {
const options = {
host: 'localhost',
host: ipv6Host,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that // This test that the family option of https.get is honored. would it be correct to replace this with '::1' since this what the server bind to?

Copy link
Copy Markdown
Member Author

@joyeecheung joyeecheung Nov 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@refack I think replacing it with a ip would skip the family option handling altogether. The family option is used when performing a lookup, so if the connection doesn't even need to lookup then it won't be tested. In net.js:

  // If host is an IP, skip performing a lookup
  var addressType = cares.isIP(host);
  if (addressType) {
    nextTick(self[async_id_symbol], function() {
      if (self.connecting)
        internalConnect(self, host, port, addressType, localAddress, localPort);
    });
    return;
  }

....

  var dnsopts = {
    family: options.family,
    hints: options.hints || 0
  };

port: this.address().port,
family: 6,
rejectUnauthorized: false,
Expand All @@ -31,18 +30,4 @@ function runTest() {
this.destroy();
}));
}));
}

dns.lookup('localhost', { family: 6, all: true }, (err, addresses) => {
if (err) {
if (err.code === 'ENOTFOUND' || err.code === 'EAI_AGAIN')
common.skip('localhost does not resolve to ::1');

throw err;
}

if (addresses.some((val) => val.address === '::1'))
runTest();
else
common.skip('localhost does not resolve to ::1');
});