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. Fixes: https://github.com/nodejs/io.js/issues/1461 PR-URL: https://github.com/nodejs/io.js/pull/1836 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
975e5956f0
commit
e6ccdcc1fe
@ -125,7 +125,7 @@ var serverKey = loadPEM('agent2-key');
|
|||||||
var serverCert = loadPEM('agent2-cert');
|
var serverCert = loadPEM('agent2-cert');
|
||||||
|
|
||||||
|
|
||||||
function runClient(port, options, cb) {
|
function runClient(prefix, port, options, cb) {
|
||||||
|
|
||||||
// Client can connect in three ways:
|
// Client can connect in three ways:
|
||||||
// - Self-signed cert
|
// - Self-signed cert
|
||||||
@ -135,7 +135,7 @@ function runClient(port, options, cb) {
|
|||||||
var args = ['s_client', '-connect', '127.0.0.1:' + port];
|
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) {
|
switch (options.name) {
|
||||||
case 'agent1':
|
case 'agent1':
|
||||||
@ -176,7 +176,7 @@ function runClient(port, options, cb) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error('Unknown agent name');
|
throw new Error(prefix + 'Unknown agent name');
|
||||||
}
|
}
|
||||||
|
|
||||||
// To test use: openssl s_client -connect localhost:8000
|
// To test use: openssl s_client -connect localhost:8000
|
||||||
@ -193,7 +193,7 @@ function runClient(port, options, cb) {
|
|||||||
out += d;
|
out += d;
|
||||||
|
|
||||||
if (!goodbye && /_unauthed/g.test(out)) {
|
if (!goodbye && /_unauthed/g.test(out)) {
|
||||||
console.error(' * unauthed');
|
console.error(prefix + ' * unauthed');
|
||||||
goodbye = true;
|
goodbye = true;
|
||||||
client.stdin.end('goodbye\n');
|
client.stdin.end('goodbye\n');
|
||||||
authed = false;
|
authed = false;
|
||||||
@ -201,7 +201,7 @@ function runClient(port, options, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!goodbye && /_authed/g.test(out)) {
|
if (!goodbye && /_authed/g.test(out)) {
|
||||||
console.error(' * authed');
|
console.error(prefix + ' * authed');
|
||||||
goodbye = true;
|
goodbye = true;
|
||||||
client.stdin.end('goodbye\n');
|
client.stdin.end('goodbye\n');
|
||||||
authed = true;
|
authed = true;
|
||||||
@ -212,15 +212,17 @@ function runClient(port, options, cb) {
|
|||||||
//client.stdout.pipe(process.stdout);
|
//client.stdout.pipe(process.stdout);
|
||||||
|
|
||||||
client.on('exit', function(code) {
|
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);
|
// ": s_client exited with error code " + code);
|
||||||
if (options.shouldReject) {
|
if (options.shouldReject) {
|
||||||
assert.equal(true, rejected, options.name +
|
assert.equal(true, rejected, prefix + options.name +
|
||||||
' NOT rejected, but should have been');
|
' NOT rejected, but should have been');
|
||||||
} else {
|
} else {
|
||||||
assert.equal(false, rejected, options.name +
|
assert.equal(false, rejected, prefix + options.name +
|
||||||
' rejected, but should NOT have been');
|
' 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();
|
cb();
|
||||||
@ -231,10 +233,11 @@ function runClient(port, options, cb) {
|
|||||||
// Run the tests
|
// Run the tests
|
||||||
var successfulTests = 0;
|
var successfulTests = 0;
|
||||||
function runTest(port, testIndex) {
|
function runTest(port, testIndex) {
|
||||||
|
var prefix = testIndex + ' ';
|
||||||
var tcase = testCases[testIndex];
|
var tcase = testCases[testIndex];
|
||||||
if (!tcase) return;
|
if (!tcase) return;
|
||||||
|
|
||||||
console.error("Running '%s'", tcase.title);
|
console.error(prefix + "Running '%s'", tcase.title);
|
||||||
|
|
||||||
var cas = tcase.CAs.map(loadPEM);
|
var cas = tcase.CAs.map(loadPEM);
|
||||||
|
|
||||||
@ -265,7 +268,7 @@ function runTest(port, testIndex) {
|
|||||||
if (tcase.renegotiate && !renegotiated) {
|
if (tcase.renegotiate && !renegotiated) {
|
||||||
renegotiated = true;
|
renegotiated = true;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
console.error('- connected, renegotiating');
|
console.error(prefix + '- connected, renegotiating');
|
||||||
c.write('\n_renegotiating\n');
|
c.write('\n_renegotiating\n');
|
||||||
return c.renegotiate({
|
return c.renegotiate({
|
||||||
requestCert: true,
|
requestCert: true,
|
||||||
@ -281,11 +284,11 @@ function runTest(port, testIndex) {
|
|||||||
|
|
||||||
connections++;
|
connections++;
|
||||||
if (c.authorized) {
|
if (c.authorized) {
|
||||||
console.error('- authed connection: ' +
|
console.error(prefix + '- authed connection: ' +
|
||||||
c.getPeerCertificate().subject.CN);
|
c.getPeerCertificate().subject.CN);
|
||||||
c.write('\n_authed\n');
|
c.write('\n_authed\n');
|
||||||
} else {
|
} else {
|
||||||
console.error('- unauthed connection: %s', c.authorizationError);
|
console.error(prefix + '- unauthed connection: %s', c.authorizationError);
|
||||||
c.write('\n_unauthed\n');
|
c.write('\n_unauthed\n');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -293,7 +296,7 @@ function runTest(port, testIndex) {
|
|||||||
function runNextClient(clientIndex) {
|
function runNextClient(clientIndex) {
|
||||||
var options = tcase.clients[clientIndex];
|
var options = tcase.clients[clientIndex];
|
||||||
if (options) {
|
if (options) {
|
||||||
runClient(port, options, function() {
|
runClient(prefix + clientIndex + ' ', port, options, function() {
|
||||||
runNextClient(clientIndex + 1);
|
runNextClient(clientIndex + 1);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -305,14 +308,14 @@ function runTest(port, testIndex) {
|
|||||||
|
|
||||||
server.listen(port, function() {
|
server.listen(port, function() {
|
||||||
if (tcase.debug) {
|
if (tcase.debug) {
|
||||||
console.error('TLS server running on port ' + port);
|
console.error(prefix + 'TLS server running on port ' + port);
|
||||||
} else {
|
} else {
|
||||||
if (tcase.renegotiate) {
|
if (tcase.renegotiate) {
|
||||||
runNextClient(0);
|
runNextClient(0);
|
||||||
} else {
|
} else {
|
||||||
var clientsCompleted = 0;
|
var clientsCompleted = 0;
|
||||||
for (var i = 0; i < tcase.clients.length; i++) {
|
for (var i = 0; i < tcase.clients.length; i++) {
|
||||||
runClient(port, tcase.clients[i], function() {
|
runClient(prefix + i + ' ', port, tcase.clients[i], function() {
|
||||||
clientsCompleted++;
|
clientsCompleted++;
|
||||||
if (clientsCompleted === tcase.clients.length) {
|
if (clientsCompleted === tcase.clients.length) {
|
||||||
server.close();
|
server.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user