Add package base name in request close notifications
[aur.git] / test / t1300-git-update.sh
blob06d1498475cd314ddc3a625d5cc4bd526727805f
1 #!/bin/sh
3 test_description='git-update tests'
5 . ./setup.sh
7 dump_package_info() {
8 for t in Packages Licenses PackageLicenses Groups PackageGroups \
9 PackageDepends PackageRelations PackageSources \
10 PackageNotifications; do
11 echo "SELECT * FROM $t;" | sqlite3 aur.db
12 done
15 test_expect_success 'Test update hook on a fresh repository.' '
16 old=0000000000000000000000000000000000000000 &&
17 new=$(git -C aur.git rev-parse HEAD^) &&
18 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
19 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
20 cat >expected <<-EOF &&
21 1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
22 1|GPL
23 1|1
24 1|1|python-pygit2|||
25 1|1
26 EOF
27 dump_package_info >actual &&
28 test_cmp expected actual
31 test_expect_success 'Test update hook on another fresh repository.' '
32 old=0000000000000000000000000000000000000000 &&
33 test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
34 git -C aur.git checkout -q refs/namespaces/foobar2/refs/heads/master &&
35 new=$(git -C aur.git rev-parse HEAD) &&
36 AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
37 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
38 cat >expected <<-EOF &&
39 1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
40 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
41 1|GPL
42 2|MIT
43 1|1
44 2|2
45 1|1|python-pygit2|||
46 2|1|python-pygit2|||
47 1|1
48 2|1
49 EOF
50 dump_package_info >actual &&
51 test_cmp expected actual
54 test_expect_success 'Test update hook on an updated repository.' '
55 old=$(git -C aur.git rev-parse HEAD^) &&
56 new=$(git -C aur.git rev-parse HEAD) &&
57 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
58 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
59 cat >expected <<-EOF &&
60 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
61 3|1|foobar|1-2|aurweb test package.|https://aur.archlinux.org/
62 1|GPL
63 2|MIT
64 2|2
65 3|1
66 2|1|python-pygit2|||
67 3|1|python-pygit2|||
68 1|1
69 2|1
70 EOF
71 dump_package_info >actual &&
72 test_cmp expected actual
75 test_expect_success 'Test restore mode.' '
76 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
77 "$GIT_UPDATE" restore 2>&1 &&
78 cat >expected <<-EOF &&
79 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
80 3|1|foobar|1-2|aurweb test package.|https://aur.archlinux.org/
81 1|GPL
82 2|MIT
83 2|2
84 3|1
85 2|1|python-pygit2|||
86 3|1|python-pygit2|||
87 1|1
88 2|1
89 EOF
90 dump_package_info >actual &&
91 test_cmp expected actual
94 test_expect_success 'Test restore mode on a non-existent repository.' '
95 cat >expected <<-EOD &&
96 error: restore: repository not found: foobar3
97 EOD
98 test_must_fail \
99 env AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \
100 "$GIT_UPDATE" restore >actual 2>&1 &&
101 test_cmp expected actual
104 test_expect_success 'Pushing to a branch other than master.' '
105 old=0000000000000000000000000000000000000000 &&
106 new=$(git -C aur.git rev-parse HEAD) &&
107 cat >expected <<-EOD &&
108 error: pushing to a branch other than master is restricted
110 test_must_fail \
111 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
112 "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 &&
113 test_cmp expected actual
116 test_expect_success 'Performing a non-fast-forward ref update.' '
117 old=$(git -C aur.git rev-parse HEAD) &&
118 new=$(git -C aur.git rev-parse HEAD^) &&
119 cat >expected <<-EOD &&
120 error: denying non-fast-forward (you should pull first)
122 test_must_fail \
123 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
124 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
125 test_cmp expected actual
128 test_expect_success 'Performing a non-fast-forward ref update as Trusted User.' '
129 old=$(git -C aur.git rev-parse HEAD) &&
130 new=$(git -C aur.git rev-parse HEAD^) &&
131 cat >expected <<-EOD &&
132 error: denying non-fast-forward (you should pull first)
134 test_must_fail \
135 env AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
136 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
137 test_cmp expected actual
140 test_expect_success 'Performing a non-fast-forward ref update as normal user with AUR_OVERWRITE=1.' '
141 old=$(git -C aur.git rev-parse HEAD) &&
142 new=$(git -C aur.git rev-parse HEAD^) &&
143 cat >expected <<-EOD &&
144 error: denying non-fast-forward (you should pull first)
146 test_must_fail \
147 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 AUR_OVERWRITE=1 \
148 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
149 test_cmp expected actual
152 test_expect_success 'Performing a non-fast-forward ref update as Trusted User with AUR_OVERWRITE=1.' '
153 old=$(git -C aur.git rev-parse HEAD) &&
154 new=$(git -C aur.git rev-parse HEAD^) &&
155 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 AUR_OVERWRITE=1 \
156 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
159 test_expect_success 'Removing .SRCINFO.' '
160 old=$(git -C aur.git rev-parse HEAD) &&
161 test_when_finished "git -C aur.git reset --hard $old" &&
162 git -C aur.git rm -q .SRCINFO &&
163 git -C aur.git commit -q -m "Remove .SRCINFO" &&
164 new=$(git -C aur.git rev-parse HEAD) &&
165 test_must_fail \
166 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
167 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
168 grep -q "^error: missing .SRCINFO$" actual
171 test_expect_success 'Removing .SRCINFO with a follow-up fix.' '
172 old=$(git -C aur.git rev-parse HEAD) &&
173 test_when_finished "git -C aur.git reset --hard $old" &&
174 git -C aur.git rm -q .SRCINFO &&
175 git -C aur.git commit -q -m "Remove .SRCINFO" &&
176 git -C aur.git revert --no-edit HEAD &&
177 new=$(git -C aur.git rev-parse HEAD) &&
178 test_must_fail \
179 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
180 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
181 grep -q "^error: missing .SRCINFO$" actual
184 test_expect_success 'Removing PKGBUILD.' '
185 old=$(git -C aur.git rev-parse HEAD) &&
186 test_when_finished "git -C aur.git reset --hard $old" &&
187 git -C aur.git rm -q PKGBUILD &&
188 git -C aur.git commit -q -m "Remove PKGBUILD" &&
189 new=$(git -C aur.git rev-parse HEAD) &&
190 test_must_fail \
191 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
192 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
193 grep -q "^error: missing PKGBUILD$" actual
196 test_expect_success 'Pushing a tree with a subdirectory.' '
197 old=$(git -C aur.git rev-parse HEAD) &&
198 test_when_finished "git -C aur.git reset --hard $old" &&
199 mkdir aur.git/subdir &&
200 touch aur.git/subdir/file &&
201 git -C aur.git add subdir/file &&
202 git -C aur.git commit -q -m "Add subdirectory" &&
203 new=$(git -C aur.git rev-parse HEAD) &&
204 test_must_fail \
205 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
206 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
207 grep -q "^error: the repository must not contain subdirectories$" actual
210 test_expect_success 'Pushing a tree with a large blob.' '
211 old=$(git -C aur.git rev-parse HEAD) &&
212 test_when_finished "git -C aur.git reset --hard $old" &&
213 printf "%256001s" x >aur.git/file &&
214 git -C aur.git add file &&
215 git -C aur.git commit -q -m "Add large blob" &&
216 new=$(git -C aur.git rev-parse HEAD) &&
217 test_must_fail \
218 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
219 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
220 grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual
223 test_expect_success 'Pushing .SRCINFO with a non-matching package base.' '
224 old=$(git -C aur.git rev-parse HEAD) &&
225 test_when_finished "git -C aur.git reset --hard $old" &&
227 cd aur.git &&
228 sed "s/\(pkgbase.*\)foobar/\1foobar2/" .SRCINFO >.SRCINFO.new
229 mv .SRCINFO.new .SRCINFO
230 git commit -q -am "Change package base"
231 ) &&
232 new=$(git -C aur.git rev-parse HEAD) &&
233 test_must_fail \
234 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
235 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
236 grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual
239 test_expect_success 'Pushing .SRCINFO with invalid syntax.' '
240 old=$(git -C aur.git rev-parse HEAD) &&
241 test_when_finished "git -C aur.git reset --hard $old" &&
243 cd aur.git &&
244 sed "s/=//" .SRCINFO >.SRCINFO.new
245 mv .SRCINFO.new .SRCINFO
246 git commit -q -am "Break .SRCINFO"
247 ) &&
248 new=$(git -C aur.git rev-parse HEAD) &&
249 test_must_fail \
250 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
251 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
254 test_expect_success 'Pushing .SRCINFO without pkgver.' '
255 old=$(git -C aur.git rev-parse HEAD) &&
256 test_when_finished "git -C aur.git reset --hard $old" &&
258 cd aur.git &&
259 sed "/pkgver/d" .SRCINFO >.SRCINFO.new
260 mv .SRCINFO.new .SRCINFO
261 git commit -q -am "Remove pkgver"
262 ) &&
263 new=$(git -C aur.git rev-parse HEAD) &&
264 test_must_fail \
265 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
266 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
267 grep -q "^error: missing mandatory field: pkgver$" actual
270 test_expect_success 'Pushing .SRCINFO without pkgrel.' '
271 old=$(git -C aur.git rev-parse HEAD) &&
272 test_when_finished "git -C aur.git reset --hard $old" &&
274 cd aur.git &&
275 sed "/pkgrel/d" .SRCINFO >.SRCINFO.new
276 mv .SRCINFO.new .SRCINFO
277 git commit -q -am "Remove pkgrel"
278 ) &&
279 new=$(git -C aur.git rev-parse HEAD) &&
280 test_must_fail \
281 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
282 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
283 grep -q "^error: missing mandatory field: pkgrel$" actual
286 test_expect_success 'Pushing .SRCINFO with epoch.' '
287 old=$(git -C aur.git rev-parse HEAD) &&
288 test_when_finished "git -C aur.git reset --hard $old" &&
290 cd aur.git &&
291 sed "s/.*pkgrel.*/\\0\\nepoch = 1/" .SRCINFO >.SRCINFO.new
292 mv .SRCINFO.new .SRCINFO
293 git commit -q -am "Add epoch"
294 ) &&
295 new=$(git -C aur.git rev-parse HEAD) &&
296 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
297 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
298 cat >expected <<-EOF &&
299 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
300 3|1|foobar|1:1-2|aurweb test package.|https://aur.archlinux.org/
302 echo "SELECT * FROM Packages;" | sqlite3 aur.db >actual &&
303 test_cmp expected actual
306 test_expect_success 'Pushing .SRCINFO with invalid pkgname.' '
307 old=$(git -C aur.git rev-parse HEAD) &&
308 test_when_finished "git -C aur.git reset --hard $old" &&
310 cd aur.git &&
311 sed "s/\(pkgname.*\)foobar/\1!/" .SRCINFO >.SRCINFO.new
312 mv .SRCINFO.new .SRCINFO
313 git commit -q -am "Change pkgname"
314 ) &&
315 new=$(git -C aur.git rev-parse HEAD) &&
316 test_must_fail \
317 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
318 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
319 grep -q "^error: invalid package name: !$" actual
322 test_expect_success 'Pushing .SRCINFO with invalid epoch.' '
323 old=$(git -C aur.git rev-parse HEAD) &&
324 test_when_finished "git -C aur.git reset --hard $old" &&
326 cd aur.git &&
327 sed "s/.*pkgrel.*/\\0\\nepoch = !/" .SRCINFO >.SRCINFO.new
328 mv .SRCINFO.new .SRCINFO
329 git commit -q -am "Change epoch"
330 ) &&
331 new=$(git -C aur.git rev-parse HEAD) &&
332 test_must_fail \
333 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
334 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
335 grep -q "^error: invalid epoch: !$" actual
338 test_expect_success 'Pushing .SRCINFO with too long URL.' '
339 old=$(git -C aur.git rev-parse HEAD) &&
340 url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
341 test_when_finished "git -C aur.git reset --hard $old" &&
343 cd aur.git &&
344 sed "s#.*url.*#\\0\\nurl = $url#" .SRCINFO >.SRCINFO.new
345 mv .SRCINFO.new .SRCINFO
346 git commit -q -am "Change URL"
347 ) &&
348 new=$(git -C aur.git rev-parse HEAD) &&
349 test_must_fail \
350 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
351 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
352 grep -q "^error: url field too long: $url\$" actual
355 test_expect_success 'Missing install file.' '
356 old=$(git -C aur.git rev-parse HEAD) &&
357 test_when_finished "git -C aur.git reset --hard $old" &&
359 cd aur.git &&
360 sed "s/.*depends.*/\\0\\ninstall = install/" .SRCINFO >.SRCINFO.new
361 mv .SRCINFO.new .SRCINFO
362 git commit -q -am "Add install field"
363 ) &&
364 new=$(git -C aur.git rev-parse HEAD) &&
365 test_must_fail \
366 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
367 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
368 grep -q "^error: missing install file: install$" actual
371 test_expect_success 'Missing changelog file.' '
372 old=$(git -C aur.git rev-parse HEAD) &&
373 test_when_finished "git -C aur.git reset --hard $old" &&
375 cd aur.git &&
376 sed "s/.*depends.*/\\0\\nchangelog = changelog/" .SRCINFO >.SRCINFO.new
377 mv .SRCINFO.new .SRCINFO
378 git commit -q -am "Add changelog field"
379 ) &&
380 new=$(git -C aur.git rev-parse HEAD) &&
381 test_must_fail \
382 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
383 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
384 grep -q "^error: missing changelog file: changelog$" actual
387 test_expect_success 'Missing source file.' '
388 old=$(git -C aur.git rev-parse HEAD) &&
389 test_when_finished "git -C aur.git reset --hard $old" &&
391 cd aur.git &&
392 sed "s/.*depends.*/\\0\\nsource = file/" .SRCINFO >.SRCINFO.new
393 mv .SRCINFO.new .SRCINFO
394 git commit -q -am "Add file to the source array"
395 ) &&
396 new=$(git -C aur.git rev-parse HEAD) &&
397 test_must_fail \
398 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
399 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
400 grep -q "^error: missing source file: file$" actual
403 test_expect_success 'Pushing .SRCINFO with too long source URL.' '
404 old=$(git -C aur.git rev-parse HEAD) &&
405 url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
406 test_when_finished "git -C aur.git reset --hard $old" &&
408 cd aur.git &&
409 sed "s#.*depends.*#\\0\\nsource = $url#" .SRCINFO >.SRCINFO.new
410 mv .SRCINFO.new .SRCINFO
411 git commit -q -am "Add huge source URL"
412 ) &&
413 new=$(git -C aur.git rev-parse HEAD) &&
414 test_must_fail \
415 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
416 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
417 grep -q "^error: source entry too long: $url\$" actual
420 test_expect_success 'Pushing a blacklisted package.' '
421 old=$(git -C aur.git rev-parse HEAD) &&
422 test_when_finished "git -C aur.git reset --hard $old" &&
423 echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
424 git -C aur.git commit -q -am "Add blacklisted package" &&
425 new=$(git -C aur.git rev-parse HEAD) &&
426 cat >expected <<-EOD &&
427 error: package is blacklisted: forbidden
429 test_must_fail \
430 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
431 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
432 test_cmp expected actual
435 test_expect_success 'Pushing a blacklisted package as Trusted User.' '
436 old=$(git -C aur.git rev-parse HEAD) &&
437 test_when_finished "git -C aur.git reset --hard $old" &&
438 echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
439 git -C aur.git commit -q -am "Add blacklisted package" &&
440 new=$(git -C aur.git rev-parse HEAD) &&
441 cat >expected <<-EOD &&
442 warning: package is blacklisted: forbidden
444 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
445 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
446 test_cmp expected actual
449 test_expect_success 'Pushing a package already in the official repositories.' '
450 old=$(git -C aur.git rev-parse HEAD) &&
451 test_when_finished "git -C aur.git reset --hard $old" &&
452 echo "pkgname = official" >>aur.git/.SRCINFO &&
453 git -C aur.git commit -q -am "Add official package" &&
454 new=$(git -C aur.git rev-parse HEAD) &&
455 cat >expected <<-EOD &&
456 error: package already provided by [core]: official
458 test_must_fail \
459 env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
460 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
461 test_cmp expected actual
464 test_expect_success 'Pushing a package already in the official repositories as Trusted User.' '
465 old=$(git -C aur.git rev-parse HEAD) &&
466 test_when_finished "git -C aur.git reset --hard $old" &&
467 echo "pkgname = official" >>aur.git/.SRCINFO &&
468 git -C aur.git commit -q -am "Add official package" &&
469 new=$(git -C aur.git rev-parse HEAD) &&
470 cat >expected <<-EOD &&
471 warning: package already provided by [core]: official
473 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
474 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
475 test_cmp expected actual
478 test_expect_success 'Trying to hijack a package.' '
479 old=0000000000000000000000000000000000000000 &&
480 test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
482 cd aur.git &&
483 git checkout -q refs/namespaces/foobar2/refs/heads/master &&
484 sed "s/\\(.*pkgname.*\\)2/\\1/" .SRCINFO >.SRCINFO.new
485 mv .SRCINFO.new .SRCINFO
486 git commit -q -am "Change package name"
487 ) &&
488 new=$(git -C aur.git rev-parse HEAD) &&
489 cat >expected <<-EOD &&
490 error: cannot overwrite package: foobar
492 test_must_fail \
493 env AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
494 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
495 test_cmp expected actual
498 test_done