summaryrefslogtreecommitdiffstats
path: root/t/mirror-test
blob: 3ace59b1338e9644678260fca2f4b7c8ee5d1dde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/usr/bin/perl
use strict;
use warnings;

# you need 3 disposable userids: sam, frodo, gollum.  Then the test user (say
# "g3") needs to be able to sudo into them.  Put this in /etc/sudoers:

#       g3 ALL = (sam,frodo,gollum) NOPASSWD: ALL

$ENV{TSH_ERREXIT} = 1;

# this is hardcoded; change it if needed
use lib "src/lib";
use Gitolite::Test;
use Cwd;
my $workdir = getcwd();
my $h = $ENV{HOME};
my ($t, $t2);   # temp vars

# basic tests
# ----------------------------------------------------------------------

try "plan 152";
##  try "DEF POK = !/DENIED/; !/failed to push/";

##  confreset;confadd '

##  ';

##  try "ADMIN_PUSH set1; !/FATAL/" or die text();

# ----------------------------------------------------------------------

# switch keys
sub swk {
    my $h = $ENV{HOME};
    my $k = shift;
    system("cp $h/.ssh/$k $h/.ssh/id_rsa");
    system("cp $h/.ssh/$k.pub $h/.ssh/id_rsa.pub");
}

sub all {
    try "F " . join(" ", @_);
    try "S " . join(" ", @_);
    try "G " . join(" ", @_);
}

try "
    DEF F   =   sudo -u frodo -i
    DEF S   =   sudo -u sam -i
    DEF G   =   sudo -u gollum -i
";

my $bd = `gitolite query-rc -n GL_BINDIR`;

try "
    $bd/../t/mirror-test-setup.sh;   ok or die mirror setup shell script failed
        /hello server-frodo, this is frodo/
        /hello server-sam, this is frodo/
        /hello server-gollum, this is frodo/
        /hello server-frodo, this is sam/
        /hello server-sam, this is sam/
        /hello server-gollum, this is sam/
        /hello server-frodo, this is gollum/
        /hello server-sam, this is gollum/
        /hello server-gollum, this is gollum/
        /hello admin, this is frodo/
        /Initialized empty .*/gitolite-admin.git/
        /Initialized empty .*/r1.git/
        /Initialized empty .*/r2.git/
        /Initialized empty .*/testing.git/
        /Initialized empty .*/gitolite-admin.git/
        /Initialized empty .*/r1.git/
        /Initialized empty .*/r2.git/
        /Initialized empty .*/testing.git/
        /Initialized empty .*/gitolite-admin.git/
        /Initialized empty .*/r1.git/
        /Initialized empty .*/r2.git/
        /Initialized empty .*/testing.git/
";

# ----------------------------------------------------------------------
# SECTION 1: gitolite-admin shenanigans

# push to frodo and see sam and gollum change
try "
    git clone frodo\@localhost:gitolite-admin fga
        ok; /Cloning into 'fga'.../
    cd fga;                             ok
    cp $h/.ssh/u?.pub keydir;           ok
    git add keydir;                     ok
    git commit -m 6keys;                ok
    git push;                           ok
        /To localhost:gitolite-admin/
        /master -> master/
    sleep 5
    git rev-parse HEAD
";

chomp($t = text());

try "
    git ls-remote sam\@localhost:gitolite-admin
        ok; /$t/
    git ls-remote gollum\@localhost:gitolite-admin
        ok; /$t/
";

try "
    cd ..

";

# push to sam and see frodo and gollum change
try "
    git clone sam\@localhost:gitolite-admin sga
        ok; /Cloning into 'sga'.../
    cd sga;                             ok
    empty;                              ok
    git push;                           ok
        /To localhost:gitolite-admin/
        /master -> master/
    sleep 5
    git rev-parse HEAD
";

chomp($t = text());

try "
    git ls-remote frodo\@localhost:gitolite-admin
        ok; /$t/
    git ls-remote gollum\@localhost:gitolite-admin
        ok; /$t/
";

try "
    cd ..

";

# push to gollum and fail at gollum
try "
    git clone gollum\@localhost:gitolite-admin gga
        ok; /Cloning into 'gga'.../
    cd gga;                             ok
    empty;                              ok
    git push;                           !ok
        !/To localhost:gitolite-admin/
        !/master -> master/
        /gollum: pushing 'gitolite-admin' to copy 'gollum' not allowed/
    git rev-parse HEAD
";

chomp($t2 = text());

try "
    git ls-remote frodo\@localhost:gitolite-admin
        ok; /$t/; !/$t2/
    git ls-remote sam\@localhost:gitolite-admin
        ok; /$t/; !/$t2/
    git ls-remote gollum\@localhost:gitolite-admin
        ok; /$t/; !/$t2/
";

# fake out the gollum failure to continue the redirected push and fail at frodo
try "
    sudo -u gollum -i gitolite git-config -r gitolite-admin .
        ok
        /redirectOK.*sam/
        !/redirectOK.*gollum/

    sudo -u gollum -i bash -c 'echo repo gitolite-admin > junk'
    sudo -u gollum -i bash -c 'echo option mirror.redirectOK-1 = gollum   >> junk'
    sudo -u gollum -i bash -c 'cat junk >> .gitolite/conf/gitolite.conf'
    sudo -u gollum -i gitolite compile
    sudo -u gollum -i gitolite git-config -r gitolite-admin .
        ok
        /redirectOK.*sam/
        /redirectOK.*gollum/

    git push;                           !ok
        /frodo: redirection not allowed from 'gollum'/
        !/To gollum\@localhost:gitolite-admin/
        !/master -> master/
";

# reset gollum via frodo
try "
    cd ..
    rm -rf fga
    git clone frodo\@localhost:gitolite-admin fga
        ok; /Cloning into 'fga'.../
    cd fga;                             ok
    empty;                              ok
    git push;                           ok
        /To localhost:gitolite-admin/
        /master -> master/
    sleep 5

    sudo -u gollum -i gitolite git-config -r gitolite-admin .
        ok
        /redirectOK.*sam/
        !/redirectOK.*gollum/

    git rev-parse HEAD
";

chomp($t = text());

try "
    git ls-remote sam\@localhost:gitolite-admin
        ok; /$t/
    git ls-remote gollum\@localhost:gitolite-admin
        ok; /$t/
";

# ----------------------------------------------------------------------
# user repo shenanigans

# for a recap of the perms see t/mirror-test-setup.sh

try "
    cd ..
    pwd
    /tmp/tsh_tempdir/ or die not in the right place
" or die;

swk('u1');

# u1 sam r1, R ok, W ok
try "
    rm -rf fga sga gga

    git clone sam\@localhost:r1 sr1
        /Cloning into 'sr1'.../
        /warning: You appear to have cloned an empty repository/
    cd sr1
    empty
    git push origin master
        /new branch/;   /master -> master/
    sleep 5
    git rev-parse HEAD
";
chomp($t = text());

# u1 sam r1, W mirrors to frodo but not gollum
try "
    git ls-remote sam\@localhost:r1
        /$t/
    git ls-remote frodo\@localhost:r1
        /$t/
    git ls-remote gollum\@localhost:r1
        /gollum: 'r1' is mirrored but not here/
";

swk("u2");
try "
    empty
    git rev-parse HEAD
";
chomp($t2 = text());

# u2 sam r2 W ok, mirrors to all
try "
    git push sam\@localhost:r2 master
        /new branch/;   /master -> master/
        /master -> master/
    sleep 5
    git ls-remote frodo\@localhost:r2
        !/$t/
        /$t2/
    git ls-remote gollum\@localhost:r2
        !/$t/
        /$t2/
";

swk("u1");

# u1 gollum r1 -- "known unknown" :-)
# u1 frodo r1 R ok, W not ok
# u1 sam r1 R ok, W ok
try "
    cd ..
    rm -rf sr1

    git clone gollum\@localhost:r1 fr1
        /gollum: 'r1' is mirrored but not here/

    git clone frodo\@localhost:r1 fr1;       ok
    cd fr1
    empty
    git push
        /frodo: pushing 'r1' to copy 'frodo' not allowed/
    cd ..
    git clone sam\@localhost:r1 sr1;         ok
    cd sr1
    empty
    git push;                               ok
        /master -> master/
    sleep 5
    git rev-parse HEAD
";
chomp($t = text());

# u1 sam r1 W mirrored to frodo but not gollum
try "
    git ls-remote sam\@localhost:r1
        /$t/
    git ls-remote frodo\@localhost:r1
        /$t/

    git ls-remote gollum\@localhost:r1
        /gollum: 'r1' is mirrored but not here/

    git reset --hard HEAD^;                 ok
    tc a
    git push;                               !ok
        /rejected/
        /failed to push/

    git push -f
        /\\+ .......\\.\\.\\........ master -> master .forced update/
    sleep 5
";

swk("u2");

# u2 frodo r1 R ok, W not allowed (no redirectOK)
# u2 frodo r2 W ok
try "
    cd ..
    rm -rf fr1 sr1

    git clone frodo\@localhost:r1 fr1;       ok
    cd fr1
    tc b
    git push
        /frodo: pushing 'r1' to copy 'frodo' not allowed/
    cd ..
    git clone frodo\@localhost:r2 fr2;       ok
    cd fr2
    tc c
    git push
        /master -> master/
    sleep 5
    git rev-parse HEAD
";
chomp($t = text());

# u2 frodo r2 W mirrors to sam and gollum
try "
    git ls-remote sam\@localhost:r2
        /$t/
    git ls-remote gollum\@localhost:r2
        /$t/

    git reset --hard HEAD^;                 ok
    tc d
    git push
        /rejected/
        /failed to push/

    git push -f
        /\\+ .......\\.\\.\\........ master -> master .forced update/
    sleep 5

    cd ..
    rm -rf fr1 fr2
";

swk("u3");

# u3 frodo r2 R ok W ok
try "
    git clone frodo\@localhost:r2 fr2;       ok
    cd fr2
    tc e
    git push;                               ok
    sleep 5

    git rev-parse HEAD
";
chomp($t = text());

# u3 frodo r2 W mirrors to sam and gollum
try "
    git ls-remote sam\@localhost:r2
        /$t/
    git ls-remote gollum\@localhost:r2
        /$t/

    git reset --hard HEAD^;                 ok
    tc f
    git push
        /rejected/
        /failed to push/

    sleep 10
    git push -f
        /\\+ refs/heads/master r2 u3 DENIED by fallthru/
        /hook declined/
        /rejected/
";

# ----------------------------------------------------------------------
# all those vague edge cases where the two servers have totally wrong ideas
# about each other

swk('u1');

try "sudo -u frodo -i ls .gitolite/logs";
chomp($t = text());
my $lfn = ".gitolite/logs/$t";

try "
    ssh sam\@localhost mirror push frodo lfrodo;  !ok
    /FATAL: frodo: 'lfrodo' is local/

    ssh sam\@localhost mirror push frodo mboth;  !ok
    /FATAL: frodo: 'mboth' is native/

    ssh sam\@localhost mirror push frodo mnotsam;  !ok
    /FATAL: frodo: 'sam' is not the master for 'mnotsam'/

    cd ..
    git clone sam\@localhost:lfrodo2 lfrodo2;   ok
    cd lfrodo2
    empty
    git push origin master;                     !ok
    /FATAL: frodo: 'lfrodo2' is local/

    cd ..
    git clone sam\@localhost:nnfrodo nnfrodo;   ok
    cd nnfrodo
    empty
    git push origin master;                     !ok
    /FATAL: frodo: 'nnfrodo' is not native/

    cd ..
    git clone sam\@localhost:nvsfrodo nvsfrodo; ok
    cd nvsfrodo
    empty
    git push origin master;                     !ok
    /FATAL: frodo: 'sam' is not a valid copy for 'nvsfrodo'/
";