mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
Defer reading until user-land has a chance to add listeners. This allows the TLS wrapper to listen for _tlsError and trigger a clientError event if the socket already has data that could trigger. Fixes: https://github.com/nodejs/io.js/issues/1114 PR-URL: https://github.com/nodejs/io.js/pull/1496 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
47 lines
1.0 KiB
JavaScript
47 lines
1.0 KiB
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
console.log('1..0 # Skipped: missing crypto');
|
|
process.exit();
|
|
}
|
|
var tls = require('tls');
|
|
var fs = require('fs');
|
|
var net = require('net');
|
|
|
|
var bonkers = new Buffer(1024);
|
|
bonkers.fill(42);
|
|
|
|
var receivedError = false;
|
|
var options = {
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
};
|
|
|
|
var server = net.createServer(function(c) {
|
|
setTimeout(function() {
|
|
var s = new tls.TLSSocket(c, {
|
|
isServer: true,
|
|
secureContext: tls.createSecureContext(options)
|
|
});
|
|
|
|
s.on('_tlsError', function() {
|
|
receivedError = true;
|
|
});
|
|
|
|
s.on('close', function() {
|
|
server.close();
|
|
s.destroy();
|
|
});
|
|
}, 200);
|
|
}).listen(common.PORT, function() {
|
|
var c = net.connect({port: common.PORT}, function() {
|
|
c.write(bonkers);
|
|
});
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.ok(receivedError);
|
|
});
|