Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 3 | test_description='test dumb fetching over http via static file' |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 4 | . ./test-lib.sh |
| 5 | |
| 6 | if test -n "$NO_CURL"; then |
Ævar Arnfjörð Bjarmason | fadb515 | 2010-06-24 17:44:48 +0000 | [diff] [blame] | 7 | skip_all='skipping test, git built without http support' |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 8 | test_done |
| 9 | fi |
| 10 | |
Clemens Buchacher | 55bc3dc | 2011-10-17 21:55:47 +0200 | [diff] [blame] | 11 | . "$TEST_DIRECTORY"/lib-httpd.sh |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 12 | start_httpd |
| 13 | |
| 14 | test_expect_success 'setup repository' ' |
Brian Gernhardt | c9704aa | 2013-01-15 21:05:06 -0500 | [diff] [blame] | 15 | git config push.default matching && |
Clemens Buchacher | 5a9681f | 2012-04-10 11:53:39 +0200 | [diff] [blame] | 16 | echo content1 >file && |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 17 | git add file && |
| 18 | git commit -m one |
Clemens Buchacher | 5a9681f | 2012-04-10 11:53:39 +0200 | [diff] [blame] | 19 | echo content2 >file && |
| 20 | git add file && |
| 21 | git commit -m two |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 22 | ' |
| 23 | |
Clemens Buchacher | 5a9681f | 2012-04-10 11:53:39 +0200 | [diff] [blame] | 24 | test_expect_success 'create http-accessible bare repository with loose objects' ' |
Ben Walton | d4a7ffa | 2012-10-08 09:08:01 +0100 | [diff] [blame] | 25 | cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 26 | (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && |
Clemens Buchacher | 5a9681f | 2012-04-10 11:53:39 +0200 | [diff] [blame] | 27 | git config core.bare true && |
| 28 | mkdir -p hooks && |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 29 | echo "exec git update-server-info" >hooks/post-update && |
Clemens Buchacher | 5a9681f | 2012-04-10 11:53:39 +0200 | [diff] [blame] | 30 | chmod +x hooks/post-update && |
| 31 | hooks/post-update |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 32 | ) && |
| 33 | git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && |
| 34 | git push public master:master |
| 35 | ' |
| 36 | |
| 37 | test_expect_success 'clone http repository' ' |
Tay Ray Chuan | 6cfc028 | 2010-11-25 16:21:03 +0800 | [diff] [blame] | 38 | git clone $HTTPD_URL/dumb/repo.git clone-tmpl && |
| 39 | cp -R clone-tmpl clone && |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 40 | test_cmp file clone/file |
| 41 | ' |
| 42 | |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 43 | test_expect_success 'create password-protected repository' ' |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 44 | mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" && |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 45 | cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 46 | "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 47 | ' |
| 48 | |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 49 | setup_askpass_helper |
Jeff King | 148bb6a | 2011-12-10 05:31:21 -0500 | [diff] [blame] | 50 | |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 51 | test_expect_success 'cloning password-protected repository can fail' ' |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 52 | set_askpass wrong && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 53 | test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail && |
Jeff King | 148bb6a | 2011-12-10 05:31:21 -0500 | [diff] [blame] | 54 | expect_askpass both wrong |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 55 | ' |
| 56 | |
| 57 | test_expect_success 'http auth can use user/pass in URL' ' |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 58 | set_askpass wrong && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 59 | git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none && |
Jeff King | 148bb6a | 2011-12-10 05:31:21 -0500 | [diff] [blame] | 60 | expect_askpass none |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 61 | ' |
| 62 | |
Jeff King | dfa1725 | 2012-04-10 11:53:40 +0200 | [diff] [blame] | 63 | test_expect_success 'http auth can use just user in URL' ' |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 64 | set_askpass wrong pass@host && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 65 | git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass && |
Jeff King | 148bb6a | 2011-12-10 05:31:21 -0500 | [diff] [blame] | 66 | expect_askpass pass user@host |
Jeff King | 5232586 | 2011-07-18 03:49:12 -0400 | [diff] [blame] | 67 | ' |
| 68 | |
Jeff King | dfa1725 | 2012-04-10 11:53:40 +0200 | [diff] [blame] | 69 | test_expect_success 'http auth can request both user and pass' ' |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 70 | set_askpass user@host pass@host && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 71 | git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both && |
Jeff King | 148bb6a | 2011-12-10 05:31:21 -0500 | [diff] [blame] | 72 | expect_askpass both user@host |
Gabriel Corona | 3cf8fe1 | 2010-11-14 02:51:14 +0100 | [diff] [blame] | 73 | ' |
| 74 | |
Jeff King | dfa1725 | 2012-04-10 11:53:40 +0200 | [diff] [blame] | 75 | test_expect_success 'http auth respects credential helper config' ' |
Jeff King | 1182507 | 2011-12-10 05:31:24 -0500 | [diff] [blame] | 76 | test_config_global credential.helper "!f() { |
| 77 | cat >/dev/null |
| 78 | echo username=user@host |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 79 | echo password=pass@host |
Jeff King | 1182507 | 2011-12-10 05:31:24 -0500 | [diff] [blame] | 80 | }; f" && |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 81 | set_askpass wrong && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 82 | git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper && |
Jeff King | 1182507 | 2011-12-10 05:31:24 -0500 | [diff] [blame] | 83 | expect_askpass none |
| 84 | ' |
| 85 | |
Jeff King | dfa1725 | 2012-04-10 11:53:40 +0200 | [diff] [blame] | 86 | test_expect_success 'http auth can get username from config' ' |
Jeff King | d574242 | 2011-12-10 05:31:30 -0500 | [diff] [blame] | 87 | test_config_global "credential.$HTTPD_URL.username" user@host && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 88 | set_askpass wrong pass@host && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 89 | git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user && |
Jeff King | d574242 | 2011-12-10 05:31:30 -0500 | [diff] [blame] | 90 | expect_askpass pass user@host |
| 91 | ' |
| 92 | |
Jeff King | dfa1725 | 2012-04-10 11:53:40 +0200 | [diff] [blame] | 93 | test_expect_success 'configured username does not override URL' ' |
Jeff King | d574242 | 2011-12-10 05:31:30 -0500 | [diff] [blame] | 94 | test_config_global "credential.$HTTPD_URL.username" wrong && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 95 | set_askpass wrong pass@host && |
Jeff King | 726800a | 2012-08-27 09:23:37 -0400 | [diff] [blame] | 96 | git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 && |
Jeff King | d574242 | 2011-12-10 05:31:30 -0500 | [diff] [blame] | 97 | expect_askpass pass user@host |
| 98 | ' |
| 99 | |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 100 | test_expect_success 'fetch changes via http' ' |
| 101 | echo content >>file && |
| 102 | git commit -a -m two && |
Tay Ray Chuan | 2bcd9ec | 2010-11-25 16:21:02 +0800 | [diff] [blame] | 103 | git push public && |
Jeff King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 104 | (cd clone && git pull) && |
| 105 | test_cmp file clone/file |
| 106 | ' |
| 107 | |
Tay Ray Chuan | 6cfc028 | 2010-11-25 16:21:03 +0800 | [diff] [blame] | 108 | test_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 King | fbb074c | 2009-02-27 14:10:06 -0500 | [diff] [blame] | 119 | test_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 Chuan | 96a4f18 | 2009-06-06 16:43:32 +0800 | [diff] [blame] | 130 | test_expect_success 'fetch packed objects' ' |
| 131 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && |
Shawn O. Pearce | d761b2a | 2010-04-17 13:07:35 -0700 | [diff] [blame] | 132 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && |
Clemens Buchacher | 1327d83 | 2012-01-04 16:55:34 +0100 | [diff] [blame] | 133 | git --bare repack -a -d |
Shawn O. Pearce | d761b2a | 2010-04-17 13:07:35 -0700 | [diff] [blame] | 134 | ) && |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 135 | git clone $HTTPD_URL/dumb/repo_pack.git |
Tay Ray Chuan | 96a4f18 | 2009-06-06 16:43:32 +0800 | [diff] [blame] | 136 | ' |
| 137 | |
Shawn O. Pearce | fe72d42 | 2010-04-19 07:23:09 -0700 | [diff] [blame] | 138 | test_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. Pearce | 750ef42 | 2010-04-19 07:23:10 -0700 | [diff] [blame] | 153 | test_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. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 168 | test_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 King | 119c8ee | 2009-02-25 03:32:09 -0500 | [diff] [blame] | 174 | stop_httpd |
| 175 | test_done |