зеркало из https://github.com/microsoft/git.git
t0212: test URL redacting in EVENT format
Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
This commit is contained in:
Родитель
ff13c04686
Коммит
8548168d1d
|
@ -412,6 +412,56 @@ static int ut_201counter(int argc, const char **argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ut_300redact_start(int argc, const char **argv)
|
||||
{
|
||||
if (!argc)
|
||||
die("expect <argv...>");
|
||||
|
||||
trace2_cmd_start(argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_301redact_child_start(int argc, const char **argv)
|
||||
{
|
||||
struct child_process cmd = CHILD_PROCESS_INIT;
|
||||
int k;
|
||||
|
||||
if (!argc)
|
||||
die("expect <argv...>");
|
||||
|
||||
for (k = 0; argv[k]; k++)
|
||||
strvec_push(&cmd.args, argv[k]);
|
||||
|
||||
trace2_child_start(&cmd);
|
||||
|
||||
strvec_clear(&cmd.args);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_302redact_exec(int argc, const char **argv)
|
||||
{
|
||||
if (!argc)
|
||||
die("expect <exe> <argv...>");
|
||||
|
||||
trace2_exec(argv[0], &argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ut_303redact_def_param(int argc, const char **argv)
|
||||
{
|
||||
struct key_value_info kvi = KVI_INIT;
|
||||
|
||||
if (argc < 2)
|
||||
die("expect <key> <value>");
|
||||
|
||||
trace2_def_param(argv[0], argv[1], &kvi);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Usage:
|
||||
* test-tool trace2 <ut_name_1> <ut_usage_1>
|
||||
|
@ -438,6 +488,11 @@ static struct unit_test ut_table[] = {
|
|||
|
||||
{ ut_200counter, "200counter", "<v1> [<v2> [<v3> [...]]]" },
|
||||
{ ut_201counter, "201counter", "<v1> <v2> <threads>" },
|
||||
|
||||
{ ut_300redact_start, "300redact_start", "<argv...>" },
|
||||
{ ut_301redact_child_start, "301redact_child_start", "<argv...>" },
|
||||
{ ut_302redact_exec, "302redact_exec", "<exe> <argv...>" },
|
||||
{ ut_303redact_def_param, "303redact_def_param", "<key> <value>" },
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
|
|
|
@ -323,4 +323,44 @@ test_expect_success 'discard traces when there are too many files' '
|
|||
head -n2 trace_target_dir/git-trace2-discard | tail -n1 | grep \"event\":\"too_many_files\"
|
||||
'
|
||||
|
||||
# In the following "...redact..." tests, 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 basic tests above and I do not think it is worth it.
|
||||
|
||||
test_expect_success 'unsafe URLs are redacted by default in cmd_start events' '
|
||||
test_when_finished \
|
||||
"rm -r trace.event" &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
|
||||
test-tool trace2 300redact_start git clone https://user:pwd@example.com/ clone2 &&
|
||||
! grep user:pwd trace.event
|
||||
'
|
||||
|
||||
test_expect_success 'unsafe URLs are redacted by default in child_start events' '
|
||||
test_when_finished \
|
||||
"rm -r trace.event" &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
|
||||
test-tool trace2 301redact_child_start git clone https://user:pwd@example.com/ clone2 &&
|
||||
! grep user:pwd trace.event
|
||||
'
|
||||
|
||||
test_expect_success 'unsafe URLs are redacted by default in exec events' '
|
||||
test_when_finished \
|
||||
"rm -r trace.event" &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
|
||||
test-tool trace2 302redact_exec git clone https://user:pwd@example.com/ clone2 &&
|
||||
! grep user:pwd trace.event
|
||||
'
|
||||
|
||||
test_expect_success 'unsafe URLs are redacted by default in def_param events' '
|
||||
test_when_finished \
|
||||
"rm -r trace.event" &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \
|
||||
test-tool trace2 303redact_def_param url https://user:pwd@example.com/ &&
|
||||
! grep user:pwd trace.event
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче