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
|
test_description='Check the ref listing and diff size limits'
. ./setup.sh
test_expect_success 'set up limit fixtures' '
mkrepo repos/limits 1 &&
(
cd repos/limits &&
test_seq 1 60 >big.c &&
printf "int x;\n" >small.c &&
git add -A &&
git commit -m sources &&
test_seq 301 360 >big.c &&
printf "int y;\n" >small.c &&
git commit -am change &&
for i in 1 2 3
do
git branch branch-$i &&
git tag tag-$i || exit 1
done
) &&
cgitrc_repo limitrc limits max-ref-count=2 max-diff-lines=20 max-diff-files=0 &&
cgitrc_repo limitfilesrc limits max-diff-files=1
'
test_expect_success 'an enormous query is clamped, not rejected' '
long=$(awk "BEGIN{s=\"\";for(i=0;i<4000;i++)s=s \"a\"; print s}") &&
cgit_query "q=$long" >tmp &&
grep "</html>" tmp &&
longest=$(grep -o "aaaa*" tmp | awk "{print length}" | sort -n | tail -1) &&
test "$longest" -eq 512
'
test_expect_success 'an ordinary query still filters the index' '
cgit_query "q=foo" >tmp &&
grep ">foo</a>" tmp &&
! grep ">bar<" tmp
'
test_expect_success 'refs page lists max-ref-count branches and tags' '
cgit_rc limitrc "url=limits/refs/" >tmp &&
test $(grep -c "log/?h=" tmp) -eq 2 &&
test $(grep -c "/tag/?h=tag-" tmp) -eq 2
'
test_expect_success 'refs page links each overflow to its own category' '
grep "refs/heads" tmp &&
grep "refs/tags" tmp
'
test_expect_success 'branch page paginates independently' '
cgit_rc limitrc "url=limits/refs/heads/" >tmp &&
test $(grep -c "log/?h=" tmp) -eq 2 &&
grep "\[next\]" tmp &&
cgit_rc limitrc "url=limits/refs/heads/&ofs=2" >tmp &&
grep "\[prev\]" tmp &&
! grep "/tag/?h=tag-" tmp
'
test_expect_success 'tag page paginates independently' '
cgit_rc limitrc "url=limits/refs/tags/&ofs=2" >tmp &&
grep "/tag/?h=tag-" tmp &&
grep "\[prev\]" tmp &&
! grep "log/?h=" tmp
'
test_expect_success 'a negative ref count lists every ref' '
for n in 0 -1
do
{
echo "summary-branches=$n" &&
echo "summary-tags=$n" &&
sed "s/^max-ref-count=2$/max-ref-count=$n/" limitrc
} >count$n.rc &&
cgit_rc count$n.rc "url=limits/refs/" >refs$n &&
cgit_rc count$n.rc "url=limits/" >summary$n ||
return 1
done &&
grep "log/?h=branch-3" refs0 &&
grep "/tag/?h=tag-3" summary0 &&
test_cmp refs0 refs-1 &&
test_cmp summary0 summary-1
'
test_expect_success 'oversized file diff is replaced by a link' '
cgit_rc limitrc "url=limits/commit/" >tmp &&
grep "too large to be rendered inline" tmp &&
grep "View it on its own page" tmp
'
test_expect_success 'small file in the same commit still renders inline' '
grep "class=.add.>+int y;" tmp
'
test_expect_success 'the single-file diff page always renders in full' '
cgit_rc limitrc "url=limits/diff/big.c" >tmp &&
grep "class=.hunk." tmp &&
! grep "too large to be rendered inline" tmp
'
test_expect_success 'a commit changing too many files shows stat only' '
cgit_rc limitfilesrc "url=limits/commit/" >tmp &&
grep "too large to be rendered inline" tmp &&
! grep "class=.hunk." tmp
'
test_expect_success 'the single-file page is not limited by max-diff-files' '
cgit_rc limitfilesrc "url=limits/diff/small.c" >tmp &&
grep "class=.hunk." tmp
'
test_expect_success 'a diff of an oversized blob is not inlined' '
mkrepo repos/blobdiff 1 &&
(
cd repos/blobdiff &&
awk "BEGIN{for(i=0;i<400;i++)print \"aaaaaaaa\"}" >big.txt &&
git add -A &&
git commit -m add &&
awk "BEGIN{for(i=0;i<401;i++)print \"aaaaaaaa\"}" >big.txt &&
git commit -am change
) &&
cgitrc_repo blobdiffrc blobdiff max-blob-size=1 &&
sha=$(git -C repos/blobdiff rev-parse HEAD) &&
cgit_rc blobdiffrc "url=blobdiff/commit/&id=$sha" >tmp &&
grep "Binary files differ" tmp &&
! grep "aaaaaaaa" tmp
'
test_expect_success 'every page showing a blob refuses an oversized one alike' '
{
echo "enable-blame=1" &&
cat blobdiffrc
} >blobpagesrc &&
for page in tree plain blob blame
do
cgit_rc blobpagesrc "url=blobdiff/$page/big.txt" >tmp &&
grep "^Status: 413 Content Too Large" tmp &&
grep "Blob size (3 KB) exceeds the limit (1 KB)" tmp || return 1
done
'
test_expect_success 'patch and rawdiff show an oversized blob as binary' '
test_seq 1 2000 >repos/limits/big.txt &&
git -C repos/limits add big.txt &&
git -C repos/limits commit -q -m "big blob" &&
{
echo "max-blob-size=1" &&
cat limitrc
} >blobrc &&
for p in patch rawdiff
do
cgit_rc blobrc "url=limits/$p/" >tmp &&
grep "^Binary files" tmp &&
! grep "^+1999$" tmp || return 1
done
'
test_done
|