You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

352 lines
16 KiB

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