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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 '/Ign / d' -e '/Release/ d' -e 's#Get:[0-9]\+ #Get: #' -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_CMD > aptarchive/Packages.$COMPRESS
  28. fi
  29. touch aptarchive/Packages
  30. echo -n "" | $COMPRESSOR_CMD > 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_CMD > 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. COMPRESSOR_CMD="$1"
  48. case $COMPRESSOR in
  49. gzip) COMPRESS="gz";;
  50. bzip2) COMPRESS="bz2";;
  51. lzma) COMPRESS="lzma";;
  52. xz) COMPRESS="xz";;
  53. esac
  54. echo "Acquire::CompressionTypes::Order { \"${COMPRESS}\"; };
  55. Dir::Bin::uncompressed \"/does/not/exist\";
  56. Dir::Bin::gzip \"/does/not/exist\";
  57. Dir::Bin::bzip2 \"/does/not/exist\";
  58. Dir::Bin::lzma \"/does/not/exist\";
  59. Dir::Bin::xz \"/does/not/exist\";" > rootdir/etc/apt/apt.conf.d/00compressor
  60. if [ -e "/bin/${COMPRESSOR}" ]; then
  61. echo "Dir::Bin::${COMPRESSOR} \"/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
  62. elif [ -e "/usr/bin/${COMPRESSOR}" ]; then
  63. echo "Dir::Bin::${COMPRESSOR} \"/usr/bin/${COMPRESSOR}\";" >> rootdir/etc/apt/apt.conf.d/00compressor
  64. elif [ "${COMPRESSOR}" = 'lzma' ]; then
  65. echo "Dir::Bin::xz \"/usr/bin/xz\";" >> rootdir/etc/apt/apt.conf.d/00compressor
  66. COMPRESSOR_CMD='xz --format=lzma'
  67. else
  68. msgtest "Test for availability of compressor" "${COMPRESSOR}"
  69. msgfail
  70. #exit 1
  71. fi
  72. }
  73. testoverfile() {
  74. setupcompressor "$1"
  75. createemptyfile 'en'
  76. testaptgetupdate 'Reading package lists...' "empty file en.$COMPRESS over file"
  77. createemptyarchive 'en'
  78. testaptgetupdate 'Reading package lists...' "empty archive en.$COMPRESS over file"
  79. createemptyarchive 'Packages'
  80. # FIXME: Why omits the file transport the Packages Get line?
  81. #Get:3 file: Packages []
  82. testaptgetupdate 'Reading package lists...' "empty archive Packages.$COMPRESS over file"
  83. createemptyfile 'Packages'
  84. testaptgetupdate "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: http://localhost:8080 Packages []
  93. Get: http://localhost:8080 Translation-en
  94. Reading package lists..." "empty file en.$COMPRESS over http"
  95. createemptyarchive 'en'
  96. testaptgetupdate "Get: http://localhost:8080 Packages []
  97. Get: http://localhost:8080 Translation-en []
  98. Reading package lists..." "empty archive en.$COMPRESS over http"
  99. createemptyarchive 'Packages'
  100. testaptgetupdate "Get: http://localhost:8080 Packages []
  101. Reading package lists..." "empty archive Packages.$COMPRESS over http"
  102. createemptyfile 'Packages'
  103. #FIXME: we should response with a good error message instead
  104. testaptgetupdate "Get: http://localhost:8080 Packages
  105. Err http://localhost:8080 Packages
  106. Empty files can't be valid archives
  107. W: Failed to fetch ${COMPRESSOR}:$(readlink -f rootdir/var/lib/apt/lists/partial/localhost:8080_Packages) Empty files can't be valid archives
  108. E: Some index files failed to download. They have been ignored, or old ones used instead." "empty file Packages.$COMPRESS over http"
  109. }
  110. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverfile $COMPRESSOR; done
  111. # do the same again with http instead of file
  112. changetowebserver
  113. for COMPRESSOR in 'gzip' 'bzip2' 'lzma' 'xz'; do testoverhttp $COMPRESSOR; done