0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-tls-socket-destroy.js
Anna Henningsen 7c4b09b24b
src: refactor stream callbacks and ownership
Instead of setting individual callbacks on streams and tracking
stream ownership through a boolean `consume_` flag, always have
one specific listener object in charge of a stream, and call
methods on that object rather than generic C-style callbacks.

PR-URL: https://github.com/nodejs/node/pull/18334
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-02-01 10:53:26 +01:00

37 lines
1012 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const net = require('net');
const tls = require('tls');
const fixtures = require('../common/fixtures');
const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');
const secureContext = tls.createSecureContext({ key, cert });
const server = net.createServer(common.mustCall((conn) => {
const options = { isServer: true, secureContext, server };
const socket = new tls.TLSSocket(conn, options);
socket.once('data', common.mustCall(() => {
socket._destroySSL(); // Should not crash.
socket.destroy();
server.close();
}));
}));
server.listen(0, function() {
const options = {
port: this.address().port,
rejectUnauthorized: false,
};
tls.connect(options, function() {
this.write('*'.repeat(1 << 20)); // Write more data than fits in a frame.
this.on('error', this.destroy); // Server closes connection on us.
});
});