Require TUs to explicitly request to overwrite a pkgbase
[aur.git] / test / t1200-git-serve.sh
blob038a7989a6df9cc6c02bd1d5663241affeb12765
1 #!/bin/sh
3 test_description='git-serve tests'
5 . ./setup.sh
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 &&
13 save_IFS=$IFS
14 IFS=
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
19 done <actual
20 IFS=$save_IFS
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.
29 EOF
30 test_cmp expected actual &&
31 mv config.old config
34 test_expect_success 'Test IP address logging.' '
35 SSH_ORIGINAL_COMMAND=help AUR_USER=user "$GIT_SERVE" 2>actual &&
36 cat >expected <<-EOF &&
37 1.2.3.4
38 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.
50 EOF
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 \
57 "$GIT_SERVE" 2>&1 &&
58 SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=tu \
59 "$GIT_SERVE" 2>&1 &&
60 cat >expected <<-EOF &&
61 *foobar
62 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 &&
70 user
71 foobar
72 foobar
73 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 &&
88 user
89 foobar
90 foobar
91 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 &&
100 user
101 foobar2
102 foobar2
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 &&
119 foobar
120 foobar
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\";" | \
130 sqlite3 aur.db &&
131 cat >expected <<-EOF &&
132 user
133 foobar
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 \
147 "$GIT_SERVE" 2>&1 &&
148 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
149 "$GIT_SERVE" 2>&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 \
162 "$GIT_SERVE" 2>&1 &&
163 cat >expected <<-EOF &&
164 *foobar
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 \
178 "$GIT_SERVE" 2>&1 &&
179 cat >expected <<-EOF &&
180 *foobar2
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 \
189 "$GIT_SERVE" 2>&1 &&
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 \
199 "$GIT_SERVE" 2>&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 \
209 "$GIT_SERVE" 2>&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 &&
218 *foobar2
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 \
224 "$GIT_SERVE" 2>&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 \
229 "$GIT_SERVE" 2>&1 &&
230 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
231 "$GIT_SERVE" 2>&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 &&
238 *foobar
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 \
244 "$GIT_SERVE" 2>&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 \
249 "$GIT_SERVE" 2>&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 &&
253 *foobar2
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 \
259 "$GIT_SERVE" 2>&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 \
264 "$GIT_SERVE" 2>&1 &&
265 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
266 "$GIT_SERVE" 2>&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 \
273 "$GIT_SERVE" 2>&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 \
278 "$GIT_SERVE" 2>&1 &&
279 SSH_ORIGINAL_COMMAND="set-comaintainers foobar user3 user4" \
280 AUR_USER=user AUR_PRIVILEGED=0 \
281 "$GIT_SERVE" 2>&1 &&
282 cat >expected <<-EOF &&
283 5|3|1
284 6|3|2
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 \
294 "$GIT_SERVE" 2>&1 &&
295 cat >expected <<-EOF &&
296 4|3|1
297 5|3|2
298 6|3|3
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 &&
310 4|3|1
311 5|3|2
312 6|3|3
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 \
321 "$GIT_SERVE" 2>&1 &&
322 cat >expected <<-EOF &&
323 *foobar
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 &&
329 5|3|1
330 6|3|2
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 \
339 "$GIT_SERVE" 2>&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 \
354 "$GIT_SERVE" 2>&1 &&
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, "", "");
360 >sendmail.out &&
361 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
362 "$GIT_SERVE" 2>&1 &&
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 \
377 "$GIT_SERVE" 2>&1 &&
378 cat >expected <<-EOF &&
379 1|Because.
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 \
388 "$GIT_SERVE" 2>&1 &&
389 cat >expected <<-EOF &&
390 0|Because.
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 \
399 "$GIT_SERVE" 2>&1 &&
400 SSH_ORIGINAL_COMMAND="flag foobar Because." AUR_USER=user2 AUR_PRIVILEGED=0 \
401 "$GIT_SERVE" 2>&1 &&
402 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user AUR_PRIVILEGED=0 \
403 "$GIT_SERVE" 2>&1 &&
404 cat >expected <<-EOF &&
405 0|Because.
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 \
414 "$GIT_SERVE" 2>&1 &&
415 SSH_ORIGINAL_COMMAND="unflag foobar" AUR_USER=user3 AUR_PRIVILEGED=0 \
416 "$GIT_SERVE" 2>&1 &&
417 cat >expected <<-EOF &&
418 1|Because.
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 \
427 "$GIT_SERVE" 2>&1 &&
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 &&
431 0|Because.
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 \
440 "$GIT_SERVE" 2>&1 &&
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 \
474 "$GIT_SERVE" 2>&1 &&
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
504 test_done