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.
 
 
 
 
 
 

256 lines
11 KiB

  1. #!/bin/sh
  2. set -e
  3. umask 0
  4. TESTDIR="$(readlink -f "$(dirname "$0")")"
  5. . "$TESTDIR/framework"
  6. umask 022
  7. setupenvironment
  8. configarchitecture "i386"
  9. buildsimplenativepackage 'foo' 'all' '1' 'stable'
  10. buildsimplenativepackage 'foo' 'all' '2' 'unstable'
  11. setupaptarchive --no-update
  12. changetowebserver
  13. webserverconfig 'aptwebserver::redirect::replace::/redirectme/' "http://localhost:${APTHTTPPORT}/"
  14. addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/var/lib/apt/lists || true;"
  15. mkdir -m 755 -p rootdir/var/lib/apt
  16. touch rootdir/var/lib/apt/extended_states
  17. testrundownload_internal_debs() {
  18. local WORKDIR="$1"
  19. shift
  20. if [ "$WORKDIR" != '.' ]; then cd "$WORKDIR"; fi
  21. while [ -n "$1" ]; do
  22. if [ "$1" = 'foo=1' ]; then shift; continue; fi
  23. local fndeb="$(echo "$1" | tr '=' '_')_all.deb"
  24. testsuccess test -e "$fndeb"
  25. rm -f "$fndeb"
  26. shift
  27. done
  28. if [ "$WORKDIR" != '.' ]; then cd - >/dev/null; fi
  29. }
  30. testrundownload_internal() {
  31. cd downloaded
  32. testsuccess apt install --download-only -o Debug::NoLocking=true -y "$@"
  33. testrundownload_internal_debs '../rootdir/var/cache/apt/archives' "$@"
  34. msgtest 'Repeat the download only install test with' 'aptitude'
  35. if dpkg-checkbuilddeps -d 'aptitude' /dev/null >/dev/null 2>&1; then
  36. if aptitude install --download-only -o Debug::NoLocking=true -y "$@" > ../rootdir/tmp/aptitude.log 2>&1; then
  37. msgpass
  38. else
  39. msgfail
  40. cat >&2 ../rootdir/tmp/aptitude.log
  41. fi
  42. testrundownload_internal_debs '../rootdir/var/cache/apt/archives' "$@"
  43. else
  44. msgskip 'not installed'
  45. fi
  46. testsuccess apt download "$@" -o Debug::pkgAcquire::Worker=1
  47. testrundownload_internal_debs '.' "$@"
  48. testempty find . -name '*mirror*'
  49. cd ..
  50. }
  51. testrundownload() {
  52. if [ "$(id -u)" = '0' ]; then
  53. testrundownload_internal "$@"
  54. else
  55. mkdir -p rootdir/var/cache/apt/archives/partial
  56. echo 'Debug::SetupAPTPartialDirectory::AssumeGood "true";' > rootdir/etc/apt/apt.conf.d/assumegooddirs.conf
  57. chmod -f 555 rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists/auxfiles rootdir/var/lib/apt/lists/partial
  58. testrundownload_internal "$@"
  59. testnotempty find rootdir/var/lib/apt/lists/auxfiles
  60. testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/auxfiles" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:555"
  61. chmod -f 755 rootdir/var/lib/apt/lists/auxfiles
  62. rm -f rootdir/var/lib/apt/lists/auxfiles/*
  63. chmod -f 555 rootdir/var/lib/apt/lists/auxfiles
  64. testrundownload_internal "$@"
  65. testfilestats "${TMPWORKINGDIRECTORY}/rootdir/var/lib/apt/lists/auxfiles" '%U:%G:%a' '=' "${TEST_DEFAULT_USER}:${TEST_DEFAULT_GROUP}:555"
  66. testempty find rootdir/var/lib/apt/lists/auxfiles ! -type d
  67. chmod -f 755 rootdir/var/lib/apt/lists
  68. rm -rf rootdir/var/lib/apt/lists/auxfiles
  69. chmod -f 555 rootdir/var/lib/apt/lists
  70. testrundownload_internal "$@"
  71. chmod -f 755 rootdir/var/lib/apt/lists
  72. testsuccess test ! -d rootdir/var/lib/apt/lists/auxfiles
  73. rm -f rootdir/etc/apt/apt.conf.d/assumegooddirs.conf
  74. fi
  75. }
  76. testrun() {
  77. rm -rf rootdir/var/lib/apt/lists
  78. testsuccess apt update #-o Debug::Acquire::mirror=1 -o Debug::Acquire::http=1 -o Debug::pkgAcquire::Worker=1
  79. cp -a rootdir/tmp/testsuccess.output aptupdate.output
  80. test -z "$1" || testempty find rootdir/var/lib/apt/lists -maxdepth 1 -name "$1" -type f
  81. test -z "$2" || testnotempty find rootdir/var/lib/apt/lists -maxdepth 1 -name "$2" -type f
  82. testsuccess apt show foo=1
  83. testrundownload 'foo=1' 'foo=2'
  84. }
  85. msgmsg 'basic setup'
  86. testrun '' ''
  87. msgmsg 'redirect setup'
  88. sed -i -e 's#/ stable#/redirectme stable#' rootdir/etc/apt/sources.list.d/*-stable-*
  89. testrun '' '*_redirectme_*'
  90. msgmsg 'mirror file does not exist'
  91. sed -i -e 's# http:# mirror:#' -e 's#/redirectme stable#/mirror.txt stable#' rootdir/etc/apt/sources.list.d/*-stable-*
  92. testfailure apt update
  93. echo "http://localhost:${APTHTTPPORT}" > aptarchive/mirror.txt
  94. msgmsg 'stable mirror setup'
  95. testrun '*_redirectme_stable_*' '*_mirror.txt_*'
  96. msgmsg 'all mirror setup'
  97. sed -i -e 's# http:# mirror:#' -e 's#/ unstable#/mirror.txt unstable#' rootdir/etc/apt/sources.list.d/*
  98. testrun '*_redirectme_stable_*' '*_mirror.txt_*'
  99. msgmsg 'all mirror+http setup'
  100. sed -i -e 's# mirror:# mirror+http:#' rootdir/etc/apt/sources.list.d/*
  101. testrun '*_redirectme_*' '*_mirror.txt_*'
  102. msgmsg 'stable gzipped redirect setup'
  103. echo "http://localhost:${APTHTTPPORT}/redirectme" > aptarchive/mirror.txt
  104. compressfile aptarchive/mirror.txt
  105. sed -i -e 's#/mirror\.txt stable#/mirror.txt.gz stable#' rootdir/etc/apt/sources.list.d/*-stable-*
  106. testrun '*_redirectme_*' '*_mirror.txt.gz_*'
  107. msgmsg 'all mirrored via file'
  108. APTARCHIVE="$(readlink -f ./aptarchive)"
  109. sed -i -e "s#mirror+http://localhost:${APTHTTPPORT}#mirror+file:${APTARCHIVE}#" rootdir/etc/apt/sources.list.d/*
  110. testrun '*_localhost_*' '*_aptarchive_mirror.txt.gz_*'
  111. msgmsg 'fallback mirrors are used if needed' 'as usual'
  112. sed -i -e 's#/mirror\.txt\.gz stable#/mirror.txt stable#' rootdir/etc/apt/sources.list.d/*
  113. echo "http://localhost:${APTHTTPPORT}/failure2 priority:3
  114. http://localhost:${APTHTTPPORT}/redirectme priority:2
  115. http://localhost:${APTHTTPPORT}/failure priority:1" > aptarchive/mirror.txt
  116. testrun '*_localhost_*' '*_aptarchive_mirror.txt_*'
  117. testsuccessequal "Get:1 file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  118. Ign:2 http://localhost:${APTHTTPPORT}/failure stable InRelease
  119. 404 Not Found
  120. Ign:3 http://localhost:${APTHTTPPORT}/failure unstable InRelease
  121. 404 Not Found" head -n 5 aptupdate.output
  122. msgmsg 'fallback mirrors are used if needed' 'by tags'
  123. echo "http://localhost:${APTHTTPPORT}/failure2 priority:1 release:stable
  124. http://localhost:${APTHTTPPORT}/redirectme priority:2
  125. http://localhost:${APTHTTPPORT}/failure priority:1 release:unstable" > aptarchive/mirror.txt
  126. testrun '*_localhost_*' '*_aptarchive_mirror.txt_*'
  127. testsuccessequal "Get:1 file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  128. Ign:2 http://localhost:${APTHTTPPORT}/failure2 stable InRelease
  129. 404 Not Found
  130. Ign:3 http://localhost:${APTHTTPPORT}/failure unstable InRelease
  131. 404 Not Found" head -n 5 aptupdate.output
  132. changetohttpswebserver
  133. rm -f rootdir/etc/apt/sources.list.d/*-stable-*
  134. msgmsg 'fallback mirrors are used if needed' 'random'
  135. echo "http://localhost:${APTHTTPPORT}/failure2 priority:1
  136. http://localhost:${APTHTTPPORT}/redirectme priority:2
  137. https://localhost:${APTHTTPSPORT}/failure priority:1
  138. http://localhost:${APTHTTPPORT}/unused-failure1
  139. http://localhost:${APTHTTPPORT}/unused-failure2
  140. http://localhost:${APTHTTPPORT}/unused-failure3
  141. http://localhost:${APTHTTPPORT}/unused-failure4
  142. http://localhost:${APTHTTPPORT}/unused-failure5
  143. http://localhost:${APTHTTPPORT}/unused-failure6
  144. http://localhost:${APTHTTPPORT}/unused-failure7
  145. http://localhost:${APTHTTPPORT}/unused-failure8
  146. http://localhost:${APTHTTPPORT}/unused-failure9
  147. " > aptarchive/mirror.txt
  148. testequalor2 "Get:1 file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  149. Ign:2 http://localhost:${APTHTTPPORT}/failure2 unstable InRelease
  150. 404 Not Found
  151. Ign:2 https://localhost:${APTHTTPSPORT}/failure unstable InRelease
  152. 404 Not Found
  153. Hit:2 http://localhost:${APTHTTPPORT}/redirectme unstable InRelease
  154. Reading package lists...
  155. Building dependency tree...
  156. Reading state information...
  157. All packages are up to date." "Get:1 file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  158. Ign:2 https://localhost:${APTHTTPSPORT}/failure unstable InRelease
  159. 404 Not Found
  160. Ign:2 http://localhost:${APTHTTPPORT}/failure2 unstable InRelease
  161. 404 Not Found
  162. Hit:2 http://localhost:${APTHTTPPORT}/failure2 unstable InRelease
  163. Reading package lists...
  164. Building dependency tree...
  165. Reading state information...
  166. All packages are up to date." apt update
  167. testfailure grep '/unused-failure' aptarchive/webserver.log
  168. msgmsg 'Mirrors can be filtered by' 'type'
  169. echo "http://localhost:${APTHTTPPORT}/failure
  170. http://localhost:${APTHTTPPORT}/redirectme type:deb
  171. " > aptarchive/mirror.txt
  172. testfailure apt update
  173. testrundownload 'foo=2'
  174. msgmsg 'The prefix for the mirrorlist is' 'passed on'
  175. echo 'Dir::Bin::Methods::foo+mirror+file "mirror";
  176. Dir::Bin::Methods::foo+mirror+http "mirror";
  177. Dir::Bin::Methods::foo+http "http";
  178. Dir::Bin::Methods::foo+https "https";
  179. ' > rootdir/etc/apt/apt.conf.d/99add-foo-method
  180. echo "http://localhost:${APTHTTPPORT}/redirectme
  181. " > aptarchive/mirror.txt
  182. testsuccessequal "Get:1 file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  183. Hit:2 http://localhost:${APTHTTPPORT}/redirectme unstable InRelease
  184. Reading package lists...
  185. Building dependency tree...
  186. Reading state information...
  187. All packages are up to date." apt update
  188. testrundownload 'foo=2'
  189. sed -i -e 's# mirror+# foo+mirror+#' rootdir/etc/apt/sources.list.d/*
  190. testfailure apt update
  191. testsuccess grep 'package apt-transport-foo installed' rootdir/tmp/testfailure.output
  192. echo 'Dir::Bin::Methods::foo+file "file";' >> rootdir/etc/apt/apt.conf.d/99add-foo-method
  193. testsuccessequal "Get:1 foo+file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  194. Hit:2 foo+http://localhost:${APTHTTPPORT}/redirectme unstable InRelease
  195. Reading package lists...
  196. Building dependency tree...
  197. Reading state information...
  198. All packages are up to date." apt update
  199. testrundownload 'foo=2'
  200. echo "file:/nonexistent/apt/archive priority:1
  201. http://localhost:${APTHTTPPORT}/redirectme
  202. " > aptarchive/mirror.txt
  203. testsuccessequal "Get:1 foo+file:${APTARCHIVE}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  204. Get:2 foo+file:/nonexistent/apt/archive unstable InRelease
  205. Ign:2 foo+file:/nonexistent/apt/archive unstable InRelease
  206. File not found - /nonexistent/apt/archive/dists/unstable/InRelease (2: No such file or directory)
  207. Hit:2 foo+http://localhost:${APTHTTPPORT}/redirectme unstable InRelease
  208. Reading package lists...
  209. Building dependency tree...
  210. Reading state information...
  211. All packages are up to date." apt update
  212. sed -i -e "s#+file:${APTARCHIVE}#+http://localhost:${APTHTTPPORT}#" rootdir/etc/apt/sources.list.d/*
  213. testsuccess apt update
  214. testrundownload 'foo=2'
  215. testsuccessequal "Get:1 foo+http://localhost:${APTHTTPPORT}/mirror.txt Mirrorlist [$(stat -c%s 'aptarchive/mirror.txt') B]
  216. Hit:2 foo+http://localhost:${APTHTTPPORT}/redirectme unstable InRelease
  217. Reading package lists...
  218. Building dependency tree...
  219. Reading state information...
  220. All packages are up to date." apt update
  221. testrundownload 'foo=2'
  222. echo "https://localhost:${APTHTTPSPORT}/
  223. http://localhost:${APTHTTPPORT}/redirectme" > aptarchive/mirror.txt
  224. rm -rf rootdir/var/lib/apt/lists
  225. sed -i -e "s# foo+# [signed-by=$(readlink -f ./keys/joesixpack.pub)] foo+#g" rootdir/etc/apt/sources.list.d/apt-test-unstable-deb*
  226. testsuccess apt update
  227. testrundownload 'foo=2'
  228. rm -rf rootdir/var/lib/apt/lists
  229. sed -i -e "s# \[signed-by=[^]]\+\] foo+# [signed-by=$(readlink -f ./keys/marvinparanoid.pub)] foo+#g" rootdir/etc/apt/sources.list.d/apt-test-unstable-deb*
  230. testfailure apt update