Skip to content
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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: improve console output of tls-server-verify
When running in parallel, it is not easy to identify what server and
client failed when the test fails. This adds identifiers to all lines
of console output.

(cherry picked from commit 29c651522df2f47c4360660264eb857fb6232b23)
  • Loading branch information
joaocgreis committed Jun 1, 2015
commit f49019f1f415619dd83738713d46f60026448a37
35 changes: 19 additions & 16 deletions test/parallel/test-tls-server-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var serverKey = loadPEM('agent2-key');
var serverCert = loadPEM('agent2-cert');


function runClient(port, options, cb) {
function runClient(prefix, port, options, cb) {

// Client can connect in three ways:
// - Self-signed cert
Expand All @@ -135,7 +135,7 @@ function runClient(port, options, cb) {
var args = ['s_client', '-connect', '127.0.0.1:' + port];


console.log(' connecting with', options.name);
console.log(prefix + ' connecting with', options.name);

switch (options.name) {
case 'agent1':
Expand Down Expand Up @@ -176,7 +176,7 @@ function runClient(port, 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
Expand All @@ -193,15 +193,15 @@ function runClient(port, options, cb) {
out += d;

if (!goodbye && /_unauthed/g.test(out)) {
console.error(' * unauthed');
console.error(prefix + ' * unauthed');
goodbye = true;
client.stdin.end('goodbye\n');
authed = false;
rejected = false;
}

if (!goodbye && /_authed/g.test(out)) {
console.error(' * authed');
console.error(prefix + ' * authed');
goodbye = true;
client.stdin.end('goodbye\n');
authed = true;
Expand All @@ -212,15 +212,17 @@ function runClient(port, 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();
Expand All @@ -231,10 +233,11 @@ function runClient(port, options, cb) {
// Run the tests
var successfulTests = 0;
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);

Expand Down Expand Up @@ -265,7 +268,7 @@ function runTest(port, testIndex) {
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,
Expand All @@ -281,19 +284,19 @@ function runTest(port, 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(port, options, function() {
runClient(prefix + clientIndex + ' ', port, options, function() {
runNextClient(clientIndex + 1);
});
} else {
Expand All @@ -305,14 +308,14 @@ function runTest(port, testIndex) {

server.listen(port, function() {
if (tcase.debug) {
console.error('TLS server running on port ' + port);
console.error(prefix + 'TLS server running on port ' + port);
} else {
if (tcase.renegotiate) {
runNextClient(0);
} else {
var clientsCompleted = 0;
for (var i = 0; i < tcase.clients.length; i++) {
runClient(port, tcase.clients[i], function() {
runClient(prefix + i + ' ', port, tcase.clients[i], function() {
clientsCompleted++;
if (clientsCompleted === tcase.clients.length) {
server.close();
Expand Down