4 TESTDIR
="$(readlink -f "$(dirname "$0")")"
8 configarchitecture 'i386'
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
";
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
33 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
34 find rootdir
/var
/lib
/apt
/lists
/partial
-name '*-patched*' -delete
37 testsuccess apt update
"$@"
38 #apt update "$@" 2>&1 | tee rootdir/tmp/testsuccess.output
40 msgtest
'No intermediate patch files' 'still exist'
41 local EDS
="$(find rootdir/var/lib/apt/lists -name '*.ed' -o -name '*.ed.*')"
42 if [ -z "$EDS" ]; then
50 if echo "$*" | grep -q -- '-o test::cannot-use-pdiff=1'; then
51 msgtest
'Check if pdiff was' 'not used'
52 cp -a rootdir
/tmp
/testsuccess.output rootdir
/tmp
/aptupdate.output
53 testsuccess
--nomsg grep "diff/Index with Message: Couldn't parse pdiff index" rootdir
/tmp
/aptupdate.output
57 msgtest
'Check if the right pdiff merger was used'
58 if grep -q '^pkgAcqIndexMergeDiffs::Done(): rred' rootdir
/tmp
/testsuccess.output
; then
59 if echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
62 msgfail
"Merge shouldn't have been used, but was"
64 elif echo "$*" | grep -q -- '-o Acquire::PDiffs::Merge=1'; then
65 msgfail
"Merge should have been used, but wasn't"
70 testequal
'1' grep -c rred
:601 rootdir
/tmp
/testsuccess.output
74 configcompression
'.' 'xz'
75 msgmsg
"Testcase: setup the base with: $*"
76 find aptarchive
-name 'Packages*' -type f
-delete
77 cp "${PKGFILE}" aptarchive
/Packages
78 compressfile
'aptarchive/Packages'
81 rm -rf aptarchive
/Packages.
diff rootdir
/var
/lib
/apt
/lists rootdir
/var
/lib
/apt
/lists
-bak
82 testsuccess aptget update
"$@"
83 cp -a rootdir
/var
/lib
/apt
/lists rootdir
/var
/lib
/apt
/lists
-bak
84 testnopackage newstuff
85 testsuccessequal
"$(cat "${PKGFILE}")
86 " aptcache show apt oldstuff
87 configcompression
'.' 'gz'
89 # see if the code deals properly with leftover partial files
92 msgmsg
"Testcase: apply with one patch: $*"
93 find aptarchive
-name 'Packages*' -type f
-delete
94 cp "${PKGFILE}-new" aptarchive
/Packages
95 compressfile
'aptarchive/Packages'
96 mkdir -p aptarchive
/Packages.
diff
97 PATCHFILE
="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
98 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
99 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
100 PATCHINDEX
='aptarchive/Packages.diff/Index'
101 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
103 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
104 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
106 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
107 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
109 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
110 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
112 generatereleasefiles
'+1hour'
114 find aptarchive
-name 'Packages*' -type f
-delete
116 testnopackage oldstuff
117 testsuccessequal
"$(cat "${PKGFILE}-new")
118 " aptcache show apt newstuff
120 msgmsg
"Testcase: apply with compressed Index and one patch: $*"
121 cp "${PKGFILE}-new" aptarchive
/Packages
122 compressfile
'aptarchive/Packages'
123 cat "$PATCHINDEX" | gzip > "${PATCHINDEX}.gz"
124 generatereleasefiles
'+1hour'
126 find aptarchive
-name 'Packages*' -type f
-delete
128 rm -rf rootdir
/var
/lib
/apt
/lists
129 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
131 testnopackage oldstuff
132 testsuccessequal
"$(cat "${PKGFILE}-new")
133 " aptcache show apt newstuff
135 msgmsg
"Testcase: apply with by-hash compressed Index and one patch: $*"
136 local NORMAL
="$(readlink -f "./aptarchive/Packages.diff")"
137 local BYHASH
="${NORMAL}/by-hash/SHA256"
139 find "${NORMAL}/" -maxdepth 1 -name "Index*" -exec mv '{}' "$BYHASH" \
;
140 ln -s "${BYHASH}/Index.gz" "${BYHASH}/$(sha256sum "${BYHASH}/Index.gz" | cut -f1 -d' ')"
141 rm -rf rootdir
/var
/lib
/apt
/lists
142 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
143 wasmergeused
"$@" -o Acquire
::By
-Hash=force
144 testnopackage oldstuff
145 testsuccessequal
"$(cat "${PKGFILE}-new")
146 " aptcache show apt newstuff
148 msgmsg
"Testcase: SHA1-only patches are not used: $*"
149 find aptarchive
-name 'Packages*' -type f
-delete
150 cp "${PKGFILE}-new" aptarchive
/Packages
151 compressfile
'aptarchive/Packages'
152 mkdir -p aptarchive
/Packages.
diff
153 PATCHFILE
="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
154 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
155 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
156 PATCHINDEX
='aptarchive/Packages.diff/Index'
157 echo "SHA1-Current: $(sha1sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
159 9f4148e06d7faa37062994ff10d0c842d7017513 33053002 2010-08-18-2013.28
160 $(sha1sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
162 7651fc0ac57cd83d41c63195a9342e2db5650257 19722 2010-08-18-2013.28
163 $(sha1sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
165 2365ac0ac57cde3d43c63145e8251a3bd5410213 197 2010-08-18-2013.28.gz
166 $(sha1sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
167 generatereleasefiles
'+1hour'
169 rm -rf rootdir
/var
/lib
/apt
/lists
170 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
171 wasmergeused
"$@" -o test::cannot
-use-pdiff=1
172 testnopackage oldstuff
173 testsuccessequal
"$(cat "${PKGFILE}-new")
174 " aptcache show apt newstuff
176 msgmsg
"Testcase: no download-hashes patches are not used: $*"
177 find aptarchive
-name 'Packages*' -type f
-delete
178 cp "${PKGFILE}-new" aptarchive
/Packages
179 compressfile
'aptarchive/Packages'
180 mkdir -p aptarchive
/Packages.
diff
181 PATCHFILE
="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
182 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
183 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
184 PATCHINDEX
='aptarchive/Packages.diff/Index'
185 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
187 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
188 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
190 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
191 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")" > "$PATCHINDEX"
192 generatereleasefiles
'+1hour'
194 rm -rf rootdir
/var
/lib
/apt
/lists
195 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
196 wasmergeused
"$@" -o test::cannot
-use-pdiff=1
197 testnopackage oldstuff
198 testsuccessequal
"$(cat "${PKGFILE}-new")
199 " aptcache show apt newstuff
201 msgmsg
"Testcase: apply with two patches: $*"
202 cp "${PKGFILE}-new" aptarchive
/Packages
207 Maintainer: Joe Sixpack <joe@example.org>
209 Filename: pool/futurestuff_1.0_i386.deb
211 SHA256: b46fd154615edaae5ba33c56a5cc0e7deaef23e2da3e4f129727fd660f28f050
212 Description: some cool and shiny future stuff
213 This package will appear in the next next mirror update
214 Description-md5: d5f89fbbc2ce34c455dfee9b67d82b6b' >> aptarchive
/Packages
216 compressfile
'aptarchive/Packages'
217 PATCHFILE2
="aptarchive/Packages.diff/$(date -d 'now + 1hour' '+%Y-%m-%d-%H%M.%S')"
218 diff -e "${PKGFILE}-new" aptarchive
/Packages
> "${PATCHFILE2}" || true
219 cat "$PATCHFILE2" | gzip > "${PATCHFILE2}.gz"
220 echo "SHA256-Current: $(sha256sum aptarchive/Packages | cut -d' ' -f 1) $(stat -c%s aptarchive/Packages)
222 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
223 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
224 $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new") $(basename "${PATCHFILE2}")
226 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
227 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
228 $(sha256sum "${PATCHFILE2}" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}") $(basename "${PATCHFILE2}")
230 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
231 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")
232 $(sha256sum "${PATCHFILE2}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE2}.gz") $(basename "${PATCHFILE2}.gz")" > "$PATCHINDEX"
234 generatereleasefiles
'+2hour'
236 cp -a aptarchive
/Packages Packages
-future
237 find aptarchive
-name 'Packages*' -type f
-delete
238 rm -rf rootdir
/var
/lib
/apt
/lists
239 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
241 testnopackage oldstuff
242 testsuccessequal
"$(cat Packages-future)
243 " aptcache show apt newstuff futurestuff
245 # we reuse the archive state of the previous test here
246 msgmsg
"Testcase: pdiff handling is stopped if transaction fails $*"
247 rm -rf rootdir
/var
/lib
/apt
/lists
248 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
249 cp Packages
-future aptarchive
/Packages
250 rm -f rootdir
/var
/lib
/apt
/lists
/*_Contents
-*
251 webserverconfig
'aptwebserver::overwrite::.*Contents-.*::filename' '/hacked-i386.gz'
252 testfailure apt update
"$@"
253 webserverconfig
'aptwebserver::overwrite::.*Contents-.*::filename' '/Contents-i386.gz'
254 cp rootdir
/tmp
/testfailure.output patchdownload.output
255 testfailure
grep 'rred:600' patchdownload.output
256 testnopackage newstuff futurestuff
257 testsuccessequal
"$(cat "${PKGFILE}")
258 " aptcache show apt oldstuff
260 # we reuse the entire state of the previous test here
261 msgmsg
"Testcase: good files from previous fails are picked up from partial: $*"
263 testfailure
grep '^GET /Packages.diff/Index HTTP/1.1' rootdir
/tmp
/testsuccess.output
264 testnopackage oldstuff
265 testsuccessequal
"$(cat Packages-future)
266 " aptcache show apt newstuff futurestuff
268 # we reuse the archive state of the previous test here
269 msgmsg
"Testcase: downloading a patch fails, but successful fallback: $*"
270 rm -rf rootdir
/var
/lib
/apt
/lists
271 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
272 cp Packages
-future aptarchive
/Packages
274 testsuccess apt update
"$@"
275 cp rootdir
/tmp
/testsuccess.output patchdownload.output
276 testsuccess
grep '^Falling back to normal index file acquire' patchdownload.output
277 testnopackage oldstuff
278 testsuccessequal
"$(cat Packages-future)
279 " aptcache show apt newstuff futurestuff
281 msgmsg
"Testcase: patch applying fails, but successful fallback: $*"
282 rm -rf rootdir
/var
/lib
/apt
/lists
283 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
284 cp "${PKGFILE}-new" aptarchive
/Packages
285 compressfile
'aptarchive/Packages'
286 mkdir -p aptarchive
/Packages.
diff
287 PATCHFILE
="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
288 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
289 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
290 PATCHINDEX
='aptarchive/Packages.diff/Index'
291 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
293 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
294 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
296 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
297 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
299 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
300 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz") $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
301 # needs to look like a valid command, otherwise the parser will fail before hashes are checked
302 echo '1d' > "$PATCHFILE"
303 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
304 generatereleasefiles
'+1hour'
306 testsuccess apt update
"$@"
307 cp -f rootdir
/tmp
/testsuccess.output rootdir
/tmp
/aptupdate.output
308 testsuccess
grep 'Hash Sum mismatch' rootdir
/tmp
/aptupdate.output
309 testnopackage oldstuff
310 testsuccessequal
"$(cat "${PKGFILE}-new")
311 " aptcache show apt newstuff
313 msgmsg
"Testcase: pdiff patch bigger than index itself: $*"
314 rm -rf rootdir
/var
/lib
/apt
/lists
315 cp -a rootdir
/var
/lib
/apt
/lists
-bak rootdir
/var
/lib
/apt
/lists
316 # the general testcode checks for leftovers in partial, but as this file
317 # is never touched in this test as it exits earlier its not a leftover…
318 rm -f rootdir
/var
/lib
/apt
/lists
/partial
/localhost
:${APTHTTPPORT}_Packages
319 cp "${PKGFILE}-new" aptarchive
/Packages
320 compressfile
'aptarchive/Packages'
321 mkdir -p aptarchive
/Packages.
diff
322 PATCHFILE
="aptarchive/Packages.diff/$(date +%Y-%m-%d-%H%M.%S)"
323 diff -e "${PKGFILE}" "${PKGFILE}-new" > "${PATCHFILE}" || true
324 cat "$PATCHFILE" | gzip > "${PATCHFILE}.gz"
325 PATCHINDEX
='aptarchive/Packages.diff/Index'
326 echo "SHA256-Current: $(sha256sum "${PKGFILE}-new" | cut -d' ' -f 1) $(stat -c%s "${PKGFILE}-new")
328 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 33053002 2010-08-18-2013.28
329 $(sha256sum "$PKGFILE" | cut -d' ' -f 1) $(stat -c%s "$PKGFILE") $(basename "$PATCHFILE")
331 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 19722 2010-08-18-2013.28
332 $(sha256sum "$PATCHFILE" | cut -d' ' -f 1) $(stat -c%s "$PATCHFILE") $(basename "$PATCHFILE")
334 d2a1b33187ed2d248eeae3b1223ea71791ea35f2138a713ed371332a6421f467 197 2010-08-18-2013.28.gz
335 $(sha256sum "${PATCHFILE}.gz" | cut -d' ' -f 1) $(stat -c%s "${PATCHFILE}.gz")000 $(basename "${PATCHFILE}.gz")" > "$PATCHINDEX"
336 generatereleasefiles
'+1hour'
338 wasmergeused
"$@" -o test::cannot
-use-pdiff=1
339 testsuccess
grep 'bytes (Limit is' rootdir
/tmp
/aptupdate.output
340 testnopackage oldstuff
341 testsuccessequal
"$(cat "${PKGFILE}-new")
342 " aptcache show apt newstuff
344 echo 'Debug::pkgAcquire::Diffs "true";
345 Debug::Acquire::Transaction "true";
346 Debug::pkgAcquire::Worker "true";
347 Debug::Acquire::http "true";
348 Debug::pkgAcquire "true";
349 Debug::Acquire::rred "true";' > rootdir
/etc
/apt
/apt.conf.d
/rreddebug.conf
352 testrun
-o Acquire
::PDiffs
::Merge
=0 -o APT
::Get
::List
-Cleanup=1 "$@"
353 testrun
-o Acquire
::PDiffs
::Merge
=1 -o APT
::Get
::List
-Cleanup=1 "$@"
354 testrun
-o Acquire
::PDiffs
::Merge
=0 -o APT
::Get
::List
-Cleanup=0 "$@"
355 testrun
-o Acquire
::PDiffs
::Merge
=1 -o APT
::Get
::List
-Cleanup=0 "$@"
357 generatepartialleftovers
() {
359 cat "${PKGFILE}" "${PKGFILE}" > "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
360 printf '\n\nInvalid\nStanza: yes\n\n' >> "rootdir/var/lib/apt/lists-bak/partial/localhost:${APTHTTPPORT}_${f}"
364 partialleftovers
() { generatepartialleftovers
'Packages' 'Packages-patched'; }
365 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; testsuccess
test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages"; }
366 testcase
-o Acquire
::IndexTargets
::deb
::Packages
::KeepCompressed
=false
367 partialleftovers
() { generatepartialleftovers
"Packages.${LOWCOSTEXT}" "Packages-patched.${LOWCOSTEXT}"; }
368 aptautotest_apt_update
() { aptautotest_aptget_update
"$@"; testsuccess
test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_Packages.$LOWCOSTEXT"; }
369 testcase
-o Acquire
::IndexTargets
::deb
::Packages
::KeepCompressed
=true
372 partialleftovers
() { generatepartialleftovers
"redirectme_Packages.${LOWCOSTEXT}" "redirectme_Packages-patched.${LOWCOSTEXT}"; }
373 webserverconfig
'aptwebserver::redirect::replace::/redirectme/' "http://0.0.0.0:${APTHTTPPORT}/"
374 rewritesourceslist
"http://localhost:${APTHTTPPORT}/redirectme"
375 aptautotest_apt_update
() {
376 aptautotest_aptget_update
"$@"
377 testsuccess
test -e "rootdir/var/lib/apt/lists/localhost:${APTHTTPPORT}_redirectme_Packages.$LOWCOSTEXT"
378 testempty
find rootdir
/var
/lib
/apt
/lists
-type f \
! \
( -name lock
-o -name '*_redirectme_*' \
)
380 testcase
-o Acquire
::IndexTargets
::deb
::Packages
::KeepCompressed
=true