t9400-git-cvsserver-server: Wrap setup into test case
[alt-git.git] / t / t9400-git-cvsserver-server.sh
blob1f2749eefba9baa4b3b88bac3ff8f2d9525896a2
1 #!/bin/sh
3 # Copyright (c) 2007 Frank Lichtenheld
6 test_description='git-cvsserver access
8 tests read access to a git repository with the
9 cvs CLI client via git-cvsserver server'
11 . ./test-lib.sh
13 cvs >/dev/null 2>&1
14 if test $? -ne 1
15 then
16 test_expect_success 'skipping git-cvsserver tests, cvs not found' :
17 test_done
18 exit
20 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
21 test_expect_success 'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
22 test_done
23 exit
26 unset GIT_DIR GIT_CONFIG
27 WORKDIR=$(pwd)
28 SERVERDIR=$(pwd)/gitcvs.git
29 git_config="$SERVERDIR/config"
30 CVSROOT=":fork:$SERVERDIR"
31 CVSWORK="$(pwd)/cvswork"
32 CVS_SERVER=git-cvsserver
33 export CVSROOT CVS_SERVER
35 rm -rf "$CVSWORK" "$SERVERDIR"
36 test_expect_success 'setup' '
37 echo >empty &&
38 git add empty &&
39 git commit -q -m "First Commit" &&
40 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
41 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
42 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
45 # note that cvs doesn't accept absolute pathnames
46 # as argument to co -d
47 test_expect_success 'basic checkout' \
48 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
49 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5))" = "empty/1.1/"'
51 #------------------------
52 # PSERVER AUTHENTICATION
53 #------------------------
55 cat >request-anonymous <<EOF
56 BEGIN AUTH REQUEST
57 $SERVERDIR
58 anonymous
60 END AUTH REQUEST
61 EOF
63 cat >request-git <<EOF
64 BEGIN AUTH REQUEST
65 $SERVERDIR
66 git
68 END AUTH REQUEST
69 EOF
71 cat >login-anonymous <<EOF
72 BEGIN VERIFICATION REQUEST
73 $SERVERDIR
74 anonymous
76 END VERIFICATION REQUEST
77 EOF
79 cat >login-git <<EOF
80 BEGIN VERIFICATION REQUEST
81 $SERVERDIR
82 git
84 END VERIFICATION REQUEST
85 EOF
87 test_expect_success 'pserver authentication' \
88 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
89 tail -n1 log | grep -q "^I LOVE YOU$"'
91 test_expect_success 'pserver authentication failure (non-anonymous user)' \
92 'if cat request-git | git-cvsserver pserver >log 2>&1
93 then
94 false
95 else
96 true
97 fi &&
98 tail -n1 log | grep -q "^I HATE YOU$"'
100 test_expect_success 'pserver authentication (login)' \
101 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
102 tail -n1 log | grep -q "^I LOVE YOU$"'
104 test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
105 'if cat login-git | git-cvsserver pserver >log 2>&1
106 then
107 false
108 else
109 true
110 fi &&
111 tail -n1 log | grep -q "^I HATE YOU$"'
114 # misuse pserver authentication for testing of req_Root
116 cat >request-relative <<EOF
117 BEGIN AUTH REQUEST
118 gitcvs.git
119 anonymous
121 END AUTH REQUEST
124 cat >request-conflict <<EOF
125 BEGIN AUTH REQUEST
126 $SERVERDIR
127 anonymous
129 END AUTH REQUEST
130 Root $WORKDIR
133 test_expect_success 'req_Root failure (relative pathname)' \
134 'if cat request-relative | git-cvsserver pserver >log 2>&1
135 then
136 echo unexpected success
137 false
138 else
139 true
140 fi &&
141 tail log | grep -q "^error 1 Root must be an absolute pathname$"'
143 test_expect_success 'req_Root failure (conflicting roots)' \
144 'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
145 tail log | grep -q "^error 1 Conflicting roots specified$"'
147 test_expect_success 'req_Root (strict paths)' \
148 'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
149 tail -n1 log | grep -q "^I LOVE YOU$"'
151 test_expect_failure 'req_Root failure (strict-paths)' \
152 'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
154 test_expect_success 'req_Root (w/o strict-paths)' \
155 'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
156 tail -n1 log | grep -q "^I LOVE YOU$"'
158 test_expect_failure 'req_Root failure (w/o strict-paths)' \
159 'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
161 cat >request-base <<EOF
162 BEGIN AUTH REQUEST
163 /gitcvs.git
164 anonymous
166 END AUTH REQUEST
167 Root /gitcvs.git
170 test_expect_success 'req_Root (base-path)' \
171 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
172 tail -n1 log | grep -q "^I LOVE YOU$"'
174 test_expect_failure 'req_Root failure (base-path)' \
175 'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
177 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
179 test_expect_success 'req_Root (export-all)' \
180 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
181 tail -n1 log | grep -q "^I LOVE YOU$"'
183 test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
184 'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
185 false'
187 test_expect_success 'req_Root (everything together)' \
188 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
189 tail -n1 log | grep -q "^I LOVE YOU$"'
191 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
193 #--------------
194 # CONFIG TESTS
195 #--------------
197 test_expect_success 'gitcvs.enabled = false' \
198 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
199 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
200 then
201 echo unexpected cvs success
202 false
203 else
204 true
205 fi &&
206 cat cvs.log | grep -q "GITCVS emulation disabled" &&
207 test ! -d cvswork2'
209 rm -fr cvswork2
210 test_expect_success 'gitcvs.ext.enabled = true' \
211 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
212 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
213 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
214 diff -q cvswork cvswork2'
216 rm -fr cvswork2
217 test_expect_success 'gitcvs.ext.enabled = false' \
218 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
219 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
220 if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
221 then
222 echo unexpected cvs success
223 false
224 else
225 true
226 fi &&
227 cat cvs.log | grep -q "GITCVS emulation disabled" &&
228 test ! -d cvswork2'
230 rm -fr cvswork2
231 test_expect_success 'gitcvs.dbname' \
232 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
233 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
234 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
235 diff -q cvswork cvswork2 &&
236 test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
237 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
239 rm -fr cvswork2
240 test_expect_success 'gitcvs.ext.dbname' \
241 'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
242 GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
243 GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
244 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
245 diff -q cvswork cvswork2 &&
246 test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
247 test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
248 cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
251 #------------
252 # CVS UPDATE
253 #------------
255 rm -fr "$SERVERDIR"
256 cd "$WORKDIR" &&
257 git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
258 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
259 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
260 exit 1
262 test_expect_success 'cvs update (create new file)' \
263 'echo testfile1 >testfile1 &&
264 git add testfile1 &&
265 git commit -q -m "Add testfile1" &&
266 git push gitcvs.git >/dev/null &&
267 cd cvswork &&
268 GIT_CONFIG="$git_config" cvs -Q update &&
269 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
270 diff -q testfile1 ../testfile1'
272 cd "$WORKDIR"
273 test_expect_success 'cvs update (update existing file)' \
274 'echo line 2 >>testfile1 &&
275 git add testfile1 &&
276 git commit -q -m "Append to testfile1" &&
277 git push gitcvs.git >/dev/null &&
278 cd cvswork &&
279 GIT_CONFIG="$git_config" cvs -Q update &&
280 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
281 diff -q testfile1 ../testfile1'
283 cd "$WORKDIR"
284 #TODO: cvsserver doesn't support update w/o -d
285 test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
286 'mkdir test &&
287 echo >test/empty &&
288 git add test &&
289 git commit -q -m "Single Subdirectory" &&
290 git push gitcvs.git >/dev/null &&
291 cd cvswork &&
292 GIT_CONFIG="$git_config" cvs -Q update &&
293 test ! -d test'
295 cd "$WORKDIR"
296 test_expect_success 'cvs update (subdirectories)' \
297 '(for dir in A A/B A/B/C A/D E; do
298 mkdir $dir &&
299 echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" &&
300 git add $dir;
301 done) &&
302 git commit -q -m "deep sub directory structure" &&
303 git push gitcvs.git >/dev/null &&
304 cd cvswork &&
305 GIT_CONFIG="$git_config" cvs -Q update -d &&
306 (for dir in A A/B A/B/C A/D E; do
307 filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
308 if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
309 diff -q "$dir/$filename" "../$dir/$filename"; then
311 else
312 echo >failure
314 done) &&
315 test ! -f failure'
317 cd "$WORKDIR"
318 test_expect_success 'cvs update (delete file)' \
319 'git rm testfile1 &&
320 git commit -q -m "Remove testfile1" &&
321 git push gitcvs.git >/dev/null &&
322 cd cvswork &&
323 GIT_CONFIG="$git_config" cvs -Q update &&
324 test -z "$(grep testfile1 CVS/Entries)" &&
325 test ! -f testfile1'
327 cd "$WORKDIR"
328 test_expect_success 'cvs update (re-add deleted file)' \
329 'echo readded testfile >testfile1 &&
330 git add testfile1 &&
331 git commit -q -m "Re-Add testfile1" &&
332 git push gitcvs.git >/dev/null &&
333 cd cvswork &&
334 GIT_CONFIG="$git_config" cvs -Q update &&
335 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
336 diff -q testfile1 ../testfile1'
338 cd "$WORKDIR"
339 test_expect_success 'cvs update (merge)' \
340 'echo Line 0 >expected &&
341 for i in 1 2 3 4 5 6 7
343 echo Line $i >>merge
344 echo Line $i >>expected
345 done &&
346 echo Line 8 >>expected &&
347 git add merge &&
348 git commit -q -m "Merge test (pre-merge)" &&
349 git push gitcvs.git >/dev/null &&
350 cd cvswork &&
351 GIT_CONFIG="$git_config" cvs -Q update &&
352 test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
353 diff -q merge ../merge &&
354 ( echo Line 0; cat merge ) >merge.tmp &&
355 mv merge.tmp merge &&
356 cd "$WORKDIR" &&
357 echo Line 8 >>merge &&
358 git add merge &&
359 git commit -q -m "Merge test (merge)" &&
360 git push gitcvs.git >/dev/null &&
361 cd cvswork &&
362 sleep 1 && touch merge &&
363 GIT_CONFIG="$git_config" cvs -Q update &&
364 diff -q merge ../expected'
366 cd "$WORKDIR"
368 cat >expected.C <<EOF
369 <<<<<<< merge.mine
370 Line 0
371 =======
372 LINE 0
373 >>>>>>> merge.3
376 for i in 1 2 3 4 5 6 7 8
378 echo Line $i >>expected.C
379 done
381 test_expect_success 'cvs update (conflict merge)' \
382 '( echo LINE 0; cat merge ) >merge.tmp &&
383 mv merge.tmp merge &&
384 git add merge &&
385 git commit -q -m "Merge test (conflict)" &&
386 git push gitcvs.git >/dev/null &&
387 cd cvswork &&
388 GIT_CONFIG="$git_config" cvs -Q update &&
389 diff -q merge ../expected.C'
391 cd "$WORKDIR"
392 test_expect_success 'cvs update (-C)' \
393 'cd cvswork &&
394 GIT_CONFIG="$git_config" cvs -Q update -C &&
395 diff -q merge ../merge'
397 cd "$WORKDIR"
398 test_expect_success 'cvs update (merge no-op)' \
399 'echo Line 9 >>merge &&
400 cp merge cvswork/merge &&
401 git add merge &&
402 git commit -q -m "Merge test (no-op)" &&
403 git push gitcvs.git >/dev/null &&
404 cd cvswork &&
405 sleep 1 && touch merge &&
406 GIT_CONFIG="$git_config" cvs -Q update &&
407 diff -q merge ../merge'
409 test_done