diff options
author | Bryan English <bryan@bryanenglish.com> | 2017-07-31 23:58:39 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-09-25 11:21:38 -0700 |
commit | ee157e5a7ffc81ba6be588460a8fba6a89528413 (patch) | |
tree | 899cb2aad9683d92073eb1d85a949db7f4f6b103 /test/parallel/test-tls-net-connect-prefer-path.js | |
parent | 1fbb86c64be7016bdde7f3ed3d6a2885baac9897 (diff) | |
download | node-new-ee157e5a7ffc81ba6be588460a8fba6a89528413.tar.gz |
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: https://github.com/nodejs/node/pull/14564
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-tls-net-connect-prefer-path.js')
-rw-r--r-- | test/parallel/test-tls-net-connect-prefer-path.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/parallel/test-tls-net-connect-prefer-path.js b/test/parallel/test-tls-net-connect-prefer-path.js new file mode 100644 index 0000000000..10f00b4eb2 --- /dev/null +++ b/test/parallel/test-tls-net-connect-prefer-path.js @@ -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()))); |