Skip to content

Commit f1c12e1

Browse files
committed
Merge branch 'jk/maint-push-over-dav' into maint
* jk/maint-push-over-dav: http-push: enable "proactive auth" t5540: test DAV push with authentication
2 parents 699eb54 + a4ddbc3 commit f1c12e1

File tree

7 files changed

+49
-5
lines changed

7 files changed

+49
-5
lines changed

http-fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(int argc, const char **argv)
6767

6868
git_config(git_default_config, NULL);
6969

70-
http_init(NULL, url);
70+
http_init(NULL, url, 0);
7171
walker = get_http_walker(url);
7272
walker->get_tree = get_tree;
7373
walker->get_history = get_history;

http-push.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ int main(int argc, char **argv)
18201820

18211821
memset(remote_dir_exists, -1, 256);
18221822

1823-
http_init(NULL, repo->url);
1823+
http_init(NULL, repo->url, 1);
18241824

18251825
#ifdef USE_CURL_MULTI
18261826
is_running_queue = 0;

http.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ static int curl_ftp_no_epsv;
4242
static const char *curl_http_proxy;
4343
static const char *curl_cookie_file;
4444
static char *user_name, *user_pass, *description;
45+
static int http_proactive_auth;
4546
static const char *user_agent;
4647

4748
#if LIBCURL_VERSION_NUM >= 0x071700
@@ -276,6 +277,9 @@ static CURL *get_curl_handle(void)
276277
curl_easy_setopt(result, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
277278
#endif
278279

280+
if (http_proactive_auth)
281+
init_curl_http_auth(result);
282+
279283
if (ssl_cert != NULL)
280284
curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert);
281285
if (has_cert_password())
@@ -364,7 +368,7 @@ static void set_from_env(const char **var, const char *envname)
364368
*var = val;
365369
}
366370

367-
void http_init(struct remote *remote, const char *url)
371+
void http_init(struct remote *remote, const char *url, int proactive_auth)
368372
{
369373
char *low_speed_limit;
370374
char *low_speed_time;
@@ -375,6 +379,8 @@ void http_init(struct remote *remote, const char *url)
375379

376380
curl_global_init(CURL_GLOBAL_ALL);
377381

382+
http_proactive_auth = proactive_auth;
383+
378384
if (remote && remote->http_proxy)
379385
curl_http_proxy = xstrdup(remote->http_proxy);
380386

http.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ extern void add_fill_function(void *data, int (*fill)(void *));
8585
extern void step_active_slots(void);
8686
#endif
8787

88-
extern void http_init(struct remote *remote, const char *url);
88+
extern void http_init(struct remote *remote, const char *url,
89+
int proactive_auth);
8990
extern void http_cleanup(void);
9091

9192
extern int active_requests;

remote-curl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ int main(int argc, const char **argv)
859859

860860
url = strbuf_detach(&buf, NULL);
861861

862-
http_init(remote, url);
862+
http_init(remote, url, 0);
863863

864864
do {
865865
if (strbuf_getline(&buf, stdin, '\n') == EOF) {

t/lib-httpd/apache.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ SSLEngine On
9292
<Location /dumb/>
9393
Dav on
9494
</Location>
95+
<Location /auth/dumb>
96+
Dav on
97+
</Location>
9598
</IfDefine>
9699

97100
<IfDefine SVN>

t/t5540-http-push.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ test_expect_success 'setup remote repository' '
4040
mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
4141
'
4242

43+
test_expect_success 'create password-protected repository' '
44+
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
45+
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
46+
"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
47+
'
48+
49+
test_expect_success 'setup askpass helper' '
50+
cat >askpass <<-\EOF &&
51+
#!/bin/sh
52+
echo user@host
53+
EOF
54+
chmod +x askpass &&
55+
GIT_ASKPASS="$PWD/askpass" &&
56+
export GIT_ASKPASS
57+
'
58+
4359
test_expect_success 'clone remote repository' '
4460
cd "$ROOT_PATH" &&
4561
git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
@@ -144,6 +160,24 @@ test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
144160
test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
145161
"$ROOT_PATH"/test_repo_clone master
146162

163+
test_expect_success 'push to password-protected repository (user in URL)' '
164+
test_commit pw-user &&
165+
git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
166+
git rev-parse --verify HEAD >expect &&
167+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
168+
rev-parse --verify HEAD >actual &&
169+
test_cmp expect actual
170+
'
171+
172+
test_expect_failure 'push to password-protected repository (no user in URL)' '
173+
test_commit pw-nouser &&
174+
git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
175+
git rev-parse --verify HEAD >expect &&
176+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
177+
rev-parse --verify HEAD >actual &&
178+
test_cmp expect actual
179+
'
180+
147181
stop_httpd
148182

149183
test_done

0 commit comments

Comments
 (0)