mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 21:35:34 +00:00

Accept `new net.Socket()` as a `socket` option to `tls.connect()` without triggering an assertion error in C++. This is done by wrapping it into a JSStream to ensure that there will be a handle at the time of wrapping the socket into TLSSocket. Fix: https://github.com/iojs/io.js/issues/987 PR-URL: https://github.com/iojs/io.js/pull/1046 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <rod@vagg.org>
42 lines
901 B
JavaScript
42 lines
901 B
JavaScript
if (!process.versions.openssl) {
|
|
console.error('Skipping because node compiled without OpenSSL.');
|
|
process.exit(0);
|
|
}
|
|
|
|
var assert = require('assert');
|
|
var fs = require('fs');
|
|
var net = require('net');
|
|
var tls = require('tls');
|
|
|
|
var common = require('../common');
|
|
|
|
var out = '';
|
|
|
|
var server = tls.createServer({
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
}, function(c) {
|
|
c.end('hello');
|
|
}).listen(common.PORT, function() {
|
|
var socket = new net.Socket();
|
|
|
|
var s = tls.connect({
|
|
socket: socket,
|
|
rejectUnauthorized: false
|
|
}, function() {
|
|
s.on('data', function(chunk) {
|
|
out += chunk;
|
|
});
|
|
s.on('end', function() {
|
|
s.destroy();
|
|
server.close();
|
|
});
|
|
});
|
|
|
|
socket.connect(common.PORT);
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
assert.equal(out, 'hello');
|
|
});
|