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