gendummydata.py: Fix NOT NULL constraint problems
[aur.git] / test / t1300-git-update.sh
blobf16e2ad464946b6323e76fd7bbb8ea069b4c7ac0
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 AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \
99 test_must_fail "$GIT_UPDATE" restore >actual 2>&1 &&
100 test_cmp expected actual
103 test_expect_success 'Pushing to a branch other than master.' '
104 old=0000000000000000000000000000000000000000 &&
105 new=$(git -C aur.git rev-parse HEAD) &&
106 cat >expected <<-EOD &&
107 error: pushing to a branch other than master is restricted
109 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
110 test_must_fail "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 &&
111 test_cmp expected actual
114 test_expect_success 'Performing a non-fast-forward ref update.' '
115 old=$(git -C aur.git rev-parse HEAD) &&
116 new=$(git -C aur.git rev-parse HEAD^) &&
117 cat >expected <<-EOD &&
118 error: denying non-fast-forward (you should pull first)
120 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
121 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
122 test_cmp expected actual
125 test_expect_success 'Performing a non-fast-forward ref update as Trusted User.' '
126 old=$(git -C aur.git rev-parse HEAD) &&
127 new=$(git -C aur.git rev-parse HEAD^) &&
128 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
129 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
132 test_expect_success 'Removing .SRCINFO.' '
133 old=$(git -C aur.git rev-parse HEAD) &&
134 test_when_finished "git -C aur.git reset --hard $old" &&
135 git -C aur.git rm -q .SRCINFO &&
136 git -C aur.git commit -q -m "Remove .SRCINFO" &&
137 new=$(git -C aur.git rev-parse HEAD) &&
138 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
139 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
140 grep -q "^error: missing .SRCINFO$" actual
143 test_expect_success 'Removing .SRCINFO with a follow-up fix.' '
144 old=$(git -C aur.git rev-parse HEAD) &&
145 test_when_finished "git -C aur.git reset --hard $old" &&
146 git -C aur.git rm -q .SRCINFO &&
147 git -C aur.git commit -q -m "Remove .SRCINFO" &&
148 git -C aur.git revert --no-edit HEAD &&
149 new=$(git -C aur.git rev-parse HEAD) &&
150 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
151 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
152 grep -q "^error: missing .SRCINFO$" actual
155 test_expect_success 'Removing PKGBUILD.' '
156 old=$(git -C aur.git rev-parse HEAD) &&
157 test_when_finished "git -C aur.git reset --hard $old" &&
158 git -C aur.git rm -q PKGBUILD &&
159 git -C aur.git commit -q -m "Remove PKGBUILD" &&
160 new=$(git -C aur.git rev-parse HEAD) &&
161 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
162 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
163 grep -q "^error: missing PKGBUILD$" actual
166 test_expect_success 'Pushing a tree with a subdirectory.' '
167 old=$(git -C aur.git rev-parse HEAD) &&
168 test_when_finished "git -C aur.git reset --hard $old" &&
169 mkdir aur.git/subdir &&
170 touch aur.git/subdir/file &&
171 git -C aur.git add subdir/file &&
172 git -C aur.git commit -q -m "Add subdirectory" &&
173 new=$(git -C aur.git rev-parse HEAD) &&
174 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
175 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
176 grep -q "^error: the repository must not contain subdirectories$" actual
179 test_expect_success 'Pushing a tree with a large blob.' '
180 old=$(git -C aur.git rev-parse HEAD) &&
181 test_when_finished "git -C aur.git reset --hard $old" &&
182 printf "%256001s" x >aur.git/file &&
183 git -C aur.git add file &&
184 git -C aur.git commit -q -m "Add large blob" &&
185 new=$(git -C aur.git rev-parse HEAD) &&
186 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
187 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
188 grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual
191 test_expect_success 'Pushing .SRCINFO with a non-matching package base.' '
192 old=$(git -C aur.git rev-parse HEAD) &&
193 test_when_finished "git -C aur.git reset --hard $old" &&
195 cd aur.git &&
196 sed "s/\(pkgbase.*\)foobar/\1foobar2/" .SRCINFO >.SRCINFO.new
197 mv .SRCINFO.new .SRCINFO
198 git commit -q -am "Change package base"
199 ) &&
200 new=$(git -C aur.git rev-parse HEAD) &&
201 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
202 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
203 grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual
206 test_expect_success 'Pushing .SRCINFO with invalid syntax.' '
207 old=$(git -C aur.git rev-parse HEAD) &&
208 test_when_finished "git -C aur.git reset --hard $old" &&
210 cd aur.git &&
211 sed "s/=//" .SRCINFO >.SRCINFO.new
212 mv .SRCINFO.new .SRCINFO
213 git commit -q -am "Break .SRCINFO"
214 ) &&
215 new=$(git -C aur.git rev-parse HEAD) &&
216 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
217 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
220 test_expect_success 'Pushing .SRCINFO without pkgver.' '
221 old=$(git -C aur.git rev-parse HEAD) &&
222 test_when_finished "git -C aur.git reset --hard $old" &&
224 cd aur.git &&
225 sed "/pkgver/d" .SRCINFO >.SRCINFO.new
226 mv .SRCINFO.new .SRCINFO
227 git commit -q -am "Remove pkgver"
228 ) &&
229 new=$(git -C aur.git rev-parse HEAD) &&
230 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
231 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
232 grep -q "^error: missing mandatory field: pkgver$" actual
235 test_expect_success 'Pushing .SRCINFO without pkgrel.' '
236 old=$(git -C aur.git rev-parse HEAD) &&
237 test_when_finished "git -C aur.git reset --hard $old" &&
239 cd aur.git &&
240 sed "/pkgrel/d" .SRCINFO >.SRCINFO.new
241 mv .SRCINFO.new .SRCINFO
242 git commit -q -am "Remove pkgrel"
243 ) &&
244 new=$(git -C aur.git rev-parse HEAD) &&
245 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
246 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
247 grep -q "^error: missing mandatory field: pkgrel$" actual
250 test_expect_success 'Pushing .SRCINFO with epoch.' '
251 old=$(git -C aur.git rev-parse HEAD) &&
252 test_when_finished "git -C aur.git reset --hard $old" &&
254 cd aur.git &&
255 sed "s/.*pkgrel.*/\\0\\nepoch = 1/" .SRCINFO >.SRCINFO.new
256 mv .SRCINFO.new .SRCINFO
257 git commit -q -am "Add epoch"
258 ) &&
259 new=$(git -C aur.git rev-parse HEAD) &&
260 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
261 "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
262 cat >expected <<-EOF &&
263 2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
264 3|1|foobar|1:1-2|aurweb test package.|https://aur.archlinux.org/
266 echo "SELECT * FROM Packages;" | sqlite3 aur.db >actual &&
267 test_cmp expected actual
270 test_expect_success 'Pushing .SRCINFO with invalid pkgname.' '
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 "s/\(pkgname.*\)foobar/\1!/" .SRCINFO >.SRCINFO.new
276 mv .SRCINFO.new .SRCINFO
277 git commit -q -am "Change pkgname"
278 ) &&
279 new=$(git -C aur.git rev-parse HEAD) &&
280 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
281 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
282 grep -q "^error: invalid package name: !$" actual
285 test_expect_success 'Pushing .SRCINFO with invalid epoch.' '
286 old=$(git -C aur.git rev-parse HEAD) &&
287 test_when_finished "git -C aur.git reset --hard $old" &&
289 cd aur.git &&
290 sed "s/.*pkgrel.*/\\0\\nepoch = !/" .SRCINFO >.SRCINFO.new
291 mv .SRCINFO.new .SRCINFO
292 git commit -q -am "Change epoch"
293 ) &&
294 new=$(git -C aur.git rev-parse HEAD) &&
295 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
296 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
297 grep -q "^error: invalid epoch: !$" actual
300 test_expect_success 'Pushing .SRCINFO with too long URL.' '
301 old=$(git -C aur.git rev-parse HEAD) &&
302 url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
303 test_when_finished "git -C aur.git reset --hard $old" &&
305 cd aur.git &&
306 sed "s#.*url.*#\\0\\nurl = $url#" .SRCINFO >.SRCINFO.new
307 mv .SRCINFO.new .SRCINFO
308 git commit -q -am "Change URL"
309 ) &&
310 new=$(git -C aur.git rev-parse HEAD) &&
311 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
312 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
313 grep -q "^error: url field too long: $url\$" actual
316 test_expect_success 'Missing install file.' '
317 old=$(git -C aur.git rev-parse HEAD) &&
318 test_when_finished "git -C aur.git reset --hard $old" &&
320 cd aur.git &&
321 sed "s/.*depends.*/\\0\\ninstall = install/" .SRCINFO >.SRCINFO.new
322 mv .SRCINFO.new .SRCINFO
323 git commit -q -am "Add install field"
324 ) &&
325 new=$(git -C aur.git rev-parse HEAD) &&
326 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
327 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
328 grep -q "^error: missing install file: install$" actual
331 test_expect_success 'Missing changelog file.' '
332 old=$(git -C aur.git rev-parse HEAD) &&
333 test_when_finished "git -C aur.git reset --hard $old" &&
335 cd aur.git &&
336 sed "s/.*depends.*/\\0\\nchangelog = changelog/" .SRCINFO >.SRCINFO.new
337 mv .SRCINFO.new .SRCINFO
338 git commit -q -am "Add changelog field"
339 ) &&
340 new=$(git -C aur.git rev-parse HEAD) &&
341 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
342 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
343 grep -q "^error: missing changelog file: changelog$" actual
346 test_expect_success 'Missing source file.' '
347 old=$(git -C aur.git rev-parse HEAD) &&
348 test_when_finished "git -C aur.git reset --hard $old" &&
350 cd aur.git &&
351 sed "s/.*depends.*/\\0\\nsource = file/" .SRCINFO >.SRCINFO.new
352 mv .SRCINFO.new .SRCINFO
353 git commit -q -am "Add file to the source array"
354 ) &&
355 new=$(git -C aur.git rev-parse HEAD) &&
356 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
357 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
358 grep -q "^error: missing source file: file$" actual
361 test_expect_success 'Pushing .SRCINFO with too long source URL.' '
362 old=$(git -C aur.git rev-parse HEAD) &&
363 url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
364 test_when_finished "git -C aur.git reset --hard $old" &&
366 cd aur.git &&
367 sed "s#.*depends.*#\\0\\nsource = $url#" .SRCINFO >.SRCINFO.new
368 mv .SRCINFO.new .SRCINFO
369 git commit -q -am "Add huge source URL"
370 ) &&
371 new=$(git -C aur.git rev-parse HEAD) &&
372 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
373 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
374 grep -q "^error: source entry too long: $url\$" actual
377 test_expect_success 'Pushing a blacklisted package.' '
378 old=$(git -C aur.git rev-parse HEAD) &&
379 test_when_finished "git -C aur.git reset --hard $old" &&
380 echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
381 git -C aur.git commit -q -am "Add blacklisted package" &&
382 new=$(git -C aur.git rev-parse HEAD) &&
383 cat >expected <<-EOD &&
384 error: package is blacklisted: forbidden
386 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
387 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
388 test_cmp expected actual
391 test_expect_success 'Pushing a blacklisted package as Trusted User.' '
392 old=$(git -C aur.git rev-parse HEAD) &&
393 test_when_finished "git -C aur.git reset --hard $old" &&
394 echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
395 git -C aur.git commit -q -am "Add blacklisted package" &&
396 new=$(git -C aur.git rev-parse HEAD) &&
397 cat >expected <<-EOD &&
398 warning: package is blacklisted: forbidden
400 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
401 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
402 test_cmp expected actual
405 test_expect_success 'Pushing a package already in the official repositories.' '
406 old=$(git -C aur.git rev-parse HEAD) &&
407 test_when_finished "git -C aur.git reset --hard $old" &&
408 echo "pkgname = official" >>aur.git/.SRCINFO &&
409 git -C aur.git commit -q -am "Add official package" &&
410 new=$(git -C aur.git rev-parse HEAD) &&
411 cat >expected <<-EOD &&
412 error: package already provided by [core]: official
414 AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
415 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
416 test_cmp expected actual
419 test_expect_success 'Pushing a package already in the official repositories as Trusted User.' '
420 old=$(git -C aur.git rev-parse HEAD) &&
421 test_when_finished "git -C aur.git reset --hard $old" &&
422 echo "pkgname = official" >>aur.git/.SRCINFO &&
423 git -C aur.git commit -q -am "Add official package" &&
424 new=$(git -C aur.git rev-parse HEAD) &&
425 cat >expected <<-EOD &&
426 warning: package already provided by [core]: official
428 AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
429 "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
430 test_cmp expected actual
433 test_expect_success 'Trying to hijack a package.' '
434 old=0000000000000000000000000000000000000000 &&
435 test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
437 cd aur.git &&
438 git checkout -q refs/namespaces/foobar2/refs/heads/master &&
439 sed "s/\\(.*pkgname.*\\)2/\\1/" .SRCINFO >.SRCINFO.new
440 mv .SRCINFO.new .SRCINFO
441 git commit -q -am "Change package name"
442 ) &&
443 new=$(git -C aur.git rev-parse HEAD) &&
444 cat >expected <<-EOD &&
445 error: cannot overwrite package: foobar
447 AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
448 test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
449 test_cmp expected actual
452 test_done