]> git.saurik.com Git - apt.git/blob - test/integration/test-ubuntu-bug-1098738-apt-get-source-md5sum
test-apt-update-reporting: Make more use of framework
[apt.git] / test / integration / test-ubuntu-bug-1098738-apt-get-source-md5sum
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'native'
9
10 cat > aptarchive/Sources <<EOF
11 Package: pkg-md5-ok
12 Binary: pkg-md5-ok
13 Version: 1.0
14 Maintainer: Joe Sixpack <joe@example.org>
15 Architecture: all
16 Files:
17 9604ba9427a280db542279d9ed78400b 3 pkg-md5-ok_1.0.dsc
18 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-ok_1.0.tar.gz
19
20 Package: pkg-sha1-ok
21 Binary: pkg-sha1-ok
22 Version: 1.0
23 Maintainer: Joe Sixpack <joe@example.org>
24 Architecture: all
25 Files:
26 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha1-ok_1.0.dsc
27 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha1-ok_1.0.tar.gz
28
29 Package: pkg-sha256-ok
30 Binary: pkg-sha256-ok
31 Version: 1.0
32 Maintainer: Joe Sixpack <joe@example.org>
33 Architecture: all
34 Files:
35 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-ok_1.0.dsc
36 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-ok_1.0.tar.gz
37 Checksums-Sha1:
38 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-ok_1.0.dsc
39 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-ok_1.0.tar.gz
40 Checksums-Sha256:
41 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-sha256-ok_1.0.dsc
42 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-sha256-ok_1.0.tar.gz
43
44 Package: pkg-size-bad
45 Binary: pkg-size-bad
46 Version: 1.0
47 Maintainer: Joe Sixpack <joe@example.org>
48 Architecture: all
49 Checksums-Sha256:
50 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 2 pkg-size-bad_1.0.dsc
51 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 4 pkg-size-bad_1.0.tar.gz
52
53 Package: pkg-sha256-bad
54 Binary: pkg-sha256-bad
55 Version: 1.0
56 Maintainer: Joe Sixpack <joe@example.org>
57 Architecture: all
58 Files:
59 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-bad_1.0.dsc
60 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-bad_1.0.tar.gz
61 Checksums-Sha1:
62 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-bad_1.0.dsc
63 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-bad_1.0.tar.gz
64 Checksums-Sha256:
65 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-sha256-bad_1.0.dsc
66 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-sha256-bad_1.0.tar.gz
67
68 Package: pkg-md5-bad
69 Binary: pkg-md5-bad
70 Version: 1.0
71 Maintainer: Joe Sixpack <joe@example.org>
72 Architecture: all
73 Files:
74 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-md5-bad_1.0.dsc
75 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-md5-bad_1.0.tar.gz
76
77 Package: pkg-no-md5
78 Binary: pkg-no-md5
79 Version: 1.0
80 Maintainer: Joe Sixpack <joe@example.org>
81 Architecture: all
82 Checksums-Sha1:
83 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-no-md5_1.0.dsc
84 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-no-md5_1.0.tar.gz
85 Checksums-Sha256:
86 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-no-md5_1.0.dsc
87 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-no-md5_1.0.tar.gz
88
89 Package: pkg-mixed-ok
90 Binary: pkg-mixed-ok
91 Version: 1.0
92 Maintainer: Joe Sixpack <joe@example.org>
93 Architecture: all
94 Checksums-Sha1:
95 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-mixed-ok_1.0.tar.gz
96 Checksums-Sha256:
97 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-mixed-ok_1.0.dsc
98
99 Package: pkg-mixed-sha1-bad
100 Binary: pkg-mixed-sha1-bad
101 Version: 1.0
102 Maintainer: Joe Sixpack <joe@example.org>
103 Architecture: all
104 Checksums-Sha1:
105 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-mixed-sha1-bad_1.0.dsc
106 Checksums-Sha256:
107 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-mixed-sha1-bad_1.0.tar.gz
108
109 Package: pkg-mixed-sha2-bad
110 Binary: pkg-mixed-sha2-bad
111 Version: 1.0
112 Maintainer: Joe Sixpack <joe@example.org>
113 Architecture: all
114 Checksums-Sha1:
115 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-mixed-sha2-bad_1.0.dsc
116 Checksums-Sha256:
117 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-mixed-sha2-bad_1.0.tar.gz
118
119 Package: pkg-md5-disagree
120 Binary: pkg-md5-disagree
121 Version: 1.0
122 Maintainer: Joe Sixpack <joe@example.org>
123 Architecture: all
124 Files:
125 9604ba9427a280db542279d9ed78400b 3 pkg-md5-disagree_1.0.dsc
126 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-disagree_1.0.tar.gz
127 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-md5-disagree_1.0.dsc
128 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-md5-disagree_1.0.tar.gz
129
130 Package: pkg-md5-agree
131 Binary: pkg-md5-agree
132 Version: 1.0
133 Maintainer: Joe Sixpack <joe@example.org>
134 Architecture: all
135 Files:
136 9604ba9427a280db542279d9ed78400b 3 pkg-md5-agree_1.0.dsc
137 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-agree_1.0.tar.gz
138 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-md5-agree_1.0.tar.gz
139 9604ba9427a280db542279d9ed78400b 3 pkg-md5-agree_1.0.dsc
140
141 Package: pkg-sha256-disagree
142 Binary: pkg-sha256-disagree
143 Version: 1.0
144 Maintainer: Joe Sixpack <joe@example.org>
145 Architecture: all
146 Files:
147 9604ba9427a280db542279d9ed78400b 3 pkg-sha256-disagree_1.0.dsc
148 db5570bf61464b46e2bde31ed61a7dc6 3 pkg-sha256-disagree_1.0.tar.gz
149 Checksums-Sha1:
150 324f464e6151a92cf57b26ef95dcfcf2059a8c44 3 pkg-sha256-disagree_1.0.dsc
151 680254bad1d7ca0d65ec46aaa315d363abf6a50a 3 pkg-sha256-disagree_1.0.tar.gz
152 Checksums-Sha256:
153 943d3bf22ac661fb0f59bc4ff68cc12b04ff17a838dfcc2537008eb9c7f3770a 3 pkg-sha256-disagree_1.0.dsc
154 90aebae315675cbf04612de4f7d5874850f48e0b8dd82becbeaa47ca93f5ebfb 3 pkg-sha256-disagree_1.0.tar.gz
155 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3 pkg-sha256-disagree_1.0.dsc
156 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb 3 pkg-sha256-disagree_1.0.tar.gz
157 EOF
158
159 # create fetchable files
160 for x in 'pkg-md5-ok' 'pkg-sha1-ok' 'pkg-sha256-ok' 'pkg-sha256-bad' 'pkg-no-md5' \
161 'pkg-mixed-ok' 'pkg-mixed-sha1-bad' 'pkg-mixed-sha2-bad' \
162 'pkg-md5-agree' 'pkg-md5-disagree' 'pkg-sha256-disagree' \
163 'pkg-md5-bad' 'pkg-size-bad'; do
164 echo -n 'dsc' > aptarchive/${x}_1.0.dsc
165 echo -n 'tar' > aptarchive/${x}_1.0.tar.gz
166 done
167
168 setupaptarchive --no-update
169 changetowebserver
170 testsuccess aptget update
171
172 cd downloaded
173
174 testok() {
175 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
176 testsuccessequal "Reading package lists...
177 Need to get 6 B of source archives.
178 Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
179 Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
180 Download complete and in download only mode" aptget source -d "$@"
181 msgtest 'Files were successfully downloaded for' "$1"
182 testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
183 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
184 }
185
186 testkeep() {
187 echo -n 'dsc' > ${1}_1.0.dsc
188 echo -n 'tar' > ${1}_1.0.tar.gz
189 testsuccessequal "Reading package lists...
190 Skipping already downloaded file '${1}_1.0.dsc'
191 Skipping already downloaded file '${1}_1.0.tar.gz'
192 Need to get 0 B of source archives.
193 Download complete and in download only mode" aptget source -d "$@"
194 msgtest 'Files already downloaded are kept for' "$1"
195 testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
196 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
197 }
198
199 testnohash() {
200 #FIXME: Maybe we should fail in this case instead of skipping
201 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
202 testsuccessequal "Reading package lists...
203 Skipping download of file '${1}_1.0.dsc' as requested hashsum is not available for authentication
204 Skipping download of file '${1}_1.0.tar.gz' as requested hashsum is not available for authentication
205 Need to get 0 B of source archives.
206 Download complete and in download only mode" aptget source -d "$@"
207 msgtest 'Files are not downloaded for' "$1"
208 testfailure --nomsg test -e ${1}_1.0.dsc -o -e ${1}_1.0.tar.gz
209 }
210
211 testmismatch() {
212 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
213 local FAILURE
214 if [ "$1" = 'pkg-size-bad' ]; then
215 FAILURE="Reading package lists...
216 Need to get 6 B of source archives.
217 Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [2 B]
218 Err:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc)
219 Writing more data than expected (3 > 2)
220 Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [4 B]
221 Err:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar)
222 Hash Sum mismatch
223 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc Writing more data than expected (3 > 2)
224
225 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz Hash Sum mismatch
226
227 E: Failed to fetch some archives."
228 else
229 FAILURE="Reading package lists...
230 Need to get 6 B of source archives.
231 Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
232 Err:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc)
233 Hash Sum mismatch
234 Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
235 Err:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar)
236 Hash Sum mismatch
237 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.dsc Hash Sum mismatch
238
239 E: Failed to fetch http://localhost:${APTHTTPPORT}/${1}_1.0.tar.gz Hash Sum mismatch
240
241 E: Failed to fetch some archives."
242 fi
243 testfailureequal "$FAILURE" aptget source -d "$@"
244
245 msgtest 'Files were not download as they have hashsum mismatches for' "$1"
246 testfailure --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
247
248 if [ "$2" != '--allow-unauthenticated' ]; then
249 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
250 testsuccessequal "Reading package lists...
251 Skipping download of file '${1}_1.0.dsc' as requested hashsum is not available for authentication
252 Skipping download of file '${1}_1.0.tar.gz' as requested hashsum is not available for authentication
253 Need to get 0 B of source archives.
254 Download complete and in download only mode" aptget source -d "$@" -o Acquire::ForceHash=ROT26
255 msgtest 'Files were not download as hash is unavailable for' "$1"
256 testfailure --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
257 fi
258
259 if [ "$1" != 'pkg-size-bad' ]; then
260 rm -f ${1}_1.0.dsc ${1}_1.0.tar.gz
261 testsuccessequal "Reading package lists...
262 Need to get 6 B of source archives.
263 Get:1 http://localhost:${APTHTTPPORT} $1 1.0 (dsc) [3 B]
264 Get:2 http://localhost:${APTHTTPPORT} $1 1.0 (tar) [3 B]
265 Download complete and in download only mode" aptget source --allow-unauthenticated -d "$@" -o Acquire::ForceHash=ROT26
266 msgtest 'Files were downloaded unauthenticated as user allowed it' "$1"
267 testsuccess --nomsg test -e ${1}_1.0.dsc -a -e ${1}_1.0.tar.gz
268 fi
269 }
270
271 testnohash pkg-md5-ok
272 testnohash pkg-sha1-ok
273 testok pkg-sha256-ok
274 testkeep pkg-sha256-ok
275
276 # pkg-sha256-bad has a bad SHA sum, but good MD5 sum. If apt is
277 # checking the best available hash (as it should), this will trigger
278 # a hash mismatch.
279 testmismatch pkg-sha256-bad
280 testok pkg-sha256-bad -o Acquire::ForceHash=MD5Sum
281
282 testnohash pkg-md5-bad
283 testmismatch pkg-md5-bad --allow-unauthenticated
284
285 testmismatch pkg-size-bad
286
287 # not having MD5 sum doesn't mean the file doesn't exist at all …
288 testok pkg-no-md5
289 testok pkg-no-md5 -o Acquire::ForceHash=SHA256
290 testsuccessequal "Reading package lists...
291 Skipping download of file 'pkg-no-md5_1.0.dsc' as requested hashsum is not available for authentication
292 Skipping download of file 'pkg-no-md5_1.0.tar.gz' as requested hashsum is not available for authentication
293 Need to get 0 B of source archives.
294 Download complete and in download only mode" aptget source -d pkg-no-md5 -o Acquire::ForceHash=MD5Sum
295 msgtest 'Files were not download as MD5 is not available for this package' 'pkg-no-md5'
296 testfailure --nomsg test -e pkg-no-md5_1.0.dsc -a -e pkg-no-md5_1.0.tar.gz
297
298 # deal with cases in which we haven't for all files the same checksum type
299 # mostly pathologic as this shouldn't happen, but just to be sure
300 testsuccessequal "Reading package lists...
301 Skipping download of file 'pkg-mixed-ok_1.0.tar.gz' as requested hashsum is not available for authentication
302 Need to get 3 B of source archives.
303 Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-ok 1.0 (dsc) [3 B]
304 Download complete and in download only mode" aptget source -d pkg-mixed-ok
305
306 testsuccessequal "Reading package lists...
307 Skipping download of file 'pkg-mixed-sha1-bad_1.0.dsc' as requested hashsum is not available for authentication
308 Need to get 3 B of source archives.
309 Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha1-bad 1.0 (tar) [3 B]
310 Download complete and in download only mode" aptget source -d pkg-mixed-sha1-bad
311 msgtest 'Only tar file is downloaded as the dsc has hashsum mismatch' 'pkg-mixed-sha1-bad'
312 testsuccess --nomsg test ! -e pkg-mixed-sha1-bad_1.0.dsc -a -e pkg-mixed-sha1-bad_1.0.tar.gz
313 testfailureequal "Reading package lists...
314 Skipping download of file 'pkg-mixed-sha2-bad_1.0.dsc' as requested hashsum is not available for authentication
315 Need to get 3 B of source archives.
316 Get:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar) [3 B]
317 Err:1 http://localhost:${APTHTTPPORT} pkg-mixed-sha2-bad 1.0 (tar)
318 Hash Sum mismatch
319 E: Failed to fetch http://localhost:${APTHTTPPORT}/pkg-mixed-sha2-bad_1.0.tar.gz Hash Sum mismatch
320
321 E: Failed to fetch some archives." aptget source -d pkg-mixed-sha2-bad
322
323 # it gets even more pathologic: multiple entries for one file, some even disagreeing!
324 testnohash pkg-md5-agree
325 testfailureequal 'Reading package lists...
326 E: Error parsing checksum in Files of source package pkg-md5-disagree' aptget source -d pkg-md5-disagree
327 testfailureequal 'Reading package lists...
328 E: Error parsing checksum in Checksums-SHA256 of source package pkg-sha256-disagree' aptget source -d pkg-sha256-disagree