mirror of
https://github.com/nodejs/node.git
synced 2025-05-14 23:19:09 +00:00

Lots of changes, but mostly just search/replace of fixtures.readSync(...) to fixtures.readKey([new key]...) Benchmarks modified to use fixtures.readKey(...): benchmark/tls/throughput.js benchmark/tls/tls-connect.js benchmark/tls/secure-pair.js Also be sure to review the change to L16 of test/parallel/test-crypto-sign-verify.js PR-URL: https://github.com/nodejs/node/pull/27962 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
// This tests that both tls and net will ignore host and port if path is
|
|
// provided.
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
tmpdir.refresh();
|
|
|
|
const tls = require('tls');
|
|
const net = require('net');
|
|
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: fixtures.readKey('rsa_cert.crt'),
|
|
key: fixtures.readKey('rsa_private.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())));
|