fix http auth with multiple curl handles
HTTP authentication is currently handled by get_refs and fetch_ref, but not by fetch_object, fetch_pack or fetch_alternates. In the single-threaded case, this is not an issue, since get_refs is always called first. It recognigzes the 401 and prompts the user for credentials, which will then be used subsequently. If the curl multi interface is used, however, only the multi handle used by get_refs will have credentials configured. Requests made by other handles fail with an authentication error. Fix this by setting CURLOPT_USERPWD whenever a slot is requested. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 10, 2012 at 11:53 UTC
dfa1725a3ec57098637b698ffc2b2e2459acc518
2 files changed
+7
-5
http.c
+2
@@ -494,6 +494,8 @@ struct active_request_slot *get_active_slot(void)
494
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
495
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
496
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
497
+ if (http_auth.password)
498
+ init_curl_http_auth(slot->curl);
499
500
return slot;
501
}
t/t5550-http-fetch.sh
+5
-5
@@ -92,21 +92,21 @@ test_expect_success 'http auth can use user/pass in URL' '
92
expect_askpass none
93
'
94
95
-test_expect_failure 'http auth can use just user in URL' '
95
+test_expect_success 'http auth can use just user in URL' '
96
>askpass-query &&
97
echo user@host >askpass-response &&
98
git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
99
expect_askpass pass user@host
100
'
101
102
-test_expect_failure 'http auth can request both user and pass' '
102
+test_expect_success 'http auth can request both user and pass' '
103
>askpass-query &&
104
echo user@host >askpass-response &&
105
git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
106
expect_askpass both user@host
107
'
108
109
-test_expect_failure 'http auth respects credential helper config' '
109
+test_expect_success 'http auth respects credential helper config' '
110
test_config_global credential.helper "!f() {
111
cat >/dev/null
112
echo username=user@host
@@ -118,7 +118,7 @@ test_expect_failure 'http auth respects credential helper config' '
118
expect_askpass none
119
'
120
121
-test_expect_failure 'http auth can get username from config' '
121
+test_expect_success 'http auth can get username from config' '
122
test_config_global "credential.$HTTPD_URL.username" user@host &&
123
>askpass-query &&
124
echo user@host >askpass-response &&
@@ -126,7 +126,7 @@ test_expect_failure 'http auth can get username from config' '
126
expect_askpass pass user@host
127
'
128
129
-test_expect_failure 'configured username does not override URL' '
129
+test_expect_success 'configured username does not override URL' '
130
test_config_global "credential.$HTTPD_URL.username" wrong &&
131
>askpass-query &&
132
echo user@host >askpass-response &&