node/test/parallel/test-tls-no-sslv3.js
David Benjamin ffb8f031a4 test: update test expectations for OpenSSL 1.1.0
Some errors in the two versions are different. The test-tls-no-sslv3 one
because OpenSSL 1.1.x finally does version negotiation properly. 1.0.x's
logic was somewhat weird and resulted in very inconsistent errors for
SSLv3 in particular.

Also the function codes are capitalized differently, but function codes
leak implementation details, so don't assert on them to begin with.

PR-URL: https://github.com/nodejs/node/pull/16130
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rod Vagg <rod@vagg.org>
2017-11-11 20:42:49 +11:00

54 lines
1.7 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
if (common.opensslCli === false)
common.skip('node compiled without OpenSSL CLI.');
const assert = require('assert');
const tls = require('tls');
const spawn = require('child_process').spawn;
const fixtures = require('../common/fixtures');
const cert = fixtures.readSync('test_cert.pem');
const key = fixtures.readSync('test_key.pem');
const server = tls.createServer({ cert: cert, key: key }, common.mustNotCall());
const errors = [];
let stderr = '';
server.listen(0, '127.0.0.1', function() {
const address = `${this.address().address}:${this.address().port}`;
const args = ['s_client',
'-ssl3',
'-connect', address];
// for the performance and stability issue in s_client on Windows
if (common.isWindows)
args.push('-no_rand_screen');
const client = spawn(common.opensslCli, args, { stdio: 'pipe' });
client.stdout.pipe(process.stdout);
client.stderr.pipe(process.stderr);
client.stderr.setEncoding('utf8');
client.stderr.on('data', (data) => stderr += data);
client.once('exit', common.mustCall(function(exitCode) {
assert.strictEqual(exitCode, 1);
server.close();
}));
});
server.on('tlsClientError', (err) => errors.push(err));
process.on('exit', function() {
if (/unknown option -ssl3/.test(stderr)) {
common.printSkipMessage('`openssl s_client -ssl3` not supported.');
} else {
assert.strictEqual(errors.length, 1);
// OpenSSL 1.0.x and 1.1.x report invalid client versions differently.
assert(/:wrong version number/.test(errors[0].message) ||
/:version too low/.test(errors[0].message));
}
});