Skip to content

Commit 06f934f

Browse files
TrottMylesBorins
authored andcommitted
test: refactor test-tls-alert-handling
* process.on('exit',...) checks -> common.mustCall() * remove unused function parameters * var -> const/let PR-URL: #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>
1 parent 5215377 commit 06f934f

1 file changed

Lines changed: 17 additions & 27 deletions

File tree

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
2-
varcommon=require('../common');
3-
varassert=require('assert');
2+
constcommon=require('../common');
43

54
if(!common.opensslCli){
65
common.skip('node compiled without OpenSSL CLI.');
@@ -12,11 +11,9 @@ if (!common.hasCrypto) {
1211
return;
1312
}
1413

15-
vartls=require('tls');
16-
varnet=require('net');
17-
varfs=require('fs');
18-
19-
varsuccess=false;
14+
consttls=require('tls');
15+
constnet=require('net');
16+
constfs=require('fs');
2017

2118
functionfilenamePEM(n){
2219
returnrequire('path').join(common.fixturesDir,'keys',n+'.pem');
@@ -26,17 +23,16 @@ function loadPEM(n) {
2623
returnfs.readFileSync(filenamePEM(n));
2724
}
2825

29-
varopts={
26+
constopts={
3027
key: loadPEM('agent2-key'),
3128
cert: loadPEM('agent2-cert')
3229
};
30+
constmax_iter=20;
31+
letiter=0;
3332

34-
varmax_iter=20;
35-
variter=0;
36-
37-
varserver=tls.createServer(opts,function(s){
33+
constserver=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

4945
functionsendClient(){
50-
varclient=tls.connect(server.address().port,{
46+
constclient=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

7368
functionsendBADTLSRecord(){
74-
varBAD_RECORD=Buffer.from([0xff,0xff,0xff,0xff,0xff,0xff]);
75-
varsocket=net.connect(server.address().port);
76-
varclient=tls.connect({
69+
constBAD_RECORD=Buffer.from([0xff,0xff,0xff,0xff,0xff,0xff]);
70+
constsocket=net.connect(server.address().port);
71+
constclient=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

Comments
 (0)