Skip to content

Commit ef6c86c

Browse files
tniessendanielleadams
authored andcommitted
test: simplify test-tls-ecdh-multiple
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>
1 parent 4652dfd commit ef6c86c

File tree

1 file changed

+12
-28
lines changed

1 file changed

+12
-28
lines changed

test/parallel/test-tls-ecdh-multiple.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (!common.opensslCli)
1212

1313
const assert = require('assert');
1414
const tls = require('tls');
15-
const spawn = require('child_process').spawn;
15+
const { execFile } = require('child_process');
1616
const fixtures = require('../common/fixtures');
1717

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

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

32-
const server = tls.createServer(options, function(conn) {
32+
const server = tls.createServer(options, (conn) => {
3333
conn.end(reply);
34-
});
35-
36-
let gotReply = false;
37-
38-
server.listen(0, function() {
34+
}).listen(0, common.mustCall(() => {
3935
const args = ['s_client',
4036
'-cipher', `${options.ciphers}`,
41-
'-connect', `127.0.0.1:${this.address().port}`];
42-
43-
const client = spawn(common.opensslCli, args);
44-
45-
client.stdout.on('data', function(data) {
46-
const message = data.toString();
47-
if (message.includes(reply))
48-
gotReply = true;
49-
});
37+
'-connect', `127.0.0.1:${server.address().port}`];
5038

51-
client.on('exit', function(code) {
52-
assert.strictEqual(code, 0);
39+
execFile(common.opensslCli, args, common.mustSucceed((stdout) => {
40+
assert(stdout.includes(reply));
5341
server.close();
54-
});
55-
56-
client.on('error', assert.ifError);
57-
});
42+
}));
43+
}));
5844

59-
process.on('exit', function() {
60-
assert.ok(gotReply);
61-
62-
// Some of unsupported curves
45+
{
46+
// Some unsupported curves.
6347
const unsupportedCurves = [
6448
'wap-wsg-idm-ecid-wtls1',
6549
'c2pnb163v1',
6650
'prime192v3',
6751
];
6852

69-
// Brainpool is not supported in FIPS mode
53+
// Brainpool is not supported in FIPS mode.
7054
if (common.hasFipsCrypto)
7155
unsupportedCurves.push('brainpoolP256r1');
7256

7357
unsupportedCurves.forEach((ecdhCurve) => {
7458
assert.throws(() => tls.createServer({ ecdhCurve }),
7559
/Error: Failed to set ECDH curve/);
7660
});
77-
});
61+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy