]> git.saurik.com Git - apt.git/blob - test/integration/test-policy-pinning
1c8d92bccf0126af5446ac4148b6673a896d9198
[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 testsuccessequal "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 testglobalpolicy() {
29 aptgetupdate
30
31 testequalpolicy 100 500
32 testequalpolicy 990 500 -t now
33
34 sed -i aptarchive/Release -e 1i"NotAutomatic: yes"
35 aptgetupdate
36
37 testequalpolicy 100 1 -o Test=NotAutomatic
38 testequalpolicy 990 1 -o Test=NotAutomatic -t now
39
40 sed -i aptarchive/Release -e 1i"ButAutomaticUpgrades: yes"
41 aptgetupdate
42
43 testequalpolicy 100 100 -o Test=ButAutomaticUpgrades
44 testequalpolicy 990 100 -o Test=ButAutomaticUpgrades -t now
45
46 sed -i aptarchive/Release -e 's#NotAutomatic: yes#NotAutomatic: no#' -e '/ButAutomaticUpgrades: / d'
47 aptgetupdate
48
49 testequalpolicy 100 500 -o Test=Automatic
50 testequalpolicy 990 500 -o Test=Automatic -t now
51
52 sed -i aptarchive/Release -e '/NotAutomatic: / d' -e '/ButAutomaticUpgrades: / d'
53 }
54
55 msgmsg 'Test with not signed archive'
56 aptgetupdate() {
57 rm -rf rootdir/var/lib/apt
58 testwarning aptget update --allow-insecure-repositories
59 }
60 testglobalpolicy
61
62 msgmsg 'Test with signed but no key in trusted'
63 aptgetupdate() {
64 rm -rf rootdir/var/lib/apt
65 signreleasefiles 'Marvin Paranoid'
66 testwarning aptget update --allow-insecure-repositories
67 }
68 testglobalpolicy
69
70 # much the same tests will be executed below in more detail again for this one
71 msgmsg 'Test with signed and valid key'
72 aptgetupdate() {
73 rm -rf rootdir/var/lib/apt
74 signreleasefiles 'Joe Sixpack'
75 testsuccess aptget update
76 }
77 testglobalpolicy
78
79 msgmsg 'Test with specific packages'
80
81 buildsimplenativepackage "coolstuff" "all" "1.0" "stable"
82 buildsimplenativepackage "coolstuff" "all" "2.0~bpo1" "backports"
83
84 setupaptarchive
85
86 testequalpolicycoolstuff() {
87 local INSTALLED="${1:-(none)}"
88 local CANDIDATE="${2:-(none)}"
89 local AB="$3"
90 local AS="$4"
91 local PB="$5"
92 fi
93 local IS=""
94 local IB=""
95 local SB=""
96 local SS=""
97 [ "$1" = "2.0~bpo1" ] && IB="***" && SB="
98 100 $STATUS" || IB=" "
99 [ "$1" = "1.0" ] && IS="***" && SS="
100 100 $STATUS" || IS=" "
101 local BPO1ARCHIVE=""
102 local BPO2ARCHIVE=""
103 if [ ! "$7" = "2.0~bpo2" ]; then
104 BPO1PIN="$AB"
105 BPO1ARCHIVE=" $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main i386 Packages"
106 else
107 BPO2ARCHIVE="
108 2.0~bpo2 $AB
109 $(echo "$AB" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} backports/main i386 Packages"
110 SB="$(echo "$SB" | tail -n 1)"
111 shift
112 fi
113 shift 6
114 testsuccessequal "coolstuff:
115 Installed: $INSTALLED
116 Candidate: $CANDIDATE
117 Version table:${BPO2ARCHIVE}
118 $IB 2.0~bpo1 $PB
119 ${BPO1ARCHIVE}$SB
120 $IS 1.0 $AS
121 $(echo "$AS" | awk '{ printf("%3s\n",$0) }') file:${APTARCHIVE} stable/main i386 Packages$SS" \
122 aptcache policy coolstuff -o Policy=${INSTALLED}-${CANDIDATE}-${AB}-${AS}-${PB} $*
123 }
124
125 testequalpolicycoolstuff "" "2.0~bpo1" 500 500 500 ""
126 testequalpolicycoolstuff "" "1.0" 500 990 500 "" -t stable
127 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -t backports
128 echo "Package: *
129 Pin: release n=backports
130 Pin-Priority: 200" > rootdir/etc/apt/preferences
131 testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=GlobalPin
132 testequalpolicycoolstuff "" "1.0" 200 990 200 "" -o Test=GlobalPin -t stable
133 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=GlobalPin -t backports
134 echo "Package: *
135 Pin: release n=backports
136 Pin-Priority: 600" > rootdir/etc/apt/preferences
137 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=GlobalPin
138 testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=GlobalPin -t stable
139 echo "Package: coolstuff
140 Pin: release n=backports
141 Pin-Priority: 200" > rootdir/etc/apt/preferences
142 #FIXME: policy can't differentiate between two sources where one has a package specific pin in place
143 # testequalpolicycoolstuff "" "1.0" 500 500 200 "2.0~bpo1" -o Test=PackagePin
144 # testequalpolicycoolstuff "" "1.0" 990 500 200 "2.0~bpo1" -o Test=PackagePin -t backports
145 testequalpolicycoolstuff "" "1.0" 500 990 200 "2.0~bpo1" -o Test=PackagePin -t stable
146 echo "Package: coolstuff
147 Pin: release n=backports
148 Pin-Priority: 600" > rootdir/etc/apt/preferences
149 testequalpolicycoolstuff "" "2.0~bpo1" 500 500 600 "2.0~bpo1" -o Test=PackagePin
150 testequalpolicycoolstuff "" "1.0" 500 990 600 "2.0~bpo1" -o Test=PackagePin -t stable
151 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=PackagePin -t backports
152
153 echo "Package: coolstuff
154 Pin: release n=backports
155 Pin-Priority: -1" > rootdir/etc/apt/preferences
156 # testequalpolicycoolstuff "" "1.0" 500 500 -1 "2.0~bpo1" -o Test=PackagePin
157 # testequalpolicycoolstuff "" "1.0" 990 500 -1 "2.0~bpo1" -o Test=PackagePin -t backports
158 # testequalpolicycoolstuff "" "1.0" 500 990 -1 "2.0~bpo1" -o Test=PackagePin -t stable
159
160 rm rootdir/etc/apt/preferences
161 sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
162 signreleasefiles
163 aptgetupdate
164
165 testequalpolicycoolstuff "" "1.0" 1 500 1 "" -o Test=NotAutomatic
166 testequalpolicycoolstuff "" "1.0" 1 990 1 "" -o Test=NotAutomatic -t stable
167 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=NotAutomatic -t backports
168 echo "Package: *
169 Pin: release n=backports
170 Pin-Priority: 200" > rootdir/etc/apt/preferences
171 testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=NotAutomatic
172 echo "Package: *
173 Pin: release n=backports
174 Pin-Priority: 600" > rootdir/etc/apt/preferences
175 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=NotAutomatic
176 testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=NotAutomatic -t stable
177 echo "Package: coolstuff
178 Pin: release n=backports
179 Pin-Priority: 200" > rootdir/etc/apt/preferences
180 testequalpolicycoolstuff "" "1.0" 1 500 200 "2.0~bpo1" -o Test=NotAutomatic
181 echo "Package: coolstuff
182 Pin: release n=backports
183 Pin-Priority: 600" > rootdir/etc/apt/preferences
184 testequalpolicycoolstuff "" "2.0~bpo1" 1 500 600 "2.0~bpo1" -o Test=NotAutomatic
185 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=NotAutomatic -t backports
186 testequalpolicycoolstuff "" "1.0" 1 990 600 "2.0~bpo1" -o Test=NotAutomatic -t stable
187
188 rm rootdir/etc/apt/preferences
189 sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
190 signreleasefiles
191 aptgetupdate
192
193 testequalpolicycoolstuff "" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
194 testequalpolicycoolstuff "" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
195 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
196 echo "Package: *
197 Pin: release n=backports
198 Pin-Priority: 200" > rootdir/etc/apt/preferences
199 testequalpolicycoolstuff "" "1.0" 200 500 200 "" -o Test=ButAutomaticUpgrades
200 echo "Package: *
201 Pin: release n=backports
202 Pin-Priority: 600" > rootdir/etc/apt/preferences
203 testequalpolicycoolstuff "" "2.0~bpo1" 600 500 600 "" -o Test=ButAutomaticUpgrades
204 testequalpolicycoolstuff "" "1.0" 600 990 600 "" -o Test=ButAutomaticUpgrades -t stable
205 echo "Package: coolstuff
206 Pin: release n=backports
207 Pin-Priority: 200" > rootdir/etc/apt/preferences
208 testequalpolicycoolstuff "" "1.0" 100 500 200 "2.0~bpo1" -o Test=ButAutomaticUpgrades
209 echo "Package: coolstuff
210 Pin: release n=backports
211 Pin-Priority: 600" > rootdir/etc/apt/preferences
212 testequalpolicycoolstuff "" "2.0~bpo1" 100 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades
213 testequalpolicycoolstuff "" "2.0~bpo1" 990 500 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t backports
214 testequalpolicycoolstuff "" "1.0" 100 990 600 "2.0~bpo1" -o Test=ButAutomaticUpgrades -t stable
215
216 rm rootdir/etc/apt/preferences
217 testsuccess aptget install coolstuff -y
218 testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
219 testsuccess aptget dist-upgrade -y
220 testequalpolicycoolstuff "1.0" "1.0" 100 500 100 "" -o Test=ButAutomaticUpgrades
221 testequalpolicycoolstuff "1.0" "1.0" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
222 testequalpolicycoolstuff "1.0" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
223
224 testsuccess aptget install coolstuff -t backports -y
225 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
226 testsuccess aptget dist-upgrade -y
227 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 500 100 "" -o Test=ButAutomaticUpgrades
228 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 100 990 100 "" -o Test=ButAutomaticUpgrades -t stable
229 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 990 500 990 "" -o Test=ButAutomaticUpgrades -t backports
230
231 rm incoming/backports.main.pkglist incoming/backports.main.srclist
232 buildsimplenativepackage "coolstuff" "all" "2.0~bpo2" "backports"
233 setupaptarchive
234
235 sed -i aptarchive/dists/backports/Release -e 1i"NotAutomatic: yes"
236 signreleasefiles
237 aptgetupdate
238
239 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 500 100 "" "2.0~bpo2" -o Test=NotAutomatic
240 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo1" 1 990 100 "" "2.0~bpo2" -o Test=NotAutomatic -t stable
241 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=NotAutomatic -t backports
242
243 sed -i aptarchive/dists/backports/Release -e 1i"ButAutomaticUpgrades: yes"
244 signreleasefiles
245 aptgetupdate
246
247 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades
248 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 100 990 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t stable
249 testequalpolicycoolstuff "2.0~bpo1" "2.0~bpo2" 990 500 100 "" "2.0~bpo2" -o Test=ButAutomaticUpgrades -t backports