]> git.saurik.com Git - apt.git/blame - test/integration/test-policy-pinning
rred: truncate result file before writing to it
[apt.git] / test / integration / test-policy-pinning
CommitLineData
5ed56f93
DK
1#!/bin/sh
2set -e
3
3abb6a6a
DK
4TESTDIR="$(readlink -f "$(dirname "$0")")"
5. "$TESTDIR/framework"
5ed56f93
DK
6
7setupenvironment
8configarchitecture "i386"
9
10buildaptarchive
11setupflataptarchive
12
13STATUS=$(readlink -f rootdir/var/lib/dpkg/status)
14APTARCHIVE=$(readlink -f aptarchive)
15
16testequalpolicy() {
17 local SP="$1"
18 local AP="$2"
19 shift 2
25b86db1 20 testsuccessequal "Package files:
5ed56f93
DK
21 $(echo "$SP" | awk '{ printf("%3s\n",$0) }') ${STATUS}
22 release a=now
1da3b7b8 23 $(echo "$AP" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} Packages
5ed56f93 24 release c=
b07aeb1a 25Pinned packages:" aptcache policy "$@"
5ed56f93
DK
26}
27
3f732aa6
DK
28testglobalpolicy() {
29 aptgetupdate
5ed56f93 30
3f732aa6
DK
31 testequalpolicy 100 500
32 testequalpolicy 990 500 -t now
5ed56f93 33
3f732aa6
DK
34 sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
35 aptgetupdate
5ed56f93 36
3f732aa6
DK
37 testequalpolicy 100 1 -o Test=NotAutomatic
38 testequalpolicy 990 1 -o Test=NotAutomatic -t now
451ea3d4 39
3f732aa6
DK
40 sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
41 aptgetupdate
451ea3d4 42
3f732aa6
DK
43 testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
44 testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
451ea3d4 45
3f732aa6
DK
46 sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
47 aptgetupdate
451ea3d4 48
3f732aa6
DK
49 testequalpolicy 100 500 -o Test=Automatic
50 testequalpolicy 990 500 -o Test=Automatic -t now
451ea3d4 51
3f732aa6
DK
52 sed -i aptarchive/Release -e '/NotAutomatic: / d' -e '/ButAutomaticUpgrades: / d'
53}
451ea3d4 54
3f732aa6
DK
55msgmsg 'Test with not signed archive'
56aptgetupdate() {
57 rm -rf rootdir/var/lib/apt
58 testwarning aptget update --allow-insecure-repositories
59}
60testglobalpolicy
451ea3d4 61
3f732aa6
DK
62msgmsg 'Test with signed but no key in trusted'
63aptgetupdate() {
64 rm -rf rootdir/var/lib/apt
65 signreleasefiles 'Marvin Paranoid'
66 testwarning aptget update --allow-insecure-repositories
67}
68testglobalpolicy
451ea3d4 69
3f732aa6
DK
70# much the same tests will be executed below in more detail again for this one
71msgmsg 'Test with signed and valid key'
72aptgetupdate() {
73 rm -rf rootdir/var/lib/apt
74 signreleasefiles 'Joe Sixpack'
75 testsuccess aptget update
76}
77testglobalpolicy
451ea3d4 78
3f732aa6 79msgmsg 'Test with specific packages'
451ea3d4 80
5ed56f93
DK
81buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
82buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
83
84setupaptarchive
85
27e4c166
DK
86testsuccessequal "coolstuff:
87 Installed: (none)
88 Candidate: 2.0~bpo1
89 Version table:
90 2.0~bpo1 500
91 500 file:${APTARCHIVE} backports/main all Packages
92 1.0 500
93 500 file:${APTARCHIVE} stable/main all Packages" apt policy '^cool.*'
94
5ed56f93
DK
95testequalpolicycoolstuff() {
96 local INSTALLED="${1:-(none)}"
97 local CANDIDATE="${2:-(none)}"
98 local AB="$3"
99 local AS="$4"
100 local PB="$5"
5ed56f93
DK
101 local IS=""
102 local IB=""
103 local SB=""
104 local SS=""
105 [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
106 100 $STATUS" || IB=" "
107 [ "$1" = "1.0" ] && IS="***" && SS="
108 100 $STATUS" || IS=" "
109 local BPO1ARCHIVE=""
110 local BPO2ARCHIVE=""
111 if [ ! "$7" = "2.0~bpo2" ]; then
76b004d1 112 BPO1PIN="$AB"
1dd20368 113 BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main all Packages"
5ed56f93
DK
114 else
115 BPO2ARCHIVE="
76b004d1 116 2.0~bpo2 $AB
1dd20368 117 $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main all Packages"
5ed56f93
DK
118 SB="$(echo "$SB" | tail -n 1)"
119 shift
120 fi
121 shift 6
25b86db1 122 testsuccessequal "coolstuff:
5ed56f93
DK
123 Installed: $INSTALLED
124 Candidate: $CANDIDATE
bb08e204 125 Version table:${BPO2ARCHIVE}
5ed56f93
DK
126 $IB 2.0~bpo1 $PB
127${BPO1ARCHIVE}$SB
76b004d1 128 $IS 1.0 $AS
1dd20368 129 $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} stable/main all Packages$SS" \
5ed56f93
DK
130 aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
131}
132
76b004d1
JAK
133testequalpolicycoolstuff "" "2.0~bpo1" 500 500 500 ""
134testequalpolicycoolstuff "" "1.0" 500 990 500 "" -t stable
135testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -t backports
5ed56f93
DK
136echo "Package: *
137Pin: release n=backports
138Pin-Priority: 200" > rootdir/etc/apt/preferences
76b004d1
JAK
139testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=GlobalPin
140testequalpolicycoolstuff "" "1.0" 200 990 200 "" -o Test=GlobalPin -t stable
141testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=GlobalPin -t backports
5ed56f93
DK
142echo "Package: *
143Pin: release n=backports
144Pin-Priority: 600" > rootdir/etc/apt/preferences
76b004d1
JAK
145testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=GlobalPin
146testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=GlobalPin -t stable
5ed56f93
DK
147echo "Package: coolstuff
148Pin: release n=backports
149Pin-Priority: 200" > rootdir/etc/apt/preferences
150#FIXME: policy can't differentiate between two sources where one has a package specific pin in place
151# testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
152# testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
153testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
154echo "Package: coolstuff
155Pin: release n=backports
156Pin-Priority: 600" > rootdir/etc/apt/preferences
157testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
158testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
159testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
160
161echo "Package: coolstuff
162Pin: release n=backports
163Pin-Priority: -1" > rootdir/etc/apt/preferences
164# testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
165# testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
166# testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
167
168rm rootdir/etc/apt/preferences
169sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
170signreleasefiles
451ea3d4 171aptgetupdate
5ed56f93 172
76b004d1
JAK
173testequalpolicycoolstuff "" "1.0" 1 500 1 "" -o Test=NotAutomatic
174testequalpolicycoolstuff "" "1.0" 1 990 1 "" -o Test=NotAutomatic -t stable
175testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=NotAutomatic -t backports
5ed56f93
DK
176echo "Package: *
177Pin: release n=backports
178Pin-Priority: 200" > rootdir/etc/apt/preferences
76b004d1 179testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=NotAutomatic
5ed56f93
DK
180echo "Package: *
181Pin: release n=backports
182Pin-Priority: 600" > rootdir/etc/apt/preferences
76b004d1
JAK
183testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=NotAutomatic
184testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=NotAutomatic -t stable
5ed56f93
DK
185echo "Package: coolstuff
186Pin: release n=backports
187Pin-Priority: 200" > rootdir/etc/apt/preferences
188testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
189echo "Package: coolstuff
190Pin: release n=backports
191Pin-Priority: 600" > rootdir/etc/apt/preferences
192testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
193testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
194testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
195
196rm rootdir/etc/apt/preferences
197sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
198signreleasefiles
451ea3d4 199aptgetupdate
5ed56f93 200
76b004d1
JAK
201testequalpolicycoolstuff "" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
202testequalpolicycoolstuff "" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
203testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
5ed56f93
DK
204echo "Package: *
205Pin: release n=backports
206Pin-Priority: 200" > rootdir/etc/apt/preferences
76b004d1 207testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=ButAutomaticUpgrades
5ed56f93
DK
208echo "Package: *
209Pin: release n=backports
210Pin-Priority: 600" > rootdir/etc/apt/preferences
76b004d1
JAK
211testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=ButAutomaticUpgrades
212testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=ButAutomaticUpgrades -t stable
5ed56f93
DK
213echo "Package: coolstuff
214Pin: release n=backports
215Pin-Priority: 200" > rootdir/etc/apt/preferences
216testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
217echo "Package: coolstuff
218Pin: release n=backports
219Pin-Priority: 600" > rootdir/etc/apt/preferences
220testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
221testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
222testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
223
224rm rootdir/etc/apt/preferences
0440d936 225testsuccess aptget install coolstuff -y
76b004d1 226testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
0440d936 227testsuccess aptget dist-upgrade -y
76b004d1
JAK
228testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
229testequalpolicycoolstuff "1.0" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
230testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
5ed56f93 231
0440d936 232testsuccess aptget install coolstuff -t backports -y
76b004d1 233testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
0440d936 234testsuccess aptget dist-upgrade -y
76b004d1
JAK
235testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
236testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
237testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
5ed56f93
DK
238
239rm incoming/backports.main.pkglist incoming/backports.main.srclist
240buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
241setupaptarchive
242
243sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
244signreleasefiles
451ea3d4 245aptgetupdate
5ed56f93 246
76b004d1
JAK
247testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 100 "" "2.0~bpo2" -o Test=NotAutomatic
248testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 100 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
249testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
5ed56f93
DK
250
251sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
252signreleasefiles
451ea3d4 253aptgetupdate
5ed56f93 254
76b004d1
JAK
255testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
256testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
257testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports
e916a815
JAK
258
259
260tmppath=$(readlink -f .)
261
262# Check 16-bit integers
263echo "Package: coolstuff
264Pin: release n=backports
265Pin-Priority: 32767
266" > rootdir/etc/apt/preferences
267
268testsuccess aptget install -s coolstuff -o PinPriority=32767
269
270echo "Package: coolstuff
271Pin: release n=backports
272Pin-Priority: -32768
273" > rootdir/etc/apt/preferences
274testsuccess aptget install -s coolstuff -o PinPriority=-32768
275
e916a815
JAK
276# Check for 32-bit integers
277echo "Package: coolstuff
278Pin: release n=backports
279Pin-Priority: 32768
280" > rootdir/etc/apt/preferences
281
282testfailureequal "Reading package lists...
283E: ${tmppath}/rootdir/etc/apt/preferences: Value 32768 is outside the range of valid pin priorities (-32768 to 32767)" \
284 aptget install -s coolstuff -o PinPriority=32768
285
286
287echo "Package: coolstuff
288Pin: release n=backports
289Pin-Priority: -32769
290" > rootdir/etc/apt/preferences
291
292testfailureequal "Reading package lists...
293E: ${tmppath}/rootdir/etc/apt/preferences: Value -32769 is outside the range of valid pin priorities (-32768 to 32767)" \
294 aptget install -s coolstuff -o PinPriority=-32769
295
296# Check for 64-bit integers
297
298echo "Package: coolstuff
299Pin: release n=backports
300Pin-Priority: 2147483648
301" > rootdir/etc/apt/preferences
302
303testfailureequal "Reading package lists...
137e8ad4 304E: Cannot convert 2147483648 to integer: out of range
e916a815
JAK
305E: ${tmppath}/rootdir/etc/apt/preferences: Value 2147483648 is outside the range of valid pin priorities (-32768 to 32767)" \
306 aptget install -s coolstuff -o PinPriority=2147483648
307
fd2e438b
DK
308# Check that short-max/min is a valid pin
309currentpin() {
310echo "Package: *
311Pin: release n=backports
312Pin-Priority: $1
313" > rootdir/etc/apt/preferences
314testsuccessequal "coolstuff:
315 Installed: 2.0~bpo1
316 Candidate: $2
317 Version table:
318 2.0~bpo2 $1
319 $1 file:${tmppath}/aptarchive backports/main all Packages
320 *** 2.0~bpo1 100
321 100 ${tmppath}/rootdir/var/lib/dpkg/status
322 1.0 500
323 500 file:${tmppath}/aptarchive stable/main all Packages" apt policy coolstuff
324}
325currentpin '32767' '2.0~bpo2'
326currentpin '-32768' '2.0~bpo1'
327
e916a815
JAK
328# Check for 0
329echo "Package: coolstuff
330Pin: release n=backports
331Pin-Priority: 0
332" > rootdir/etc/apt/preferences
333
334testfailureequal "Reading package lists...
335E: No priority (or zero) specified for pin" \
336 aptget install -s coolstuff -o PinPriority=0
f6459e64
DK
337
338# Check with comments
339echo "#Package: coolstuff
340#Pin: release n=backports
341#Pin-Priority: 0
342
343# Test
344
345Package: coolstuff
346Pin: release n=backports
347#Pin: release n=unstable
348#Pin-Priority: 999
349Pin-Priority: 999
350#Pin-Priority: 999" > rootdir/etc/apt/preferences
351
352testsuccessequal "coolstuff:
353 Installed: 2.0~bpo1
354 Candidate: 2.0~bpo2
355 Version table:
356 2.0~bpo2 999
357 100 file:${tmppath}/aptarchive backports/main all Packages
358 *** 2.0~bpo1 100
359 100 ${tmppath}/rootdir/var/lib/dpkg/status
360 1.0 500
361 500 file:${tmppath}/aptarchive stable/main all Packages" aptcache policy coolstuff