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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
|
test_description='Check the audit regressions'
. ./setup.sh
cgitrc_site() {
cgitrc_site_file=$1
shift
printf '%s\n' virtual-root=/ cache-size=0 "$@" >"$cgitrc_site_file"
}
expect_status() {
sed -n 1p "$2" >status-line &&
test_grep "^Status: $1 " status-line &&
grep "^Status:" "$2" >status-lines &&
test_line_count = 1 status-lines
}
test_expect_success 'set up a repository and a config to vary' '
mkrepo repos/rob 3 &&
sha=$(git -C repos/rob rev-parse HEAD~1) &&
cgitrc_repo robrc rob snapshots=tar.gz
'
test_expect_success 'a repository without a path answers 404' '
cgitrc_site nopathrc repo.url=nopath repo.url=emptypath repo.path= &&
for r in nopath emptypath
do
cgit_rc nopathrc "url=$r/log/" >tmp &&
expect_status 404 tmp &&
grep "Failed to open $r: Not a valid git repository" tmp || return 1
done
'
test_expect_success 'a repository without a path has no age on the index' '
cgitrc_site nopathagerc repo.url=nopath &&
mkdir -p "(null)/refs/heads" &&
>"(null)/refs/heads/master" &&
cgit_ok nopathagerc "url=" >tmp &&
test_grep ">nopath</a>" tmp &&
test_grep "<td class=.col-idle.></td>" tmp &&
test_grep ! "<time " tmp
'
test_expect_success 'a repository with an empty url is skipped with a warning' '
cgitrc_site nourlrc repo.url= "repo.path=$PWD/repos/rob/.git" repo.desc=nourl \
repo.url=rob "repo.path=$PWD/repos/rob/.git" &&
cgit_rc nourlrc "url=rob/" >tmp 2>err &&
expect_status 200 tmp &&
grep "Ignoring repository with an empty url" err &&
for query in url= r=
do
cgit_rc nourlrc "$query" >tmp 2>err &&
expect_status 200 tmp &&
test_grep ">rob</a>" tmp &&
test_grep ! nourl tmp || return 1
done
'
test_expect_success 'a scan path that is itself a repository is named after it' '
cgitrc_site rootrc remove-suffix=1 "scan-path=$PWD/repos/rob" &&
cgit_rc rootrc "url=" >tmp &&
grep "toplevel-repo.><a href=./rob/.>rob</a>" tmp
'
test_expect_success 'a repo key after scan-path is reported instead of applied' '
cgitrc_site stalerc repo.url=first "repo.path=$PWD/repos/rob/.git" "scan-path=$PWD/repos" repo.desc=misplaced &&
cgit_rc stalerc "url=" >tmp 2>err &&
! grep "misplaced" tmp &&
grep "Ignoring repo.desc before any repo.url" err
'
test_expect_success 'a valueless or broken git config in a scanned repository is skipped' '
git clone -q --bare repos/rob/.git scan/a.git &&
printf "[cgit]\n\thide\n[cgit\n" >>scan/a.git/config &&
cgitrc_site gitcfgrc enable-git-config=1 "scan-path=$PWD/scan" &&
cgit_rc gitcfgrc "url=" >tmp 2>err &&
grep "toplevel-repo.><a href=./a.git/.>" tmp &&
grep "Ignoring unreadable config in $PWD/scan/a.git/config" err
'
test_expect_success 'set up a scanned repository setting every key that waits on trust' '
mkrepo scankeys/k 1 &&
sub=$(git -C scankeys/k rev-parse HEAD) &&
git -C scankeys/k update-index --add --cacheinfo 160000,$sub,sub &&
git -C scankeys/k update-index --add --cacheinfo 160000,$sub,other &&
git -C scankeys/k commit -q -m gitlinks &&
write_script evil-filter.sh <<-\EOF &&
echo "evil filter"
cat
EOF
cat >scankeys/k/.git/cgitrc <<-EOF &&
desc=from the repo
readme=master:file-1
about-filter=exec:$PWD/evil-filter.sh
head-content=<script>alert(1)</script>
logo=/evil/logo.png
logo-link=https://evil.example/logo-link
clone-url=https://evil.example/clone
module-link=https://evil.example/module/%s
module-link.sub=https://evil.example/path/%s
EOF
cgitrc_site scankeysrc "scan-path=$PWD/scankeys" &&
cgitrc_site scankeystrustrc trust-scan-config=1 "scan-path=$PWD/scankeys"
'
test_expect_success 'only descriptive keys are taken from a scanned repository' '
for page in about/ "" tree/
do
cgit_rc scankeysrc "url=k/$page" >tmp 2>err &&
expect_status 200 tmp &&
test_grep "<p class=.sub desc.>from the repo</p>" tmp &&
test_grep ! "evil" tmp &&
test_grep ! "alert(" tmp || return 1
done &&
for key in about-filter head-content logo logo-link clone-url module-link module-link.sub
do
test_grep "Ignoring $key in $PWD/scankeys/k/.git/: trust-scan-config is not set" err || return 1
done &&
cgit_rc scankeysrc "url=k/about/" >tmp &&
test_grep "<pre class=.plaintext.>1$" tmp
'
test_expect_success 'with trust-scan-config the same keys apply' '
sub=$(git -C scankeys/k rev-parse HEAD~1) &&
cgit_ok scankeystrustrc "url=k/about/" >tmp &&
test_grep "^<script>alert(1)</script></head>$" tmp &&
test_grep "<a class=.logo. href=.https://evil.example/logo-link.><img src=./evil/logo.png." tmp &&
test_grep "<div id=.about.>evil filter$" tmp &&
cgit_ok scankeystrustrc "url=k/" >tmp &&
test_grep "https://evil.example/clone" tmp &&
cgit_ok scankeystrustrc "url=k/tree/" >tmp &&
test_grep "href=.https://evil.example/path/$sub.>sub</a>" tmp &&
test_grep "href=.https://evil.example/module/other.>other</a>" tmp
'
test_expect_success 'a filesystem readme from a scanned repository is refused' '
git clone -q --bare repos/rob/.git readmescan/b.git &&
echo "outside the repository" >outside &&
echo "outside the repository" >"readmescan/outside:" &&
cgitrc_site readmescanrc "scan-path=$PWD/readmescan" &&
cgitrc_site readmescantrustrc trust-scan-config=1 "scan-path=$PWD/readmescan" &&
for readme in "$PWD/outside" ../outside:
do
echo "readme=$readme" >readmescan/b.git/cgitrc &&
cgit_rc readmescanrc "url=b.git/about/" >tmp 2>err &&
expect_status 302 tmp &&
test_grep "Ignoring readme in $PWD/readmescan/b.git/: trust-scan-config is not set" err &&
cgit_rc readmescantrustrc "url=b.git/about/" >tmp &&
expect_status 200 tmp &&
test_grep "outside the repository" tmp || return 1
done
'
test_expect_success 'a readme set after scan-path reaches a scanned repository' '
git clone -q --bare repos/rob/.git laterscan/b.git &&
cgitrc_site laterrc "scan-path=$PWD/laterscan" readme=master:file-1 &&
cgit_rc laterrc "url=b.git/about/" >tmp &&
grep "<pre class=.plaintext.>1$" tmp
'
test_expect_success 'html serving from a scanned repository waits on trust' '
mkrepo repos/html 1 &&
test_commit -C repos/html --no-tag html page.html "<p>page</p>" &&
mkdir -p scan2 &&
git clone -q --bare repos/html/.git scan2/c.git &&
git -C scan2/c.git config cgit.enable-html-serving 1 &&
cgitrc_site htmlrc enable-git-config=1 mimetype.html=text/html "scan-path=$PWD/scan2" &&
cgit_rc htmlrc "url=c.git/plain/page.html" >tmp 2>err &&
grep "^Content-Type: text/plain" tmp &&
grep "^X-Content-Type-Options: nosniff" tmp &&
grep "Ignoring enable-html-serving in $PWD/scan2/c.git/: trust-scan-config is not set" err
'
test_expect_success 'with trust-scan-config the same repository serves html' '
cgitrc_site htmltrustrc trust-scan-config=1 enable-git-config=1 \
mimetype.html=text/html "scan-path=$PWD/scan2" &&
cgit_rc htmltrustrc "url=c.git/plain/page.html" >tmp &&
grep "^Content-Type: text/html" tmp &&
! grep "^X-Content-Type-Options" tmp
'
test_expect_success SYMLINKS 'a symlink cycle under the scan path is entered once' '
mkdir loopscan &&
git clone -q --bare repos/rob/.git loopscan/r.git &&
ln -s . loopscan/loop &&
cgitrc_site looprc "scan-path=$PWD/loopscan" &&
cgit_ok looprc "url=" >tmp &&
test_grep "<td class=.col-name toplevel-repo.><a href=./r.git/.>r.git</a>" tmp &&
test $(grep -c "<tr class=.repo.>" tmp) = 1
'
test_expect_success 'a bare query parameter does not swallow the next one' '
cgit_rc robrc "url=rob/commit/&x&id=$sha" >tmp &&
grep "<div class=.commit-subject.>commit 2" tmp
'
test_expect_success 'a filter that cannot run answers one error page' '
cgitrc_repo badfilterrc rob "commit-filter=exec:$PWD/no/such/filter" &&
cgit_rc badfilterrc "url=rob/commit/" >tmp 2>err &&
expect_status 200 tmp &&
grep "Unable to complete the request" tmp &&
grep -e "Unable to run filter $PWD/no/such/filter" -e "Unable to write the page" err &&
grep "Unable to exec filter" err
'
test_expect_success 'a filter that exits without reading does not end cgit' '
mkrepo repos/quit 1 &&
test_commit -C repos/quit --no-tag big big.txt "$(test_seq 20000)" &&
cgitrc_repo quitrc quit source-filter=exec:true &&
cgit_rc quitrc "url=quit/tree/big.txt" >tmp 2>err &&
expect_status 200 tmp &&
test_grep "<div class=.blob-header.>blob: " tmp
'
test_expect_success 'a commit encoding header is read without its newline' '
mkrepo repos/latin 1 &&
(
cd repos/latin &&
echo more >file-1 &&
git add file-1 &&
git -c i18n.commitEncoding=ISO-8859-1 commit -m "$(printf "caf\351")"
) &&
cgitrc_repo latinrc latin &&
cgit_rc latinrc "url=latin/commit/" >tmp &&
grep "<div class=.commit-subject.>caf$(printf "\303\251")<" tmp
'
test_expect_success 'a path below the about page answers 404' '
mkrepo repos/about 3 &&
(
cd repos/about &&
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD~1),sub &&
git commit -m gitlink
) &&
cgitrc_repo aboutrc about mimetype.png=image/png repo.readme=master:file-1 &&
for path in sub sub/ missing.png file-1 ../aboutrc
do
cgit_rc aboutrc "url=about/about/$path" >tmp 2>err &&
expect_status 404 tmp &&
grep "^Content-Type: text/html" tmp &&
! grep fatal err || return 1
done &&
cgit_rc aboutrc "p=about&path=x" >tmp &&
expect_status 404 tmp
'
test_expect_success 'a path opening with a colon is refused on the log and patch pages' '
cgit_rc robrc "url=rob/log/:%25x" >tmp &&
expect_status 400 tmp &&
cgit_rc robrc "url=rob/patch/:%25x" >tmp &&
expect_status 400 tmp
'
test_expect_success 'a revision spelled like an option is refused' '
mkrepo repos/optref 1 &&
git -C repos/optref update-ref refs/heads/--stdin HEAD &&
cgitrc_repo optrefrc optref &&
cgit_rc optrefrc "url=optref/log/&h=--stdin" >tmp &&
expect_status 404 tmp &&
cgit_rc optrefrc "url=optref/blame/file-1&id=--stdin" >tmp &&
expect_status 400 tmp &&
cgit_rc optrefrc "url=optref/atom/&h=--stdin" >tmp &&
expect_status 404 tmp
'
test_expect_success 'set up a repository with an annotated tag' '
mkrepo repos/tagged 3 &&
git -C repos/tagged tag -a -m note ann HEAD &&
cgitrc_repo taggedrc tagged
'
test_expect_success 'the blob page reads a file through an annotated tag' '
git -C repos/tagged cat-file blob ann:file-1 >want &&
cgit_ok taggedrc "url=tagged/blob/&h=ann&path=file-1" >tmp &&
strip_headers <tmp >body &&
test_cmp want body
'
test_expect_success 'the blob page walks a path out of the commit or tag the id names' '
tip=$(git -C repos/tagged rev-parse HEAD) &&
git -C repos/tagged cat-file blob HEAD:file-1 >want &&
cgit_ok taggedrc "url=tagged/blob/file-1&id=$tip" >tmp &&
strip_headers <tmp >body &&
test_cmp want body &&
tag=$(git -C repos/tagged rev-parse ann) &&
git -C repos/tagged cat-file blob ann:file-1 >want &&
cgit_ok taggedrc "url=tagged/blob/file-1&id=$tag" >tmp &&
strip_headers <tmp >body &&
test_cmp want body &&
cgit_rc taggedrc "url=tagged/blob/missing&id=$tip" >tmp &&
expect_status 404 tmp
'
test_expect_success 'a revision expression that walks the history is refused' '
cgit_rc robrc "url=rob/log/&h=:/zzzz" >tmp &&
expect_status 404 tmp &&
cgit_rc robrc "url=rob/commit/&id=HEAD^{/zzzz}" >tmp &&
expect_status 400 tmp &&
cgit_rc robrc "url=rob/log/&qt=range&q=:/zzzz" >tmp &&
expect_status 400 tmp &&
cgit_rc robrc "url=rob/log/&qt=range&q=master~1..master" >tmp &&
expect_status 400 tmp &&
cgit_rc robrc "url=rob/log/&qt=range&q=$sha..master" >tmp &&
expect_status 200 tmp
'
test_expect_success REFFILES 'a commit with a broken tree line does not crash the blob page' '
git clone -q repos/rob broken &&
git -C broken cat-file commit HEAD >commit &&
sed "s/^tree .*/tree not-a-hash/" commit >bad-commit &&
bad=$(git -C broken hash-object -t commit -w --literally "$PWD/bad-commit") &&
echo $bad >broken/.git/refs/heads/bad &&
cgitrc_repo brokenrc broken "repo.path=$PWD/broken/.git" repo.readme=:file-1 &&
cgit_rc brokenrc "url=broken/blob/&h=bad&path=file-1" >tmp &&
expect_status 404 tmp
'
test_expect_success 'a die inside git answers one 500 page and logs the reason' '
git clone -q repos/rob badconfig &&
printf "[core\n" >>badconfig/.git/config &&
cgitrc_repo badconfigrc badconfig "repo.path=$PWD/badconfig/.git" &&
cgit_rc badconfigrc "url=badconfig/log/" >tmp 2>err &&
expect_status 500 tmp &&
test_grep "bad config line" err &&
test_grep ! "bad config line" tmp
'
test_expect_success 'a history with a missing parent answers one error' '
test_create_repo gap &&
test_commit -C gap --no-tag first &&
test_commit -C gap --no-tag second &&
test_commit -C gap --no-tag third &&
older=$(git -C gap rev-parse HEAD~2) &&
parent=$(git -C gap rev-parse HEAD~1) &&
tip=$(git -C gap rev-parse HEAD) &&
rm "gap/.git/objects/$(test_oid_to_path $parent)" &&
cgitrc_repo gaprc gap "repo.path=$PWD/gap/.git" &&
cgit_rc gaprc "url=gap/log/" >tmp 2>err &&
expect_status 200 tmp &&
test_grep "<div class=.error.>Unable to complete the request</div>" tmp &&
test_grep "Failed to traverse parents of commit $tip" err &&
cgit_rc gaprc "url=gap/patch/&id2=$older" >tmp &&
expect_status 500 tmp
'
test_expect_success 'a corrupt blob in a collected diff answers the error' '
git init -q corrupt &&
(
cd corrupt &&
test_seq 2000 >f &&
git add f &&
git commit -q -m one &&
test_seq 2000 | sed "s/^5/X/" >f &&
git commit -q -a -m two &&
blob=$(git rev-parse HEAD:f) &&
obj=.git/objects/$(test_oid_to_path $blob) &&
size=$(wc -c <$obj) &&
chmod u+w $obj &&
test_copy_bytes $((size / 2)) <$obj >half &&
mv half $obj
) &&
cgitrc_repo corruptrc corrupt "repo.path=$PWD/corrupt/.git" &&
cgit_rc corruptrc "url=corrupt/commit/" >tmp 2>err &&
expect_status 200 tmp &&
test_grep "<div class=.error.>Unable to complete the request</div>" tmp &&
test_grep "is corrupt" err
'
test_expect_success 'a filter pipeline sees the default SIGPIPE disposition' '
write_script writer.sh <<-\EOF &&
n=0
while test $n -lt 20000
do
echo line
n=$((n + 1))
done
echo outlived >"$PWD/outlived"
EOF
write_script pipe.sh <<-EOF &&
"$PWD/writer.sh" | head -n 1
EOF
cgitrc_repo piperc rob "source-filter=exec:$PWD/pipe.sh" &&
cgit_ok piperc "url=rob/tree/file-1" >tmp &&
test_grep "<pre><code>line$" tmp &&
test_path_is_missing outlived
'
test_expect_success 'the fallback branch skips a name spelled like an option' '
mkrepo repos/fallback 1 &&
git -C repos/fallback update-ref refs/heads/-first HEAD &&
git -C repos/fallback symbolic-ref HEAD refs/heads/gone &&
cgitrc_repo fallbackrc fallback &&
cgit_ok fallbackrc "url=fallback/" >tmp &&
test_grep "<option value=.master. selected>" tmp &&
test_grep ! "<option value=.-first." tmp
'
test_expect_success 'a refs page named with an id is not cached for ever' '
mkrepo repos/ttl 1 &&
cgitrc_repo ttlrc ttl cache-size=10 "cache-root=$PWD/ttlcache" \
cache-static-ttl=-1 cache-dynamic-ttl=0 cache-summary-ttl=0 &&
cgitrc_repo foreverrc ttl cache-size=10 "cache-root=$PWD/forevercache" \
cache-static-ttl=-1 cache-dynamic-ttl=-1 cache-summary-ttl=0 &&
mkdir ttlcache forevercache &&
full=$(git -C repos/ttl rev-parse HEAD) &&
cgit_ok ttlrc "url=ttl/refs/&id=$full" >tmp &&
cgit_ok foreverrc "url=ttl/refs/&id=$full" >tmp &&
git -C repos/ttl tag later HEAD &&
cgit_ok ttlrc "url=ttl/refs/&id=$full" >tmp &&
test_grep ">later<" tmp &&
cgit_ok foreverrc "url=ttl/refs/&id=$full" >tmp &&
test_grep "<tr class=.branch.>" tmp &&
test_grep ! ">later<" tmp
'
test_lazy_prereq GZIP 'command -v gzip'
test_expect_success GZIP 'a snapshot of a tag spelled like an option is archived' '
mkrepo repos/opttag 1 &&
git -C repos/opttag update-ref refs/tags/-l HEAD &&
cgitrc_repo opttagrc opttag snapshots=tar.gz &&
cgit_ok opttagrc "url=opttag/snapshot/-l.tar.gz" >tmp &&
strip_headers <tmp >archive.tar.gz &&
gzip -dc archive.tar.gz >archive.tar &&
tar -tf archive.tar >list &&
test_grep "^-l/file-1$" list
'
test -n "$CGIT_VALGRIND" || test_set_prereq NO_VALGRIND
test_expect_success NO_VALGRIND 'a snapshot format whose compressor is missing answers 500' '
cgitrc_repo xzrc rob snapshots=tar.xz &&
cgitbin=$(command -v cgit) &&
mkdir -p nobin &&
PATH="$PWD/nobin" CGIT_CONFIG="$PWD/xzrc" \
QUERY_STRING="url=rob/snapshot/rob-master.tar.xz" "$cgitbin" >tmp &&
expect_status 500 tmp
'
test_expect_success 'a disk readme in the repository directory serves no sibling' '
mkrepo repos/disk 1 &&
echo hello >repos/disk/.git/README &&
cgitrc_repo diskrc disk repo.readme=README &&
cgit_rc diskrc "url=disk/about/" >tmp &&
grep "hello" tmp &&
cgit_rc diskrc "url=disk/about/config" >tmp &&
expect_status 404 tmp &&
! grep "repositoryformatversion" tmp
'
test_expect_success 'a tag pointing at a tag links the inner tag by id' '
git -C repos/tagged tag -a -m outer outer ann &&
inner=$(git -C repos/tagged rev-parse ann) &&
cgit_ok taggedrc "url=tagged/tag/&h=outer" >tmp &&
test_grep "<th scope=.row.>tagged object</th><td class=.oid.><a href=./tagged/tag/?h=outer&id=$inner.>tag $inner</a>" tmp &&
cgit_ok taggedrc "url=tagged/tag/&h=outer&id=$inner" >tmp &&
test_grep "<th scope=.row.>tag name</th><td>$inner " tmp &&
test_grep "<div class=.commit-subject.>note</div>" tmp
'
test_expect_success 'the dumb transport serves an empty repository' '
git init -q --bare empty.git &&
cgitrc_repo emptyrc empty "repo.path=$PWD/empty.git" &&
cgit_rc emptyrc "url=empty/info/refs" >tmp &&
expect_status 200 tmp &&
grep "^Content-Type: text/plain" tmp &&
cgit_rc emptyrc "url=empty/objects/info" >tmp &&
expect_status 404 tmp
'
test_expect_success 'the dumb transport sends a file with its size' '
mkrepo repos/packed 1 &&
git -C repos/packed repack -q -d &&
cgitrc_repo packedrc packed &&
cgit_rc packedrc "url=packed/objects/info/packs" >tmp &&
pack=$(strip_headers <tmp | sed -n "s/^P //p" | head -n 1) &&
test -n "$pack" &&
cgit_rc packedrc "url=packed/objects/pack/$pack" >tmp &&
expect_status 200 tmp &&
size=$(wc -c <repos/packed/.git/objects/pack/$pack | tr -d " ") &&
grep "^Content-Length: $size$" tmp &&
strip_headers <tmp >body &&
cmp body repos/packed/.git/objects/pack/$pack
'
test_expect_success 'the dumb transport answers HEAD from the refs' '
cgit_rc robrc "url=rob/HEAD" >tmp &&
expect_status 200 tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/master" >expect &&
test_cmp expect head &&
git init -q --bare --ref-format=reftable -b trunk rt.git &&
git -C repos/rob push -q "$PWD/rt.git" master:trunk &&
cgitrc_repo rtrc rt "repo.path=$PWD/rt.git" &&
cgit_rc rtrc "url=rt/HEAD" >tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/trunk" >expect &&
test_cmp expect head &&
git init -q --bare emptyhead.git &&
cgitrc_repo emptyheadrc emptyhead "repo.path=$PWD/emptyhead.git" &&
cgit_rc emptyheadrc "url=emptyhead/HEAD" >tmp &&
strip_headers <tmp >head &&
echo "ref: refs/heads/master" >expect &&
test_cmp expect head
'
test_expect_success 'a reftable repository shows its age on the index' '
git init -q --bare --ref-format=reftable -b trunk rtage.git &&
git -C repos/rob push -q "$PWD/rtage.git" master:trunk &&
cgitrc_repo rtagerc rtage "repo.path=$PWD/rtage.git" &&
cgit_rc rtagerc "url=" >tmp &&
grep "<td class=.col-idle.><time " tmp
'
test_expect_success 'a client that disconnects ends the request quietly' '
mkrepo repos/long 1 &&
test_commit -C repos/long --no-tag long long.txt \
"$(awk "BEGIN{for(i=0;i<20000;i++) print \"line \" i}")" &&
cgitrc_repo longrc long &&
{ cgit_rc longrc "url=long/tree/long.txt" 2>err; echo $? >status; } | test_copy_bytes 1 >/dev/null &&
test "$(cat status)" = 0 &&
! grep -i "broken pipe" err &&
! grep "die()" err
'
test_expect_success 'pages behind an auth filter are marked private' '
write_script letin.sh <<-\EOF &&
exit 1
EOF
cgitrc_repo letinrc rob "auth-filter=exec:$PWD/letin.sh" &&
cgit_rc letinrc "url=rob/log/" >tmp &&
expect_status 200 tmp &&
grep "^Cache-Control: private$" tmp &&
grep "^Vary: Cookie$" tmp &&
cgit_ok robrc "url=rob/log/" >tmp &&
test_grep ! "^Cache-Control" tmp &&
test_grep ! "^Vary" tmp
'
test_expect_success 'the about redirect keeps the query string' '
mkrepo repos/redirect 1 &&
git -C repos/redirect branch other HEAD &&
cgitrc_repo redirectrc redirect &&
cgit_rc redirectrc "url=redirect/about&h=other&x=1" >tmp &&
expect_status 302 tmp &&
grep "^Location: /redirect/?h=other&x=1$" tmp &&
cgitrc_repo redirectreadmerc redirect repo.readme=master:file-1 &&
cgit_rc redirectreadmerc "url=redirect/about&h=other" >tmp &&
expect_status 200 tmp
'
test_expect_success 'the readme follows an annotated tag as the head' '
mkrepo repos/tagreadme 1 &&
git -C repos/tagreadme tag -a -m release v1 HEAD &&
cgitrc_repo tagreadmerc tagreadme repo.readme=:file-1 &&
cgit_rc tagreadmerc "url=tagreadme/about/&h=v1" >tmp &&
expect_status 200 tmp &&
cgit_rc tagreadmerc "url=tagreadme/tree/&h=v1" >tmp &&
grep ">about<" tmp
'
test_expect_success 'the about redirect encodes the repository url once' '
cgit_url "foo%2Bbar/about/" >tmp &&
expect_status 302 tmp &&
grep "^Location: /foo%2Bbar/$" tmp
'
test_expect_success 'a symlink whose target is a large blob is listed without it' '
mkrepo repos/biglink 1 &&
printf "%05000d" 0 | tr 0 a >big-target &&
big=$(git -C repos/biglink hash-object -w --stdin <big-target) &&
test $(git -C repos/biglink cat-file -s $big) = 5000 &&
(
cd repos/biglink &&
git update-index --add --cacheinfo 120000,$big,biglink &&
git commit -m biglink
) &&
cgitrc_repo biglinkrc biglink &&
cgit_ok biglinkrc "url=biglink/tree/" >tmp &&
test_grep "<tr class=.link.>.*>biglink</a></td><td class=.ls-size.>5000<" tmp &&
test_grep ! "aaaaaaaaaa" tmp
'
test_expect_success 'an unreadable project list is named with its error' '
mkdir -p projdir &&
cgitrc_site projrc "project-list=$PWD/projdir" "scan-path=$PWD/repos" &&
cgit_rc projrc "url=" >tmp 2>err &&
grep "project list .*projdir: Is a directory" err
'
test_expect_success SANITY 'a scan entry that cannot be searched is named in full' '
mkdir -p scanperm/locked &&
test_when_finished "chmod 755 scanperm/locked" &&
chmod 644 scanperm/locked &&
cgitrc_site scanpermrc "scan-path=$PWD/scanperm" &&
cgit_rc scanpermrc "url=" >tmp 2>err &&
grep "Unable to stat .*scanperm/locked/objects: Permission denied" err
'
test_expect_success 'a readme past max-blob-size is reported on the about page' '
mkrepo repos/bigreadme 1 &&
test_commit -C repos/bigreadme --no-tag "big readme" big-readme "$(test_seq 1 1000)" &&
cgitrc_repo bigreadmerc bigreadme max-blob-size=1 repo.readme=:big-readme &&
cgit_rc bigreadmerc "url=bigreadme/about/" >tmp &&
grep "The readme is larger than max-blob-size (1 KB)" tmp
'
test_expect_success 'the error page does not resolve the id it refused' '
cgit_rc robrc "url=rob/log/&id=$sha" >tmp &&
grep "<title>.* @ " tmp &&
cgit_rc robrc "url=rob/log/&id=%3A/commit" >tmp &&
expect_status 400 tmp &&
test_grep "<title>Bad Request - rob - " tmp &&
test_grep ! "<title>.* @ " tmp
'
test_expect_success 'a notes ref that names no tree is passed over' '
test_create_repo repos/notes &&
test_commit -C repos/notes base &&
blob=$(echo not-a-tree | git -C repos/notes hash-object -w --stdin) &&
git -C repos/notes update-ref refs/notes/commits $blob &&
git -C repos/notes update-ref refs/notes/signatures/tar $blob &&
cgitrc_repo notesrc notes snapshots=tar &&
for q in "url=notes/" "url=notes/log/" "url=notes/refs/" "url=notes/tree/"
do
cgit_ok notesrc "$q" >tmp || return 1
done &&
cgit_rc notesrc "url=notes/snapshot/notes-base.tar.asc" >tmp 2>err &&
expect_status 404 tmp &&
test_grep "<div class=.error.>No signature for notes-base.tar</div>" tmp &&
test_grep ! "notes tree" err
'
test_expect_success REFFILES 'a scanned defbranch cannot name a path outside the repository' '
git clone -q --bare repos/rob/.git defscan/b.git &&
mkdir -p secret &&
touch -t 200001010000 secret/file &&
echo "defbranch=../../../../secret/file" >defscan/b.git/cgitrc &&
cgitrc_site defscanrc "scan-path=$PWD/defscan" &&
cgit_rc defscanrc "url=" >tmp &&
grep ">b.git</a>" tmp &&
! grep "data-ut=.946" tmp
'
test_expect_success REFFILES 'a crafted HEAD cannot date a repository from outside it' '
mkdir -p aimed &&
touch -t 200001010000 aimed/file &&
git init -q --bare headscan/h.git &&
echo "ref: refs/heads/../../../../aimed/file" >headscan/h.git/HEAD &&
cgitrc_site headrc "scan-path=$PWD/headscan" &&
cgit_rc headrc "url=" >tmp &&
expect_status 200 tmp &&
test_grep ">h.git</a>" tmp &&
test_grep ! "data-ut=.946" tmp
'
test_expect_success 'blame turns away a binary file' '
mkrepo repos/binblame 1 &&
test_commit -C repos/binblame --no-tag --printf binary bin.dat "a\000b\n" &&
cgitrc_repo binblamerc binblame repo.enable-blame=1 &&
cgit_ok binblamerc "url=binblame/blame/bin.dat" >tmp &&
test_grep "<div class=.error.>Blob is binary</div>" tmp &&
test_grep ! "<table class=.blame blob.>" tmp &&
cgit_ok binblamerc "url=binblame/tree/bin.dat" >tmp &&
test_grep "<div class=.blob-header.>blob: " tmp &&
test_grep ! "href=./binblame/blame/" tmp &&
cgit_ok binblamerc "url=binblame/tree/file-1" >tmp &&
test_grep "(<a href=./binblame/blame/file-1.>blame</a>)" tmp
'
test_expect_success 'descriptive values from a scanned repository are escaped' '
git clone -q --bare repos/rob/.git descscan/d.git &&
cat >descscan/d.git/cgitrc <<-\EOF &&
desc=desc <x> & "q" '\''s
owner=owner <x> & "q" '\''s
section=section <x> & "q" '\''s
EOF
cgitrc_site descrc enable-index-owner=1 "scan-path=$PWD/descscan" &&
cgit_ok descrc "url=" >tmp &&
test_grep "<a href=./d.git/.>desc <x> & \"q\" .s</a>" tmp &&
test_grep "<a href=./?q=owner+%3Cx%3E+%26+%22q%22+%27s.>owner <x> & \"q\" .s</a>" tmp &&
test_grep "class=.reposection.>section <x> & \"q\" .s</td>" tmp &&
test_grep ! "<x>" tmp &&
cgit_ok descrc "url=d.git/" >tmp &&
test_grep "<meta name=.description. content=.desc <x> & "q" 's.>" tmp &&
test_grep ! "<x>" tmp
'
test_expect_success 'only a .mailmap at HEAD within max-blob-size is applied' '
test_create_repo repos/mapped &&
(
cd repos/mapped &&
echo content >file &&
git add file &&
GIT_AUTHOR_NAME="Old Name" GIT_AUTHOR_EMAIL=old@example.com \
git commit -q -m first &&
echo "New Name <new@example.com> <old@example.com>" >.mailmap &&
test_seq -f "# padding line %d" 1 200 >>.mailmap &&
echo "Blob Name <blob@example.com> <old@example.com>" >other-map &&
git add .mailmap other-map &&
git commit -q -m "add the mailmaps" &&
echo "File Name <file@example.com> <old@example.com>" >../map-on-disk &&
git config mailmap.file "$PWD/../map-on-disk" &&
git config mailmap.blob HEAD:other-map
) &&
test $(git -C repos/mapped cat-file -s HEAD:.mailmap) -ge 2048 &&
cgitrc_repo mappedrc mapped &&
cgit_ok mappedrc "url=mapped/log/" >tmp &&
test_grep "<td class=.col-author.>New Name</td>" tmp &&
test_grep ! -e "File Name" -e "Blob Name" tmp &&
cgitrc_repo mappedcaprc mapped max-blob-size=1 &&
cgit_ok mappedcaprc "url=mapped/log/" >tmp &&
test_grep "<td class=.col-author.>Old Name</td>" tmp &&
test_grep ! "New Name" tmp
'
test_done
|