t1300-git-update.t 16.7 KB
Newer Older
1
2
3
4
#!/bin/sh

test_description='git-update tests'

5
. "$(dirname "$0")/setup.sh"
6

7
8
9
10
11
12
13
14
dump_package_info() {
	for t in Packages Licenses PackageLicenses Groups PackageGroups \
		PackageDepends PackageRelations PackageSources \
		PackageNotifications; do
		echo "SELECT * FROM $t;" | sqlite3 aur.db
	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 \
Kevin Morris's avatar
Kevin Morris committed
19
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
20
21
	cat >expected <<-EOF &&
	1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
22
23
	1|GPL
	1|1
24
	1|1|python-pygit2|||
25
26
	1|1
	EOF
27
	dump_package_info >actual &&
28
29
30
31
32
33
34
35
36
	test_cmp expected actual
'

test_expect_success 'Test update hook on another fresh repository.' '
	old=0000000000000000000000000000000000000000 &&
	test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
	git -C aur.git checkout -q refs/namespaces/foobar2/refs/heads/master &&
	new=$(git -C aur.git rev-parse HEAD) &&
	AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
37
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
38
39
40
41
42
43
44
	cat >expected <<-EOF &&
	1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
	2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
	1|GPL
	2|MIT
	1|1
	2|2
45
46
	1|1|python-pygit2|||
	2|1|python-pygit2|||
47
48
49
	1|1
	2|1
	EOF
50
	dump_package_info >actual &&
51
52
53
54
55
56
57
	test_cmp expected actual
'

test_expect_success 'Test update hook on an updated repository.' '
	old=$(git -C aur.git rev-parse HEAD^) &&
	new=$(git -C aur.git rev-parse HEAD) &&
	AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
58
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
59
60
61
62
63
64
65
	cat >expected <<-EOF &&
	2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
	3|1|foobar|1-2|aurweb test package.|https://aur.archlinux.org/
	1|GPL
	2|MIT
	2|2
	3|1
66
67
	2|1|python-pygit2|||
	3|1|python-pygit2|||
68
69
70
	1|1
	2|1
	EOF
71
	dump_package_info >actual &&
72
73
74
	test_cmp expected actual
'

75
76
test_expect_success 'Test restore mode.' '
	AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
77
	cover "$GIT_UPDATE" restore 2>&1 &&
78
79
80
81
82
83
84
	cat >expected <<-EOF &&
	2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
	3|1|foobar|1-2|aurweb test package.|https://aur.archlinux.org/
	1|GPL
	2|MIT
	2|2
	3|1
85
86
	2|1|python-pygit2|||
	3|1|python-pygit2|||
87
88
89
	1|1
	2|1
	EOF
90
	dump_package_info >actual &&
91
92
93
94
	test_cmp expected actual
'

test_expect_success 'Test restore mode on a non-existent repository.' '
95
96
97
	cat >expected <<-EOD &&
	error: restore: repository not found: foobar3
	EOD
98
99
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
100
	cover "$GIT_UPDATE" restore >actual 2>&1 &&
101
	test_cmp expected actual
102
103
'

104
105
106
test_expect_success 'Pushing to a branch other than master.' '
	old=0000000000000000000000000000000000000000 &&
	new=$(git -C aur.git rev-parse HEAD) &&
107
108
109
	cat >expected <<-EOD &&
	error: pushing to a branch other than master is restricted
	EOD
110
111
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
112
	cover "$GIT_UPDATE" refs/heads/pu "$old" "$new" >actual 2>&1 &&
113
	test_cmp expected actual
114
115
116
117
118
'

test_expect_success 'Performing a non-fast-forward ref update.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	new=$(git -C aur.git rev-parse HEAD^) &&
119
120
121
	cat >expected <<-EOD &&
	error: denying non-fast-forward (you should pull first)
	EOD
122
123
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
124
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
125
	test_cmp expected actual
126
127
128
129
130
'

test_expect_success 'Performing a non-fast-forward ref update as Trusted User.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	new=$(git -C aur.git rev-parse HEAD^) &&
131
132
133
	cat >expected <<-EOD &&
	error: denying non-fast-forward (you should pull first)
	EOD
134
135
	test_must_fail \
	env AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
Kevin Morris's avatar
Kevin Morris committed
136
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
137
138
139
	test_cmp expected actual
'

140
141
142
143
144
145
146
147
test_expect_success 'Performing a non-fast-forward ref update as normal user with AUR_OVERWRITE=1.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	new=$(git -C aur.git rev-parse HEAD^) &&
	cat >expected <<-EOD &&
	error: denying non-fast-forward (you should pull first)
	EOD
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 AUR_OVERWRITE=1 \
Kevin Morris's avatar
Kevin Morris committed
148
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
149
150
151
152
	test_cmp expected actual
'

test_expect_success 'Performing a non-fast-forward ref update as Trusted User with AUR_OVERWRITE=1.' '
153
154
155
	old=$(git -C aur.git rev-parse HEAD) &&
	new=$(git -C aur.git rev-parse HEAD^) &&
	AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 AUR_OVERWRITE=1 \
Kevin Morris's avatar
Kevin Morris committed
156
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
157
158
159
160
161
162
163
164
'

test_expect_success 'Removing .SRCINFO.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	git -C aur.git rm -q .SRCINFO &&
	git -C aur.git commit -q -m "Remove .SRCINFO" &&
	new=$(git -C aur.git rev-parse HEAD) &&
165
166
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
167
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
168
	grep -q "^error: missing .SRCINFO$" actual
169
170
171
172
173
174
175
176
177
'

test_expect_success 'Removing .SRCINFO with a follow-up fix.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	git -C aur.git rm -q .SRCINFO &&
	git -C aur.git commit -q -m "Remove .SRCINFO" &&
	git -C aur.git revert --no-edit HEAD &&
	new=$(git -C aur.git rev-parse HEAD) &&
178
179
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
180
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
181
	grep -q "^error: missing .SRCINFO$" actual
182
183
184
185
186
187
188
189
'

test_expect_success 'Removing PKGBUILD.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	git -C aur.git rm -q PKGBUILD &&
	git -C aur.git commit -q -m "Remove PKGBUILD" &&
	new=$(git -C aur.git rev-parse HEAD) &&
190
191
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
192
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
193
	grep -q "^error: missing PKGBUILD$" actual
194
195
196
197
198
199
200
201
202
203
'

test_expect_success 'Pushing a tree with a subdirectory.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	mkdir aur.git/subdir &&
	touch aur.git/subdir/file &&
	git -C aur.git add subdir/file &&
	git -C aur.git commit -q -m "Add subdirectory" &&
	new=$(git -C aur.git rev-parse HEAD) &&
204
205
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
206
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
207
	grep -q "^error: the repository must not contain subdirectories$" actual
208
209
210
211
212
213
214
215
216
'

test_expect_success 'Pushing a tree with a large blob.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	printf "%256001s" x >aur.git/file &&
	git -C aur.git add file &&
	git -C aur.git commit -q -m "Add large blob" &&
	new=$(git -C aur.git rev-parse HEAD) &&
217
218
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
219
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
220
	grep -q "^error: maximum blob size (250.00KiB) exceeded$" actual
221
222
223
224
225
226
227
228
229
230
231
232
'

test_expect_success 'Pushing .SRCINFO with a non-matching package base.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/\(pkgbase.*\)foobar/\1foobar2/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Change package base"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
233
234
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
235
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
236
	grep -q "^error: invalid pkgbase: foobar2, expected foobar$" actual
237
238
239
240
241
242
243
244
245
246
247
248
'

test_expect_success 'Pushing .SRCINFO with invalid syntax.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/=//" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Break .SRCINFO"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
249
250
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
251
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
252
253
254
255
256
257
258
259
260
261
262
263
'

test_expect_success 'Pushing .SRCINFO without pkgver.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "/pkgver/d" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Remove pkgver"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
264
265
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
266
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
267
	grep -q "^error: missing mandatory field: pkgver$" actual
268
269
270
271
272
273
274
275
276
277
278
279
'

test_expect_success 'Pushing .SRCINFO without pkgrel.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "/pkgrel/d" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Remove pkgrel"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
280
281
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
282
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
283
	grep -q "^error: missing mandatory field: pkgrel$" actual
284
285
286
287
288
289
290
291
292
293
294
295
296
'

test_expect_success 'Pushing .SRCINFO with epoch.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/.*pkgrel.*/\\0\\nepoch = 1/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Add epoch"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
	AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
297
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
298
299
300
	cat >expected <<-EOF &&
	2|2|foobar2|1-1|aurweb test package.|https://aur.archlinux.org/
	3|1|foobar|1:1-2|aurweb test package.|https://aur.archlinux.org/
301
302
303
304
305
	EOF
	echo "SELECT * FROM Packages;" | sqlite3 aur.db >actual &&
	test_cmp expected actual
'

306
307
308
309
310
311
312
313
314
315
test_expect_success 'Pushing .SRCINFO with invalid pkgname.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/\(pkgname.*\)foobar/\1!/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Change pkgname"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
316
317
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
318
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
319
	grep -q "^error: invalid package name: !$" actual
320
321
322
323
324
325
326
327
328
329
330
331
'

test_expect_success 'Pushing .SRCINFO with invalid epoch.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/.*pkgrel.*/\\0\\nepoch = !/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Change epoch"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
332
333
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
334
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
335
	grep -q "^error: invalid epoch: !$" actual
336
337
'

338
339
340
341
342
343
344
345
346
347
348
test_expect_success 'Pushing .SRCINFO with too long URL.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s#.*url.*#\\0\\nurl = $url#" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Change URL"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
349
350
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
351
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
352
353
354
	grep -q "^error: url field too long: $url\$" actual
'

355
356
357
358
359
360
361
362
363
364
test_expect_success 'Missing install file.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/.*depends.*/\\0\\ninstall = install/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Add install field"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
365
366
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
367
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
368
	grep -q "^error: missing install file: install$" actual
369
370
371
372
373
374
375
376
377
378
379
380
'

test_expect_success 'Missing changelog file.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/.*depends.*/\\0\\nchangelog = changelog/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Add changelog field"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
381
382
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
383
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
384
	grep -q "^error: missing changelog file: changelog$" actual
385
386
387
388
389
390
391
392
393
394
395
396
'

test_expect_success 'Missing source file.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s/.*depends.*/\\0\\nsource = file/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Add file to the source array"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
397
398
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
399
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
400
	grep -q "^error: missing source file: file$" actual
401
402
'

403
404
405
406
407
408
409
410
411
412
413
test_expect_success 'Pushing .SRCINFO with too long source URL.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	url="http://$(printf "%7993s" x | sed "s/ /x/g")/" &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	(
		cd aur.git &&
		sed "s#.*depends.*#\\0\\nsource = $url#" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Add huge source URL"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
414
415
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
416
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
417
418
419
	grep -q "^error: source entry too long: $url\$" actual
'

420
421
422
423
424
425
test_expect_success 'Pushing a blacklisted package.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
	git -C aur.git commit -q -am "Add blacklisted package" &&
	new=$(git -C aur.git rev-parse HEAD) &&
426
427
428
	cat >expected <<-EOD &&
	error: package is blacklisted: forbidden
	EOD
429
430
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
431
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
432
	test_cmp expected actual
433
434
'

435
test_expect_success 'Pushing a blacklisted package as Trusted User.' '
436
437
438
439
440
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	echo "pkgname = forbidden" >>aur.git/.SRCINFO &&
	git -C aur.git commit -q -am "Add blacklisted package" &&
	new=$(git -C aur.git rev-parse HEAD) &&
441
442
443
	cat >expected <<-EOD &&
	warning: package is blacklisted: forbidden
	EOD
444
	AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
Kevin Morris's avatar
Kevin Morris committed
445
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
446
	test_cmp expected actual
447
448
449
450
451
452
453
454
'

test_expect_success 'Pushing a package already in the official repositories.' '
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	echo "pkgname = official" >>aur.git/.SRCINFO &&
	git -C aur.git commit -q -am "Add official package" &&
	new=$(git -C aur.git rev-parse HEAD) &&
455
456
457
	cat >expected <<-EOD &&
	error: package already provided by [core]: official
	EOD
458
459
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
460
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
461
	test_cmp expected actual
462
463
'

464
test_expect_success 'Pushing a package already in the official repositories as Trusted User.' '
465
466
467
468
469
	old=$(git -C aur.git rev-parse HEAD) &&
	test_when_finished "git -C aur.git reset --hard $old" &&
	echo "pkgname = official" >>aur.git/.SRCINFO &&
	git -C aur.git commit -q -am "Add official package" &&
	new=$(git -C aur.git rev-parse HEAD) &&
470
471
472
	cat >expected <<-EOD &&
	warning: package already provided by [core]: official
	EOD
473
	AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
Kevin Morris's avatar
Kevin Morris committed
474
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
475
	test_cmp expected actual
476
477
478
479
480
481
482
483
484
485
486
487
488
'

test_expect_success 'Trying to hijack a package.' '
	old=0000000000000000000000000000000000000000 &&
	test_when_finished "git -C aur.git checkout refs/namespaces/foobar/refs/heads/master" &&
	(
		cd aur.git &&
		git checkout -q refs/namespaces/foobar2/refs/heads/master &&
		sed "s/\\(.*pkgname.*\\)2/\\1/" .SRCINFO >.SRCINFO.new
		mv .SRCINFO.new .SRCINFO
		git commit -q -am "Change package name"
	) &&
	new=$(git -C aur.git rev-parse HEAD) &&
489
490
491
	cat >expected <<-EOD &&
	error: cannot overwrite package: foobar
	EOD
492
493
	test_must_fail \
	env AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
Kevin Morris's avatar
Kevin Morris committed
494
	cover "$GIT_UPDATE" refs/heads/master "$old" "$new" >actual 2>&1 &&
495
	test_cmp expected actual
496
497
'

498
test_done