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

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