blob: a982781a2e5b288da5b0f8330e6c4a1cd7cbd293 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
var common = require('../common');
var assert = require('assert');
var tls = require('tls');
var fs = require('fs');
var clientConnected = 0;
var serverConnected = 0;
var serverCloseCallbacks = 0;
var serverCloseEvents = 0;
var options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};
var server = tls.Server(options, function(socket) {
if (++serverConnected === 2) {
server.close(function() {
++serverCloseCallbacks;
});
server.on('close', function() {
++serverCloseEvents;
});
}
});
server.listen(common.PORT, function() {
var client1 = tls.connect({
port: common.PORT,
rejectUnauthorized: false
}, function() {
++clientConnected;
client1.end();
});
var client2 = tls.connect({
port: common.PORT,
rejectUnauthorized: false
});
client2.on('secureConnect', function() {
++clientConnected;
client2.end();
});
});
process.on('exit', function() {
assert.equal(clientConnected, 2);
assert.equal(serverConnected, 2);
assert.equal(serverCloseCallbacks, 1);
assert.equal(serverCloseEvents, 1);
});
|