11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
2+ const common = require ( '../common' ) ;
43
54if ( ! common . opensslCli ) {
65 common . skip ( 'node compiled without OpenSSL CLI.' ) ;
@@ -12,11 +11,9 @@ if (!common.hasCrypto) {
1211 return ;
1312}
1413
15- var tls = require ( 'tls' ) ;
16- var net = require ( 'net' ) ;
17- var fs = require ( 'fs' ) ;
18-
19- var success = false ;
14+ const tls = require ( 'tls' ) ;
15+ const net = require ( 'net' ) ;
16+ const fs = require ( 'fs' ) ;
2017
2118function filenamePEM ( n ) {
2219 return require ( 'path' ) . join ( common . fixturesDir , 'keys' , n + '.pem' ) ;
@@ -26,17 +23,16 @@ function loadPEM(n) {
2623 return fs . readFileSync ( filenamePEM ( n ) ) ;
2724}
2825
29- var opts = {
26+ const opts = {
3027 key : loadPEM ( 'agent2-key' ) ,
3128 cert : loadPEM ( 'agent2-cert' )
3229} ;
30+ const max_iter = 20 ;
31+ let iter = 0 ;
3332
34- var max_iter = 20 ;
35- var iter = 0 ;
36-
37- var server = tls . createServer ( opts , function ( s ) {
33+ const server = tls . createServer ( opts , function ( s ) {
3834 s . pipe ( s ) ;
39- s . on ( 'error' , function ( e ) {
35+ s . on ( 'error' , function ( ) {
4036 // ignore error
4137 } ) ;
4238} ) ;
@@ -47,21 +43,20 @@ server.listen(0, function() {
4743
4844
4945function sendClient ( ) {
50- var client = tls . connect ( server . address ( ) . port , {
46+ const client = tls . connect ( server . address ( ) . port , {
5147 rejectUnauthorized : false
5248 } ) ;
53- client . on ( 'data' , function ( chunk ) {
49+ client . on ( 'data' , common . mustCall ( function ( ) {
5450 if ( iter ++ === 2 ) sendBADTLSRecord ( ) ;
5551 if ( iter < max_iter ) {
5652 client . write ( 'a' ) ;
5753 return ;
5854 }
5955 client . end ( ) ;
6056 server . close ( ) ;
61- success = true ;
62- } ) ;
57+ } , max_iter ) ) ;
6358 client . write ( 'a' ) ;
64- client . on ( 'error' , function ( e ) {
59+ client . on ( 'error' , function ( ) {
6560 // ignore error
6661 } ) ;
6762 client . on ( 'close' , function ( ) {
@@ -71,21 +66,16 @@ function sendClient() {
7166
7267
7368function sendBADTLSRecord ( ) {
74- var BAD_RECORD = Buffer . from ( [ 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ] ) ;
75- var socket = net . connect ( server . address ( ) . port ) ;
76- var client = tls . connect ( {
69+ const BAD_RECORD = Buffer . from ( [ 0xff , 0xff , 0xff , 0xff , 0xff , 0xff ] ) ;
70+ const socket = net . connect ( server . address ( ) . port ) ;
71+ const client = tls . connect ( {
7772 socket : socket ,
7873 rejectUnauthorized : false
7974 } , function ( ) {
8075 socket . write ( BAD_RECORD ) ;
8176 socket . end ( ) ;
8277 } ) ;
83- client . on ( 'error' , function ( e ) {
78+ client . on ( 'error' , function ( ) {
8479 // ignore error
8580 } ) ;
8681}
87-
88- process . on ( 'exit' , function ( ) {
89- assert . strictEqual ( iter , max_iter ) ;
90- assert ( success ) ;
91- } ) ;
0 commit comments