keeping the profs at Cambridge happy...
[gitolite.git] / t / mirror-test
blobe0c4e36bf2f504c169e004f8e784472ff3a5c6a3
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # you need 3 disposable userids: sam, frodo, gollum. Then the test user (say
6 # "g3") needs to be able to sudo into them. Put this in /etc/sudoers:
8 # g3 ALL = (sam,frodo,gollum) NOPASSWD: ALL
10 $ENV{TSH_ERREXIT} = 1;
12 # this is hardcoded; change it if needed
13 use lib "src/lib";
14 use Gitolite::Test;
15 use Cwd;
16 my $workdir = getcwd();
17 my $h = $ENV{HOME};
18 my ($t, $t2); # temp vars
20 # basic tests
21 # ----------------------------------------------------------------------
23 try "plan 152";
24 ## try "DEF POK = !/DENIED/; !/failed to push/";
26 ## confreset;confadd '
28 ## ';
30 ## try "ADMIN_PUSH set1; !/FATAL/" or die text();
32 # ----------------------------------------------------------------------
34 # switch keys
35 sub swk {
36 my $h = $ENV{HOME};
37 my $k = shift;
38 system("cp $h/.ssh/$k $h/.ssh/id_rsa");
39 system("cp $h/.ssh/$k.pub $h/.ssh/id_rsa.pub");
42 sub all {
43 try "F " . join(" ", @_);
44 try "S " . join(" ", @_);
45 try "G " . join(" ", @_);
48 try "
49 DEF F = sudo -u frodo -i
50 DEF S = sudo -u sam -i
51 DEF G = sudo -u gollum -i
54 my $bd = `gitolite query-rc -n GL_BINDIR`;
56 try "
57 $bd/../t/mirror-test-setup.sh; ok or die mirror setup shell script failed
58 /hello server-frodo, this is frodo/
59 /hello server-sam, this is frodo/
60 /hello server-gollum, this is frodo/
61 /hello server-frodo, this is sam/
62 /hello server-sam, this is sam/
63 /hello server-gollum, this is sam/
64 /hello server-frodo, this is gollum/
65 /hello server-sam, this is gollum/
66 /hello server-gollum, this is gollum/
67 /hello admin, this is frodo/
68 /Initialized empty .*/gitolite-admin.git/
69 /Initialized empty .*/r1.git/
70 /Initialized empty .*/r2.git/
71 /Initialized empty .*/testing.git/
72 /Initialized empty .*/gitolite-admin.git/
73 /Initialized empty .*/r1.git/
74 /Initialized empty .*/r2.git/
75 /Initialized empty .*/testing.git/
76 /Initialized empty .*/gitolite-admin.git/
77 /Initialized empty .*/r1.git/
78 /Initialized empty .*/r2.git/
79 /Initialized empty .*/testing.git/
82 # ----------------------------------------------------------------------
83 # SECTION 1: gitolite-admin shenanigans
85 # push to frodo and see sam and gollum change
86 try "
87 git clone frodo\@localhost:gitolite-admin fga
88 ok; /Cloning into 'fga'.../
89 cd fga; ok
90 cp $h/.ssh/u?.pub keydir; ok
91 git add keydir; ok
92 git commit -m 6keys; ok
93 git push; ok
94 /To localhost:gitolite-admin/
95 /master -> master/
96 sleep 5
97 git rev-parse HEAD
100 chomp($t = text());
102 try "
103 git ls-remote sam\@localhost:gitolite-admin
104 ok; /$t/
105 git ls-remote gollum\@localhost:gitolite-admin
106 ok; /$t/
109 try "
110 cd ..
114 # push to sam and see frodo and gollum change
115 try "
116 git clone sam\@localhost:gitolite-admin sga
117 ok; /Cloning into 'sga'.../
118 cd sga; ok
119 empty; ok
120 git push; ok
121 /To localhost:gitolite-admin/
122 /master -> master/
123 sleep 5
124 git rev-parse HEAD
127 chomp($t = text());
129 try "
130 git ls-remote frodo\@localhost:gitolite-admin
131 ok; /$t/
132 git ls-remote gollum\@localhost:gitolite-admin
133 ok; /$t/
136 try "
137 cd ..
141 # push to gollum and fail at gollum
142 try "
143 git clone gollum\@localhost:gitolite-admin gga
144 ok; /Cloning into 'gga'.../
145 cd gga; ok
146 empty; ok
147 git push; !ok
148 !/To localhost:gitolite-admin/
149 !/master -> master/
150 /gollum: pushing 'gitolite-admin' to slave 'gollum' not allowed/
151 git rev-parse HEAD
154 chomp($t2 = text());
156 try "
157 git ls-remote frodo\@localhost:gitolite-admin
158 ok; /$t/; !/$t2/
159 git ls-remote sam\@localhost:gitolite-admin
160 ok; /$t/; !/$t2/
161 git ls-remote gollum\@localhost:gitolite-admin
162 ok; /$t/; !/$t2/
165 # fake out the gollum failure to continue the redirected push and fail at frodo
166 try "
167 sudo -u gollum -i gitolite git-config -r gitolite-admin .
169 /redirectOK.*sam/
170 !/redirectOK.*gollum/
172 sudo -u gollum -i bash -c 'echo repo gitolite-admin > junk'
173 sudo -u gollum -i bash -c 'echo option mirror.redirectOK-1 = gollum >> junk'
174 sudo -u gollum -i bash -c 'cat junk >> .gitolite/conf/gitolite.conf'
175 sudo -u gollum -i gitolite compile
176 sudo -u gollum -i gitolite git-config -r gitolite-admin .
178 /redirectOK.*sam/
179 /redirectOK.*gollum/
181 git push; !ok
182 /frodo: redirection not allowed from 'gollum'/
183 !/To gollum\@localhost:gitolite-admin/
184 !/master -> master/
187 # reset gollum via frodo
188 try "
189 cd ..
190 rm -rf fga
191 git clone frodo\@localhost:gitolite-admin fga
192 ok; /Cloning into 'fga'.../
193 cd fga; ok
194 empty; ok
195 git push; ok
196 /To localhost:gitolite-admin/
197 /master -> master/
198 sleep 5
200 sudo -u gollum -i gitolite git-config -r gitolite-admin .
202 /redirectOK.*sam/
203 !/redirectOK.*gollum/
205 git rev-parse HEAD
208 chomp($t = text());
210 try "
211 git ls-remote sam\@localhost:gitolite-admin
212 ok; /$t/
213 git ls-remote gollum\@localhost:gitolite-admin
214 ok; /$t/
217 # ----------------------------------------------------------------------
218 # user repo shenanigans
220 # for a recap of the perms see t/mirror-test-setup.sh
222 try "
223 cd ..
225 /tmp/tsh_tempdir/ or die not in the right place
226 " or die;
228 swk('u1');
230 # u1 sam r1, R ok, W ok
231 try "
232 rm -rf fga sga gga
234 git clone sam\@localhost:r1 sr1
235 /Cloning into 'sr1'.../
236 /warning: You appear to have cloned an empty repository/
237 cd sr1
238 empty
239 git push origin master
240 /new branch/; /master -> master/
241 sleep 5
242 git rev-parse HEAD
244 chomp($t = text());
246 # u1 sam r1, W mirrors to frodo but not gollum
247 try "
248 git ls-remote sam\@localhost:r1
249 /$t/
250 git ls-remote frodo\@localhost:r1
251 /$t/
252 git ls-remote gollum\@localhost:r1
253 /gollum: 'r1' is mirrored but not here/
256 swk("u2");
257 try "
258 empty
259 git rev-parse HEAD
261 chomp($t2 = text());
263 # u2 sam r2 W ok, mirrors to all
264 try "
265 git push sam\@localhost:r2 master
266 /new branch/; /master -> master/
267 /master -> master/
268 sleep 5
269 git ls-remote frodo\@localhost:r2
270 !/$t/
271 /$t2/
272 git ls-remote gollum\@localhost:r2
273 !/$t/
274 /$t2/
277 swk("u1");
279 # u1 gollum r1 -- "known unknown" :-)
280 # u1 frodo r1 R ok, W not ok
281 # u1 sam r1 R ok, W ok
282 try "
283 cd ..
284 rm -rf sr1
286 git clone gollum\@localhost:r1 fr1
287 /gollum: 'r1' is mirrored but not here/
289 git clone frodo\@localhost:r1 fr1; ok
290 cd fr1
291 empty
292 git push
293 /frodo: pushing 'r1' to slave 'frodo' not allowed/
294 cd ..
295 git clone sam\@localhost:r1 sr1; ok
296 cd sr1
297 empty
298 git push; ok
299 /master -> master/
300 sleep 5
301 git rev-parse HEAD
303 chomp($t = text());
305 # u1 sam r1 W mirrored to frodo but not gollum
306 try "
307 git ls-remote sam\@localhost:r1
308 /$t/
309 git ls-remote frodo\@localhost:r1
310 /$t/
312 git ls-remote gollum\@localhost:r1
313 /gollum: 'r1' is mirrored but not here/
315 git reset --hard HEAD^; ok
316 tc a
317 git push; !ok
318 /rejected/
319 /failed to push/
321 git push -f
322 /\\+ .......\\.\\.\\........ master -> master .forced update/
323 sleep 5
326 swk("u2");
328 # u2 frodo r1 R ok, W not allowed (no redirectOK)
329 # u2 frodo r2 W ok
330 try "
331 cd ..
332 rm -rf fr1 sr1
334 git clone frodo\@localhost:r1 fr1; ok
335 cd fr1
336 tc b
337 git push
338 /frodo: pushing 'r1' to slave 'frodo' not allowed/
339 cd ..
340 git clone frodo\@localhost:r2 fr2; ok
341 cd fr2
342 tc c
343 git push
344 /master -> master/
345 sleep 5
346 git rev-parse HEAD
348 chomp($t = text());
350 # u2 frodo r2 W mirrors to sam and gollum
351 try "
352 git ls-remote sam\@localhost:r2
353 /$t/
354 git ls-remote gollum\@localhost:r2
355 /$t/
357 git reset --hard HEAD^; ok
358 tc d
359 git push
360 /rejected/
361 /failed to push/
363 git push -f
364 /\\+ .......\\.\\.\\........ master -> master .forced update/
365 sleep 5
367 cd ..
368 rm -rf fr1 fr2
371 swk("u3");
373 # u3 frodo r2 R ok W ok
374 try "
375 git clone frodo\@localhost:r2 fr2; ok
376 cd fr2
377 tc e
378 git push; ok
379 sleep 5
381 git rev-parse HEAD
383 chomp($t = text());
385 # u3 frodo r2 W mirrors to sam and gollum
386 try "
387 git ls-remote sam\@localhost:r2
388 /$t/
389 git ls-remote gollum\@localhost:r2
390 /$t/
392 git reset --hard HEAD^; ok
393 tc f
394 git push
395 /rejected/
396 /failed to push/
398 sleep 10
399 git push -f
400 /\\+ refs/heads/master r2 u3 DENIED by fallthru/
401 /hook declined/
402 /rejected/
405 # ----------------------------------------------------------------------
406 # all those vague edge cases where the two servers have totally wrong ideas
407 # about each other
409 swk('u1');
411 try "sudo -u frodo -i ls .gitolite/logs";
412 chomp($t = text());
413 my $lfn = ".gitolite/logs/$t";
415 try "
416 ssh sam\@localhost mirror push frodo lfrodo; !ok
417 /FATAL: frodo: 'lfrodo' is local/
419 ssh sam\@localhost mirror push frodo mboth; !ok
420 /FATAL: frodo: 'mboth' is native/
422 ssh sam\@localhost mirror push frodo mnotsam; !ok
423 /FATAL: frodo: 'sam' is not the master for 'mnotsam'/
425 cd ..
426 git clone sam\@localhost:lfrodo2 lfrodo2; ok
427 cd lfrodo2
428 empty
429 git push origin master; !ok
430 /FATAL: frodo: 'lfrodo2' is local/
432 cd ..
433 git clone sam\@localhost:nnfrodo nnfrodo; ok
434 cd nnfrodo
435 empty
436 git push origin master; !ok
437 /FATAL: frodo: 'nnfrodo' is not native/
439 cd ..
440 git clone sam\@localhost:nvsfrodo nvsfrodo; ok
441 cd nvsfrodo
442 empty
443 git push origin master; !ok
444 /FATAL: frodo: 'sam' is not a valid slave for 'nvsfrodo'/