summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Nießen <tniessen@tnie.de>2023-03-05 18:36:55 +0000
committerDanielle Adams <adamzdanielle@gmail.com>2023-04-10 20:55:12 -0400
commitef6c86c59fbf0509157b5ae8116da691aeeba81d (patch)
treed2f79cbb10ceb44af32b63f9d3767a265148b725
parent4652dfdc888cc1a2fc2aeb7c6000c84239a5ebf1 (diff)
downloadnode-new-ef6c86c59fbf0509157b5ae8116da691aeeba81d.tar.gz
test: simplify test-tls-ecdh-multiple
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/46963 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
-rw-r--r--test/parallel/test-tls-ecdh-multiple.js40
1 files changed, 12 insertions, 28 deletions
diff --git a/test/parallel/test-tls-ecdh-multiple.js b/test/parallel/test-tls-ecdh-multiple.js
index 3cf02701f4..5bf119f48b 100644
--- a/test/parallel/test-tls-ecdh-multiple.js
+++ b/test/parallel/test-tls-ecdh-multiple.js
@@ -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) {
@@ -29,44 +29,28 @@ 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');
@@ -74,4 +58,4 @@ process.on('exit', function() {
assert.throws(() => tls.createServer({ ecdhCurve }),
/Error: Failed to set ECDH curve/);
});
-});
+}