diff options
author | Rich Trott <rtrott@gmail.com> | 2016-12-27 22:14:37 -0800 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-12-30 22:35:01 -0800 |
commit | a6ca94a5f5bc29e70a9ad34cc41eacfded499a4a (patch) | |
tree | 08b7b99ae82e7e84f58e66934ca486d7fa220675 | |
parent | 0b33ef80f1fd7af314fd5a0e93ca906f15292732 (diff) | |
download | node-new-a6ca94a5f5bc29e70a9ad34cc41eacfded499a4a.tar.gz |
test: refactor test-tls-alert-handling
* process.on('exit',...) checks -> common.mustCall()
* remove unused function parameters
* var -> const/let
PR-URL: https://github.com/nodejs/node/pull/10482
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
-rw-r--r-- | test/parallel/test-tls-alert-handling.js | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js index 284a32ea0d..699b1acfc4 100644 --- a/test/parallel/test-tls-alert-handling.js +++ b/test/parallel/test-tls-alert-handling.js @@ -1,6 +1,5 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -12,11 +11,9 @@ if (!common.hasCrypto) { return; } -var tls = require('tls'); -var net = require('net'); -var fs = require('fs'); - -var success = false; +const tls = require('tls'); +const net = require('net'); +const fs = require('fs'); function filenamePEM(n) { return require('path').join(common.fixturesDir, 'keys', n + '.pem'); @@ -26,17 +23,16 @@ function loadPEM(n) { return fs.readFileSync(filenamePEM(n)); } -var opts = { +const opts = { key: loadPEM('agent2-key'), cert: loadPEM('agent2-cert') }; +const max_iter = 20; +let iter = 0; -var max_iter = 20; -var iter = 0; - -var server = tls.createServer(opts, function(s) { +const server = tls.createServer(opts, function(s) { s.pipe(s); - s.on('error', function(e) { + s.on('error', function() { // ignore error }); }); @@ -47,10 +43,10 @@ server.listen(0, function() { function sendClient() { - var client = tls.connect(server.address().port, { + const client = tls.connect(server.address().port, { rejectUnauthorized: false }); - client.on('data', function(chunk) { + client.on('data', common.mustCall(function() { if (iter++ === 2) sendBADTLSRecord(); if (iter < max_iter) { client.write('a'); @@ -58,10 +54,9 @@ function sendClient() { } client.end(); server.close(); - success = true; - }); + }, max_iter)); client.write('a'); - client.on('error', function(e) { + client.on('error', function() { // ignore error }); client.on('close', function() { @@ -71,21 +66,16 @@ function sendClient() { function sendBADTLSRecord() { - var BAD_RECORD = Buffer.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); - var socket = net.connect(server.address().port); - var client = tls.connect({ + const BAD_RECORD = Buffer.from([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]); + const socket = net.connect(server.address().port); + const client = tls.connect({ socket: socket, rejectUnauthorized: false }, function() { socket.write(BAD_RECORD); socket.end(); }); - client.on('error', function(e) { + client.on('error', function() { // ignore error }); } - -process.on('exit', function() { - assert.strictEqual(iter, max_iter); - assert(success); -}); |