Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> |
| 4 | # |
| 5 | |
Shawn O. Pearce | 7da4e22 | 2009-10-30 17:47:47 -0700 | [diff] [blame] | 6 | test_description='test WebDAV http-push |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 7 | |
| 8 | This test runs various sanity checks on http-push.' |
| 9 | |
| 10 | . ./test-lib.sh |
| 11 | |
Mike Hommey | 9608626 | 2008-07-07 21:02:50 +0200 | [diff] [blame] | 12 | if git http-push > /dev/null 2>&1 || [ $? -eq 128 ] |
| 13 | then |
Ævar Arnfjörð Bjarmason | fadb515 | 2010-06-24 17:44:48 +0000 | [diff] [blame] | 14 | skip_all="skipping test, USE_CURL_MULTI is not defined" |
Mike Hommey | 9608626 | 2008-07-07 21:02:50 +0200 | [diff] [blame] | 15 | test_done |
Mike Hommey | 9608626 | 2008-07-07 21:02:50 +0200 | [diff] [blame] | 16 | fi |
| 17 | |
Clemens Buchacher | 859d1fb | 2009-10-30 17:47:45 -0700 | [diff] [blame] | 18 | LIB_HTTPD_DAV=t |
Junio C Hamano | bfdbee9 | 2008-08-08 02:26:28 -0700 | [diff] [blame] | 19 | . "$TEST_DIRECTORY"/lib-httpd.sh |
Clemens Buchacher | 859d1fb | 2009-10-30 17:47:45 -0700 | [diff] [blame] | 20 | ROOT_PATH="$PWD" |
Jeff King | 75318a3 | 2009-02-25 03:32:08 -0500 | [diff] [blame] | 21 | start_httpd |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 22 | |
| 23 | test_expect_success 'setup remote repository' ' |
| 24 | cd "$ROOT_PATH" && |
| 25 | mkdir test_repo && |
| 26 | cd test_repo && |
| 27 | git init && |
| 28 | : >path1 && |
| 29 | git add path1 && |
| 30 | test_tick && |
| 31 | git commit -m initial && |
| 32 | cd - && |
| 33 | git clone --bare test_repo test_repo.git && |
| 34 | cd test_repo.git && |
| 35 | git --bare update-server-info && |
Petr Baudis | 7dce991 | 2008-08-12 00:34:46 +0200 | [diff] [blame] | 36 | mv hooks/post-update.sample hooks/post-update && |
Shawn O. Pearce | ae4efe1 | 2009-10-30 17:47:30 -0700 | [diff] [blame] | 37 | ORIG_HEAD=$(git rev-parse --verify HEAD) && |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 38 | cd - && |
Mike Hommey | 13b5481 | 2008-07-07 21:02:37 +0200 | [diff] [blame] | 39 | mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 40 | ' |
Jeff King | 3b2eb18 | 2008-06-14 03:25:56 -0400 | [diff] [blame] | 41 | |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 42 | test_expect_success 'create password-protected repository' ' |
| 43 | mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" && |
| 44 | cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ |
| 45 | "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" |
| 46 | ' |
| 47 | |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 48 | setup_askpass_helper |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 49 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 50 | test_expect_success 'clone remote repository' ' |
| 51 | cd "$ROOT_PATH" && |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 52 | git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 53 | ' |
| 54 | |
Shawn O. Pearce | ae4efe1 | 2009-10-30 17:47:30 -0700 | [diff] [blame] | 55 | test_expect_success 'push to remote repository with packed refs' ' |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 56 | cd "$ROOT_PATH"/test_repo_clone && |
| 57 | : >path2 && |
| 58 | git add path2 && |
| 59 | test_tick && |
| 60 | git commit -m path2 && |
Johannes Schindelin | 8ee09ac | 2009-01-17 16:41:41 +0100 | [diff] [blame] | 61 | HEAD=$(git rev-parse --verify HEAD) && |
Mike Hommey | b5cd2d1 | 2008-07-07 23:06:46 +0200 | [diff] [blame] | 62 | git push && |
Johannes Schindelin | 8ee09ac | 2009-01-17 16:41:41 +0100 | [diff] [blame] | 63 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
| 64 | test $HEAD = $(git rev-parse --verify HEAD)) |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 65 | ' |
| 66 | |
Clemens Buchacher | d8f67d2 | 2009-10-30 17:47:31 -0700 | [diff] [blame] | 67 | test_expect_success 'push already up-to-date' ' |
Shawn O. Pearce | ae4efe1 | 2009-10-30 17:47:30 -0700 | [diff] [blame] | 68 | git push |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'push to remote repository with unpacked refs' ' |
Johannes Schindelin | 8ee09ac | 2009-01-17 16:41:41 +0100 | [diff] [blame] | 72 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
| 73 | rm packed-refs && |
Shawn O. Pearce | ae4efe1 | 2009-10-30 17:47:30 -0700 | [diff] [blame] | 74 | git update-ref refs/heads/master $ORIG_HEAD && |
| 75 | git --bare update-server-info) && |
Johannes Schindelin | 8ee09ac | 2009-01-17 16:41:41 +0100 | [diff] [blame] | 76 | git push && |
| 77 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && |
| 78 | test $HEAD = $(git rev-parse --verify HEAD)) |
| 79 | ' |
| 80 | |
Tay Ray Chuan | 4f66250 | 2009-06-06 16:43:27 +0800 | [diff] [blame] | 81 | test_expect_success 'http-push fetches unpacked objects' ' |
Tay Ray Chuan | 242a907 | 2009-06-06 16:43:23 +0800 | [diff] [blame] | 82 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
| 83 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && |
| 84 | |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 85 | git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ |
Tay Ray Chuan | 242a907 | 2009-06-06 16:43:23 +0800 | [diff] [blame] | 86 | "$ROOT_PATH"/fetch_unpacked && |
| 87 | |
| 88 | # By reset, we force git to retrieve the object |
| 89 | (cd "$ROOT_PATH"/fetch_unpacked && |
| 90 | git reset --hard HEAD^ && |
| 91 | git remote rm origin && |
| 92 | git reflog expire --expire=0 --all && |
| 93 | git prune && |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 94 | git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master) |
Tay Ray Chuan | 242a907 | 2009-06-06 16:43:23 +0800 | [diff] [blame] | 95 | ' |
| 96 | |
Tay Ray Chuan | 4f66250 | 2009-06-06 16:43:27 +0800 | [diff] [blame] | 97 | test_expect_success 'http-push fetches packed objects' ' |
Tay Ray Chuan | 86d99f6 | 2009-06-06 16:43:24 +0800 | [diff] [blame] | 98 | cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
| 99 | "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && |
| 100 | |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 101 | git clone $HTTPD_URL/dumb/test_repo_packed.git \ |
Tay Ray Chuan | 86d99f6 | 2009-06-06 16:43:24 +0800 | [diff] [blame] | 102 | "$ROOT_PATH"/test_repo_clone_packed && |
| 103 | |
| 104 | (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && |
| 105 | git --bare repack && |
| 106 | git --bare prune-packed) && |
| 107 | |
| 108 | # By reset, we force git to retrieve the packed object |
| 109 | (cd "$ROOT_PATH"/test_repo_clone_packed && |
| 110 | git reset --hard HEAD^ && |
Nguyễn Thái Ngọc Duy | e17dba8 | 2012-09-06 19:25:23 +0700 | [diff] [blame] | 111 | git remote remove origin && |
Tay Ray Chuan | 86d99f6 | 2009-06-06 16:43:24 +0800 | [diff] [blame] | 112 | git reflog expire --expire=0 --all && |
| 113 | git prune && |
Shawn O. Pearce | 024bb12 | 2009-10-30 17:47:46 -0700 | [diff] [blame] | 114 | git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master) |
Tay Ray Chuan | 86d99f6 | 2009-06-06 16:43:24 +0800 | [diff] [blame] | 115 | ' |
| 116 | |
Johannes Schindelin | 8ee09ac | 2009-01-17 16:41:41 +0100 | [diff] [blame] | 117 | test_expect_success 'create and delete remote branch' ' |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 118 | cd "$ROOT_PATH"/test_repo_clone && |
| 119 | git checkout -b dev && |
| 120 | : >path3 && |
| 121 | git add path3 && |
| 122 | test_tick && |
| 123 | git commit -m dev && |
| 124 | git push origin dev && |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 125 | git push origin :dev && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 126 | test_must_fail git show-ref --verify refs/remotes/origin/dev |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 127 | ' |
| 128 | |
Johannes Schindelin | 466ddf9 | 2009-01-17 16:11:51 +0100 | [diff] [blame] | 129 | test_expect_success 'MKCOL sends directory names with trailing slashes' ' |
| 130 | |
| 131 | ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log |
| 132 | |
| 133 | ' |
| 134 | |
Jay Soffian | 2591838 | 2009-02-26 18:44:40 -0500 | [diff] [blame] | 135 | x1="[0-9a-f]" |
| 136 | x2="$x1$x1" |
| 137 | x5="$x1$x1$x1$x1$x1" |
| 138 | x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1" |
| 139 | x40="$x38$x2" |
Tay Ray Chuan | dfab7c1 | 2009-02-14 17:52:14 +0800 | [diff] [blame] | 140 | |
Jay Soffian | 2591838 | 2009-02-26 18:44:40 -0500 | [diff] [blame] | 141 | test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' |
Brian Gernhardt | f6918da | 2011-08-29 02:42:21 -0400 | [diff] [blame] | 142 | sed \ |
| 143 | -e "s/PUT /OP /" \ |
| 144 | -e "s/MOVE /OP /" \ |
| 145 | -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \ |
| 146 | "$HTTPD_ROOT_PATH"/access.log | |
| 147 | grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " |
Tay Ray Chuan | dfab7c1 | 2009-02-14 17:52:14 +0800 | [diff] [blame] | 148 | |
| 149 | ' |
| 150 | |
Tay Ray Chuan | 6cbd6e9 | 2010-03-02 18:49:26 +0800 | [diff] [blame] | 151 | test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ |
| 152 | "$ROOT_PATH"/test_repo_clone master |
| 153 | |
Jeff King | a4ddbc3 | 2011-12-13 19:11:56 -0500 | [diff] [blame] | 154 | test_expect_success 'push to password-protected repository (user in URL)' ' |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 155 | test_commit pw-user && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 156 | set_askpass user@host pass@host && |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 157 | git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD && |
| 158 | git rev-parse --verify HEAD >expect && |
| 159 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ |
| 160 | rev-parse --verify HEAD >actual && |
| 161 | test_cmp expect actual |
| 162 | ' |
| 163 | |
Jeff King | e837936 | 2012-08-27 09:24:31 -0400 | [diff] [blame] | 164 | test_expect_failure 'user was prompted only once for password' ' |
| 165 | expect_askpass pass user@host |
| 166 | ' |
| 167 | |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 168 | test_expect_failure 'push to password-protected repository (no user in URL)' ' |
| 169 | test_commit pw-nouser && |
Jeff King | afbf5ca | 2014-01-02 02:38:35 -0500 | [diff] [blame] | 170 | set_askpass user@host pass@host && |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 171 | git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && |
Jeff King | 8fb2687 | 2015-03-20 06:06:15 -0400 | [diff] [blame] | 172 | expect_askpass both user@host && |
Jeff King | 0521710 | 2011-12-13 15:17:04 -0500 | [diff] [blame] | 173 | git rev-parse --verify HEAD >expect && |
| 174 | git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ |
| 175 | rev-parse --verify HEAD >actual && |
| 176 | test_cmp expect actual |
| 177 | ' |
| 178 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 179 | test_done |