1#!/bin/sh
2#
3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4#
5
6test_description='test WebDAV http-push
7
8This test runs various sanity checks on http-push.'
9
10. ./test-lib.sh
11
12if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
13then
14 skip_all="skipping test, USE_CURL_MULTI is not defined"
15 test_done
16fi
17
18LIB_HTTPD_DAV=t
19LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'}
20. "$TEST_DIRECTORY"/lib-httpd.sh
21ROOT_PATH="$PWD"
22start_httpd
23
24test_expect_success 'setup remote repository' '
25 cd "$ROOT_PATH" &&
26 mkdir test_repo &&
27 cd test_repo &&
28 git init &&
29 : >path1 &&
30 git add path1 &&
31 test_tick &&
32 git commit -m initial &&
33 cd - &&
34 git clone --bare test_repo test_repo.git &&
35 cd test_repo.git &&
36 git --bare update-server-info &&
37 mv hooks/post-update.sample hooks/post-update &&
38 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
39 cd - &&
40 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
41'
42
43test_expect_success 'create password-protected repository' '
44 mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" &&
45 cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \
46 "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git"
47'
48
49setup_askpass_helper
50
51test_expect_success 'clone remote repository' '
52 cd "$ROOT_PATH" &&
53 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
54'
55
56test_expect_success 'push to remote repository with packed refs' '
57 cd "$ROOT_PATH"/test_repo_clone &&
58 : >path2 &&
59 git add path2 &&
60 test_tick &&
61 git commit -m path2 &&
62 HEAD=$(git rev-parse --verify HEAD) &&
63 git push &&
64 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
65 test $HEAD = $(git rev-parse --verify HEAD))
66'
67
68test_expect_success 'push already up-to-date' '
69 git push
70'
71
72test_expect_success 'push to remote repository with unpacked refs' '
73 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
74 rm packed-refs &&
75 git update-ref refs/heads/master $ORIG_HEAD &&
76 git --bare update-server-info) &&
77 git push &&
78 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
79 test $HEAD = $(git rev-parse --verify HEAD))
80'
81
82test_expect_success 'http-push fetches unpacked objects' '
83 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
84 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
85
86 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
87 "$ROOT_PATH"/fetch_unpacked &&
88
89 # By reset, we force git to retrieve the object
90 (cd "$ROOT_PATH"/fetch_unpacked &&
91 git reset --hard HEAD^ &&
92 git remote rm origin &&
93 git reflog expire --expire=0 --all &&
94 git prune &&
95 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
96'
97
98test_expect_success 'http-push fetches packed objects' '
99 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
100 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
101
102 git clone $HTTPD_URL/dumb/test_repo_packed.git \
103 "$ROOT_PATH"/test_repo_clone_packed &&
104
105 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
106 git --bare repack &&
107 git --bare prune-packed) &&
108
109 # By reset, we force git to retrieve the packed object
110 (cd "$ROOT_PATH"/test_repo_clone_packed &&
111 git reset --hard HEAD^ &&
112 git remote remove origin &&
113 git reflog expire --expire=0 --all &&
114 git prune &&
115 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
116'
117
118test_expect_success 'create and delete remote branch' '
119 cd "$ROOT_PATH"/test_repo_clone &&
120 git checkout -b dev &&
121 : >path3 &&
122 git add path3 &&
123 test_tick &&
124 git commit -m dev &&
125 git push origin dev &&
126 git push origin :dev &&
127 test_must_fail git show-ref --verify refs/remotes/origin/dev
128'
129
130test_expect_success 'MKCOL sends directory names with trailing slashes' '
131
132 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
133
134'
135
136x1="[0-9a-f]"
137x2="$x1$x1"
138x5="$x1$x1$x1$x1$x1"
139x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"
140x40="$x38$x2"
141
142test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
143 sed \
144 -e "s/PUT /OP /" \
145 -e "s/MOVE /OP /" \
146 -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \
147 "$HTTPD_ROOT_PATH"/access.log |
148 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
149
150'
151
152test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
153 "$ROOT_PATH"/test_repo_clone master
154
155test_expect_success 'push to password-protected repository (user in URL)' '
156 test_commit pw-user &&
157 set_askpass user@host &&
158 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
159 git rev-parse --verify HEAD >expect &&
160 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
161 rev-parse --verify HEAD >actual &&
162 test_cmp expect actual
163'
164
165test_expect_failure 'user was prompted only once for password' '
166 expect_askpass pass user@host
167'
168
169test_expect_failure 'push to password-protected repository (no user in URL)' '
170 test_commit pw-nouser &&
171 set_askpass user@host &&
172 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
173 expect_askpass both user@host
174 git rev-parse --verify HEAD >expect &&
175 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
176 rev-parse --verify HEAD >actual &&
177 test_cmp expect actual
178'
179
180stop_httpd
181
182test_done