]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5540-http-push-webdav.sh
blame.c: replace instance of !oidcmp for oideq
[thirdparty/git.git] / t / t5540-http-push-webdav.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
4 #
5
6 test_description='test WebDAV http-push
7
8 This test runs various sanity checks on http-push.'
9
10 . ./test-lib.sh
11
12 if git http-push > /dev/null 2>&1 || [ $? -eq 128 ]
13 then
14 skip_all="skipping test, USE_CURL_MULTI is not defined"
15 test_done
16 fi
17
18 LIB_HTTPD_DAV=t
19 . "$TEST_DIRECTORY"/lib-httpd.sh
20 ROOT_PATH="$PWD"
21 start_httpd
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 &&
36 mv hooks/post-update.sample hooks/post-update &&
37 ORIG_HEAD=$(git rev-parse --verify HEAD) &&
38 cd - &&
39 mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH"
40 '
41
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
48 setup_askpass_helper
49
50 test_expect_success 'clone remote repository' '
51 cd "$ROOT_PATH" &&
52 git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone
53 '
54
55 test_expect_success 'push to remote repository with packed refs' '
56 cd "$ROOT_PATH"/test_repo_clone &&
57 : >path2 &&
58 git add path2 &&
59 test_tick &&
60 git commit -m path2 &&
61 HEAD=$(git rev-parse --verify HEAD) &&
62 git push &&
63 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
64 test $HEAD = $(git rev-parse --verify HEAD))
65 '
66
67 test_expect_success 'push already up-to-date' '
68 git push
69 '
70
71 test_expect_success 'push to remote repository with unpacked refs' '
72 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
73 rm packed-refs &&
74 git update-ref refs/heads/master $ORIG_HEAD &&
75 git --bare update-server-info) &&
76 git push &&
77 (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git &&
78 test $HEAD = $(git rev-parse --verify HEAD))
79 '
80
81 test_expect_success 'http-push fetches unpacked objects' '
82 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
83 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
84
85 git clone $HTTPD_URL/dumb/test_repo_unpacked.git \
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 &&
94 git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)
95 '
96
97 test_expect_success 'http-push fetches packed objects' '
98 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
99 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
100
101 git clone $HTTPD_URL/dumb/test_repo_packed.git \
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^ &&
111 git remote remove origin &&
112 git reflog expire --expire=0 --all &&
113 git prune &&
114 git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)
115 '
116
117 test_expect_success 'create and delete remote branch' '
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 &&
125 git push origin :dev &&
126 test_must_fail git show-ref --verify refs/remotes/origin/dev
127 '
128
129 test_expect_success 'MKCOL sends directory names with trailing slashes' '
130
131 ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log
132
133 '
134
135 x1="[0-9a-f]"
136 x2="$x1$x1"
137 xtrunc=$(echo $OID_REGEX | sed -e "s/\[0-9a-f\]\[0-9a-f\]//")
138
139 test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' '
140 sed \
141 -e "s/PUT /OP /" \
142 -e "s/MOVE /OP /" \
143 -e "s|/objects/$x2/${xtrunc}_$OID_REGEX|WANTED_PATH_REQUEST|" \
144 "$HTTPD_ROOT_PATH"/access.log |
145 grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] "
146
147 '
148
149 test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
150 "$ROOT_PATH"/test_repo_clone master
151
152 test_expect_success 'push to password-protected repository (user in URL)' '
153 test_commit pw-user &&
154 set_askpass user@host pass@host &&
155 git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD &&
156 git rev-parse --verify HEAD >expect &&
157 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
158 rev-parse --verify HEAD >actual &&
159 test_cmp expect actual
160 '
161
162 test_expect_failure 'user was prompted only once for password' '
163 expect_askpass pass user@host
164 '
165
166 test_expect_failure 'push to password-protected repository (no user in URL)' '
167 test_commit pw-nouser &&
168 set_askpass user@host pass@host &&
169 git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD &&
170 expect_askpass both user@host &&
171 git rev-parse --verify HEAD >expect &&
172 git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \
173 rev-parse --verify HEAD >actual &&
174 test_cmp expect actual
175 '
176
177 test_done