From 364479644c5c62e3aee89b4e16564b3cbf85af34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sat, 25 Feb 2023 19:19:19 +0100 Subject: [PATCH] test: simplify test-tls-alert Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: https://github.com/nodejs/node/pull/46751 PR-URL: https://github.com/nodejs/node/pull/46805 Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- test/parallel/test-tls-alert.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/test/parallel/test-tls-alert.js b/test/parallel/test-tls-alert.js index 5847f9ce9ad684..31b07104c241a9 100644 --- a/test/parallel/test-tls-alert.js +++ b/test/parallel/test-tls-alert.js @@ -28,12 +28,10 @@ if (!common.opensslCli) common.skip('node compiled without OpenSSL CLI.'); const assert = require('assert'); -const { spawn } = require('child_process'); +const { execFile } = require('child_process'); const tls = require('tls'); const fixtures = require('../common/fixtures'); -let success = false; - function loadPEM(n) { return fixtures.readKey(`${n}.pem`); } @@ -42,21 +40,13 @@ const server = tls.Server({ secureProtocol: 'TLSv1_2_server_method', key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert') -}, null).listen(0, function() { +}, null).listen(0, common.mustCall(() => { const args = ['s_client', '-quiet', '-tls1_1', - '-connect', `127.0.0.1:${this.address().port}`]; + '-connect', `127.0.0.1:${server.address().port}`]; - const client = spawn(common.opensslCli, args); - let out = ''; - client.stderr.setEncoding('utf8'); - client.stderr.on('data', function(d) { - out += d; - if (/SSL alert number 70/.test(out)) { - success = true; - server.close(); - } - }); -}); -process.on('exit', function() { - assert(success); -}); + execFile(common.opensslCli, args, common.mustCall((err, _, stderr) => { + assert.strictEqual(err.code, 1); + assert.match(stderr, /SSL alert number 70/); + server.close(); + })); +}));