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