Skip to content

Commit dfa1725

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a9681f commit dfa1725

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

http.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ struct active_request_slot *get_active_slot(void)
494494
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
495495
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
496496
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
497+
if (http_auth.password)
498+
init_curl_http_auth(slot->curl);
497499

498500
return slot;
499501
}

t/t5550-http-fetch.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,21 @@ test_expect_success 'http auth can use user/pass in URL' '
9292
expect_askpass none
9393
'
9494

95-
test_expect_failure 'http auth can use just user in URL' '
95+
test_expect_success 'http auth can use just user in URL' '
9696
>askpass-query &&
9797
echo user@host >askpass-response &&
9898
git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
9999
expect_askpass pass user@host
100100
'
101101

102-
test_expect_failure 'http auth can request both user and pass' '
102+
test_expect_success 'http auth can request both user and pass' '
103103
>askpass-query &&
104104
echo user@host >askpass-response &&
105105
git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
106106
expect_askpass both user@host
107107
'
108108

109-
test_expect_failure 'http auth respects credential helper config' '
109+
test_expect_success 'http auth respects credential helper config' '
110110
test_config_global credential.helper "!f() {
111111
cat >/dev/null
112112
echo username=user@host
@@ -118,15 +118,15 @@ test_expect_failure 'http auth respects credential helper config' '
118118
expect_askpass none
119119
'
120120

121-
test_expect_failure 'http auth can get username from config' '
121+
test_expect_success 'http auth can get username from config' '
122122
test_config_global "credential.$HTTPD_URL.username" user@host &&
123123
>askpass-query &&
124124
echo user@host >askpass-response &&
125125
git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
126126
expect_askpass pass user@host
127127
'
128128

129-
test_expect_failure 'configured username does not override URL' '
129+
test_expect_success 'configured username does not override URL' '
130130
test_config_global "credential.$HTTPD_URL.username" wrong &&
131131
>askpass-query &&
132132
echo user@host >askpass-response &&

0 commit comments

Comments
 (0)