0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-tls-async-cb-after-socket-end.js
Dolapo Toki c42cdd4919 test: replaced fixturesDir with common.fixtures
PR-URL: https://github.com/nodejs/node/pull/15836
Reviewed-By: Lance Ball <lball@redhat.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-10-13 20:36:40 +08:00

67 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET;
const tls = require('tls');
const options = {
secureOptions: SSL_OP_NO_TICKET,
key: fixtures.readSync('test_key.pem'),
cert: fixtures.readSync('test_cert.pem')
};
const server = tls.createServer(options, function(c) {
});
let sessionCb = null;
let client = null;
server.on('newSession', function(key, session, done) {
done();
});
server.on('resumeSession', function(id, cb) {
sessionCb = cb;
next();
});
server.listen(0, function() {
const clientOpts = {
port: this.address().port,
rejectUnauthorized: false,
session: false
};
const s1 = tls.connect(clientOpts, function() {
clientOpts.session = s1.getSession();
console.log('1st secure');
s1.destroy();
const s2 = tls.connect(clientOpts, function(s) {
console.log('2nd secure');
s2.destroy();
}).on('connect', function() {
console.log('2nd connected');
client = s2;
next();
});
});
});
function next() {
if (!client || !sessionCb)
return;
client.destroy();
setTimeout(function() {
sessionCb();
server.close();
}, 100);
}