blob: 1a3a2b6c1a20558a019143d1abbd2168af0caf53 [file] [log] [blame]
Jeff King119c8ee2009-02-25 03:32:09 -05001#!/bin/sh
2
Shawn O. Pearce7da4e222009-10-30 17:47:47 -07003test_description='test dumb fetching over http via static file'
Jeff King119c8ee2009-02-25 03:32:09 -05004. ./test-lib.sh
5
6if test -n "$NO_CURL"; then
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +00007 skip_all='skipping test, git built without http support'
Jeff King119c8ee2009-02-25 03:32:09 -05008 test_done
9fi
10
Clemens Buchacher55bc3dc2011-10-17 21:55:47 +020011. "$TEST_DIRECTORY"/lib-httpd.sh
Jeff King119c8ee2009-02-25 03:32:09 -050012start_httpd
13
14test_expect_success 'setup repository' '
Brian Gernhardtc9704aa2013-01-15 21:05:06 -050015 git config push.default matching &&
Clemens Buchacher5a9681f2012-04-10 11:53:39 +020016 echo content1 >file &&
Jeff King119c8ee2009-02-25 03:32:09 -050017 git add file &&
18 git commit -m one
Clemens Buchacher5a9681f2012-04-10 11:53:39 +020019 echo content2 >file &&
20 git add file &&
21 git commit -m two
Jeff King119c8ee2009-02-25 03:32:09 -050022'
23
Clemens Buchacher5a9681f2012-04-10 11:53:39 +020024test_expect_success 'create http-accessible bare repository with loose objects' '
Ben Waltond4a7ffa2012-10-08 09:08:01 +010025 cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
Jeff King119c8ee2009-02-25 03:32:09 -050026 (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
Clemens Buchacher5a9681f2012-04-10 11:53:39 +020027 git config core.bare true &&
28 mkdir -p hooks &&
Jeff King119c8ee2009-02-25 03:32:09 -050029 echo "exec git update-server-info" >hooks/post-update &&
Clemens Buchacher5a9681f2012-04-10 11:53:39 +020030 chmod +x hooks/post-update &&
31 hooks/post-update
Jeff King119c8ee2009-02-25 03:32:09 -050032 ) &&
33 git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
34 git push public master:master
35'
36
37test_expect_success 'clone http repository' '
Tay Ray Chuan6cfc0282010-11-25 16:21:03 +080038 git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
39 cp -R clone-tmpl clone &&
Jeff King119c8ee2009-02-25 03:32:09 -050040 test_cmp file clone/file
41'
42
Jeff King52325862011-07-18 03:49:12 -040043test_expect_success 'create password-protected repository' '
Jeff King726800a2012-08-27 09:23:37 -040044 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
Jeff King52325862011-07-18 03:49:12 -040045 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
Jeff King726800a2012-08-27 09:23:37 -040046 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
Jeff King52325862011-07-18 03:49:12 -040047'
48
Jeff Kinge8379362012-08-27 09:24:31 -040049setup_askpass_helper
Jeff King148bb6a2011-12-10 05:31:21 -050050
Jeff King52325862011-07-18 03:49:12 -040051test_expect_success 'cloning password-protected repository can fail' '
Jeff Kinge8379362012-08-27 09:24:31 -040052 set_askpass wrong &&
Jeff King726800a2012-08-27 09:23:37 -040053 test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
Jeff King148bb6a2011-12-10 05:31:21 -050054 expect_askpass both wrong
Jeff King52325862011-07-18 03:49:12 -040055'
56
57test_expect_success 'http auth can use user/pass in URL' '
Jeff Kinge8379362012-08-27 09:24:31 -040058 set_askpass wrong &&
Jeff King726800a2012-08-27 09:23:37 -040059 git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
Jeff King148bb6a2011-12-10 05:31:21 -050060 expect_askpass none
Jeff King52325862011-07-18 03:49:12 -040061'
62
Jeff Kingdfa17252012-04-10 11:53:40 +020063test_expect_success 'http auth can use just user in URL' '
Jeff Kingafbf5ca2014-01-02 02:38:35 -050064 set_askpass wrong pass@host &&
Jeff King726800a2012-08-27 09:23:37 -040065 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
Jeff King148bb6a2011-12-10 05:31:21 -050066 expect_askpass pass user@host
Jeff King52325862011-07-18 03:49:12 -040067'
68
Jeff Kingdfa17252012-04-10 11:53:40 +020069test_expect_success 'http auth can request both user and pass' '
Jeff Kingafbf5ca2014-01-02 02:38:35 -050070 set_askpass user@host pass@host &&
Jeff King726800a2012-08-27 09:23:37 -040071 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
Jeff King148bb6a2011-12-10 05:31:21 -050072 expect_askpass both user@host
Gabriel Corona3cf8fe12010-11-14 02:51:14 +010073'
74
Jeff Kingdfa17252012-04-10 11:53:40 +020075test_expect_success 'http auth respects credential helper config' '
Jeff King11825072011-12-10 05:31:24 -050076 test_config_global credential.helper "!f() {
77 cat >/dev/null
78 echo username=user@host
Jeff Kingafbf5ca2014-01-02 02:38:35 -050079 echo password=pass@host
Jeff King11825072011-12-10 05:31:24 -050080 }; f" &&
Jeff Kinge8379362012-08-27 09:24:31 -040081 set_askpass wrong &&
Jeff King726800a2012-08-27 09:23:37 -040082 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
Jeff King11825072011-12-10 05:31:24 -050083 expect_askpass none
84'
85
Jeff Kingdfa17252012-04-10 11:53:40 +020086test_expect_success 'http auth can get username from config' '
Jeff Kingd5742422011-12-10 05:31:30 -050087 test_config_global "credential.$HTTPD_URL.username" user@host &&
Jeff Kingafbf5ca2014-01-02 02:38:35 -050088 set_askpass wrong pass@host &&
Jeff King726800a2012-08-27 09:23:37 -040089 git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
Jeff Kingd5742422011-12-10 05:31:30 -050090 expect_askpass pass user@host
91'
92
Jeff Kingdfa17252012-04-10 11:53:40 +020093test_expect_success 'configured username does not override URL' '
Jeff Kingd5742422011-12-10 05:31:30 -050094 test_config_global "credential.$HTTPD_URL.username" wrong &&
Jeff Kingafbf5ca2014-01-02 02:38:35 -050095 set_askpass wrong pass@host &&
Jeff King726800a2012-08-27 09:23:37 -040096 git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
Jeff Kingd5742422011-12-10 05:31:30 -050097 expect_askpass pass user@host
98'
99
Jeff King119c8ee2009-02-25 03:32:09 -0500100test_expect_success 'fetch changes via http' '
101 echo content >>file &&
102 git commit -a -m two &&
Tay Ray Chuan2bcd9ec2010-11-25 16:21:02 +0800103 git push public &&
Jeff King119c8ee2009-02-25 03:32:09 -0500104 (cd clone && git pull) &&
105 test_cmp file clone/file
106'
107
Tay Ray Chuan6cfc0282010-11-25 16:21:03 +0800108test_expect_success 'fetch changes via manual http-fetch' '
109 cp -R clone-tmpl clone2 &&
110
111 HEAD=$(git rev-parse --verify HEAD) &&
112 (cd clone2 &&
113 git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
114 git checkout master-new &&
115 test $HEAD = $(git rev-parse --verify HEAD)) &&
116 test_cmp file clone2/file
117'
118
Jeff Kingfbb074c2009-02-27 14:10:06 -0500119test_expect_success 'http remote detects correct HEAD' '
120 git push public master:other &&
121 (cd clone &&
122 git remote set-head origin -d &&
123 git remote set-head origin -a &&
124 git symbolic-ref refs/remotes/origin/HEAD > output &&
125 echo refs/remotes/origin/master > expect &&
126 test_cmp expect output
127 )
128'
129
Tay Ray Chuan96a4f182009-06-06 16:43:32 +0800130test_expect_success 'fetch packed objects' '
131 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
Shawn O. Pearced761b2a2010-04-17 13:07:35 -0700132 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
Clemens Buchacher1327d832012-01-04 16:55:34 +0100133 git --bare repack -a -d
Shawn O. Pearced761b2a2010-04-17 13:07:35 -0700134 ) &&
Shawn O. Pearce024bb122009-10-30 17:47:46 -0700135 git clone $HTTPD_URL/dumb/repo_pack.git
Tay Ray Chuan96a4f182009-06-06 16:43:32 +0800136'
137
Shawn O. Pearcefe72d422010-04-19 07:23:09 -0700138test_expect_success 'fetch notices corrupt pack' '
139 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
140 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
141 p=`ls objects/pack/pack-*.pack` &&
142 chmod u+w $p &&
143 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
144 ) &&
145 mkdir repo_bad1.git &&
146 (cd repo_bad1.git &&
147 git --bare init &&
148 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
149 test 0 = `ls objects/pack/pack-*.pack | wc -l`
150 )
151'
152
Shawn O. Pearce750ef422010-04-19 07:23:10 -0700153test_expect_success 'fetch notices corrupt idx' '
154 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
155 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
156 p=`ls objects/pack/pack-*.idx` &&
157 chmod u+w $p &&
158 printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
159 ) &&
160 mkdir repo_bad2.git &&
161 (cd repo_bad2.git &&
162 git --bare init &&
163 test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
164 test 0 = `ls objects/pack | wc -l`
165 )
166'
167
Shawn O. Pearce7da4e222009-10-30 17:47:47 -0700168test_expect_success 'did not use upload-pack service' '
169 grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
170 : >exp
171 test_cmp exp act
172'
173
Jeff King119c8ee2009-02-25 03:32:09 -0500174stop_httpd
175test_done