3 test_description
='git-serve tests'
7 test_expect_success
'Test interactive shell.' '
8 "$GIT_SERVE" 2>&1 | grep -q "Interactive shell is disabled."
11 test_expect_success
'Test help.' '
12 SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>actual &&
15 while read -r line; do
16 echo $line | grep -q "^Commands:$" && continue
17 echo $line | grep -q "^ [a-z]" || return 1
18 [ ${#line} -le 80 ] || return 1
23 test_expect_success
'Test maintenance mode.' '
24 mv config config.old &&
25 sed "s/^\(enable-maintenance = \)0$/\\11/" config.old >config &&
26 SSH_ORIGINAL_COMMAND=help test_must_fail "$GIT_SERVE" 2>actual &&
27 cat >expected <<-EOF &&
28 The AUR is down due to maintenance. We will be back soon.
30 test_cmp expected actual &&
34 test_expect_success
'Test IP address logging.' '
35 SSH_ORIGINAL_COMMAND=help AUR_USER=user "$GIT_SERVE" 2>actual &&
36 cat >expected <<-EOF &&
39 echo "SELECT LastSSHLoginIPAddress FROM Users WHERE UserName = \"user\";" | \
40 sqlite3 aur.db >actual &&
41 test_cmp expected actual
44 test_expect_success
'Test IP address bans.' '
45 SSH_CLIENT_ORIG="$SSH_CLIENT" &&
46 SSH_CLIENT="1.3.3.7 1337 22" &&
47 SSH_ORIGINAL_COMMAND=help test_must_fail "$GIT_SERVE" 2>actual &&
48 cat >expected <<-EOF &&
49 The SSH interface is disabled for your IP address.
51 test_cmp expected actual &&
52 SSH_CLIENT="$SSH_CLIENT_ORIG"
55 test_expect_success
'Test setup-repo and list-repos.' '
56 SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user \
58 SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=tu \
60 cat >expected <<-EOF &&
63 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user \
64 "$GIT_SERVE" 2>&1 >actual &&
65 test_cmp expected actual
68 test_expect_success
'Test git-receive-pack.' '
69 cat >expected <<-EOF &&
74 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \
75 AUR_USER=user AUR_PRIVILEGED=0 \
76 "$GIT_SERVE" 2>&1 >actual &&
77 test_cmp expected actual
80 test_expect_success
'Test git-receive-pack with an invalid repository name.' '
81 SSH_ORIGINAL_COMMAND="git-receive-pack /!.git/" \
82 AUR_USER=user AUR_PRIVILEGED=0 \
83 test_must_fail "$GIT_SERVE" 2>&1 >actual
86 test_expect_success
"Test git-upload-pack." '
87 cat >expected <<-EOF &&
92 SSH_ORIGINAL_COMMAND="git-upload-pack /foobar.git/" \
93 AUR_USER=user AUR_PRIVILEGED=0 \
94 "$GIT_SERVE" 2>&1 >actual &&
95 test_cmp expected actual
98 test_expect_success
"Try to pull from someone else's repository." '
99 cat >expected <<-EOF &&
104 SSH_ORIGINAL_COMMAND="git-upload-pack /foobar2.git/" \
105 AUR_USER=user AUR_PRIVILEGED=0 \
106 "$GIT_SERVE" 2>&1 >actual &&
107 test_cmp expected actual
110 test_expect_success
"Try to push to someone else's repository." '
111 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar2.git/" \
112 AUR_USER=user AUR_PRIVILEGED=0 \
113 test_must_fail "$GIT_SERVE" 2>&1
116 test_expect_success
"Try to push to someone else's repository as Trusted User." '
117 cat >expected <<-EOF &&
122 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \
123 AUR_USER=tu AUR_PRIVILEGED=1 \
124 "$GIT_SERVE" 2>&1 >actual &&
125 test_cmp expected actual
128 test_expect_success
"Test restore." '
129 echo "DELETE FROM PackageBases WHERE Name = \"foobar\";" | \
131 cat >expected <<-EOF &&
135 SSH_ORIGINAL_COMMAND="restore foobar" AUR_USER=user AUR_PRIVILEGED=0 \
136 "$GIT_SERVE" 2>&1 >actual
137 test_cmp expected actual
140 test_expect_success
"Try to restore an existing package base." '
141 SSH_ORIGINAL_COMMAND="restore foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
142 test_must_fail "$GIT_SERVE" 2>&1
145 test_expect_success
"Disown all package bases." '
146 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
148 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
150 cat >expected <<-EOF &&
152 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
153 "$GIT_SERVE" 2>&1 >actual &&
154 test_cmp expected actual &&
155 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
156 "$GIT_SERVE" 2>&1 >actual &&
157 test_cmp expected actual
160 test_expect_success
"Adopt a package base as a regular user." '
161 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
163 cat >expected <<-EOF &&
166 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
167 "$GIT_SERVE" 2>&1 >actual &&
168 test_cmp expected actual
171 test_expect_success
"Adopt an already adopted package base." '
172 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
173 test_must_fail "$GIT_SERVE" 2>&1
176 test_expect_success
"Adopt a package base as a Trusted User." '
177 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
179 cat >expected <<-EOF &&
182 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
183 "$GIT_SERVE" 2>&1 >actual &&
184 test_cmp expected actual
187 test_expect_success
"Disown one's own package base as a regular user." '
188 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
190 cat >expected <<-EOF &&
192 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
193 "$GIT_SERVE" 2>&1 >actual &&
194 test_cmp expected actual
197 test_expect_success
"Disown one's own package base as a Trusted User." '
198 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
200 cat >expected <<-EOF &&
202 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
203 "$GIT_SERVE" 2>&1 >actual &&
204 test_cmp expected actual
207 test_expect_success
"Try to steal another user's package as a regular user." '
208 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
210 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
211 test_must_fail "$GIT_SERVE" 2>&1 &&
212 cat >expected <<-EOF &&
214 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
215 "$GIT_SERVE" 2>&1 >actual &&
216 test_cmp expected actual &&
217 cat >expected <<-EOF &&
220 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
221 "$GIT_SERVE" 2>&1 >actual &&
222 test_cmp expected actual &&
223 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
227 test_expect_success
"Try to steal another user's package as a Trusted User." '
228 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
230 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
232 cat >expected <<-EOF &&
234 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
235 "$GIT_SERVE" 2>&1 >actual &&
236 test_cmp expected actual &&
237 cat >expected <<-EOF &&
240 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
241 "$GIT_SERVE" 2>&1 >actual &&
242 test_cmp expected actual &&
243 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
247 test_expect_success
"Try to disown another user's package as a regular user." '
248 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
250 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
251 test_must_fail "$GIT_SERVE" 2>&1 &&
252 cat >expected <<-EOF &&
255 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
256 "$GIT_SERVE" 2>&1 >actual &&
257 test_cmp expected actual &&
258 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
262 test_expect_success
"Try to disown another user's package as a Trusted User." '
263 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
265 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
267 cat >expected <<-EOF &&
269 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
270 "$GIT_SERVE" 2>&1 >actual &&
271 test_cmp expected actual &&
272 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
276 test_expect_success
"Adopt a package base and add co-maintainers." '
277 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
279 SSH_ORIGINAL_COMMAND="set-comaintainers foobar user3 user4" \
280 AUR_USER=user AUR_PRIVILEGED=0 \
282 cat >expected <<-EOF &&
286 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
287 sqlite3 aur.db >actual &&
288 test_cmp expected actual
291 test_expect_success
"Update package base co-maintainers." '
292 SSH_ORIGINAL_COMMAND="set-comaintainers foobar user2 user3 user4" \
293 AUR_USER=user AUR_PRIVILEGED=0 \
295 cat >expected <<-EOF &&
300 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
301 sqlite3 aur.db >actual &&
302 test_cmp expected actual
305 test_expect_success
"Try to add co-maintainers to an orphan package base." '
306 SSH_ORIGINAL_COMMAND="set-comaintainers foobar2 user2 user3 user4" \
307 AUR_USER=user AUR_PRIVILEGED=0 \
308 test_must_fail "$GIT_SERVE" 2>&1 &&
309 cat >expected <<-EOF &&
314 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
315 sqlite3 aur.db >actual &&
316 test_cmp expected actual
319 test_expect_success
"Disown a package base and check (co-)maintainer list." '
320 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
322 cat >expected <<-EOF &&
325 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user2 AUR_PRIVILEGED=0 \
326 "$GIT_SERVE" 2>&1 >actual &&
327 test_cmp expected actual &&
328 cat >expected <<-EOF &&
332 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
333 sqlite3 aur.db >actual &&
334 test_cmp expected actual
337 test_expect_success
"Force-disown a package base and check (co-)maintainer list." '
338 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
340 cat >expected <<-EOF &&
342 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user3 AUR_PRIVILEGED=0 \
343 "$GIT_SERVE" 2>&1 >actual &&
344 test_cmp expected actual &&
345 cat >expected <<-EOF &&
347 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
348 sqlite3 aur.db >actual &&
349 test_cmp expected actual
352 test_expect_success
"Check whether package requests are closed when disowning." '
353 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
355 cat <<-EOD | sqlite3 aur.db &&
356 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (1, 2, 3, "foobar", 4, "", "");
357 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (2, 3, 3, "foobar", 5, "", "");
358 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID, Comments, ClosureComment) VALUES (3, 2, 2, "foobar2", 6, "", "");
361 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
363 cat <<-EOD >expected &&
364 Subject: [PRQ#1] Request Accepted
366 grep "^Subject.*PRQ" sendmail.out >sendmail.parts &&
367 test_cmp sendmail.parts expected &&
368 cat <<-EOD >expected &&
369 1|2|3|foobar||4||The user user disowned the package.|0|2
371 echo "SELECT * FROM PackageRequests WHERE Status = 2;" | sqlite3 aur.db >actual &&
372 test_cmp actual expected
375 test_expect_success
"Flag a package base out-of-date." '
376 SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \
378 cat >expected <<-EOF &&
381 echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \
382 sqlite3 aur.db >actual &&
383 test_cmp expected actual
386 test_expect_success
"Unflag a package base as flagger." '
387 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \
389 cat >expected <<-EOF &&
392 echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \
393 sqlite3 aur.db >actual &&
394 test_cmp expected actual
397 test_expect_success
"Unflag a package base as maintainer." '
398 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
400 SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \
402 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user AUR_PRIVILEGED=0 \
404 cat >expected <<-EOF &&
407 echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \
408 sqlite3 aur.db >actual &&
409 test_cmp expected actual
412 test_expect_success
"Unflag a package base as random user." '
413 SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \
415 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user3 AUR_PRIVILEGED=0 \
417 cat >expected <<-EOF &&
420 echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \
421 sqlite3 aur.db >actual &&
422 test_cmp expected actual
425 test_expect_success
"Flag using a comment which is too short." '
426 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user2 AUR_PRIVILEGED=0 \
428 SSH_ORIGINAL_COMMAND="flag foobar xx" AUR_USER=user2 AUR_PRIVILEGED=0 \
429 test_must_fail "$GIT_SERVE" 2>&1 &&
430 cat >expected <<-EOF &&
433 echo "SELECT OutOfDateTS IS NOT NULL, FlaggerComment FROM PackageBases WHERE ID = 3;" | \
434 sqlite3 aur.db >actual &&
435 test_cmp expected actual
438 test_expect_success
"Vote for a package base." '
439 SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \
441 cat >expected <<-EOF &&
444 echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \
445 sqlite3 aur.db >actual &&
446 test_cmp expected actual &&
447 cat >expected <<-EOF &&
450 echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
451 sqlite3 aur.db >actual &&
452 test_cmp expected actual
455 test_expect_success
"Vote for a package base twice." '
456 SSH_ORIGINAL_COMMAND="vote foobar" AUR_USER=user AUR_PRIVILEGED=0 \
457 test_must_fail "$GIT_SERVE" 2>&1 &&
458 cat >expected <<-EOF &&
461 echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \
462 sqlite3 aur.db >actual &&
463 test_cmp expected actual &&
464 cat >expected <<-EOF &&
467 echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
468 sqlite3 aur.db >actual &&
469 test_cmp expected actual
472 test_expect_success
"Remove vote from a package base." '
473 SSH_ORIGINAL_COMMAND="unvote foobar" AUR_USER=user AUR_PRIVILEGED=0 \
475 cat >expected <<-EOF &&
477 echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \
478 sqlite3 aur.db >actual &&
479 test_cmp expected actual &&
480 cat >expected <<-EOF &&
483 echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
484 sqlite3 aur.db >actual &&
485 test_cmp expected actual
488 test_expect_success
"Try to remove the vote again." '
489 SSH_ORIGINAL_COMMAND="unvote foobar" AUR_USER=user AUR_PRIVILEGED=0 \
490 test_must_fail "$GIT_SERVE" 2>&1 &&
491 cat >expected <<-EOF &&
493 echo "SELECT PackageBaseID, UsersID FROM PackageVotes;" | \
494 sqlite3 aur.db >actual &&
495 test_cmp expected actual &&
496 cat >expected <<-EOF &&
499 echo "SELECT NumVotes FROM PackageBases WHERE Name = \"foobar\";" | \
500 sqlite3 aur.db >actual &&
501 test_cmp expected actual