0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-tls-no-sslv3.js
cjihrig 7dd82dd1c3 test: add common.mustNotCall()
This commit adds a mustNotCall() helper for testing. This provides
an alternative to using common.fail() as a callback, or creating
a callback function for the sole purpose of calling common.fail().

PR-URL: https://github.com/nodejs/node/pull/11152
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-02-06 14:07:55 -05:00

57 lines
1.6 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
const tls = require('tls');
const fs = require('fs');
const spawn = require('child_process').spawn;
if (common.opensslCli === false) {
common.skip('node compiled without OpenSSL CLI.');
return;
}
const cert = fs.readFileSync(common.fixturesDir + '/test_cert.pem');
const key = fs.readFileSync(common.fixturesDir + '/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.skip('`openssl s_client -ssl3` not supported.');
} else {
assert.strictEqual(errors.length, 1);
assert(/:wrong version number/.test(errors[0].message));
}
});