Skip to content

Commit 5b81689

Browse files
tniessentargos
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 815d2af commit 5b81689

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

‎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
constassert=require('assert');
1414
consttls=require('tls');
15-
constspawn=require('child_process').spawn;
15+
const{ execFile }=require('child_process');
1616
constfixtures=require('../common/fixtures');
1717

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

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

32-
constserver=tls.createServer(options,function(conn){
32+
constserver=tls.createServer(options,(conn)=>{
3333
conn.end(reply);
34-
});
35-
36-
letgotReply=false;
37-
38-
server.listen(0,function(){
34+
}).listen(0,common.mustCall(()=>{
3935
constargs=['s_client',
4036
'-cipher',`${options.ciphers}`,
41-
'-connect',`127.0.0.1:${this.address().port}`];
42-
43-
constclient=spawn(common.opensslCli,args);
44-
45-
client.stdout.on('data',function(data){
46-
constmessage=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
constunsupportedCurves=[
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:FailedtosetECDHcurve/);
7660
});
77-
});
61+
}

0 commit comments

Comments
 (0)