test-apt-get-download 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. confighashes 'SHA512'
  8. buildsimplenativepackage 'apt' 'all' '1.0' 'stable'
  9. buildsimplenativepackage 'apt' 'all' '2.0' 'unstable'
  10. insertinstalledpackage 'vrms' 'all' '1.0'
  11. OLD_UMASK="$(umask)"
  12. umask 0027
  13. setupaptarchive --no-update
  14. umask "$OLD_UMASK"
  15. # directories should be readable by everyone
  16. find aptarchive/dists -type d | while read dir; do
  17. chmod o+rx "$dir"
  18. done
  19. # apt-ftparchive knows how to chmod files
  20. find aptarchive/dists -name '*Packages*' -type f | while read file; do
  21. testaccessrights "$file" '644'
  22. chmod 640 "$file"
  23. done
  24. # created by the framework without special care
  25. find aptarchive/dists -name '*Release*' -type f | while read file; do
  26. testaccessrights "$file" '640'
  27. done
  28. testsuccess aptget update
  29. testdownload() {
  30. local APT="$2"
  31. if [ -n "$3" ]; then
  32. APT="${APT}/${3}"
  33. fi
  34. msgtest "Test download of package file $1 with" "$APT"
  35. testsuccess --nomsg aptget download ${APT} -o Debug::pkgAcquire::Worker=1 -o Debug::pkgAcquire::Auth=1
  36. testsuccess test -f "$1"
  37. rm -f "$1"
  38. }
  39. # normal case as "root"
  40. OLDPWD="$(pwd)"
  41. cd downloaded
  42. testdownload apt_2.0_all.deb apt
  43. cd "$OLDPWD"
  44. # simulate normal user with non-existent root-owned directories
  45. rm -rf rootdir/var/cache/apt/archives/
  46. mkdir rootdir/var/cache/apt/archives/
  47. addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/var/cache/apt/archives || true;"
  48. chmod -R -w rootdir/var/cache/apt/archives
  49. OLDPWD="$(pwd)"
  50. cd downloaded
  51. # normal case(es)
  52. testdownload apt_1.0_all.deb apt stable
  53. testdownload apt_2.0_all.deb apt
  54. DEBFILE="$(readlink -f ../aptarchive)/pool/apt_2.0_all.deb"
  55. testequal "'file://${DEBFILE}' apt_2.0_all.deb $(stat -c%s $DEBFILE) SHA512:$(sha512sum $DEBFILE | cut -d' ' -f 1)" aptget download apt --print-uris
  56. # deb:677887
  57. testequal "E: Can't find a source to download version '1.0' of 'vrms:i386'" aptget download vrms --print-uris
  58. testequal "E: Can't find a source to download version '1.0' of 'vrms:i386'" aptget download vrms
  59. # deb:736962
  60. testsuccess aptget download apt
  61. testsuccess aptget download apt
  62. testsuccess test -s apt_2.0_all.deb
  63. rm -f apt_1.0_all.deb apt_2.0_all.deb
  64. # deb:738103
  65. testsuccess aptget download apt apt apt/unstable apt=2.0
  66. testsuccess test -s apt_2.0_all.deb
  67. # restore "root" rights
  68. cd "$OLDPWD"
  69. chmod -f -R +w $PWD/rootdir/var/cache/apt/archives
  70. rm -rf rootdir/var/cache/apt/archives/
  71. # file: debs aren't copied to archives, so change to http which obviously are
  72. changetowebserver
  73. testsuccess aptget update
  74. # test with already stored deb
  75. testsuccess aptget install -d apt
  76. testsuccess test -s rootdir/var/cache/apt/archives/apt_2.0_all.deb
  77. testaccessrights 'aptarchive/pool/apt_2.0_all.deb' '644'
  78. mv aptarchive/pool/apt_2.0_all.deb aptarchive/pool/apt_2.0_all.deb.gone
  79. cd downloaded
  80. testdownload apt_2.0_all.deb apt
  81. cd "$OLDPWD"
  82. mv aptarchive/pool/apt_2.0_all.deb.gone aptarchive/pool/apt_2.0_all.deb