Skip to content

Commit 4c71009

Browse files
peffgitster
authored andcommitted
t: test http access to "half-auth" repositories
Some sites set up http access to repositories such that fetching is anonymous and unauthenticated, but pushing is authenticated. While there are multiple ways to do this, the technique advertised in the git-http-backend manpage is to block access to locations matching "/git-receive-pack$". Let's emulate that advice in our test setup, which makes it clear that this advice does not actually work. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ac2b3a commit 4c71009

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

t/lib-httpd/apache.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ SSLEngine On
8989
Require valid-user
9090
</Location>
9191

92+
<LocationMatch "^/auth-push/.*/git-receive-pack$">
93+
AuthType Basic
94+
AuthName "git-auth"
95+
AuthUserFile passwd
96+
Require valid-user
97+
</LocationMatch>
98+
9299
<IfDefine DAV>
93100
LoadModule dav_module modules/mod_dav.so
94101
LoadModule dav_fs_module modules/mod_dav_fs.so

t/t5541-http-push.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,5 +280,17 @@ test_expect_success 'push over smart http with auth' '
280280
test_cmp expect actual
281281
'
282282

283+
test_expect_failure 'push to auth-only-for-push repo' '
284+
cd "$ROOT_PATH/test_repo_clone" &&
285+
echo push-half-auth >expect &&
286+
test_commit push-half-auth &&
287+
set_askpass user@host &&
288+
git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
289+
git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
290+
log -1 --format=%s >actual &&
291+
expect_askpass both user@host &&
292+
test_cmp expect actual
293+
'
294+
283295
stop_httpd
284296
test_done

t/t5551-http-fetch.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ test_expect_success 'clone from password-protected repository' '
120120
test_cmp expect actual
121121
'
122122

123+
test_expect_success 'clone from auth-only-for-push repository' '
124+
echo two >expect &&
125+
set_askpass wrong &&
126+
git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
127+
expect_askpass none &&
128+
git --git-dir=smart-noauth log -1 --format=%s >actual &&
129+
test_cmp expect actual
130+
'
131+
123132
test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
124133

125134
test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '

0 commit comments

Comments
 (0)