mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.7 KiB
65 lines
1.7 KiB
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const net = require('net');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const options = {
|
|
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
|
|
cert: fs.readFileSync(path.join(common.fixturesDir, '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);
|
|
}
|
|
}));
|
|
|