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