blob: 81c5687dae5ecba3cde754a9b4b91a6bb818ce02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
#!/bin/sh
test_description='git-update tests'
. ./setup.sh
test_expect_success 'Setup repositories and create package bases.' '
SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user "$GIT_SERVE"
SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=user "$GIT_SERVE"
'
test_expect_success 'Test update hook on a fresh repository.' '
old=0000000000000000000000000000000000000000 &&
new=$(git -C aur.git rev-parse HEAD^) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
cat >expected <<-EOF &&
1|1|foobar|1-1|aurweb test package.|https://aur.archlinux.org/
1|GPL
1|1
1|1|python-pygit2||
1|1
2|1
EOF
>actual &&
for t in Packages Licenses PackageLicenses Groups PackageGroups \
PackageDepends PackageRelations PackageSources \
PackageNotifications; do
echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
done &&
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 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
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
1|1|python-pygit2||
2|1|python-pygit2||
1|1
2|1
EOF
>actual &&
for t in Packages Licenses PackageLicenses Groups PackageGroups \
PackageDepends PackageRelations PackageSources \
PackageNotifications; do
echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
done &&
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 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
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
2|1|python-pygit2||
3|1|python-pygit2||
1|1
2|1
EOF
>actual &&
for t in Packages Licenses PackageLicenses Groups PackageGroups \
PackageDepends PackageRelations PackageSources \
PackageNotifications; do
echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
done &&
test_cmp expected actual
'
test_expect_success 'Test restore mode.' '
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
"$GIT_UPDATE" restore 2>&1 &&
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
2|1|python-pygit2||
3|1|python-pygit2||
1|1
2|1
EOF
>actual &&
for t in Packages Licenses PackageLicenses Groups PackageGroups \
PackageDepends PackageRelations PackageSources \
PackageNotifications; do
echo "SELECT * FROM $t;" | sqlite3 aur.db >>actual
done &&
test_cmp expected actual
'
test_expect_success 'Test restore mode on a non-existent repository.' '
AUR_USER=user AUR_PKGBASE=foobar3 AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" restore 2>&1
'
test_expect_success 'Pushing to a branch other than master.' '
old=0000000000000000000000000000000000000000 &&
new=$(git -C aur.git rev-parse HEAD) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/pu "$old" "$new" 2>&1
'
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^) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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^) &&
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 &&
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/
EOF
echo "SELECT * FROM Packages;" | sqlite3 aur.db >actual &&
test_cmp expected actual
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
test_expect_success 'Pushing a blacklisted package as Trusted User.' '
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) &&
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning:
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
test_expect_success 'Pushing a package already in the official repositories as Trusted User.' '
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) &&
AUR_USER=tu AUR_PKGBASE=foobar AUR_PRIVILEGED=1 \
"$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1 | grep ^warning:
'
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) &&
AUR_USER=user AUR_PKGBASE=foobar2 AUR_PRIVILEGED=0 \
test_must_fail "$GIT_UPDATE" refs/heads/master "$old" "$new" 2>&1
'
test_done
|