mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: simplify test-tls-ecdh-auto
Avoid the process 'exit' event handler and use execFile instead of manual stream operations. Refs: https://github.com/nodejs/node/pull/46751 PR-URL: https://github.com/nodejs/node/pull/46911 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
parent
ca033c16fe
commit
06c660b1c6
@ -12,7 +12,7 @@ if (!common.opensslCli)
|
||||
|
||||
const assert = require('assert');
|
||||
const tls = require('tls');
|
||||
const spawn = require('child_process').spawn;
|
||||
const { execFile } = require('child_process');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
function loadPEM(n) {
|
||||
@ -29,33 +29,15 @@ const options = {
|
||||
|
||||
const reply = 'I AM THE WALRUS'; // Something recognizable
|
||||
|
||||
const server = tls.createServer(options, function(conn) {
|
||||
const server = tls.createServer(options, (conn) => {
|
||||
conn.end(reply);
|
||||
});
|
||||
|
||||
let gotReply = false;
|
||||
|
||||
server.listen(0, function() {
|
||||
}).listen(0, common.mustCall(() => {
|
||||
const args = ['s_client',
|
||||
'-cipher', `${options.ciphers}`,
|
||||
'-connect', `127.0.0.1:${this.address().port}`];
|
||||
'-connect', `127.0.0.1:${server.address().port}`];
|
||||
|
||||
const client = spawn(common.opensslCli, args);
|
||||
|
||||
client.stdout.on('data', function(data) {
|
||||
const message = data.toString();
|
||||
if (message.includes(reply))
|
||||
gotReply = true;
|
||||
});
|
||||
|
||||
client.on('exit', function(code) {
|
||||
assert.strictEqual(code, 0);
|
||||
execFile(common.opensslCli, args, common.mustSucceed((stdout) => {
|
||||
assert(stdout.includes(reply));
|
||||
server.close();
|
||||
});
|
||||
|
||||
client.on('error', assert.ifError);
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.ok(gotReply);
|
||||
});
|
||||
}));
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user