From 68de8d79a3130e047b53df8f89ebeec370d83969 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 22 Jan 2019 22:42:44 -0800 Subject: [PATCH] test: refactor test-*-ci-reneg-attack.js Refactor test-tls-ci-reneg-attack: * Use port 0 (OS-assigned available port) rather than common.PORT * Remove unnecessary boolean that causes race condition failure on some operating systems Refactor that test and test-https-ci-reneg-attack: * Check all stderr, not just the chunk coming in now, in case it breaks up chunks in the middle of where the regexps are supposed to match. --- test/pummel/test-https-ci-reneg-attack.js | 6 ++++-- test/pummel/test-tls-ci-reneg-attack.js | 15 +++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/test/pummel/test-https-ci-reneg-attack.js b/test/pummel/test-https-ci-reneg-attack.js index 50e16192e1b1ca..790dd8fc7ea162 100644 --- a/test/pummel/test-https-ci-reneg-attack.js +++ b/test/pummel/test-https-ci-reneg-attack.js @@ -73,11 +73,13 @@ function test(next) { // Count handshakes, start the attack after the initial handshake is done let handshakes = 0; let renegs = 0; + let stderrStuff = ''; child.stderr.on('data', function(data) { - handshakes += ((String(data)).match(/verify return:1/g) || []).length; + stderrStuff += data.toString(); + handshakes = (stderrStuff.match(/verify return:1/g) || []).length; if (handshakes === 2) spam(); - renegs += ((String(data)).match(/RENEGOTIATING/g) || []).length; + renegs = (stderrStuff.match(/RENEGOTIATING/g) || []).length; }); child.on('exit', function() { diff --git a/test/pummel/test-tls-ci-reneg-attack.js b/test/pummel/test-tls-ci-reneg-attack.js index 3509dcfd43f853..5e345271646c0b 100644 --- a/test/pummel/test-tls-ci-reneg-attack.js +++ b/test/pummel/test-tls-ci-reneg-attack.js @@ -51,20 +51,18 @@ function test(next) { key: fixtures.readSync('test_key.pem') }; - let seenError = false; - const server = tls.createServer(options, function(conn) { conn.on('error', function(err) { console.error(`Caught exception: ${err}`); assert(/TLS session renegotiation attack/.test(err)); conn.destroy(); - seenError = true; }); conn.pipe(conn); }); - server.listen(common.PORT, function() { - const args = (`s_client -connect 127.0.0.1:${common.PORT}`).split(' '); + server.listen(0, function() { + const args = + `s_client -connect 127.0.0.1:${server.address().port}`.split(' '); const child = spawn(common.opensslCli, args); child.stdout.resume(); @@ -73,12 +71,13 @@ function test(next) { // Count handshakes, start the attack after the initial handshake is done let handshakes = 0; let renegs = 0; + let stderrStuff = ''; child.stderr.on('data', function(data) { - if (seenError) return; - handshakes += ((String(data)).match(/verify return:1/g) || []).length; + stderrStuff += data.toString(); + handshakes = (stderrStuff.match(/verify return:1/g) || []).length; if (handshakes === 2) spam(); - renegs += ((String(data)).match(/RENEGOTIATING/g) || []).length; + renegs = (stderrStuff.match(/RENEGOTIATING/g) || []).length; }); child.on('exit', function() {