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
|
test_description='Check configuration diagnostics'
. ./setup.sh
test_expect_success 'set up configs' '
write_script drain-filter <<-\EOF &&
cat >/dev/null
EOF
cgitrc_repo diagrc diag no-such-key=1 "repo.path=$PWD/repos/foo/.git" repo.no-such-repo-key=1 &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "repo.desc=early" &&
echo "repo.url=diag" &&
echo "repo.path=$PWD/repos/foo/.git" &&
echo "repo.readme=:file-1" &&
echo "repo.about-filter=exec:$PWD/drain-filter"
} >earlyrc
'
test_expect_success 'unknown keys are reported and the page still renders' '
cgit_rc diagrc "url=diag/" >tmp 2>err &&
grep "Status: 200" tmp &&
grep "Unknown config key: no-such-key" err &&
grep "Unknown repo config key: no-such-repo-key" err
'
test_expect_success 'a repo key before any repo.url is reported' '
cgit_rc earlyrc "url=diag/" >tmp 2>err &&
grep "Status: 200" tmp &&
grep "Ignoring repo.desc before any repo.url" err
'
test_expect_success 'a filter in a scanned repository is reported without its flag' '
git clone -q --bare repos/foo/.git scan/foo.git &&
echo "commit-filter=exec:$FILTER_DIRECTORY/dump.sh" >scan/foo.git/cgitrc &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "scan-path=$PWD/scan"
} >scanrc &&
cgit_rc scanrc "url=foo.git/commit/" >tmp 2>err &&
grep "<div class=.commit-subject.>commit 5" tmp &&
grep "Ignoring commit-filter in $PWD/scan/foo.git/: trust-scan-config is not set" err
'
test_expect_success 'the flag lets a scanned repository set its filters' '
{
echo "trust-scan-config=1" &&
cat scanrc
} >scanrc-on &&
cgit_rc scanrc-on "url=foo.git/commit/" >tmp 2>err &&
grep "<div class=.commit-subject.>COMMIT 5" tmp &&
! grep "Ignoring" err
'
test_expect_success 'a repo filter in the main cgitrc needs no flag' '
cgit_rc earlyrc "url=diag/about/" >tmp 2>err &&
grep "<div id=.about.></div>" tmp &&
! grep "about-filter" err
'
test_expect_success 'a repository whose path is missing answers 404' '
{
echo "virtual-root=/" &&
echo "cache-size=1021" &&
echo "cache-root=$PWD/gone-cache" &&
echo "repo.url=gone" &&
echo "repo.path=$PWD/no/such/repo/.git"
} >gonerc &&
mkdir -p gone-cache &&
for page in "" log/ commit/ "tag/&h=x" atom/ plain/f
do
cgit_rc gonerc "url=gone/$page" >tmp 2>err &&
grep "^Status: 404 Not Found" tmp &&
grep "Failed to open gone: No such file or directory" tmp || return 1
done &&
test -z "$(ls gone-cache)"
'
test_expect_success 'a fully understood config stays silent' '
cgit_url "foo/" >tmp 2>err &&
grep "Status: 200" tmp &&
! grep "\[cgit\]" err
'
test_expect_success 'a NUL inside a comment does not end it' '
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
printf "# note\\000root-title=Smuggled\\n" &&
echo "repo.url=foo" &&
echo "repo.path=$PWD/repos/foo/.git"
} >nulrc &&
grep -c Smuggled nulrc &&
cgit_rc nulrc "url=" >tmp &&
grep "</html>" tmp &&
! grep Smuggled tmp
'
test_expect_success 'a config file that cannot be read is reported' '
CGIT_CONFIG="$PWD/no-such-rc" QUERY_STRING="url=" cgit >tmp 2>err &&
grep "No repositories found" tmp &&
grep "Unable to read config file $PWD/no-such-rc: No such file or directory" err &&
mkdir rc-dir &&
CGIT_CONFIG="$PWD/rc-dir" QUERY_STRING="url=" cgit >tmp 2>err &&
grep "Unable to read config file $PWD/rc-dir: Is a directory" err &&
{
echo "include=$PWD/no-such-include" &&
cat diagrc
} >includerc &&
cgit_rc includerc "url=diag/" >tmp 2>err &&
grep "Status: 200" tmp &&
grep "Unable to read config file $PWD/no-such-include: No such file or directory" err
'
test_expect_success 'a scan says nothing of the files it may lack' '
git clone -q --bare repos/foo/.git quiet/foo.git &&
mkdir quiet-cache &&
{
echo "virtual-root=/" &&
echo "cache-root=$PWD/quiet-cache" &&
echo "cache-size=64" &&
echo "cache-index-ttl=0" &&
echo "scan-path=$PWD/quiet"
} >quietrc &&
cgit_rc quietrc "url=" >tmp 2>err &&
grep ">foo.git</a>" tmp &&
cgit_rc quietrc "url=" >tmp 2>>err &&
grep ">foo.git</a>" tmp &&
test_must_be_empty err
'
test_expect_success 'a word where a number belongs is reported' '
cgitrc_repo wordrc word enable-index-owner=no "max-repo-count= 20 " \
"repo.path=$PWD/repos/foo/.git" repo.hide=yes &&
cgit_rc wordrc "url=" >tmp 2>err &&
grep ">word</a>" tmp &&
! grep "col-owner" tmp &&
grep "Reading enable-index-owner=no in $PWD/wordrc line 3 as 0, since it is not a whole number" err &&
grep "Reading hide=yes in $PWD/wordrc line 7 as 0, since it is not a whole number" err &&
! grep "max-repo-count" err &&
{
echo "include=$PWD/wordrc" &&
echo "enable-blame=on"
} >outerrc &&
cgit_rc outerrc "url=" >tmp 2>err &&
grep "Reading enable-blame=on in $PWD/outerrc line 2 as 0, since it is not a whole number" err
'
test_expect_success 'a word in a scanned git config is reported' '
git clone -q --bare repos/foo/.git wordscan/foo.git &&
git -C wordscan/foo.git config cgit.hide true &&
line=$(grep -n "hide = true" wordscan/foo.git/config | cut -d: -f1) &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "enable-git-config=1" &&
echo "scan-path=$PWD/wordscan"
} >wordscanrc &&
cgit_rc wordscanrc "url=" >tmp 2>err &&
grep ">foo.git</a>" tmp &&
grep "Reading hide=true in $PWD/wordscan/foo.git/config line $line as 0, since it is not a whole number" err
'
test_expect_success 'an unknown snapshot format is reported' '
cgitrc_repo snaprc snap "snapshots=tar zap tar.gz" \
"repo.path=$PWD/repos/foo/.git" "repo.snapshots=tar 0 tar.gzz" &&
cgit_rc snaprc "url=snap/commit/" >tmp 2>err &&
grep "href=./snap/snapshot/snap-master.tar.>" tmp &&
! grep "snap-master.tar.gz" tmp &&
grep "Ignoring unknown snapshot format zap in $PWD/snaprc line 3" err &&
grep "Ignoring unknown snapshot format tar.gzz in $PWD/snaprc line 6" err &&
test_line_count = 2 err &&
cgitrc_repo legacyrc snap "snapshots=2 zip" "repo.path=$PWD/repos/foo/.git" &&
cgit_rc legacyrc "url=snap/commit/" >tmp 2>err &&
grep "href=./snap/snapshot/snap-master.tar.>" tmp &&
! grep "snap-master.zip" tmp &&
test_must_be_empty err
'
test_expect_success 'a repository that will not open is logged with its path' '
cgit_rc gonerc "url=gone/log/" >tmp 2>err &&
grep "^Status: 404 Not Found" tmp &&
grep "Unable to open repository gone at $PWD/no/such/repo/.git: No such file or directory" err &&
test_line_count = 1 err &&
mkdir not-a-repo &&
cgitrc_repo notreporc notrepo "repo.path=$PWD/not-a-repo" &&
cgit_rc notreporc "url=notrepo/" >tmp 2>err &&
grep "^Status: 404 Not Found" tmp &&
grep "Unable to open repository notrepo at $PWD/not-a-repo: " err
'
test_done
|