Skip to content

Commit

Permalink
fix http auth with multiple curl handles
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Apr 10, 2012
1 parent 5a9681f commit dfa1725
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ struct active_request_slot *get_active_slot(void)
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, NULL);
curl_easy_setopt(slot->curl, CURLOPT_UPLOAD, 0);
curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
if (http_auth.password)
init_curl_http_auth(slot->curl);

return slot;
}
Expand Down
10 changes: 5 additions & 5 deletions t/t5550-http-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ test_expect_success 'http auth can use user/pass in URL' '
expect_askpass none
'

test_expect_failure 'http auth can use just user in URL' '
test_expect_success 'http auth can use just user in URL' '
>askpass-query &&
echo user@host >askpass-response &&
git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
expect_askpass pass user@host
'

test_expect_failure 'http auth can request both user and pass' '
test_expect_success 'http auth can request both user and pass' '
>askpass-query &&
echo user@host >askpass-response &&
git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
expect_askpass both user@host
'

test_expect_failure 'http auth respects credential helper config' '
test_expect_success 'http auth respects credential helper config' '
test_config_global credential.helper "!f() {
cat >/dev/null
echo username=user@host
Expand All @@ -118,15 +118,15 @@ test_expect_failure 'http auth respects credential helper config' '
expect_askpass none
'

test_expect_failure 'http auth can get username from config' '
test_expect_success 'http auth can get username from config' '
test_config_global "credential.$HTTPD_URL.username" user@host &&
>askpass-query &&
echo user@host >askpass-response &&
git clone "$HTTPD_URL/auth/repo.git" clone-auth-user &&
expect_askpass pass user@host
'

test_expect_failure 'configured username does not override URL' '
test_expect_success 'configured username does not override URL' '
test_config_global "credential.$HTTPD_URL.username" wrong &&
>askpass-query &&
echo user@host >askpass-response &&
Expand Down

0 comments on commit dfa1725

Please sign in to comment.