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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
tniessen authored and targos committed Mar 13, 2023
1 parent 977fcc4 commit 4a810dc
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 4a810dc

Please sign in to comment.