|
1 | 1 | 'use strict';
|
2 |
| -var common = require('../common'); |
3 |
| -var assert = require('assert'); |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
4 | 4 |
|
5 | 5 | if (!common.hasCrypto) {
|
6 | 6 | common.skip('missing crypto');
|
7 | 7 | return;
|
8 | 8 | }
|
9 |
| -var tls = require('tls'); |
| 9 | +const tls = require('tls'); |
10 | 10 |
|
11 |
| -var fs = require('fs'); |
12 |
| -var path = require('path'); |
| 11 | +const fs = require('fs'); |
| 12 | +const path = require('path'); |
13 | 13 |
|
14 |
| -var options = { |
| 14 | +const options = { |
15 | 15 | key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
|
16 | 16 | cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
|
17 | 17 | };
|
18 | 18 |
|
19 |
| -var server = tls.createServer(options, common.mustCall(function(socket) { |
| 19 | +const server = tls.createServer(options, common.mustCall(function(socket) { |
20 | 20 | socket.on('data', function(data) {
|
21 | 21 | console.error(data.toString());
|
22 |
| - assert.equal(data, 'ok'); |
| 22 | + assert.strictEqual(data.toString(), 'ok'); |
23 | 23 | });
|
24 | 24 | }, 3)).listen(0, function() {
|
25 | 25 | unauthorized();
|
26 | 26 | });
|
27 | 27 |
|
28 | 28 | function unauthorized() {
|
29 |
| - var socket = tls.connect({ |
| 29 | + const socket = tls.connect({ |
30 | 30 | port: server.address().port,
|
31 | 31 | servername: 'localhost',
|
32 | 32 | rejectUnauthorized: false
|
33 |
| - }, function() { |
| 33 | + }, common.mustCall(function() { |
34 | 34 | assert(!socket.authorized);
|
35 | 35 | socket.end();
|
36 | 36 | rejectUnauthorized();
|
37 |
| - }); |
| 37 | + })); |
38 | 38 | socket.on('error', common.fail);
|
39 | 39 | socket.write('ok');
|
40 | 40 | }
|
41 | 41 |
|
42 | 42 | function rejectUnauthorized() {
|
43 |
| - var socket = tls.connect(server.address().port, { |
| 43 | + const socket = tls.connect(server.address().port, { |
44 | 44 | servername: 'localhost'
|
45 | 45 | }, common.fail);
|
46 |
| - socket.on('error', function(err) { |
| 46 | + socket.on('error', common.mustCall(function(err) { |
47 | 47 | console.error(err);
|
48 | 48 | authorized();
|
49 |
| - }); |
| 49 | + })); |
50 | 50 | socket.write('ng');
|
51 | 51 | }
|
52 | 52 |
|
53 | 53 | function authorized() {
|
54 |
| - var socket = tls.connect(server.address().port, { |
| 54 | + const socket = tls.connect(server.address().port, { |
55 | 55 | ca: [fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))],
|
56 | 56 | servername: 'localhost'
|
57 |
| - }, function() { |
| 57 | + }, common.mustCall(function() { |
58 | 58 | assert(socket.authorized);
|
59 | 59 | socket.end();
|
60 | 60 | server.close();
|
61 |
| - }); |
| 61 | + })); |
62 | 62 | socket.on('error', common.fail);
|
63 | 63 | socket.write('ok');
|
64 | 64 | }
|
0 commit comments