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

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