node/test/parallel/test-tls-no-rsa-key.js
Santiago Gimeno 61fe86b560 test: fix tls-no-rsa-key flakiness
In some conditions it can happen that the client-side socket is destroyed
before the server-side socket has gracefully closed, thus causing a
'ECONNRESET' error in this socket. To solve this, wait in the client-side
socket for the 'end' event before closing it.

PR-URL: https://github.com/nodejs/node/pull/4043
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-02 09:19:11 -08:00

43 lines
887 B
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
return;
}
var tls = require('tls');
var fs = require('fs');
var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/ec-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/ec-cert.pem')
};
var cert = null;
var server = tls.createServer(options, function(conn) {
conn.end('ok');
}).listen(common.PORT, function() {
var c = tls.connect(common.PORT, {
rejectUnauthorized: false
}, function() {
c.on('end', common.mustCall(function() {
c.end();
server.close();
}));
c.on('data', function(data) {
assert.equal(data, 'ok');
});
cert = c.getPeerCertificate();
});
});
process.on('exit', function() {
assert(cert);
assert.equal(cert.subject.C, 'US');
});