2017-01-03 22:16:48 +01:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2017-10-06 18:32:08 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2017-07-01 01:29:09 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
const tls = require('tls');
|
2013-02-12 00:46:19 +01:00
|
|
|
|
2019-05-29 20:43:44 +02:00
|
|
|
const options = { key: fixtures.readKey('rsa_private.pem'),
|
|
|
|
cert: fixtures.readKey('rsa_cert.crt'),
|
|
|
|
ca: [ fixtures.readKey('rsa_ca.crt') ] };
|
2013-02-12 00:46:19 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = tls.createServer(options, onconnection);
|
|
|
|
let gotChunk = false;
|
|
|
|
let gotDrain = false;
|
2013-02-12 00:46:19 +01:00
|
|
|
|
|
|
|
function onconnection(conn) {
|
|
|
|
conn.on('data', function(c) {
|
|
|
|
if (!gotChunk) {
|
|
|
|
gotChunk = true;
|
|
|
|
console.log('ok - got chunk');
|
|
|
|
}
|
|
|
|
|
2019-03-07 01:03:53 +01:00
|
|
|
// Just some basic sanity checks.
|
2013-02-12 00:46:19 +01:00
|
|
|
assert(c.length);
|
|
|
|
assert(Buffer.isBuffer(c));
|
|
|
|
|
|
|
|
if (gotDrain)
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-29 09:06:56 +02:00
|
|
|
server.listen(0, function() {
|
2017-01-08 14:19:00 +01:00
|
|
|
const chunk = Buffer.alloc(1024, 'x');
|
|
|
|
const opt = { port: this.address().port, rejectUnauthorized: false };
|
|
|
|
const conn = tls.connect(opt, function() {
|
2013-02-12 00:46:19 +01:00
|
|
|
conn.on('drain', ondrain);
|
|
|
|
write();
|
|
|
|
});
|
|
|
|
function ondrain() {
|
|
|
|
if (!gotDrain) {
|
|
|
|
gotDrain = true;
|
|
|
|
console.log('ok - got drain');
|
|
|
|
}
|
|
|
|
if (gotChunk)
|
|
|
|
process.exit(0);
|
|
|
|
write();
|
|
|
|
}
|
2019-11-28 07:56:21 +01:00
|
|
|
|
2013-02-12 00:46:19 +01:00
|
|
|
function write() {
|
2019-03-07 01:03:53 +01:00
|
|
|
// This needs to return false eventually
|
2013-02-12 00:46:19 +01:00
|
|
|
while (false !== conn.write(chunk));
|
|
|
|
}
|
|
|
|
});
|