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.
 
 
 
 
 
 

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