-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test,win: speedup tls-server-verify #1836
Changes from all commits
830d454
1bcb5f0
f49019f
0368003
2107be0
e809f01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,17 +125,20 @@ var serverKey = loadPEM('agent2-key'); | |
var serverCert = loadPEM('agent2-cert'); | ||
|
||
|
||
function runClient(options, cb) { | ||
function runClient(prefix, port, options, cb) { | ||
|
||
// Client can connect in three ways: | ||
// - Self-signed cert | ||
// - Certificate, but not signed by CA. | ||
// - Certificate signed by CA. | ||
|
||
var args = ['s_client', '-connect', '127.0.0.1:' + common.PORT]; | ||
var args = ['s_client', '-connect', '127.0.0.1:' + port]; | ||
|
||
// for the performance issue in s_client on Windows | ||
if (process.platform === 'win32') | ||
args.push('-no_rand_screen'); | ||
|
||
console.log(' connecting with', options.name); | ||
console.log(prefix + ' connecting with', options.name); | ||
|
||
switch (options.name) { | ||
case 'agent1': | ||
|
@@ -176,7 +179,7 @@ function runClient(options, cb) { | |
break; | ||
|
||
default: | ||
throw new Error('Unknown agent name'); | ||
throw new Error(prefix + 'Unknown agent name'); | ||
} | ||
|
||
// To test use: openssl s_client -connect localhost:8000 | ||
|
@@ -193,17 +196,17 @@ function runClient(options, cb) { | |
out += d; | ||
|
||
if (!goodbye && /_unauthed/g.test(out)) { | ||
console.error(' * unauthed'); | ||
console.error(prefix + ' * unauthed'); | ||
goodbye = true; | ||
client.stdin.end('goodbye\n'); | ||
client.kill(); | ||
authed = false; | ||
rejected = false; | ||
} | ||
|
||
if (!goodbye && /_authed/g.test(out)) { | ||
console.error(' * authed'); | ||
console.error(prefix + ' * authed'); | ||
goodbye = true; | ||
client.stdin.end('goodbye\n'); | ||
client.kill(); | ||
authed = true; | ||
rejected = false; | ||
} | ||
|
@@ -212,15 +215,17 @@ function runClient(options, cb) { | |
//client.stdout.pipe(process.stdout); | ||
|
||
client.on('exit', function(code) { | ||
//assert.equal(0, code, options.name + | ||
//assert.equal(0, code, prefix + options.name + | ||
// ": s_client exited with error code " + code); | ||
if (options.shouldReject) { | ||
assert.equal(true, rejected, options.name + | ||
assert.equal(true, rejected, prefix + options.name + | ||
' NOT rejected, but should have been'); | ||
} else { | ||
assert.equal(false, rejected, options.name + | ||
assert.equal(false, rejected, prefix + options.name + | ||
' rejected, but should NOT have been'); | ||
assert.equal(options.shouldAuth, authed); | ||
assert.equal(options.shouldAuth, authed, prefix + | ||
options.name + ' authed is ' + authed + | ||
' but should have been ' + options.shouldAuth); | ||
} | ||
|
||
cb(); | ||
|
@@ -230,11 +235,12 @@ function runClient(options, cb) { | |
|
||
// Run the tests | ||
var successfulTests = 0; | ||
function runTest(testIndex) { | ||
function runTest(port, testIndex) { | ||
var prefix = testIndex + ' '; | ||
var tcase = testCases[testIndex]; | ||
if (!tcase) return; | ||
|
||
console.error("Running '%s'", tcase.title); | ||
console.error(prefix + "Running '%s'", tcase.title); | ||
|
||
var cas = tcase.CAs.map(loadPEM); | ||
|
||
|
@@ -262,10 +268,16 @@ function runTest(testIndex) { | |
|
||
var renegotiated = false; | ||
var server = tls.Server(serverOptions, function handleConnection(c) { | ||
c.on('error', function(e) { | ||
// child.kill() leads ECONNRESET errro in the TLS connection of | ||
// openssl s_client via spawn(). A Test result is already | ||
// checked by the data of client.stdout before child.kill() so | ||
// these tls errors can be ignored. | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it necessary to swallow errors? It looks suspect but if there is a good reason, can you add a comment explaining it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added more comment to this. Does it make sense? diff --git a/test/simple/test-tls-server-verify.js b/test/simple/test-tls-server-verify.js
index 5aad21e..ff2574b 100644
--- a/test/simple/test-tls-server-verify.js
+++ b/test/simple/test-tls-server-verify.js
@@ -285,7 +285,10 @@ function runTest(port, testIndex) {
var renegotiated = false;
var server = tls.Server(serverOptions, function handleConnection(c) {
c.on('error', function(e) {
- // ignore errors
+ // child.kill() leads ECONNRESET errro in the TLS connection of
+ // openssl s_client via spawn(). A Test result is already
+ // checked by the data of client.stdout before child.kill() so
+ // these tls errors can be ignored.
});
if (tcase.renegotiate && !renegotiated) {
renegotiated = true; |
||
if (tcase.renegotiate && !renegotiated) { | ||
renegotiated = true; | ||
setTimeout(function() { | ||
console.error('- connected, renegotiating'); | ||
console.error(prefix + '- connected, renegotiating'); | ||
c.write('\n_renegotiating\n'); | ||
return c.renegotiate({ | ||
requestCert: true, | ||
|
@@ -281,39 +293,55 @@ function runTest(testIndex) { | |
|
||
connections++; | ||
if (c.authorized) { | ||
console.error('- authed connection: ' + | ||
console.error(prefix + '- authed connection: ' + | ||
c.getPeerCertificate().subject.CN); | ||
c.write('\n_authed\n'); | ||
} else { | ||
console.error('- unauthed connection: %s', c.authorizationError); | ||
console.error(prefix + '- unauthed connection: %s', c.authorizationError); | ||
c.write('\n_unauthed\n'); | ||
} | ||
}); | ||
|
||
function runNextClient(clientIndex) { | ||
var options = tcase.clients[clientIndex]; | ||
if (options) { | ||
runClient(options, function() { | ||
runClient(prefix + clientIndex + ' ', port, options, function() { | ||
runNextClient(clientIndex + 1); | ||
}); | ||
} else { | ||
server.close(); | ||
successfulTests++; | ||
runTest(testIndex + 1); | ||
runTest(port, nextTest++); | ||
} | ||
} | ||
|
||
server.listen(common.PORT, function() { | ||
server.listen(port, function() { | ||
if (tcase.debug) { | ||
console.error('TLS server running on port ' + common.PORT); | ||
console.error(prefix + 'TLS server running on port ' + port); | ||
} else { | ||
runNextClient(0); | ||
if (tcase.renegotiate) { | ||
runNextClient(0); | ||
} else { | ||
var clientsCompleted = 0; | ||
for (var i = 0; i < tcase.clients.length; i++) { | ||
runClient(prefix + i + ' ', port, tcase.clients[i], function() { | ||
clientsCompleted++; | ||
if (clientsCompleted === tcase.clients.length) { | ||
server.close(); | ||
successfulTests++; | ||
runTest(port, nextTest++); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
runTest(0); | ||
var nextTest = 0; | ||
runTest(common.PORT, nextTest++); | ||
runTest(common.PORT + 1, nextTest++); | ||
|
||
|
||
process.on('exit', function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
if (dont_warn < 2) {
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont_warn
2 is only for the use this fix and more than 2 are not defined. I think it would rather be better to let the only 2 allocate to skipRAND_screen()
.