0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-tls-ecdh.js
Sota Yamashita 5ffb7d72bb test: skip when openssl CLI doesn't exist
PR-URL: https://github.com/nodejs/node/pull/11095
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-02-13 13:51:21 -08:00

47 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
if (!common.opensslCli) {
common.skip('missing openssl-cli');
return;
}
const assert = require('assert');
const tls = require('tls');
const exec = require('child_process').exec;
const fs = require('fs');
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent2-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent2-cert.pem'),
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
ecdhCurve: 'prime256v1'
};
const reply = 'I AM THE WALRUS'; // something recognizable
const server = tls.createServer(options, common.mustCall(function(conn) {
conn.end(reply);
}));
server.listen(0, '127.0.0.1', common.mustCall(function() {
let cmd = '"' + common.opensslCli + '" s_client -cipher ' + options.ciphers +
` -connect 127.0.0.1:${this.address().port}`;
// for the performance and stability issue in s_client on Windows
if (common.isWindows)
cmd += ' -no_rand_screen';
exec(cmd, common.mustCall(function(err, stdout, stderr) {
assert.ifError(err);
assert(stdout.includes(reply));
server.close();
}));
}));