Skip to content

Commit

Permalink
test: simplify test-tls-ecdh-multiple
Browse files Browse the repository at this point in the history
Avoid the process 'exit' event handler and use execFile instead of
manual stream operations.

Refs: #46751
PR-URL: #46963
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
  • Loading branch information
tniessen committed Mar 9, 2023
1 parent 539dcee commit bcebb91
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions test/parallel/test-tls-ecdh-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (!common.opensslCli)

const assert = require('assert');
const tls = require('tls');
const spawn = require('child_process').spawn;
const { execFile } = require('child_process');
const fixtures = require('../common/fixtures');

function loadPEM(n) {
Expand All @@ -29,49 +29,33 @@ const options = {

const reply = 'I AM THE WALRUS'; // Something recognizable

const server = tls.createServer(options, function(conn) {
const server = tls.createServer(options, (conn) => {
conn.end(reply);
});

let gotReply = false;

server.listen(0, function() {
}).listen(0, common.mustCall(() => {
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;
});
'-connect', `127.0.0.1:${server.address().port}`];

client.on('exit', function(code) {
assert.strictEqual(code, 0);
execFile(common.opensslCli, args, common.mustSucceed((stdout) => {
assert(stdout.includes(reply));
server.close();
});

client.on('error', assert.ifError);
});
}));
}));

process.on('exit', function() {
assert.ok(gotReply);

// Some of unsupported curves
{
// Some unsupported curves.
const unsupportedCurves = [
'wap-wsg-idm-ecid-wtls1',
'c2pnb163v1',
'prime192v3',
];

// Brainpool is not supported in FIPS mode
// Brainpool is not supported in FIPS mode.
if (common.hasFipsCrypto)
unsupportedCurves.push('brainpoolP256r1');

unsupportedCurves.forEach((ecdhCurve) => {
assert.throws(() => tls.createServer({ ecdhCurve }),
/Error: Failed to set ECDH curve/);
});
});
}

0 comments on commit bcebb91

Please sign in to comment.