0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/parallel/test-tls-client-destroy-soon.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

55 lines
1.2 KiB
JavaScript

// Create an ssl server. First connection, validate that not resume.
// Cache session and close connection. Use session on second connection.
// ASSERT resumption.
if (!process.versions.openssl) {
console.error('Skipping because node compiled without OpenSSL.');
process.exit(0);
}
var common = require('../common');
var assert = require('assert');
var tls = require('tls');
var fs = require('fs');
var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem')
};
var big = new Buffer(2 * 1024 * 1024);
var connections = 0;
var bytesRead = 0;
big.fill('Y');
// create server
var server = tls.createServer(options, function(socket) {
socket.end(big);
socket.destroySoon();
connections++;
});
// start listening
server.listen(common.PORT, function() {
var client = tls.connect({
port: common.PORT,
rejectUnauthorized: false
}, function() {
client.on('readable', function() {
var d = client.read();
if (d)
bytesRead += d.length;
});
client.on('end', function() {
server.close();
});
});
});
process.on('exit', function() {
assert.equal(1, connections);
assert.equal(big.length, bytesRead);
});