2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-01-18 18:03:55 -08:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2015-03-04 12:11:21 +11:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
|
|
|
console.log('1..0 # Skipped: missing crypto');
|
2015-07-07 20:55:55 +05:30
|
|
|
return;
|
2015-03-04 12:11:21 +11:00
|
|
|
}
|
2011-01-18 18:03:55 -08:00
|
|
|
var tls = require('tls');
|
2015-03-04 12:11:21 +11:00
|
|
|
|
2011-01-18 18:03:55 -08:00
|
|
|
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 connections = 0;
|
2011-10-04 18:08:18 -04:00
|
|
|
var message = 'hello world\n';
|
2011-01-18 18:03:55 -08:00
|
|
|
|
|
|
|
|
|
|
|
var server = tls.Server(options, function(socket) {
|
|
|
|
socket.end(message);
|
|
|
|
connections++;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
server.listen(common.PORT, function() {
|
2012-08-30 16:43:20 +02:00
|
|
|
var client = tls.connect({
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
});
|
2011-01-18 18:03:55 -08:00
|
|
|
|
|
|
|
var buffer = '';
|
|
|
|
|
|
|
|
client.setEncoding('utf8');
|
|
|
|
|
|
|
|
client.on('data', function(d) {
|
|
|
|
assert.ok(typeof d === 'string');
|
|
|
|
buffer += d;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
client.on('close', function() {
|
2011-05-20 10:08:08 -07:00
|
|
|
// readyState is deprecated but we want to make
|
|
|
|
// sure this isn't triggering an assert in lib/net.js
|
|
|
|
// See issue #1069.
|
|
|
|
assert.equal('closed', client.readyState);
|
|
|
|
|
2011-01-18 18:03:55 -08:00
|
|
|
assert.equal(buffer, message);
|
|
|
|
console.log(message);
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(1, connections);
|
|
|
|
});
|