]> git.saurik.com Git - apt.git/blob - test/integration/test-pdiff-usage
Do not consider SHA1 usable
[apt.git] / test / integration / test-pdiff-usage
1 #!/bin/sh
2 set -e
3
4 TESTDIR="$(readlink -f "$(dirname "$0")")"
5 . "$TESTDIR/framework"
6
7 setupenvironment
8 configarchitecture 'i386'
9 confighashes 'SHA1' 'SHA256'
10 LOWCOSTEXT='lz4'
11
12 buildaptarchive
13 setupflataptarchive
14 changetowebserver -o aptwebserver::support::modified-since=false
15
16 PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
17
18 wasmergeused() {
19 testsuccess apt update "$@"
20
21 msgtest 'No intermediate patch files' 'still exist'
22 local EDS="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
23 if [ -z "$EDS" ]; then
24 msgpass
25 else
26 echo
27 echo "$EDS"
28 msgfail
29 fi
30
31 msgtest 'Check if the right pdiff merger was used'
32 if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir/tmp/testsuccess.output; then
33 if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
34 msgpass
35 else
36 msgfail "Merge shouldn't have been used, but was"
37 fi
38 elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
39 msgfail "Merge should have been used, but wasn't"
40 else
41 msgpass
42 fi
43 }
44
45 testrun() {
46 configcompression '.' 'xz'
47 msgmsg "Testcase: setup the base with: $*"
48 local DOWNLOADHASH=true
49 if [ "$1" = 'nohash' ]; then DOWNLOADHASH=false; shift; fi
50 find aptarchive -name 'Packages*' -type f -delete
51 cp "${PKGFILE}" aptarchive/Packages
52 compressfile 'aptarchive/Packages'
53 generatereleasefiles
54 signreleasefiles
55 rm -rf aptarchive/Packages.diff rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
56 testsuccess aptget update "$@"
57 cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
58 testnopackage newstuff
59 testsuccessequal "$(cat "${PKGFILE}")
60 " aptcache show apt oldstuff
61 configcompression '.' 'gz'
62
63 # see if the code deals properly with leftover partial files
64 touch rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_Packages
65
66 msgmsg "Testcase: apply with one patch: $*"
67 find aptarchive -name 'Packages*' -type f -delete
68 cp "${PKGFILE}-new" aptarchive/Packages
69 compressfile 'aptarchive/Packages'
70 mkdir -p aptarchive/Packages.diff
71 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
72 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
73 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
74 PATCHINDEX='aptarchive/Packages.diff/Index'
75 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
76 SHA1-History:
77 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
78 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
79 SHA1-Patches:
80 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
81 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
82 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
83 SHA256-History:
84 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
85 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
86 SHA256-Patches:
87 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
88 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
89 if $DOWNLOADHASH; then
90 echo "SHA1-Download:
91 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
92 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
93 SHA256-Download:
94 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
95 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" >> "$PATCHINDEX"
96 fi
97
98 generatereleasefiles '+1hour'
99 signreleasefiles
100 find aptarchive -name 'Packages*' -type f -delete
101 wasmergeused "$@"
102 testnopackage oldstuff
103 testsuccessequal "$(cat "${PKGFILE}-new")
104 " aptcache show apt newstuff
105
106 msgmsg "Testcase: apply with two patches: $*"
107 cp "${PKGFILE}-new" aptarchive/Packages
108 echo '
109 Package: futurestuff
110 Version: 1.0
111 Architecture: i386
112 Maintainer: Joe Sixpack <joe@example.org>
113 Installed-Size: 202
114 Filename: pool/futurestuff_1.0_i386.deb
115 Size: 202200
116 MD5sum: 311aeeaaae5ba33aff1ceaf3e1f76671
117 SHA1: 3c695e028f7a1ae324deeaae5ba332desa81088c
118 SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
119 Description: some cool and shiny future stuff
120 This package will appear in the next next mirror update
121 Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive/Packages
122
123 compressfile 'aptarchive/Packages'
124 PATCHFILE2="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
125 diff -e "${PKGFILE}-new" aptarchive/Packages > "${PATCHFILE2}" || true
126 cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
127 echo "SHA1-Current: $(sha1sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
128 SHA1-History:
129 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
130 $(sha1sum "${PKGFILE}" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}") $(basename "${PATCHFILE}")
131 $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
132 SHA1-Patches:
133 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
134 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
135 $(sha1sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
136 SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
137 SHA256-History:
138 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
139 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
140 $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
141 SHA256-Patches:
142 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
143 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
144 $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")" > "$PATCHINDEX"
145 if $DOWNLOADHASH; then
146 echo "SHA1-Download:
147 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
148 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
149 $(sha1sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")
150 SHA256-Download:
151 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
152 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
153 $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" >> "$PATCHINDEX"
154 fi
155
156 generatereleasefiles '+2hour'
157 signreleasefiles
158 cp -a aptarchive/Packages Packages-future
159 find aptarchive -name 'Packages*' -type f -delete
160 rm -rf rootdir/var/lib/apt/lists
161 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
162 wasmergeused "$@"
163 testnopackage oldstuff
164 testsuccessequal "$(cat Packages-future)
165 " aptcache show apt newstuff futurestuff
166
167 # we reuse the archive state of the previous test here
168 msgmsg "Testcase: downloading a patch fails, but successful fallback: $*"
169 rm -rf rootdir/var/lib/apt/lists
170 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
171 cp Packages-future aptarchive/Packages
172 rm "${PATCHFILE}.gz"
173 testsuccess apt update "$@"
174 cp rootdir/tmp/testsuccess.output patchdownload.output
175 testsuccess grep '^Falling back to normal index file acquire' patchdownload.output
176 testnopackage oldstuff
177 testsuccessequal "$(cat Packages-future)
178 " aptcache show apt newstuff futurestuff
179
180 msgmsg "Testcase: patch applying fails, but successful fallback: $*"
181 rm -rf rootdir/var/lib/apt/lists
182 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
183 cp "${PKGFILE}-new" aptarchive/Packages
184 compressfile 'aptarchive/Packages'
185 mkdir -p aptarchive/Packages.diff
186 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
187 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
188 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
189 PATCHINDEX='aptarchive/Packages.diff/Index'
190 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
191 SHA1-History:
192 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
193 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
194 SHA1-Patches:
195 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
196 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
197 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
198 SHA256-History:
199 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
200 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
201 SHA256-Patches:
202 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
203 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > $PATCHINDEX
204 if $DOWNLOADHASH; then
205 echo "SHA1-Download:
206 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
207 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
208 SHA256-Download:
209 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
210 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" >> $PATCHINDEX
211 fi
212 # needs to look like a valid command, otherwise the parser will fail before hashes are checked
213 echo '1d' > "$PATCHFILE"
214 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
215 generatereleasefiles '+1hour'
216 signreleasefiles
217 testsuccess apt update "$@"
218 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
219 testsuccess grep 'Hash Sum mismatch' rootdir/tmp/aptupdate.output
220 testnopackage oldstuff
221 testsuccessequal "$(cat "${PKGFILE}-new")
222 " aptcache show apt newstuff
223
224 msgmsg "Testcase: pdiff patch bigger than index itself: $*"
225 rm -rf rootdir/var/lib/apt/lists
226 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
227 # the general testcode checks for leftovers in partial, but as this file
228 # is never touched in this test as it exits earlier its not a leftover…
229 rm -f rootdir/var/lib/apt/lists/partial/localhost:${APTHTTPPORT}_Packages
230 cp "${PKGFILE}-new" aptarchive/Packages
231 compressfile 'aptarchive/Packages'
232 mkdir -p aptarchive/Packages.diff
233 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
234 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
235 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
236 PATCHINDEX='aptarchive/Packages.diff/Index'
237 BIGSIZE="$(stat -c%s "$PATCHFILE")"
238 if ! $DOWNLOADHASH; then
239 BIGSIZE="${BIGSIZE}000"
240 fi
241 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
242 SHA1-History:
243 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
244 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
245 SHA1-Patches:
246 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
247 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $BIGSIZE $(basename "$PATCHFILE")
248 SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
249 SHA256-History:
250 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
251 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
252 SHA256-Patches:
253 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
254 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $BIGSIZE $(basename "$PATCHFILE")" > "$PATCHINDEX"
255 if $DOWNLOADHASH; then
256 echo "SHA1-Download:
257 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
258 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")
259 SHA256-Download:
260 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
261 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" >> "$PATCHINDEX"
262 fi
263 generatereleasefiles '+1hour'
264 signreleasefiles
265 testsuccess apt update -o Debug::pkgAcquire::Diffs=1 "$@"
266 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
267 testsuccess grep 'bytes (Limit is' rootdir/tmp/aptupdate.output
268 testnopackage oldstuff
269 testsuccessequal "$(cat "${PKGFILE}-new")
270 " aptcache show apt newstuff
271 }
272 echo 'Debug::pkgAcquire::Diffs "true";
273 Debug::Acquire::Transaction "true";
274 Debug::pkgAcquire::rred "true";' > rootdir/etc/apt/apt.conf.d/rreddebug.conf
275
276 testcase() {
277 testrun nohash -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
278 testrun nohash -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
279
280 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
281 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
282 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=0 "$@"
283 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=0 "$@"
284
285 sha256sum() {
286 echo '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b -'
287 }
288 testrun -o Acquire::PDiffs::Merge=0 -o Acquire::ForceHash=SHA1 "$@"
289 testrun -o Acquire::PDiffs::Merge=1 -o Acquire::ForceHash=SHA1 "$@"
290 unset -f sha256sum
291
292 sha1sum() {
293 echo 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc -'
294 }
295 testrun -o Acquire::PDiffs::Merge=0 -o Acquire::ForceHash=SHA256 "$@"
296 testrun -o Acquire::PDiffs::Merge=1 -o Acquire::ForceHash=SHA256 "$@"
297 unset -f sha1sum
298 }
299 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
300 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=false
301 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
302 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true