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-auto.js
Ruben Bridgewater b08a867d60
benchmark,doc,lib: capitalize more comments
PR-URL: https://github.com/nodejs/node/pull/26849
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2019-03-27 17:20:06 +01:00

61 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
// This test ensures that the value "auto" on ecdhCurve option is
// supported to enable automatic curve selection in TLS server.
if (!common.hasCrypto)
common.skip('missing crypto');
if (!common.opensslCli)
common.skip('missing openssl-cli');
const assert = require('assert');
const tls = require('tls');
const spawn = require('child_process').spawn;
const fixtures = require('../common/fixtures');
function loadPEM(n) {
return fixtures.readKey(`${n}.pem`);
}
const options = {
key: loadPEM('agent2-key'),
cert: loadPEM('agent2-cert'),
ciphers: '-ALL:ECDHE-RSA-AES128-SHA256',
ecdhCurve: 'auto'
};
const reply = 'I AM THE WALRUS'; // Something recognizable
const server = tls.createServer(options, function(conn) {
conn.end(reply);
});
let gotReply = false;
server.listen(0, function() {
const args = ['s_client',
'-cipher', `${options.ciphers}`,
'-connect', `127.0.0.1:${this.address().port}`];
const client = spawn(common.opensslCli, args);
client.stdout.on('data', function(data) {
const message = data.toString();
if (message.includes(reply))
gotReply = true;
});
client.on('exit', function(code) {
assert.strictEqual(code, 0);
server.close();
});
client.on('error', assert.ifError);
});
process.on('exit', function() {
assert.ok(gotReply);
});