Skip to content

Commit

Permalink
test: simplify test-tls-ecdh-auto
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: #46911
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
  • Loading branch information
tniessen authored and targos committed Mar 14, 2023
1 parent 762dc7c commit 21153f1
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions test/parallel/test-tls-ecdh-auto.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,33 +29,15 @@ 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);
'-connect', `127.0.0.1:${server.address().port}`];

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);
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);
});
}));
}));

0 comments on commit 21153f1

Please sign in to comment.