]> git.saurik.com Git - apt.git/blob - test/integration/test-pdiff-usage
91528389b967666a3a386c3b53e136a7af2d5027
[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 LOWCOSTEXT='lz4'
10
11 buildaptarchive
12 setupflataptarchive
13 changetowebserver
14
15 cat >rootdir/etc/apt/apt.conf.d/contents.conf <<EOF
16 Acquire::IndexTargets::deb::Contents {
17 MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
18 ShortDescription "Contents";
19 Description "\$(RELEASE)/\$(COMPONENT) \$(ARCHITECTURE) Contents";
20 MetaKey "\$(COMPONENT)/Contents-\$(ARCHITECTURE)";
21 flatMetaKey "Contents-\$(ARCHITECTURE)";
22 flatDescription "\$(RELEASE) \$(ARCHITECTURE) Contents";
23 };
24 EOF
25
26 PKGFILE="${TESTDIR}/$(echo "$(basename $0)" | sed 's#^test-#Packages-#')"
27 echo 'contents for stuff' > aptarchive/Contents-i386
28 compressfile aptarchive/Contents-i386
29 echo 'hacked' > aptarchive/hacked-i386
30 compressfile aptarchive/hacked-i386
31
32 wasmergeused() {
33 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
34 find rootdir/var/lib/apt/lists/partial -name '*-patched*' -delete
35 fi
36
37 testsuccess apt update "$@"
38
39 msgtest 'No intermediate patch files' 'still exist'
40 local EDS="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
41 if [ -z "$EDS" ]; then
42 msgpass
43 else
44 echo
45 echo "$EDS"
46 msgfail
47 fi
48
49 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
50 msgtest 'Check if pdiff was' 'not used'
51 cp -a rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
52 testsuccess --nomsg grep "diff/Index with Message: Couldn't parse pdiff index" rootdir/tmp/aptupdate.output
53 return;
54 fi
55
56 msgtest 'Check if the right pdiff merger was used'
57 if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir/tmp/testsuccess.output; then
58 if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
59 msgpass
60 else
61 msgfail "Merge shouldn't have been used, but was"
62 fi
63 elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
64 msgfail "Merge should have been used, but wasn't"
65 else
66 msgpass
67 fi
68
69 testequal '1' grep -c rred:601 rootdir/tmp/testsuccess.output
70 }
71
72 testrun() {
73 configcompression '.' 'xz'
74 msgmsg "Testcase: setup the base with: $*"
75 find aptarchive -name 'Packages*' -type f -delete
76 cp "${PKGFILE}" aptarchive/Packages
77 compressfile 'aptarchive/Packages'
78 generatereleasefiles
79 signreleasefiles
80 rm -rf aptarchive/Packages.diff rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
81 testsuccess aptget update "$@"
82 cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists-bak
83 testnopackage newstuff
84 testsuccessequal "$(cat "${PKGFILE}")
85 " aptcache show apt oldstuff
86 configcompression '.' 'gz'
87
88 # see if the code deals properly with leftover partial files
89 partialleftovers
90
91 msgmsg "Testcase: apply with one patch: $*"
92 find aptarchive -name 'Packages*' -type f -delete
93 cp "${PKGFILE}-new" aptarchive/Packages
94 compressfile 'aptarchive/Packages'
95 mkdir -p aptarchive/Packages.diff
96 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
97 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
98 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
99 PATCHINDEX='aptarchive/Packages.diff/Index'
100 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
101 SHA256-History:
102 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
103 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
104 SHA256-Patches:
105 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
106 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
107 SHA256-Download:
108 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
109 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
110
111 generatereleasefiles '+1hour'
112 signreleasefiles
113 find aptarchive -name 'Packages*' -type f -delete
114 wasmergeused "$@"
115 testnopackage oldstuff
116 testsuccessequal "$(cat "${PKGFILE}-new")
117 " aptcache show apt newstuff
118
119 msgmsg "Testcase: SHA1-only patches are not used: $*"
120 find aptarchive -name 'Packages*' -type f -delete
121 cp "${PKGFILE}-new" aptarchive/Packages
122 compressfile 'aptarchive/Packages'
123 mkdir -p aptarchive/Packages.diff
124 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
125 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
126 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
127 PATCHINDEX='aptarchive/Packages.diff/Index'
128 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
129 SHA1-History:
130 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
131 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
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 SHA1-Download:
136 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
137 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
138 generatereleasefiles '+1hour'
139 signreleasefiles
140 rm -rf rootdir/var/lib/apt/lists
141 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
142 wasmergeused "$@" -o test::cannot-use-pdiff=1
143 testnopackage oldstuff
144 testsuccessequal "$(cat "${PKGFILE}-new")
145 " aptcache show apt newstuff
146
147 msgmsg "Testcase: no download-hashes patches are not used: $*"
148 find aptarchive -name 'Packages*' -type f -delete
149 cp "${PKGFILE}-new" aptarchive/Packages
150 compressfile 'aptarchive/Packages'
151 mkdir -p aptarchive/Packages.diff
152 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
153 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
154 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
155 PATCHINDEX='aptarchive/Packages.diff/Index'
156 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
157 SHA256-History:
158 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
159 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
160 SHA256-Patches:
161 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
162 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
163 generatereleasefiles '+1hour'
164 signreleasefiles
165 rm -rf rootdir/var/lib/apt/lists
166 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
167 wasmergeused "$@" -o test::cannot-use-pdiff=1
168 testnopackage oldstuff
169 testsuccessequal "$(cat "${PKGFILE}-new")
170 " aptcache show apt newstuff
171
172 msgmsg "Testcase: apply with two patches: $*"
173 cp "${PKGFILE}-new" aptarchive/Packages
174 echo '
175 Package: futurestuff
176 Version: 1.0
177 Architecture: i386
178 Maintainer: Joe Sixpack <joe@example.org>
179 Installed-Size: 202
180 Filename: pool/futurestuff_1.0_i386.deb
181 Size: 202200
182 SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
183 Description: some cool and shiny future stuff
184 This package will appear in the next next mirror update
185 Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive/Packages
186
187 compressfile 'aptarchive/Packages'
188 PATCHFILE2="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
189 diff -e "${PKGFILE}-new" aptarchive/Packages > "${PATCHFILE2}" || true
190 cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
191 echo "SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
192 SHA256-History:
193 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
194 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
195 $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
196 SHA256-Patches:
197 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
198 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
199 $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
200 SHA256-Download:
201 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
202 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
203 $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" > "$PATCHINDEX"
204
205 generatereleasefiles '+2hour'
206 signreleasefiles
207 cp -a aptarchive/Packages Packages-future
208 find aptarchive -name 'Packages*' -type f -delete
209 rm -rf rootdir/var/lib/apt/lists
210 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
211 wasmergeused "$@"
212 testnopackage oldstuff
213 testsuccessequal "$(cat Packages-future)
214 " aptcache show apt newstuff futurestuff
215
216 # we reuse the archive state of the previous test here
217 msgmsg "Testcase: pdiff handling is stopped if transaction fails $*"
218 rm -rf rootdir/var/lib/apt/lists
219 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
220 cp Packages-future aptarchive/Packages
221 rm -f rootdir/var/lib/apt/lists/*_Contents-*
222 webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/hacked-i386.gz'
223 testfailure apt update "$@"
224 webserverconfig 'aptwebserver::overwrite::.*Contents-.*::filename' '/Contents-i386.gz'
225 cp rootdir/tmp/testfailure.output patchdownload.output
226 testfailure grep 'rred:600' patchdownload.output
227 testnopackage newstuff futurestuff
228 testsuccessequal "$(cat "${PKGFILE}")
229 " aptcache show apt oldstuff
230
231 # we reuse the entire state of the previous test here
232 msgmsg "Testcase: good files from previous fails are picked up from partial: $*"
233 wasmergeused "$@"
234 testfailure grep '^GET /Packages.diff/Index HTTP/1.1' rootdir/tmp/testsuccess.output
235 testnopackage oldstuff
236 testsuccessequal "$(cat Packages-future)
237 " aptcache show apt newstuff futurestuff
238
239 # we reuse the archive state of the previous test here
240 msgmsg "Testcase: downloading a patch fails, but successful fallback: $*"
241 rm -rf rootdir/var/lib/apt/lists
242 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
243 cp Packages-future aptarchive/Packages
244 rm "${PATCHFILE}.gz"
245 testsuccess apt update "$@"
246 cp rootdir/tmp/testsuccess.output patchdownload.output
247 testsuccess grep '^Falling back to normal index file acquire' patchdownload.output
248 testnopackage oldstuff
249 testsuccessequal "$(cat Packages-future)
250 " aptcache show apt newstuff futurestuff
251
252 msgmsg "Testcase: patch applying fails, but successful fallback: $*"
253 rm -rf rootdir/var/lib/apt/lists
254 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
255 cp "${PKGFILE}-new" aptarchive/Packages
256 compressfile 'aptarchive/Packages'
257 mkdir -p aptarchive/Packages.diff
258 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
259 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
260 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
261 PATCHINDEX='aptarchive/Packages.diff/Index'
262 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
263 SHA256-History:
264 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
265 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
266 SHA256-Patches:
267 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
268 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
269 SHA256-Download:
270 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
271 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
272 # needs to look like a valid command, otherwise the parser will fail before hashes are checked
273 echo '1d' > "$PATCHFILE"
274 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
275 generatereleasefiles '+1hour'
276 signreleasefiles
277 testsuccess apt update "$@"
278 cp -f rootdir/tmp/testsuccess.output rootdir/tmp/aptupdate.output
279 testsuccess grep 'Hash Sum mismatch' rootdir/tmp/aptupdate.output
280 testnopackage oldstuff
281 testsuccessequal "$(cat "${PKGFILE}-new")
282 " aptcache show apt newstuff
283
284 msgmsg "Testcase: pdiff patch bigger than index itself: $*"
285 rm -rf rootdir/var/lib/apt/lists
286 cp -a rootdir/var/lib/apt/lists-bak rootdir/var/lib/apt/lists
287 # the general testcode checks for leftovers in partial, but as this file
288 # is never touched in this test as it exits earlier its not a leftover…
289 rm -f rootdir/var/lib/apt/lists/partial/localhost:${APTHTTPPORT}_Packages
290 cp "${PKGFILE}-new" aptarchive/Packages
291 compressfile 'aptarchive/Packages'
292 mkdir -p aptarchive/Packages.diff
293 PATCHFILE="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
294 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
295 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
296 PATCHINDEX='aptarchive/Packages.diff/Index'
297 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
298 SHA256-History:
299 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
300 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
301 SHA256-Patches:
302 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
303 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
304 SHA256-Download:
305 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
306 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
307 generatereleasefiles '+1hour'
308 signreleasefiles
309 wasmergeused "$@" -o test::cannot-use-pdiff=1
310 testsuccess grep 'bytes (Limit is' rootdir/tmp/aptupdate.output
311 testnopackage oldstuff
312 testsuccessequal "$(cat "${PKGFILE}-new")
313 " aptcache show apt newstuff
314 }
315 echo 'Debug::pkgAcquire::Diffs "true";
316 Debug::Acquire::Transaction "true";
317 Debug::pkgAcquire::Worker "true";
318 Debug::Acquire::http "true";
319 Debug::pkgAcquire "true";
320 Debug::pkgAcquire::rred "true";' > rootdir/etc/apt/apt.conf.d/rreddebug.conf
321
322 testcase() {
323 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=1 "$@"
324 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=1 "$@"
325 testrun -o Acquire::PDiffs::Merge=0 -o APT::Get::List-Cleanup=0 "$@"
326 testrun -o Acquire::PDiffs::Merge=1 -o APT::Get::List-Cleanup=0 "$@"
327 }
328 generatepartialleftovers() {
329 for f in "$@"; do
330 cat "${PKGFILE}" "${PKGFILE}" > "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
331 printf '\n\nInvalid\nStanza: yes\n\n' >> "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
332 done
333 }
334
335 partialleftovers() { generatepartialleftovers 'Packages' 'Packages-patched'; }
336 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
337 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=false
338 partialleftovers() { generatepartialleftovers "Packages.${LOWCOSTEXT}" "Packages-patched.${LOWCOSTEXT}"; }
339 aptautotest_apt_update() { aptautotest_aptget_update "$@"; testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
340 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true
341
342
343 partialleftovers() { generatepartialleftovers "redirectme_Packages.${LOWCOSTEXT}" "redirectme_Packages-patched.${LOWCOSTEXT}"; }
344 webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "http://0.0.0.0:${APTHTTPPORT}/"
345 rewritesourceslist "http://localhost:${APTHTTPPORT}/redirectme"
346 aptautotest_apt_update() {
347 aptautotest_aptget_update "$@"
348 testsuccess test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_redirectme_Packages.$LOWCOSTEXT"
349 testempty find rootdir/var/lib/apt/lists -type f \! \( -name lock -o -name '*_redirectme_*' \)
350 }
351 testcase -o Acquire::IndexTargets::deb::Packages::KeepCompressed=true