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

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