Skip to content

Commit 8b6c45f

Browse files
rgoodwinFishrock123
rgoodwin
authored andcommitted
test: update tls test to use const/let and common.mustCall
* Replace variable defs using var with more up to date const/let. * Updated tests to use strict equality to ensure type and value comparision * wrap callback functions in common.mustCall to ensure single execution PR-URL: #9968 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent c05909b commit 8b6c45f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed
+17-17
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

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

11-
var fs = require('fs');
12-
var path = require('path');
11+
const fs = require('fs');
12+
const path = require('path');
1313

14-
var options = {
14+
const options = {
1515
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
1616
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
1717
};
1818

19-
var server = tls.createServer(options, common.mustCall(function(socket) {
19+
const server = tls.createServer(options, common.mustCall(function(socket) {
2020
socket.on('data', function(data) {
2121
console.error(data.toString());
22-
assert.equal(data, 'ok');
22+
assert.strictEqual(data.toString(), 'ok');
2323
});
2424
}, 3)).listen(0, function() {
2525
unauthorized();
2626
});
2727

2828
function unauthorized() {
29-
var socket = tls.connect({
29+
const socket = tls.connect({
3030
port: server.address().port,
3131
servername: 'localhost',
3232
rejectUnauthorized: false
33-
}, function() {
33+
}, common.mustCall(function() {
3434
assert(!socket.authorized);
3535
socket.end();
3636
rejectUnauthorized();
37-
});
37+
}));
3838
socket.on('error', common.fail);
3939
socket.write('ok');
4040
}
4141

4242
function rejectUnauthorized() {
43-
var socket = tls.connect(server.address().port, {
43+
const socket = tls.connect(server.address().port, {
4444
servername: 'localhost'
4545
}, common.fail);
46-
socket.on('error', function(err) {
46+
socket.on('error', common.mustCall(function(err) {
4747
console.error(err);
4848
authorized();
49-
});
49+
}));
5050
socket.write('ng');
5151
}
5252

5353
function authorized() {
54-
var socket = tls.connect(server.address().port, {
54+
const socket = tls.connect(server.address().port, {
5555
ca: [fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))],
5656
servername: 'localhost'
57-
}, function() {
57+
}, common.mustCall(function() {
5858
assert(socket.authorized);
5959
socket.end();
6060
server.close();
61-
});
61+
}));
6262
socket.on('error', common.fail);
6363
socket.write('ok');
6464
}

0 commit comments

Comments
 (0)