Skip to content

Commit 16fa3ee

Browse files
jeffhostetlergitster
authored andcommitted
t0212: test URL redacting in EVENT format
In the added tests cases, skip testing the `GIT_TRACE2_REDACT=0` case because we would need to exactly model the full JSON event stream like we did in the preceding basic tests and I do not think it is worth it. Furthermore, the Trace2 routines print the same content in normal, perf, or event format, and in t0210 and t0211 we already tested the basic functionality, so no need to repeat it here. In this test, we use the test-helper to unit test each of the event messages where URLs can appear and confirm that they are redacted in each event. Signed-off-by: Jeff Hostetler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c73e7f8 commit 16fa3ee

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

t/helper/test-trace2.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,56 @@ static int ut_201counter(int argc, const char **argv)
412412
return 0;
413413
}
414414

415+
static int ut_300redact_start(int argc, const char **argv)
416+
{
417+
if (!argc)
418+
die("expect <argv...>");
419+
420+
trace2_cmd_start(argv);
421+
422+
return 0;
423+
}
424+
425+
static int ut_301redact_child_start(int argc, const char **argv)
426+
{
427+
struct child_process cmd = CHILD_PROCESS_INIT;
428+
int k;
429+
430+
if (!argc)
431+
die("expect <argv...>");
432+
433+
for (k = 0; argv[k]; k++)
434+
strvec_push(&cmd.args, argv[k]);
435+
436+
trace2_child_start(&cmd);
437+
438+
strvec_clear(&cmd.args);
439+
440+
return 0;
441+
}
442+
443+
static int ut_302redact_exec(int argc, const char **argv)
444+
{
445+
if (!argc)
446+
die("expect <exe> <argv...>");
447+
448+
trace2_exec(argv[0], &argv[1]);
449+
450+
return 0;
451+
}
452+
453+
static int ut_303redact_def_param(int argc, const char **argv)
454+
{
455+
struct key_value_info kvi = KVI_INIT;
456+
457+
if (argc < 2)
458+
die("expect <key> <value>");
459+
460+
trace2_def_param(argv[0], argv[1], &kvi);
461+
462+
return 0;
463+
}
464+
415465
/*
416466
* Usage:
417467
* test-tool trace2 <ut_name_1> <ut_usage_1>
@@ -438,6 +488,11 @@ static struct unit_test ut_table[] = {
438488

439489
{ ut_200counter, "200counter", "<v1> [<v2> [<v3> [...]]]" },
440490
{ ut_201counter, "201counter", "<v1> <v2> <threads>" },
491+
492+
{ ut_300redact_start, "300redact_start", "<argv...>" },
493+
{ ut_301redact_child_start, "301redact_child_start", "<argv...>" },
494+
{ ut_302redact_exec, "302redact_exec", "<exe> <argv...>" },
495+
{ ut_303redact_def_param, "303redact_def_param", "<key> <value>" },
441496
};
442497
/* clang-format on */
443498

t/t0212-trace2-event.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,44 @@ test_expect_success 'discard traces when there are too many files' '
323323
head -n2 trace_target_dir/git-trace2-discard | tail -n1 | grep \"event\":\"too_many_files\"
324324
'
325325

326+
# In the following "...redact..." tests, skip testing the GIT_TRACE2_REDACT=0
327+
# case because we would need to exactly model the full JSON event stream like
328+
# we did in the basic tests above and I do not think it is worth it.
329+
330+
test_expect_success 'unsafe URLs are redacted by default in cmd_start events' '
331+
test_when_finished \
332+
"rm -r trace.event" &&
333+
334+
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
335+
test-tool trace2 300redact_start git clone https://user:[email protected]/ clone2 &&
336+
! grep user:pwd trace.event
337+
'
338+
339+
test_expect_success 'unsafe URLs are redacted by default in child_start events' '
340+
test_when_finished \
341+
"rm -r trace.event" &&
342+
343+
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
344+
test-tool trace2 301redact_child_start git clone https://user:[email protected]/ clone2 &&
345+
! grep user:pwd trace.event
346+
'
347+
348+
test_expect_success 'unsafe URLs are redacted by default in exec events' '
349+
test_when_finished \
350+
"rm -r trace.event" &&
351+
352+
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
353+
test-tool trace2 302redact_exec git clone https://user:[email protected]/ clone2 &&
354+
! grep user:pwd trace.event
355+
'
356+
357+
test_expect_success 'unsafe URLs are redacted by default in def_param events' '
358+
test_when_finished \
359+
"rm -r trace.event" &&
360+
361+
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
362+
test-tool trace2 303redact_def_param url https://user:[email protected]/ &&
363+
! grep user:pwd trace.event
364+
'
365+
326366
test_done

0 commit comments

Comments
 (0)