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