Skip to content

Commit 3644796

Browse files
tniessendanielleadams
authored andcommitted
test: simplify test-tls-alert
Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: #46751 PR-URL: #46805 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent df14944 commit 3644796

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

test/parallel/test-tls-alert.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ if (!common.opensslCli)
2828
common.skip('node compiled without OpenSSL CLI.');
2929

3030
const assert = require('assert');
31-
const { spawn } = require('child_process');
31+
const { execFile } = require('child_process');
3232
const tls = require('tls');
3333
const fixtures = require('../common/fixtures');
3434

35-
let success = false;
36-
3735
function loadPEM(n) {
3836
return fixtures.readKey(`${n}.pem`);
3937
}
@@ -42,21 +40,13 @@ const server = tls.Server({
4240
secureProtocol: 'TLSv1_2_server_method',
4341
key: loadPEM('agent2-key'),
4442
cert: loadPEM('agent2-cert')
45-
}, null).listen(0, function() {
43+
}, null).listen(0, common.mustCall(() => {
4644
const args = ['s_client', '-quiet', '-tls1_1',
47-
'-connect', `127.0.0.1:${this.address().port}`];
45+
'-connect', `127.0.0.1:${server.address().port}`];
4846

49-
const client = spawn(common.opensslCli, args);
50-
let out = '';
51-
client.stderr.setEncoding('utf8');
52-
client.stderr.on('data', function(d) {
53-
out += d;
54-
if (/SSL alert number 70/.test(out)) {
55-
success = true;
56-
server.close();
57-
}
58-
});
59-
});
60-
process.on('exit', function() {
61-
assert(success);
62-
});
47+
execFile(common.opensslCli, args, common.mustCall((err, _, stderr) => {
48+
assert.strictEqual(err.code, 1);
49+
assert.match(stderr, /SSL alert number 70/);
50+
server.close();
51+
}));
52+
}));

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