-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: refactor parallel/test-tls-async-cb-after-socket-end
PR-URL: #18985 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
1 parent
6613169
commit 4eef82e
Showing
1 changed file
with
17 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,65 @@ | ||
'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'); | ||
|
||
// Check tls async callback after socket ends | ||
|
||
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) { | ||
}); | ||
const server = tls.createServer(options, common.mustCall()); | ||
|
||
let sessionCb = null; | ||
let client = null; | ||
|
||
server.on('newSession', function(key, session, done) { | ||
server.on('newSession', common.mustCall((key, session, done) => { | ||
done(); | ||
}); | ||
})); | ||
|
||
server.on('resumeSession', function(id, cb) { | ||
server.on('resumeSession', common.mustCall((id, cb) => { | ||
sessionCb = cb; | ||
|
||
next(); | ||
}); | ||
})); | ||
|
||
server.listen(0, function() { | ||
server.listen(0, common.mustCall(() => { | ||
const clientOpts = { | ||
port: this.address().port, | ||
port: server.address().port, | ||
rejectUnauthorized: false, | ||
session: false | ||
}; | ||
|
||
const s1 = tls.connect(clientOpts, function() { | ||
const s1 = tls.connect(clientOpts, common.mustCall(() => { | ||
clientOpts.session = s1.getSession(); | ||
console.log('1st secure'); | ||
|
||
s1.destroy(); | ||
const s2 = tls.connect(clientOpts, function(s) { | ||
const s2 = tls.connect(clientOpts, (s) => { | ||
console.log('2nd secure'); | ||
|
||
s2.destroy(); | ||
}).on('connect', function() { | ||
}).on('connect', common.mustCall(() => { | ||
console.log('2nd connected'); | ||
client = s2; | ||
|
||
next(); | ||
}); | ||
}); | ||
}); | ||
})); | ||
})); | ||
})); | ||
|
||
function next() { | ||
if (!client || !sessionCb) | ||
return; | ||
|
||
client.destroy(); | ||
setTimeout(function() { | ||
setTimeout(common.mustCall(() => { | ||
sessionCb(); | ||
server.close(); | ||
}, 100); | ||
}), 100); | ||
} |