2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2013-03-15 19:49:31 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|
2013-03-15 19:49:31 +01:00
|
|
|
var tls = require('tls');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2013-03-15 19:49:31 +01:00
|
|
|
var fs = require('fs');
|
|
|
|
var stream = require('stream');
|
|
|
|
var util = require('util');
|
|
|
|
|
2016-01-26 00:00:06 +01:00
|
|
|
var request = Buffer.from(new Array(1024 * 256).join('ABCD')); // 1mb
|
2013-03-15 19:49:31 +01:00
|
|
|
|
|
|
|
var options = {
|
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
|
|
};
|
|
|
|
|
|
|
|
function Mediator() {
|
|
|
|
stream.Writable.call(this);
|
|
|
|
this.buf = '';
|
2016-01-15 09:53:11 +01:00
|
|
|
}
|
2013-03-15 19:49:31 +01:00
|
|
|
util.inherits(Mediator, stream.Writable);
|
|
|
|
|
2016-10-16 00:02:43 +02:00
|
|
|
Mediator.prototype._write = function _write(data, enc, cb) {
|
2013-03-15 19:49:31 +01:00
|
|
|
this.buf += data;
|
|
|
|
setTimeout(cb, 0);
|
|
|
|
|
|
|
|
if (this.buf.length >= request.length) {
|
|
|
|
assert.equal(this.buf, request.toString());
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var mediator = new Mediator();
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
var server = tls.Server(options, common.mustCall(function(socket) {
|
2013-03-15 19:49:31 +01:00
|
|
|
socket.pipe(mediator);
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
2013-03-15 19:49:31 +01:00
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
server.listen(common.PORT, common.mustCall(function() {
|
2013-03-15 19:49:31 +01:00
|
|
|
var client1 = tls.connect({
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: false
|
2016-07-15 21:43:24 +02:00
|
|
|
}, common.mustCall(function() {
|
2013-03-15 19:49:31 +01:00
|
|
|
client1.end(request);
|
2016-07-15 21:43:24 +02:00
|
|
|
}));
|
|
|
|
}));
|