tls: do not wrap net.Socket with StreamWrap

Fixes: https://github.com/nodejs/node/issues/3655
PR-URL: https://github.com/nodejs/node/pull/12799
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
This commit is contained in:
Ruslan Bekenev 2017-05-02 20:36:50 +03:00 committed by Anna Henningsen
parent ef16319eff
commit b23d414c7e
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
2 changed files with 19 additions and 6 deletions

View File

@ -31,7 +31,6 @@ const util = require('util');
const common = require('_tls_common');
const StreamWrap = require('_stream_wrap').StreamWrap;
const Buffer = require('buffer').Buffer;
const Duplex = require('stream').Duplex;
const debug = util.debuglog('tls');
const Timer = process.binding('timer_wrap').Timer;
const tls_wrap = process.binding('tls_wrap');
@ -275,12 +274,10 @@ function TLSSocket(socket, options) {
// Wrap plain JS Stream into StreamWrap
var wrap;
if (!(socket instanceof net.Socket) && socket instanceof Duplex)
wrap = new StreamWrap(socket);
else if ((socket instanceof net.Socket) && !socket._handle)
wrap = new StreamWrap(socket);
else
if ((socket instanceof net.Socket && socket._handle) || !socket)
wrap = socket;
else
wrap = new StreamWrap(socket);
// Just a documented property to make secure sockets
// distinguishable from regular ones.

View File

@ -0,0 +1,16 @@
'use strict';
/*
* Issue: https://github.com/nodejs/node/issues/3655
* Test checks if we get exception instead of runtime error
*/
require('../common');
const assert = require('assert');
const TlsSocket = require('tls').TLSSocket;
const EventEmitter = require('events').EventEmitter;
assert.throws(
() => { new TlsSocket(new EventEmitter()); },
/^TypeError: this\.stream\.pause is not a function/
);