]> git.saurik.com Git - apt.git/blob - test/integration/test-policy-pinning
Merge branch 'debian/sid' into debian/experimental
[apt.git] / test / integration / test-policy-pinning
1 #!/bin/sh
2 set -e
3
4 TESTDIR=$(readlink -f $(dirname $0))
5 . $TESTDIR/framework
6
7 setupenvironment
8 configarchitecture "i386"
9
10 buildaptarchive
11 setupflataptarchive
12
13 STATUS=$(readlink -f rootdir/var/lib/dpkg/status)
14 APTARCHIVE=$(readlink -f aptarchive)
15
16 testequalpolicy() {
17 local SP="$1"
18 local AP="$2"
19 shift 2
20 testequal "Package files:
21 $(echo "$SP" | awk '{ printf("%3s\n",$0) }') ${STATUS}
22 release a=now
23 $(echo "$AP" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ Packages
24 release c=
25 Pinned packages:" aptcache policy $*
26 }
27
28 aptgetupdate() {
29 # just to be sure that no old files are used
30 rm -rf rootdir/var/lib/apt
31 if aptget update --allow-insecure-repositories -qq 2>&1 | grep '^E: '; then
32 msgwarn 'apt-get update failed with an error'
33 fi
34 }
35
36 ### not signed archive
37
38 aptgetupdate
39
40 testequalpolicy 100 500
41 testequalpolicy 990 500 -t now
42
43 sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
44 aptgetupdate
45
46 testequalpolicy 100 1 -o Test=NotAutomatic
47 testequalpolicy 990 1 -o Test=NotAutomatic -t now
48
49 sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
50 aptgetupdate
51
52 testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
53 testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
54
55 sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
56 aptgetupdate
57
58 testequalpolicy 100 500 -o Test=Automatic
59 testequalpolicy 990 500 -o Test=Automatic -t now
60
61 sed -i aptarchive/Release -e '/NotAutomatic: / d' -e '/ButAutomaticUpgrades: / d'
62
63 ### signed but no key in trusted
64
65 signreleasefiles 'Marvin Paranoid'
66 aptgetupdate
67 testequalpolicy 100 500
68 testequalpolicy 990 500 -t now
69
70 sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
71 signreleasefiles 'Marvin Paranoid'
72 aptgetupdate
73
74 testequalpolicy 100 1 -o Test=NotAutomatic
75 testequalpolicy 990 1 -o Test=NotAutomatic -t now
76
77 sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
78 signreleasefiles 'Marvin Paranoid'
79 aptgetupdate
80
81 testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
82 testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
83
84 sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
85 signreleasefiles 'Marvin Paranoid'
86 aptgetupdate
87
88 testequalpolicy 100 500 -o Test=Automatic
89 testequalpolicy 990 500 -o Test=Automatic -t now
90
91 ### signed and valid key
92
93 buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
94 buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
95
96 setupaptarchive
97
98 testequalpolicycoolstuff() {
99 local INSTALLED="${1:-(none)}"
100 local CANDIDATE="${2:-(none)}"
101 local AB="$3"
102 local AS="$4"
103 local PB="$5"
104 local PINVERSION="$6"
105 if [ -n "$PINVERSION" ]; then
106 PINVERSION="Package pin: $PINVERSION
107 "
108 fi
109 local IS=""
110 local IB=""
111 local SB=""
112 local SS=""
113 [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
114 100 $STATUS" || IB=" "
115 [ "$1" = "1.0" ] && IS="***" && SS="
116 100 $STATUS" || IS=" "
117 local BPO1ARCHIVE=""
118 local BPO2ARCHIVE=""
119 if [ ! "$7" = "2.0~bpo2" ]; then
120 BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
121 else
122 BPO2ARCHIVE="
123 2.0~bpo2 $PB
124 $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ backports/main i386 Packages"
125 SB="$(echo "$SB" | tail -n 1)"
126 shift
127 fi
128 shift 6
129 testequal "coolstuff:
130 Installed: $INSTALLED
131 Candidate: $CANDIDATE
132 ${PINVERSION}Version table:${BPO2ARCHIVE}
133 $IB 2.0~bpo1 $PB
134 ${BPO1ARCHIVE}$SB
135 $IS 1.0 $PB
136 $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE}/ stable/main i386 Packages$SS" \
137 aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
138 }
139
140 testequalpolicycoolstuff "" "2.0~bpo1" 500 500 0 ""
141 testequalpolicycoolstuff "" "1.0" 500 990 0 "" -t stable
142 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -t backports
143 echo "Package: *
144 Pin: release n=backports
145 Pin-Priority: 200" > rootdir/etc/apt/preferences
146 testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=GlobalPin
147 testequalpolicycoolstuff "" "1.0" 200 990 0 "" -o Test=GlobalPin -t stable
148 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=GlobalPin -t backports
149 echo "Package: *
150 Pin: release n=backports
151 Pin-Priority: 600" > rootdir/etc/apt/preferences
152 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=GlobalPin
153 testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=GlobalPin -t stable
154 echo "Package: coolstuff
155 Pin: release n=backports
156 Pin-Priority: 200" > rootdir/etc/apt/preferences
157 #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
158 # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
159 # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
160 testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
161 echo "Package: coolstuff
162 Pin: release n=backports
163 Pin-Priority: 600" > rootdir/etc/apt/preferences
164 testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
165 testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
166 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
167
168 echo "Package: coolstuff
169 Pin: release n=backports
170 Pin-Priority: -1" > rootdir/etc/apt/preferences
171 # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
172 # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
173 # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
174
175 rm rootdir/etc/apt/preferences
176 sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
177 signreleasefiles
178 aptgetupdate
179
180 testequalpolicycoolstuff "" "1.0" 1 500 0 "" -o Test=NotAutomatic
181 testequalpolicycoolstuff "" "1.0" 1 990 0 "" -o Test=NotAutomatic -t stable
182 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=NotAutomatic -t backports
183 echo "Package: *
184 Pin: release n=backports
185 Pin-Priority: 200" > rootdir/etc/apt/preferences
186 testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=NotAutomatic
187 echo "Package: *
188 Pin: release n=backports
189 Pin-Priority: 600" > rootdir/etc/apt/preferences
190 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=NotAutomatic
191 testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=NotAutomatic -t stable
192 echo "Package: coolstuff
193 Pin: release n=backports
194 Pin-Priority: 200" > rootdir/etc/apt/preferences
195 testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
196 echo "Package: coolstuff
197 Pin: release n=backports
198 Pin-Priority: 600" > rootdir/etc/apt/preferences
199 testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
200 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
201 testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
202
203 rm rootdir/etc/apt/preferences
204 sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
205 signreleasefiles
206 aptgetupdate
207
208 testequalpolicycoolstuff "" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
209 testequalpolicycoolstuff "" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
210 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
211 echo "Package: *
212 Pin: release n=backports
213 Pin-Priority: 200" > rootdir/etc/apt/preferences
214 testequalpolicycoolstuff "" "1.0" 200 500 0 "" -o Test=ButAutomaticUpgrades
215 echo "Package: *
216 Pin: release n=backports
217 Pin-Priority: 600" > rootdir/etc/apt/preferences
218 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 0 "" -o Test=ButAutomaticUpgrades
219 testequalpolicycoolstuff "" "1.0" 600 990 0 "" -o Test=ButAutomaticUpgrades -t stable
220 echo "Package: coolstuff
221 Pin: release n=backports
222 Pin-Priority: 200" > rootdir/etc/apt/preferences
223 testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
224 echo "Package: coolstuff
225 Pin: release n=backports
226 Pin-Priority: 600" > rootdir/etc/apt/preferences
227 testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
228 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
229 testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
230
231 rm rootdir/etc/apt/preferences
232 testsuccess aptget install coolstuff -y
233 testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
234 testsuccess aptget dist-upgrade -y
235 testequalpolicycoolstuff "1.0" "1.0" 100 500 0 "" -o Test=ButAutomaticUpgrades
236 testequalpolicycoolstuff "1.0" "1.0" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
237 testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
238
239 testsuccess aptget install coolstuff -t backports -y
240 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
241 testsuccess aptget dist-upgrade -y
242 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 0 "" -o Test=ButAutomaticUpgrades
243 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 0 "" -o Test=ButAutomaticUpgrades -t stable
244 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 0 "" -o Test=ButAutomaticUpgrades -t backports
245
246 rm incoming/backports.main.pkglist incoming/backports.main.srclist
247 buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
248 setupaptarchive
249
250 sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
251 signreleasefiles
252 aptgetupdate
253
254 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 0 "" "2.0~bpo2" -o Test=NotAutomatic
255 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 0 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
256 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
257
258 sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
259 signreleasefiles
260 aptgetupdate
261
262 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
263 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
264 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 0 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports