Skip to content

Commit 187b259

Browse files
committed
Merge branch 'gc/http-with-non-ascii-username-url' into maint
* gc/http-with-non-ascii-username-url: Fix username and password extraction from HTTP URLs t5550: test HTTP authentication and userinfo decoding Conflicts: t/lib-httpd/apache.conf
2 parents c6d059b + f39f72d commit 187b259

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

http.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "pack.h"
33
#include "sideband.h"
44
#include "run-command.h"
5+
#include "url.h"
56

67
int data_received;
78
int active_requests;
@@ -302,7 +303,7 @@ static CURL *get_curl_handle(void)
302303

303304
static void http_auth_init(const char *url)
304305
{
305-
char *at, *colon, *cp, *slash;
306+
char *at, *colon, *cp, *slash, *decoded;
306307
int len;
307308

308309
cp = strstr(url, "://");
@@ -327,16 +328,25 @@ static void http_auth_init(const char *url)
327328
user_name = xmalloc(len + 1);
328329
memcpy(user_name, cp, len);
329330
user_name[len] = '\0';
331+
decoded = url_decode(user_name);
332+
free(user_name);
333+
user_name = decoded;
330334
user_pass = NULL;
331335
} else {
332336
len = colon - cp;
333337
user_name = xmalloc(len + 1);
334338
memcpy(user_name, cp, len);
335339
user_name[len] = '\0';
340+
decoded = url_decode(user_name);
341+
free(user_name);
342+
user_name = decoded;
336343
len = at - (colon + 1);
337344
user_pass = xmalloc(len + 1);
338345
memcpy(user_pass, colon + 1, len);
339346
user_pass[len] = '\0';
347+
decoded = url_decode(user_pass);
348+
free(user_pass);
349+
user_pass = decoded;
340350
}
341351
}
342352

t/lib-httpd.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ fi
7575

7676
prepare_httpd() {
7777
mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
78+
cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
7879

7980
ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
8081

8182
if test -n "$LIB_HTTPD_SSL"
8283
then
8384
HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
85+
AUTH_HTTPD_URL=https://user%40host:user%[email protected]:$LIB_HTTPD_PORT
8486

8587
RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
8688
-config "$TEST_PATH/ssl.cnf" \
@@ -92,6 +94,7 @@ prepare_httpd() {
9294
HTTPD_PARA="$HTTPD_PARA -DSSL"
9395
else
9496
HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
97+
AUTH_HTTPD_URL=http://user%40host:user%[email protected]:$LIB_HTTPD_PORT
9598
fi
9699

97100
if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"

t/lib-httpd/apache.conf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,30 @@ ErrorLog error.log
2020
<IfModule !mod_rewrite.c>
2121
LoadModule rewrite_module modules/mod_rewrite.so
2222
</IFModule>
23+
<IfModule !mod_version.c>
24+
LoadModule version_module modules/mod_version.so
25+
</IfModule>
26+
27+
<IfVersion < 2.1>
28+
<IfModule !mod_auth.c>
29+
LoadModule auth_module modules/mod_auth.so
30+
</IfModule>
31+
</IfVersion>
32+
33+
<IfVersion >= 2.1>
34+
<IfModule !mod_auth_basic.c>
35+
LoadModule auth_basic_module modules/mod_auth_basic.so
36+
</IfModule>
37+
<IfModule !mod_authn_file.c>
38+
LoadModule authn_file_module modules/mod_authn_file.so
39+
</IfModule>
40+
<IfModule !mod_authz_user.c>
41+
LoadModule authz_user_module modules/mod_authz_user.so
42+
</IfModule>
43+
</IfVersion>
2344

2445
Alias /dumb/ www/
46+
Alias /auth/ www/auth/
2547

2648
<Location /smart/>
2749
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
@@ -55,6 +77,13 @@ SSLMutex file:ssl_mutex
5577
SSLEngine On
5678
</IfDefine>
5779

80+
<Location /auth/>
81+
AuthType Basic
82+
AuthName "git-auth"
83+
AuthUserFile passwd
84+
Require valid-user
85+
</Location>
86+
5887
<IfDefine DAV>
5988
LoadModule dav_module modules/mod_dav.so
6089
LoadModule dav_fs_module modules/mod_dav_fs.so

t/lib-httpd/passwd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
user@host:nKpa8pZUHx/ic

t/t5550-http-fetch.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ test_expect_success 'clone http repository' '
3434
test_cmp file clone/file
3535
'
3636

37+
test_expect_success 'clone http repository with authentication' '
38+
mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
39+
cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" &&
40+
git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth &&
41+
test_cmp file clone-auth/file
42+
'
43+
3744
test_expect_success 'fetch changes via http' '
3845
echo content >>file &&
3946
git commit -a -m two &&

0 commit comments

Comments
 (0)