-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: prefer path over port in connect
Makes tls.connect() behave as documented, preferring options.path over options.port. This makes it consistent with net.connect(), so the included test demonstrates that both behave in this way. Also, for consistency, noting the precedence of options.path in net doc. PR-URL: #14564 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
Showing
3 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// This tests that both tls and net will ignore host and port if path is | ||
// provided. | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
const tls = require('tls'); | ||
const net = require('net'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
|
||
function libName(lib) { | ||
return lib === net ? 'net' : 'tls'; | ||
} | ||
|
||
function mkServer(lib, tcp, cb) { | ||
const handler = (socket) => { | ||
socket.write(`${libName(lib)}:${ | ||
server.address().port || server.address() | ||
}`); | ||
socket.end(); | ||
}; | ||
const args = [handler]; | ||
if (lib === tls) { | ||
args.unshift({ | ||
cert: fs.readFileSync(`${common.fixturesDir}/test_cert.pem`), | ||
key: fs.readFileSync(`${common.fixturesDir}/test_key.pem`) | ||
}); | ||
} | ||
const server = lib.createServer(...args); | ||
server.listen(tcp ? 0 : common.PIPE, common.mustCall(() => cb(server))); | ||
} | ||
|
||
function testLib(lib, cb) { | ||
mkServer(lib, true, (tcpServer) => { | ||
mkServer(lib, false, (unixServer) => { | ||
const client = lib.connect({ | ||
path: unixServer.address(), | ||
port: tcpServer.address().port, | ||
host: 'localhost', | ||
rejectUnauthorized: false | ||
}, () => { | ||
const bufs = []; | ||
client.on('data', common.mustCall((d) => { | ||
bufs.push(d); | ||
})); | ||
client.on('end', common.mustCall(() => { | ||
const resp = Buffer.concat(bufs).toString(); | ||
assert.strictEqual(`${libName(lib)}:${unixServer.address()}`, resp); | ||
tcpServer.close(); | ||
unixServer.close(); | ||
cb(); | ||
})); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
testLib(net, common.mustCall(() => testLib(tls, common.mustCall()))); |