Skip to content

Commit

Permalink
https: add missing localPort while create socket
Browse files Browse the repository at this point in the history
In `_tls_wrap.js` while calling `socket.connect` the `localPort` was
missing, restore it.

PR-URL: #24554
Fixes: #24543
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
leeight authored and BridgeAR committed Mar 12, 2019
1 parent 83fba1e commit 4b6c653
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ exports.connect = function connect(...args) {
host: options.host,
family: options.family,
localAddress: options.localAddress,
localPort: options.localPort,
lookup: options.lookup
};

Expand Down
32 changes: 32 additions & 0 deletions test/parallel/test-https-connect-localport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');

if (!common.hasCrypto)
common.skip('missing crypto');

const https = require('https');
const assert = require('assert');

{
https.createServer({
cert: fixtures.readKey('agent1-cert.pem'),
key: fixtures.readKey('agent1-key.pem'),
}, common.mustCall(function(req, res) {
this.close();
res.end();
})).listen(0, common.localhostIPv4, common.mustCall(function() {
const port = this.address().port;
const req = https.get({
host: common.localhostIPv4,
pathname: '/',
port,
family: 4,
localPort: 34567,
rejectUnauthorized: false
}, common.mustCall(() => {
assert.strictEqual(req.socket.localPort, 34567);
assert.strictEqual(req.socket.remotePort, port);
}));
}));
}

0 comments on commit 4b6c653

Please sign in to comment.