Skip to content

Commit e6ccdcc

Browse files
joaocgreisorangemocha
authored andcommitted
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: #1461 PR-URL: #1836 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 975e595 commit e6ccdcc

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

test/parallel/test-tls-server-verify.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ var serverKey = loadPEM('agent2-key');
125125
var serverCert = loadPEM('agent2-cert');
126126

127127

128-
function runClient(port, options, cb) {
128+
function runClient(prefix, port, options, cb) {
129129

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

137137

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

140140
switch (options.name) {
141141
case 'agent1':
@@ -176,7 +176,7 @@ function runClient(port, options, cb) {
176176
break;
177177

178178
default:
179-
throw new Error('Unknown agent name');
179+
throw new Error(prefix + 'Unknown agent name');
180180
}
181181

182182
// To test use: openssl s_client -connect localhost:8000
@@ -193,15 +193,15 @@ function runClient(port, options, cb) {
193193
out += d;
194194

195195
if (!goodbye && /_unauthed/g.test(out)) {
196-
console.error(' * unauthed');
196+
console.error(prefix + ' * unauthed');
197197
goodbye = true;
198198
client.stdin.end('goodbye\n');
199199
authed = false;
200200
rejected = false;
201201
}
202202

203203
if (!goodbye && /_authed/g.test(out)) {
204-
console.error(' * authed');
204+
console.error(prefix + ' * authed');
205205
goodbye = true;
206206
client.stdin.end('goodbye\n');
207207
authed = true;
@@ -212,15 +212,17 @@ function runClient(port, options, cb) {
212212
//client.stdout.pipe(process.stdout);
213213

214214
client.on('exit', function(code) {
215-
//assert.equal(0, code, options.name +
215+
//assert.equal(0, code, prefix + options.name +
216216
// ": s_client exited with error code " + code);
217217
if (options.shouldReject) {
218-
assert.equal(true, rejected, options.name +
218+
assert.equal(true, rejected, prefix + options.name +
219219
' NOT rejected, but should have been');
220220
} else {
221-
assert.equal(false, rejected, options.name +
221+
assert.equal(false, rejected, prefix + options.name +
222222
' rejected, but should NOT have been');
223-
assert.equal(options.shouldAuth, authed);
223+
assert.equal(options.shouldAuth, authed, prefix +
224+
options.name + ' authed is ' + authed +
225+
' but should have been ' + options.shouldAuth);
224226
}
225227

226228
cb();
@@ -231,10 +233,11 @@ function runClient(port, options, cb) {
231233
// Run the tests
232234
var successfulTests = 0;
233235
function runTest(port, testIndex) {
236+
var prefix = testIndex + ' ';
234237
var tcase = testCases[testIndex];
235238
if (!tcase) return;
236239

237-
console.error("Running '%s'", tcase.title);
240+
console.error(prefix + "Running '%s'", tcase.title);
238241

239242
var cas = tcase.CAs.map(loadPEM);
240243

@@ -265,7 +268,7 @@ function runTest(port, testIndex) {
265268
if (tcase.renegotiate && !renegotiated) {
266269
renegotiated = true;
267270
setTimeout(function() {
268-
console.error('- connected, renegotiating');
271+
console.error(prefix + '- connected, renegotiating');
269272
c.write('\n_renegotiating\n');
270273
return c.renegotiate({
271274
requestCert: true,
@@ -281,19 +284,19 @@ function runTest(port, testIndex) {
281284

282285
connections++;
283286
if (c.authorized) {
284-
console.error('- authed connection: ' +
287+
console.error(prefix + '- authed connection: ' +
285288
c.getPeerCertificate().subject.CN);
286289
c.write('\n_authed\n');
287290
} else {
288-
console.error('- unauthed connection: %s', c.authorizationError);
291+
console.error(prefix + '- unauthed connection: %s', c.authorizationError);
289292
c.write('\n_unauthed\n');
290293
}
291294
});
292295

293296
function runNextClient(clientIndex) {
294297
var options = tcase.clients[clientIndex];
295298
if (options) {
296-
runClient(port, options, function() {
299+
runClient(prefix + clientIndex + ' ', port, options, function() {
297300
runNextClient(clientIndex + 1);
298301
});
299302
} else {
@@ -305,14 +308,14 @@ function runTest(port, testIndex) {
305308

306309
server.listen(port, function() {
307310
if (tcase.debug) {
308-
console.error('TLS server running on port ' + port);
311+
console.error(prefix + 'TLS server running on port ' + port);
309312
} else {
310313
if (tcase.renegotiate) {
311314
runNextClient(0);
312315
} else {
313316
var clientsCompleted = 0;
314317
for (var i = 0; i < tcase.clients.length; i++) {
315-
runClient(port, tcase.clients[i], function() {
318+
runClient(prefix + i + ' ', port, tcase.clients[i], function() {
316319
clientsCompleted++;
317320
if (clientsCompleted === tcase.clients.length) {
318321
server.close();

0 commit comments

Comments
 (0)