test-bug-595691-empty-and-broken-archive-files 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildaptarchive
  8. touch aptarchive/Packages
  9. setupflataptarchive
  10. testaptgetupdate() {
  11. rm -rf rootdir/var/lib/apt
  12. aptget update 2>> testaptgetupdate.diff >> testaptgetupdate.diff || true
  13. sed -i -e '/^Fetched / d' -e 's#\[[0-9]* [kMGTPY]*B\]#\[\]#' testaptgetupdate.diff
  14. GIVEN="$1"
  15. shift
  16. msgtest "Test for correctness of" "apt-get update with $*"
  17. if [ -z "$GIVEN" ]; then
  18. echo -n "" | checkdiff - testaptgetupdate.diff && msgpass || msgfail
  19. else
  20. echo "$GIVEN" | checkdiff - testaptgetupdate.diff && msgpass || msgfail
  21. fi
  22. rm testaptgetupdate.diff
  23. }
  24. createemptyarchive() {
  25. find aptarchive/ \( -name "Packages*" -o -name "en*" \) -type f -delete
  26. if [ "en" = "$1" ]; then
  27. echo -n "" | $COMPRESSOR > aptarchive/Packages.$COMPRESS
  28. fi
  29. touch aptarchive/Packages
  30. echo -n "" | $COMPRESSOR > aptarchive/${1}.$COMPRESS
  31. generatereleasefiles
  32. signreleasefiles
  33. rm -f aptarchive/Packages
  34. }
  35. createemptyfile() {
  36. find aptarchive/ \( -name "Packages*" -o -name "en*" \) -type f -delete
  37. if [ "en" = "$1" ]; then
  38. echo -n "" | $COMPRESSOR > aptarchive/Packages.$COMPRESS
  39. fi
  40. touch aptarchive/Packages aptarchive/${1}.$COMPRESS
  41. generatereleasefiles
  42. signreleasefiles
  43. rm -f aptarchive/Packages
  44. }
  45. setupcompressor() {
  46. COMPRESSOR="$1"
  47. case $COMPRESSOR in
  48. gzip) COMPRESS="gz";;
  49. bzip2) COMPRESS="bz2";;
  50. lzma) COMPRESS="lzma";;
  51. xz) COMPRESS="xz";;
  52. esac
  53. echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
  54. Dir::Bin::uncompressed \"/does/not/exist\";
  55. Dir::Bin::gzip \"/does/not/exist\";
  56. Dir::Bin::bzip2 \"/does/not/exist\";
  57. Dir::Bin::lzma \"/does/not/exist\";
  58. Dir::Bin::xz \"/does/not/exist\";" > rootdir/etc/apt/apt.conf.d/00compressor
  59. if [ -e "/bin/${COMPRESSOR}" ]; then
  60. echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
  61. elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
  62. echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
  63. else
  64. msgtest "Test for availability of compressor" "${COMPRESSOR}"
  65. msgfail
  66. exit 1
  67. fi
  68. }
  69. testoverfile() {
  70. setupcompressor "$1"
  71. createemptyfile 'en'
  72. testaptgetupdate "Get:1 file: InRelease []
  73. Ign file: Translation-en
  74. Reading package lists..." "empty file en.$COMPRESS over file"
  75. createemptyarchive 'en'
  76. testaptgetupdate "Get:1 file: InRelease []
  77. Reading package lists..." "empty archive en.$COMPRESS over file"
  78. createemptyarchive 'Packages'
  79. # FIXME: Why omits the file transport the Packages Get line?
  80. #Get:3 file: Packages []
  81. testaptgetupdate "Get:1 file: InRelease []
  82. Ign file: Translation-en
  83. Reading package lists..." "empty archive Packages.$COMPRESS over file"
  84. createemptyfile 'Packages'
  85. testaptgetupdate "Get:1 file: InRelease []
  86. Ign file: Translation-en
  87. Err file: Packages
  88. Empty files can't be valid archives
  89. W: Failed to fetch ${COMPRESSOR}:$(readlink -f aptarchive/Packages.$COMPRESS) Empty files can't be valid archives
  90. E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over file"
  91. }
  92. testoverhttp() {
  93. setupcompressor "$1"
  94. createemptyfile 'en'
  95. testaptgetupdate "Get:1 http://localhost InRelease []
  96. Get:2 http://localhost Packages []
  97. Get:3 http://localhost Translation-en
  98. Ign http://localhost Translation-en
  99. Reading package lists..." "empty file en.$COMPRESS over http"
  100. createemptyarchive 'en'
  101. testaptgetupdate "Get:1 http://localhost InRelease []
  102. Get:2 http://localhost Packages []
  103. Get:3 http://localhost Translation-en []
  104. Reading package lists..." "empty archive en.$COMPRESS over http"
  105. createemptyarchive 'Packages'
  106. testaptgetupdate "Get:1 http://localhost InRelease []
  107. Get:2 http://localhost Packages []
  108. Ign http://localhost Translation-en
  109. Reading package lists..." "empty archive Packages.$COMPRESS over http"
  110. createemptyfile 'Packages'
  111. #FIXME: we should response with a good error message instead
  112. testaptgetupdate "Get:1 http://localhost InRelease []
  113. Get:2 http://localhost Packages
  114. Ign http://localhost Translation-en
  115. Err http://localhost Packages
  116. Empty files can't be valid archives
  117. W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:8080_Packages) Empty files can't be valid archives
  118. E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
  119. }
  120. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverfile $COMPRESSOR; done
  121. # do the same again with http instead of file
  122. changetowebserver
  123. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverhttp $COMPRESSOR; done