Skip to content

Commit

Permalink
test: simplify test-tls-alert
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tniessen authored and danielleadams committed Apr 11, 2023
1 parent df14944 commit 3644796
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions test/parallel/test-tls-alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand All @@ -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();
}));
}));

0 comments on commit 3644796

Please sign in to comment.