Skip to content

Commit 9d037cf

Browse files
Paul Grahamaddaleax
authored andcommitted
test: improves test-tls-client-verify
Swaps var -> const/let assert.equal becomes assert.strictEqual common.mustCall on single-use functions PR-URL: #10051 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 2565e48 commit 9d037cf

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

‎test/parallel/test-tls-client-verify.js‎

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

55
if(!common.hasCrypto){
66
common.skip('missing crypto');
77
return;
88
}
9-
vartls=require('tls');
9+
consttls=require('tls');
1010

11-
varfs=require('fs');
11+
constfs=require('fs');
1212

13-
varhosterr=/Hostname\/IPdoesn'tmatchcertificate'saltnames/g;
14-
vartestCases=
13+
consthosterr=/Hostname\/IPdoesn'tmatchcertificate'saltnames/g;
14+
consttestCases=
1515
[{ca: ['ca1-cert'],
1616
key: 'agent2-key',
1717
cert: 'agent2-cert',
@@ -52,16 +52,16 @@ function loadPEM(n){
5252
returnfs.readFileSync(filenamePEM(n));
5353
}
5454

55-
varsuccessfulTests=0;
55+
letsuccessfulTests=0;
5656

5757
functiontestServers(index,servers,clientOptions,cb){
58-
varserverOptions=servers[index];
58+
constserverOptions=servers[index];
5959
if(!serverOptions){
6060
cb();
6161
return;
6262
}
6363

64-
varok=serverOptions.ok;
64+
constok=serverOptions.ok;
6565

6666
if(serverOptions.key){
6767
serverOptions.key=loadPEM(serverOptions.key);
@@ -71,45 +71,45 @@ function testServers(index, servers, clientOptions, cb){
7171
serverOptions.cert=loadPEM(serverOptions.cert);
7272
}
7373

74-
varserver=tls.createServer(serverOptions,function(s){
74+
constserver=tls.createServer(serverOptions,common.mustCall(function(s){
7575
s.end('hello world\n');
76-
});
76+
}));
7777

78-
server.listen(0,function(){
79-
varb='';
78+
server.listen(0,common.mustCall(function(){
79+
letb='';
8080

8181
console.error('connecting...');
8282
clientOptions.port=this.address().port;
83-
varclient=tls.connect(clientOptions,function(){
84-
varauthorized=client.authorized||
85-
hosterr.test(client.authorizationError);
83+
constclient=tls.connect(clientOptions,common.mustCall(function(){
84+
constauthorized=client.authorized||
85+
hosterr.test(client.authorizationError);
8686

8787
console.error('expected: '+ok+' authed: '+authorized);
8888

89-
assert.equal(ok,authorized);
89+
assert.strictEqual(ok,authorized);
9090
server.close();
91-
});
91+
}));
9292

9393
client.on('data',function(d){
9494
b+=d.toString();
9595
});
9696

97-
client.on('end',function(){
98-
assert.equal('hello world\n',b);
99-
});
97+
client.on('end',common.mustCall(function(){
98+
assert.strictEqual('hello world\n',b);
99+
}));
100100

101-
client.on('close',function(){
101+
client.on('close',common.mustCall(function(){
102102
testServers(index+1,servers,clientOptions,cb);
103-
});
104-
});
103+
}));
104+
}));
105105
}
106106

107107

108108
functionrunTest(testIndex){
109109
vartcase=testCases[testIndex];
110110
if(!tcase)return;
111111

112-
varclientOptions={
112+
constclientOptions={
113113
port: undefined,
114114
ca: tcase.ca.map(loadPEM),
115115
key: loadPEM(tcase.key),
@@ -118,10 +118,10 @@ function runTest(testIndex){
118118
};
119119

120120

121-
testServers(0,tcase.servers,clientOptions,function(){
121+
testServers(0,tcase.servers,clientOptions,common.mustCall(function(){
122122
successfulTests++;
123123
runTest(testIndex+1);
124-
});
124+
}));
125125
}
126126

127127

0 commit comments

Comments
(0)