1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
2
+ const common = require ( '../common' ) ;
4
3
5
4
if ( ! common . opensslCli ) {
6
5
common . skip ( 'node compiled without OpenSSL CLI.' ) ;
@@ -12,11 +11,9 @@ if (!common.hasCrypto) {
12
11
return ;
13
12
}
14
13
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' ) ;
20
17
21
18
function filenamePEM ( n ) {
22
19
return require ( 'path' ) . join ( common . fixturesDir , 'keys' , n + '.pem' ) ;
@@ -26,17 +23,16 @@ function loadPEM(n) {
26
23
return fs . readFileSync ( filenamePEM ( n ) ) ;
27
24
}
28
25
29
- var opts = {
26
+ const opts = {
30
27
key : loadPEM ( 'agent2-key' ) ,
31
28
cert : loadPEM ( 'agent2-cert' )
32
29
} ;
30
+ const max_iter = 20 ;
31
+ let iter = 0 ;
33
32
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 ) {
38
34
s . pipe ( s ) ;
39
- s . on ( 'error' , function ( e ) {
35
+ s . on ( 'error' , function ( ) {
40
36
// ignore error
41
37
} ) ;
42
38
} ) ;
@@ -47,21 +43,20 @@ server.listen(0, function() {
47
43
48
44
49
45
function sendClient ( ) {
50
- var client = tls . connect ( server . address ( ) . port , {
46
+ const client = tls . connect ( server . address ( ) . port , {
51
47
rejectUnauthorized : false
52
48
} ) ;
53
- client . on ( 'data' , function ( chunk ) {
49
+ client . on ( 'data' , common . mustCall ( function ( ) {
54
50
if ( iter ++ === 2 ) sendBADTLSRecord ( ) ;
55
51
if ( iter < max_iter ) {
56
52
client . write ( 'a' ) ;
57
53
return ;
58
54
}
59
55
client . end ( ) ;
60
56
server . close ( ) ;
61
- success = true ;
62
- } ) ;
57
+ } , max_iter ) ) ;
63
58
client . write ( 'a' ) ;
64
- client . on ( 'error' , function ( e ) {
59
+ client . on ( 'error' , function ( ) {
65
60
// ignore error
66
61
} ) ;
67
62
client . on ( 'close' , function ( ) {
@@ -71,21 +66,16 @@ function sendClient() {
71
66
72
67
73
68
function 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 ( {
77
72
socket : socket ,
78
73
rejectUnauthorized : false
79
74
} , function ( ) {
80
75
socket . write ( BAD_RECORD ) ;
81
76
socket . end ( ) ;
82
77
} ) ;
83
- client . on ( 'error' , function ( e ) {
78
+ client . on ( 'error' , function ( ) {
84
79
// ignore error
85
80
} ) ;
86
81
}
87
-
88
- process . on ( 'exit' , function ( ) {
89
- assert . strictEqual ( iter , max_iter ) ;
90
- assert ( success ) ;
91
- } ) ;
0 commit comments