mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
PR-URL: https://github.com/nodejs/node/pull/15821 Reviewed-By: Ryan Graham <r.m.graham@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
65 lines
1.6 KiB
JavaScript
65 lines
1.6 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const net = require('net');
|
|
|
|
const options = {
|
|
key: fixtures.readSync('test_key.pem'),
|
|
cert: fixtures.readSync('test_cert.pem')
|
|
};
|
|
|
|
const server = tls.createServer(options, common.mustCall((socket) => {
|
|
socket.end('Hello');
|
|
}, 2)).listen(0, common.mustCall(() => {
|
|
let waiting = 2;
|
|
function establish(socket, calls) {
|
|
const client = tls.connect({
|
|
rejectUnauthorized: false,
|
|
socket: socket
|
|
}, common.mustCall(() => {
|
|
let data = '';
|
|
client.on('data', common.mustCall((chunk) => {
|
|
data += chunk.toString();
|
|
}));
|
|
client.on('end', common.mustCall(() => {
|
|
assert.strictEqual(data, 'Hello');
|
|
if (--waiting === 0)
|
|
server.close();
|
|
}));
|
|
}, calls));
|
|
assert(client.readable);
|
|
assert(client.writable);
|
|
|
|
return client;
|
|
}
|
|
|
|
const { port } = server.address();
|
|
|
|
// Immediate death socket
|
|
const immediateDeath = net.connect(port);
|
|
establish(immediateDeath, 0).destroy();
|
|
|
|
// Outliving
|
|
const outlivingTCP = net.connect(port, common.mustCall(() => {
|
|
outlivingTLS.destroy();
|
|
next();
|
|
}));
|
|
const outlivingTLS = establish(outlivingTCP, 0);
|
|
|
|
function next() {
|
|
// Already connected socket
|
|
const connected = net.connect(port, common.mustCall(() => {
|
|
establish(connected);
|
|
}));
|
|
|
|
// Connecting socket
|
|
const connecting = net.connect(port);
|
|
establish(connecting);
|
|
}
|
|
}));
|