From a45f06651c651d972efee73c355b7fef04706e0b Mon Sep 17 00:00:00 2001 From: treysis Date: Sat, 27 Mar 2021 22:55:33 +0100 Subject: [PATCH] SmartOS fixes for the test suite Explanations: test/parallel/test-net-connect-options-port.js: add `family: 4` at various places to force `localhost` or default `localhost` to be resolved to legacy IPv4 addresses. test/parallel/test-net-pingpong.js: change `localhost` to `127.0.0.1` because test is aimed at legacy IPv4, so it can be forced to literal IPv4 address without problem. NEEDS TESTING: does `pingPongTest(0);` pass? test/parallel/test-net-remote-address-port.js: change `localhost` to `127.0.0.1` and force IPv4 by adding `family: 4` because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/parallel/test-net-writable.js: listen on `common.localhostIPv4` and add `family: 4` to connect to force IPv4. because SmartOS will resolve `localhost` or no address automatically to legacy IPv4 address (`127.0.0.1`). test/sequential/test-https-connect-localport.js: revert previous change, i.e. readd `family: 4` to `https.get`. Change `localhost` on listen to `common.localhostIPv4` to force legacy IPv4. --- .../parallel/test-net-connect-options-port.js | 36 ++++++++++++------- test/parallel/test-net-pingpong.js | 2 +- test/parallel/test-net-remote-address-port.js | 9 +++-- test/parallel/test-net-writable.js | 6 ++-- .../test-https-connect-localport.js | 4 +-- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/test/parallel/test-net-connect-options-port.js b/test/parallel/test-net-connect-options-port.js index 74e78240abb5ba..d018f29ededb0b 100644 --- a/test/parallel/test-net-connect-options-port.js +++ b/test/parallel/test-net-connect-options-port.js @@ -83,7 +83,7 @@ const net = require('net'); } }, expectedConnections)); - server.listen(0, 'localhost', common.mustCall(() => { + server.listen(0, common.localhostIPv4, common.mustCall(() => { const port = server.address().port; // Total connections = 3 * 4(canConnect) * 6(doConnect) = 72 @@ -133,28 +133,35 @@ function doConnect(args, getCb) { } function syncFailToConnect(port, assertErr, optOnly) { + const family = 4; if (!optOnly) { // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], () => common.mustNotCall()); + const portArgFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port})`); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], + const portHostArgFunctions = doConnect([{ port, + host: 'localhost', + family }], () => common.mustNotCall()); for (const fn of portHostArgFunctions) { assert.throws(fn, assertErr, `${fn.name}(${port}, 'localhost')`); } } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], () => common.mustNotCall()); + const portOptFunctions = doConnect([{ port, family }], + () => common.mustNotCall()); for (const fn of portOptFunctions) { assert.throws(fn, assertErr, `${fn.name}({port: ${port}})`); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFunctions = doConnect([{ port: port, host: 'localhost' }], + const portHostOptFunctions = doConnect([{ port: port, + host: 'localhost', + family }], () => common.mustNotCall()); for (const fn of portHostOptFunctions) { assert.throws(fn, @@ -165,27 +172,30 @@ function syncFailToConnect(port, assertErr, optOnly) { function canConnect(port) { const noop = () => common.mustCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], noop); + const portArgFunctions = doConnect([{ port, family }], noop); for (const fn of portArgFunctions) { fn(); } // connect(port, host, cb) and connect(port, host) - const portHostArgFunctions = doConnect([port, 'localhost'], noop); + const portHostArgFunctions = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostArgFunctions) { fn(); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], noop); + const portOptFunctions = doConnect([{ port, family }], noop); for (const fn of portOptFunctions) { fn(); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], noop); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + noop); for (const fn of portHostOptFns) { fn(); } @@ -198,20 +208,22 @@ function asyncFailToConnect(port) { }); const dont = () => common.mustNotCall(); + const family = 4; // connect(port, cb) and connect(port) - const portArgFunctions = doConnect([port], dont); + const portArgFunctions = doConnect([{ port, family }], dont); for (const fn of portArgFunctions) { fn().on('error', onError()); } // connect({port}, cb) and connect({port}) - const portOptFunctions = doConnect([{ port }], dont); + const portOptFunctions = doConnect([{ port, family }], dont); for (const fn of portOptFunctions) { fn().on('error', onError()); } // connect({port, host}, cb) and connect({port, host}) - const portHostOptFns = doConnect([{ port, host: 'localhost' }], dont); + const portHostOptFns = doConnect([{ port, host: 'localhost', family }], + dont); for (const fn of portHostOptFns) { fn().on('error', onError()); } diff --git a/test/parallel/test-net-pingpong.js b/test/parallel/test-net-pingpong.js index 7fb6678fe1a897..b1fd2290d0f100 100644 --- a/test/parallel/test-net-pingpong.js +++ b/test/parallel/test-net-pingpong.js @@ -130,6 +130,6 @@ const tmpdir = require('../common/tmpdir'); tmpdir.refresh(); pingPongTest(common.PIPE); pingPongTest(0); -pingPongTest(0, 'localhost'); +pingPongTest(0, '127.0.0.1'); if (common.hasIPv6) pingPongTest(0, '::1'); diff --git a/test/parallel/test-net-remote-address-port.js b/test/parallel/test-net-remote-address-port.js index cc14d0c951167d..324c82b654aa44 100644 --- a/test/parallel/test-net-remote-address-port.js +++ b/test/parallel/test-net-remote-address-port.js @@ -48,9 +48,12 @@ const server = net.createServer(common.mustCall(function(socket) { socket.resume(); }, 2)); -server.listen(0, 'localhost', function() { - const client = net.createConnection(this.address().port, 'localhost'); - const client2 = net.createConnection(this.address().port); +server.listen(0, '127.0.0.1', function() { + const client = net.createConnection({ port: this.address().port, + host: 'localhost', + family: 4 }); + const client2 = net.createConnection({ port: this.address().port, + family: 4 }); client.on('connect', function() { assert.ok(remoteAddrCandidates.includes(client.remoteAddress)); assert.ok(remoteFamilyCandidates.includes(client.remoteFamily)); diff --git a/test/parallel/test-net-writable.js b/test/parallel/test-net-writable.js index dcbb64e272b830..5ed5e6b8e915c7 100644 --- a/test/parallel/test-net-writable.js +++ b/test/parallel/test-net-writable.js @@ -6,8 +6,10 @@ const net = require('net'); const server = net.createServer(common.mustCall(function(s) { server.close(); s.end(); -})).listen(0, 'localhost', common.mustCall(function() { - const socket = net.connect(this.address().port, 'localhost'); +})).listen(0, common.localhostIPv4, common.mustCall(function() { + const socket = net.connect({ port: this.address().port, + host: 'localhost', + family: 4 }); socket.on('end', common.mustCall(() => { assert.strictEqual(socket.writable, true); socket.write('hello world'); diff --git a/test/sequential/test-https-connect-localport.js b/test/sequential/test-https-connect-localport.js index ac82d5210066a4..6e3e451ee8136e 100644 --- a/test/sequential/test-https-connect-localport.js +++ b/test/sequential/test-https-connect-localport.js @@ -17,13 +17,13 @@ const assert = require('assert'); res.end(); })); - server.listen(0, 'localhost', common.mustCall(() => { + server.listen(0, common.localhostIPv4, common.mustCall(() => { const port = server.address().port; const req = https.get({ host: 'localhost', pathname: '/', port, - // family: 4, + family: 4, localPort: common.PORT, rejectUnauthorized: false, }, common.mustCall(() => {