Skip to content

Commit

Permalink
test: add tls.connect js stream write test
Browse files Browse the repository at this point in the history
  • Loading branch information
mscdex committed May 3, 2015
1 parent 2a3a190 commit b6d5bc9
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/parallel/test-tls-connect-stream-writes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var fs = require('fs'),
path = require('path'),
tls = require('tls'),
stream = require('stream'),
net = require('net');

var common = require('../common.js');

var server;
var cert_dir = path.resolve(__dirname, '../fixtures'),
options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ],
ciphers: 'AES256-GCM-SHA384' };

server = tls.createServer(options);
server.listen(common.PORT, function() {
var raw = net.connect(common.PORT);

var pending = false;
raw.on('readable', function() {
if (pending)
p._read();
});

var p = new stream.Duplex({
read: function read() {
pending = false;

var chunk = raw.read();
if (chunk) {
this.push(chunk);
} else {
pending = true;
}
},
write: function write(data, enc, cb) {
raw.write(data, enc, cb);
}
});

var socket = tls.connect({
socket: p,
rejectUnauthorized: false
}, function() {
for (var i = 0; i < 50; ++i)
socket.write('hello world');
socket.end();
});
});

0 comments on commit b6d5bc9

Please sign in to comment.