t: test http access to "half-auth" repositories
authorJeff King <peff@peff.net>
Mon, 27 Aug 2012 13:25:53 +0000 (09:25 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Aug 2012 17:49:09 +0000 (10:49 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/lib-httpd/apache.conf
t/t5541-http-push.sh
t/t5551-http-fetch.sh

index 616486f9ea60ac8b7c53be0036f321497ba787dc..ec8618dfde3b106c79f1d056bc0ed085075fc8c8 100644 (file)
@@ -89,6 +89,13 @@ SSLEngine On
        Require valid-user
 </Location>
 
+<LocationMatch "^/auth-push/.*/git-receive-pack$">
+       AuthType Basic
+       AuthName "git-auth"
+       AuthUserFile passwd
+       Require valid-user
+</LocationMatch>
+
 <IfDefine DAV>
        LoadModule dav_module modules/mod_dav.so
        LoadModule dav_fs_module modules/mod_dav_fs.so
index eeb993203f65c39d9e0bf265a1be317ab6a37e07..9b1cd603c6d23826e8e299ac5b220583abf53092 100755 (executable)
@@ -280,5 +280,17 @@ test_expect_success 'push over smart http with auth' '
        test_cmp expect actual
 '
 
+test_expect_failure 'push to auth-only-for-push repo' '
+       cd "$ROOT_PATH/test_repo_clone" &&
+       echo push-half-auth >expect &&
+       test_commit push-half-auth &&
+       set_askpass user@host &&
+       git push "$HTTPD_URL"/auth-push/smart/test_repo.git &&
+       git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
+               log -1 --format=%s >actual &&
+       expect_askpass both user@host &&
+       test_cmp expect actual
+'
+
 stop_httpd
 test_done
index 342d6af86115913c92316da09b10e105b81fe96c..7380f2a2dd3f22d65a10389d8197af94f9ea4123 100755 (executable)
@@ -120,6 +120,15 @@ test_expect_success 'clone from password-protected repository' '
        test_cmp expect actual
 '
 
+test_expect_success 'clone from auth-only-for-push repository' '
+       echo two >expect &&
+       set_askpass wrong &&
+       git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
+       expect_askpass none &&
+       git --git-dir=smart-noauth log -1 --format=%s >actual &&
+       test_cmp expect actual
+'
+
 test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
 
 test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '