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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 '/Ign / 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. Reading package lists..." "empty file en.$COMPRESS over file"
  74. createemptyarchive 'en'
  75. testaptgetupdate "Get:1 file: InRelease []
  76. Reading package lists..." "empty archive en.$COMPRESS over file"
  77. createemptyarchive 'Packages'
  78. # FIXME: Why omits the file transport the Packages Get line?
  79. #Get:3 file: Packages []
  80. testaptgetupdate "Get:1 file: InRelease []
  81. Reading package lists..." "empty archive Packages.$COMPRESS over file"
  82. createemptyfile 'Packages'
  83. testaptgetupdate "Get:1 file: InRelease []
  84. Err file: Packages
  85. Empty files can't be valid archives
  86. W: Failed to fetch ${COMPRESSOR}:$(readlink -f aptarchive/Packages.$COMPRESS) Empty files can't be valid archives
  87. E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over file"
  88. }
  89. testoverhttp() {
  90. setupcompressor "$1"
  91. createemptyfile 'en'
  92. testaptgetupdate "Get:1 http://localhost InRelease []
  93. Get:2 http://localhost Packages []
  94. Get:3 http://localhost Translation-en
  95. Reading package lists..." "empty file en.$COMPRESS over http"
  96. createemptyarchive 'en'
  97. testaptgetupdate "Get:1 http://localhost InRelease []
  98. Get:2 http://localhost Packages []
  99. Get:3 http://localhost Translation-en []
  100. Reading package lists..." "empty archive en.$COMPRESS over http"
  101. createemptyarchive 'Packages'
  102. testaptgetupdate "Get:1 http://localhost InRelease []
  103. Get:2 http://localhost Packages []
  104. Reading package lists..." "empty archive Packages.$COMPRESS over http"
  105. createemptyfile 'Packages'
  106. #FIXME: we should response with a good error message instead
  107. testaptgetupdate "Get:1 http://localhost InRelease []
  108. Get:2 http://localhost Packages
  109. Err http://localhost Packages
  110. Empty files can't be valid archives
  111. W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:8080_Packages) Empty files can't be valid archives
  112. E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
  113. }
  114. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverfile $COMPRESSOR; done
  115. # do the same again with http instead of file
  116. changetowebserver
  117. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverhttp $COMPRESSOR; done