Skip to content

Commit 3cf8fe1

Browse files
Gabriel Coronagitster
authored andcommitted
t5550: test HTTP authentication and userinfo decoding
Add a test for HTTP authentication and proper percent-decoding of the userinfo (username and password) part of the URL. Signed-off-by: Gabriel Corona <[email protected]> Acked-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f772c34 commit 3cf8fe1

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

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
@@ -17,8 +17,30 @@ ErrorLog error.log
1717
<IfModule !mod_env.c>
1818
LoadModule env_module modules/mod_env.so
1919
</IfModule>
20+
<IfModule !mod_version.c>
21+
LoadModule version_module modules/mod_version.so
22+
</IfModule>
23+
24+
<IfVersion < 2.1>
25+
<IfModule !mod_auth.c>
26+
LoadModule auth_module modules/mod_auth.so
27+
</IfModule>
28+
</IfVersion>
29+
30+
<IfVersion >= 2.1>
31+
<IfModule !mod_auth_basic.c>
32+
LoadModule auth_basic_module modules/mod_auth_basic.so
33+
</IfModule>
34+
<IfModule !mod_authn_file.c>
35+
LoadModule authn_file_module modules/mod_authn_file.so
36+
</IfModule>
37+
<IfModule !mod_authz_user.c>
38+
LoadModule authz_user_module modules/mod_authz_user.so
39+
</IfModule>
40+
</IfVersion>
2041

2142
Alias /dumb/ www/
43+
Alias /auth/ www/auth/
2244

2345
<Location /smart/>
2446
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
@@ -48,6 +70,13 @@ SSLMutex file:ssl_mutex
4870
SSLEngine On
4971
</IfDefine>
5072

73+
<Location /auth/>
74+
AuthType Basic
75+
AuthName "git-auth"
76+
AuthUserFile passwd
77+
Require valid-user
78+
</Location>
79+
5180
<IfDefine DAV>
5281
LoadModule dav_module modules/mod_dav.so
5382
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_failure '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)