зеркало из https://github.com/microsoft/git.git
Merge branch 'jt/curl-verbose-on-trace-curl'
Rewrite support for GIT_CURL_VERBOSE in terms of GIT_TRACE_CURL. Looking good. * jt/curl-verbose-on-trace-curl: http, imap-send: stop using CURLOPT_VERBOSE t5551: test that GIT_TRACE_CURL redacts password
This commit is contained in:
Коммит
0b925a469e
|
@ -721,8 +721,6 @@ of clones and fetches.
|
||||||
Enables a curl full trace dump of all incoming and outgoing data,
|
Enables a curl full trace dump of all incoming and outgoing data,
|
||||||
including descriptive information, of the git transport protocol.
|
including descriptive information, of the git transport protocol.
|
||||||
This is similar to doing curl `--trace-ascii` on the command line.
|
This is similar to doing curl `--trace-ascii` on the command line.
|
||||||
This option overrides setting the `GIT_CURL_VERBOSE` environment
|
|
||||||
variable.
|
|
||||||
See `GIT_TRACE` for available trace output options.
|
See `GIT_TRACE` for available trace output options.
|
||||||
|
|
||||||
`GIT_TRACE_CURL_NO_DATA`::
|
`GIT_TRACE_CURL_NO_DATA`::
|
||||||
|
|
8
http.c
8
http.c
|
@ -804,6 +804,12 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void http_trace_curl_no_data(void)
|
||||||
|
{
|
||||||
|
trace_override_envvar(&trace_curl, "1");
|
||||||
|
trace_curl_data = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void setup_curl_trace(CURL *handle)
|
void setup_curl_trace(CURL *handle)
|
||||||
{
|
{
|
||||||
if (!trace_want(&trace_curl))
|
if (!trace_want(&trace_curl))
|
||||||
|
@ -993,7 +999,7 @@ static CURL *get_curl_handle(void)
|
||||||
warning(_("Protocol restrictions not supported with cURL < 7.19.4"));
|
warning(_("Protocol restrictions not supported with cURL < 7.19.4"));
|
||||||
#endif
|
#endif
|
||||||
if (getenv("GIT_CURL_VERBOSE"))
|
if (getenv("GIT_CURL_VERBOSE"))
|
||||||
curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
|
http_trace_curl_no_data();
|
||||||
setup_curl_trace(result);
|
setup_curl_trace(result);
|
||||||
if (getenv("GIT_TRACE_CURL_NO_DATA"))
|
if (getenv("GIT_TRACE_CURL_NO_DATA"))
|
||||||
trace_curl_data = 0;
|
trace_curl_data = 0;
|
||||||
|
|
7
http.h
7
http.h
|
@ -252,6 +252,13 @@ int finish_http_object_request(struct http_object_request *freq);
|
||||||
void abort_http_object_request(struct http_object_request *freq);
|
void abort_http_object_request(struct http_object_request *freq);
|
||||||
void release_http_object_request(struct http_object_request *freq);
|
void release_http_object_request(struct http_object_request *freq);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Instead of using environment variables to determine if curl tracing happens,
|
||||||
|
* behave as if GIT_TRACE_CURL=1 and GIT_TRACE_CURL_NO_DATA=1 is set. Call this
|
||||||
|
* before calling setup_curl_trace().
|
||||||
|
*/
|
||||||
|
void http_trace_curl_no_data(void);
|
||||||
|
|
||||||
/* setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */
|
/* setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */
|
||||||
void setup_curl_trace(CURL *handle);
|
void setup_curl_trace(CURL *handle);
|
||||||
#endif /* HTTP_H */
|
#endif /* HTTP_H */
|
||||||
|
|
|
@ -1464,7 +1464,7 @@ static CURL *setup_curl(struct imap_server_conf *srvc, struct credential *cred)
|
||||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||||
|
|
||||||
if (0 < verbosity || getenv("GIT_CURL_VERBOSE"))
|
if (0 < verbosity || getenv("GIT_CURL_VERBOSE"))
|
||||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
http_trace_curl_no_data();
|
||||||
setup_curl_trace(curl);
|
setup_curl_trace(curl);
|
||||||
|
|
||||||
return curl;
|
return curl;
|
||||||
|
|
|
@ -185,6 +185,30 @@ test_expect_success 'redirects send auth to new location' '
|
||||||
expect_askpass both user@host auth/smart/repo.git
|
expect_askpass both user@host auth/smart/repo.git
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'GIT_TRACE_CURL redacts auth details' '
|
||||||
|
rm -rf redact-auth trace &&
|
||||||
|
set_askpass user@host pass@host &&
|
||||||
|
GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
|
||||||
|
expect_askpass both user@host &&
|
||||||
|
|
||||||
|
# Ensure that there is no "Basic" followed by a base64 string, but that
|
||||||
|
# the auth details are redacted
|
||||||
|
! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
|
||||||
|
grep "Authorization: Basic <redacted>" trace
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'GIT_CURL_VERBOSE redacts auth details' '
|
||||||
|
rm -rf redact-auth trace &&
|
||||||
|
set_askpass user@host pass@host &&
|
||||||
|
GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace &&
|
||||||
|
expect_askpass both user@host &&
|
||||||
|
|
||||||
|
# Ensure that there is no "Basic" followed by a base64 string, but that
|
||||||
|
# the auth details are redacted
|
||||||
|
! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
|
||||||
|
grep "Authorization: Basic <redacted>" trace
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'disable dumb http on server' '
|
test_expect_success 'disable dumb http on server' '
|
||||||
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
|
||||||
config http.getanyfile false
|
config http.getanyfile false
|
||||||
|
@ -442,6 +466,18 @@ test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
|
||||||
! grep "Cookie:.*Bar=2" err
|
! grep "Cookie:.*Bar=2" err
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'GIT_REDACT_COOKIES redacts cookies when GIT_CURL_VERBOSE=1' '
|
||||||
|
rm -rf clone &&
|
||||||
|
echo "Set-Cookie: Foo=1" >cookies &&
|
||||||
|
echo "Set-Cookie: Bar=2" >>cookies &&
|
||||||
|
GIT_CURL_VERBOSE=1 GIT_REDACT_COOKIES=Bar,Baz \
|
||||||
|
git -c "http.cookieFile=$(pwd)/cookies" clone \
|
||||||
|
$HTTPD_URL/smart/repo.git clone 2>err &&
|
||||||
|
grep "Cookie:.*Foo=1" err &&
|
||||||
|
grep "Cookie:.*Bar=<redacted>" err &&
|
||||||
|
! grep "Cookie:.*Bar=2" err
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
|
test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
|
||||||
rm -rf clone &&
|
rm -rf clone &&
|
||||||
echo "Set-Cookie: Foo=" >cookies &&
|
echo "Set-Cookie: Foo=" >cookies &&
|
||||||
|
|
|
@ -20,7 +20,7 @@ test_expect_success 'failure in git-upload-pack is shown' '
|
||||||
test_might_fail env GIT_CURL_VERBOSE=1 \
|
test_might_fail env GIT_CURL_VERBOSE=1 \
|
||||||
git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \
|
git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \
|
||||||
2>curl_log &&
|
2>curl_log &&
|
||||||
grep "< HTTP/1.1 500 Intentional Breakage" curl_log
|
grep "<= Recv header: HTTP/1.1 500 Intentional Breakage" curl_log
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
20
trace.c
20
trace.c
|
@ -29,7 +29,7 @@ struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);
|
||||||
struct trace_key trace_setup_key = TRACE_KEY_INIT(SETUP);
|
struct trace_key trace_setup_key = TRACE_KEY_INIT(SETUP);
|
||||||
|
|
||||||
/* Get a trace file descriptor from "key" env variable. */
|
/* Get a trace file descriptor from "key" env variable. */
|
||||||
static int get_trace_fd(struct trace_key *key)
|
static int get_trace_fd(struct trace_key *key, const char *override_envvar)
|
||||||
{
|
{
|
||||||
const char *trace;
|
const char *trace;
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ static int get_trace_fd(struct trace_key *key)
|
||||||
if (key->initialized)
|
if (key->initialized)
|
||||||
return key->fd;
|
return key->fd;
|
||||||
|
|
||||||
trace = getenv(key->key);
|
trace = override_envvar ? override_envvar : getenv(key->key);
|
||||||
|
|
||||||
if (!trace || !strcmp(trace, "") ||
|
if (!trace || !strcmp(trace, "") ||
|
||||||
!strcmp(trace, "0") || !strcasecmp(trace, "false"))
|
!strcmp(trace, "0") || !strcasecmp(trace, "false"))
|
||||||
|
@ -68,6 +68,18 @@ static int get_trace_fd(struct trace_key *key)
|
||||||
return key->fd;
|
return key->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trace_override_envvar(struct trace_key *key, const char *value)
|
||||||
|
{
|
||||||
|
trace_disable(key);
|
||||||
|
key->initialized = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Invoke get_trace_fd() to initialize key using the given value
|
||||||
|
* instead of the value of the environment variable.
|
||||||
|
*/
|
||||||
|
get_trace_fd(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
void trace_disable(struct trace_key *key)
|
void trace_disable(struct trace_key *key)
|
||||||
{
|
{
|
||||||
if (key->need_close)
|
if (key->need_close)
|
||||||
|
@ -112,7 +124,7 @@ static int prepare_trace_line(const char *file, int line,
|
||||||
|
|
||||||
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
|
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
|
||||||
{
|
{
|
||||||
if (write_in_full(get_trace_fd(key), buf, len) < 0) {
|
if (write_in_full(get_trace_fd(key, NULL), buf, len) < 0) {
|
||||||
warning("unable to write trace for %s: %s",
|
warning("unable to write trace for %s: %s",
|
||||||
key->key, strerror(errno));
|
key->key, strerror(errno));
|
||||||
trace_disable(key);
|
trace_disable(key);
|
||||||
|
@ -383,7 +395,7 @@ void trace_repo_setup(const char *prefix)
|
||||||
|
|
||||||
int trace_want(struct trace_key *key)
|
int trace_want(struct trace_key *key)
|
||||||
{
|
{
|
||||||
return !!get_trace_fd(key);
|
return !!get_trace_fd(key, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
|
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
|
||||||
|
|
6
trace.h
6
trace.h
|
@ -101,6 +101,12 @@ void trace_repo_setup(const char *prefix);
|
||||||
*/
|
*/
|
||||||
int trace_want(struct trace_key *key);
|
int trace_want(struct trace_key *key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables or disables tracing for the specified key, as if the environment
|
||||||
|
* variable was set to the given value.
|
||||||
|
*/
|
||||||
|
void trace_override_envvar(struct trace_key *key, const char *value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disables tracing for the specified key, even if the environment variable
|
* Disables tracing for the specified key, even if the environment variable
|
||||||
* was set.
|
* was set.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче