]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9400-git-cvsserver-server.sh
t9400-git-cvsserver-server: Wrap setup into test case
[thirdparty/git.git] / t / t9400-git-cvsserver-server.sh
CommitLineData
b3b53439
FL
1#!/bin/sh
2#
3# Copyright (c) 2007 Frank Lichtenheld
4#
5
6test_description='git-cvsserver access
7
8tests read access to a git repository with the
9cvs CLI client via git-cvsserver server'
10
11. ./test-lib.sh
12
13cvs >/dev/null 2>&1
14if test $? -ne 1
15then
16 test_expect_success 'skipping git-cvsserver tests, cvs not found' :
17 test_done
18 exit
19fi
469be5b2
JH
20perl -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
24}
b3b53439
FL
25
26unset GIT_DIR GIT_CONFIG
27WORKDIR=$(pwd)
28SERVERDIR=$(pwd)/gitcvs.git
a25907da 29git_config="$SERVERDIR/config"
b3b53439 30CVSROOT=":fork:$SERVERDIR"
a25907da 31CVSWORK="$(pwd)/cvswork"
b3b53439
FL
32CVS_SERVER=git-cvsserver
33export CVSROOT CVS_SERVER
34
35rm -rf "$CVSWORK" "$SERVERDIR"
75493765
SP
36test_expect_success 'setup' '
37 echo >empty &&
b3b53439
FL
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 &&
75493765
SP
42 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
43'
b3b53439
FL
44
45# note that cvs doesn't accept absolute pathnames
46# as argument to co -d
47test_expect_success 'basic checkout' \
a25907da 48 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
b3b53439
FL
49 test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5))" = "empty/1.1/"'
50
240ba7f2
FL
51#------------------------
52# PSERVER AUTHENTICATION
53#------------------------
54
55cat >request-anonymous <<EOF
56BEGIN AUTH REQUEST
57$SERVERDIR
58anonymous
59
60END AUTH REQUEST
61EOF
62
63cat >request-git <<EOF
64BEGIN AUTH REQUEST
65$SERVERDIR
66git
67
68END AUTH REQUEST
69EOF
70
24a97d84
FL
71cat >login-anonymous <<EOF
72BEGIN VERIFICATION REQUEST
73$SERVERDIR
74anonymous
75
76END VERIFICATION REQUEST
77EOF
78
79cat >login-git <<EOF
80BEGIN VERIFICATION REQUEST
81$SERVERDIR
82git
83
84END VERIFICATION REQUEST
85EOF
86
240ba7f2
FL
87test_expect_success 'pserver authentication' \
88 'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
89 tail -n1 log | grep -q "^I LOVE YOU$"'
90
91test_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$"'
99
24a97d84
FL
100test_expect_success 'pserver authentication (login)' \
101 'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
102 tail -n1 log | grep -q "^I LOVE YOU$"'
103
104test_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$"'
112
240ba7f2 113
4890888d
FL
114# misuse pserver authentication for testing of req_Root
115
116cat >request-relative <<EOF
117BEGIN AUTH REQUEST
118gitcvs.git
119anonymous
120
121END AUTH REQUEST
122EOF
123
124cat >request-conflict <<EOF
125BEGIN AUTH REQUEST
126$SERVERDIR
127anonymous
128
129END AUTH REQUEST
130Root $WORKDIR
131EOF
132
133test_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$"'
142
143test_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$"'
146
693b6327
FL
147test_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$"'
150
151test_expect_failure 'req_Root failure (strict-paths)' \
152 'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
153
154test_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$"'
157
158test_expect_failure 'req_Root failure (w/o strict-paths)' \
159 'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
160
161cat >request-base <<EOF
162BEGIN AUTH REQUEST
163/gitcvs.git
164anonymous
165
166END AUTH REQUEST
fd1cd91e 167Root /gitcvs.git
693b6327
FL
168EOF
169
170test_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$"'
173
174test_expect_failure 'req_Root failure (base-path)' \
175 'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
4890888d 176
226bccb9
FL
177GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
178
179test_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$"'
182
183test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
3c740268
AR
184 'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
185 false'
226bccb9
FL
186
187test_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$"'
190
191GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
192
1d431b22
FL
193#--------------
194# CONFIG TESTS
195#--------------
196
197test_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'
208
209rm -fr cvswork2
210test_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'
215
216rm -fr cvswork2
217test_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'
229
230rm -fr cvswork2
231test_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"'
238
239rm -fr cvswork2
240test_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"'
249
250
251#------------
252# CVS UPDATE
253#------------
254
255rm -fr "$SERVERDIR"
256cd "$WORKDIR" &&
257git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
258GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
db1696b8 259GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
1d431b22
FL
260exit 1
261
b3b53439
FL
262test_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 &&
a25907da 268 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
269 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
270 diff -q testfile1 ../testfile1'
271
272cd "$WORKDIR"
273test_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 &&
a25907da 279 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
280 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
281 diff -q testfile1 ../testfile1'
282
283cd "$WORKDIR"
284#TODO: cvsserver doesn't support update w/o -d
285test_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 &&
a25907da 292 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
293 test ! -d test'
294
295cd "$WORKDIR"
296test_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 &&
a25907da 305 GIT_CONFIG="$git_config" cvs -Q update -d &&
b3b53439
FL
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
310 :
311 else
312 echo >failure
313 fi
314 done) &&
315 test ! -f failure'
316
317cd "$WORKDIR"
318test_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 &&
a25907da 323 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
324 test -z "$(grep testfile1 CVS/Entries)" &&
325 test ! -f testfile1'
326
327cd "$WORKDIR"
328test_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 &&
a25907da 334 GIT_CONFIG="$git_config" cvs -Q update &&
b3b53439
FL
335 test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
336 diff -q testfile1 ../testfile1'
337
1978659a
FL
338cd "$WORKDIR"
339test_expect_success 'cvs update (merge)' \
340 'echo Line 0 >expected &&
341 for i in 1 2 3 4 5 6 7
342 do
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 &&
b3c81cff 362 sleep 1 && touch merge &&
1978659a
FL
363 GIT_CONFIG="$git_config" cvs -Q update &&
364 diff -q merge ../expected'
365
366cd "$WORKDIR"
367
368cat >expected.C <<EOF
369<<<<<<< merge.mine
370Line 0
371=======
372LINE 0
373>>>>>>> merge.3
374EOF
375
376for i in 1 2 3 4 5 6 7 8
377do
378 echo Line $i >>expected.C
379done
380
381test_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'
390
391cd "$WORKDIR"
392test_expect_success 'cvs update (-C)' \
393 'cd cvswork &&
394 GIT_CONFIG="$git_config" cvs -Q update -C &&
395 diff -q merge ../merge'
396
397cd "$WORKDIR"
398test_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 &&
b3c81cff 405 sleep 1 && touch merge &&
1978659a
FL
406 GIT_CONFIG="$git_config" cvs -Q update &&
407 diff -q merge ../merge'
408
b3b53439 409test_done