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