test-apt-update-not-modified 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'amd64' 'i386'
  7. insertpackage 'unstable' 'apt' 'amd64,i386' '1.0'
  8. setupaptarchive --no-update
  9. methodtest() {
  10. msgmsg 'Test InRelease with' "$1"
  11. rm -rf rootdir/var/lib/apt/lists
  12. cp -a aptarchive/dists aptarchive/dists.good
  13. # get our cache populated
  14. testsuccess aptget update
  15. listcurrentlistsdirectory > listsdir.lst
  16. # hit again with a good cache
  17. testsuccessequal "Hit:1 $1 unstable InRelease
  18. Reading package lists..." aptget update
  19. testfileequal 'listsdir.lst' "$(listcurrentlistsdirectory)"
  20. # drop an architecture, which means the file should be gone now
  21. configarchitecture 'i386'
  22. sed '/_binary-amd64_Packages/ d' listsdir.lst > listsdir-without-amd64.lst
  23. testsuccessequal "Hit:1 $1 unstable InRelease
  24. Reading package lists..." aptget update
  25. testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
  26. # readd arch so its downloaded again…
  27. configarchitecture 'amd64' 'i386'
  28. # … but oh noes, hashsum mismatch!
  29. SIZE=$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz')
  30. find aptarchive/dists/unstable/main/binary-amd64/ -type f -delete
  31. cat >> aptarchive/dists/unstable/main/binary-amd64/Packages <<EOF
  32. Package: thisisbad
  33. Architecture: amd64
  34. Version: 1
  35. EOF
  36. compressfile aptarchive/dists/unstable/main/binary-amd64/Packages
  37. testfailureequal "Hit:1 $1 unstable InRelease
  38. Get:2 $1 unstable/main amd64 Packages [$SIZE B]
  39. Err:2 $1 unstable/main amd64 Packages
  40. Hash Sum mismatch
  41. Reading package lists...
  42. W: Failed to fetch $1/dists/unstable/main/binary-amd64/Packages.gz Hash Sum mismatch
  43. E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
  44. testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
  45. rm -rf aptarchive/dists
  46. cp -a aptarchive/dists.good aptarchive/dists
  47. # … now everything is fine again
  48. testsuccessequal "Hit:1 $1 unstable InRelease
  49. Get:2 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz') B]
  50. Reading package lists..." aptget update
  51. testfileequal 'listsdir.lst' "$(listcurrentlistsdirectory)"
  52. webserverconfig 'aptwebserver::support::modified-since' 'false'
  53. webserverconfig 'aptwebserver::support::last-modified' 'false'
  54. testsuccessequal "Get:1 $1 unstable InRelease [$(stat -c '%s' 'aptarchive/dists/unstable/InRelease') B]
  55. Reading package lists..." aptget update
  56. webserverconfig 'aptwebserver::support::modified-since' 'true'
  57. webserverconfig 'aptwebserver::support::last-modified' 'true'
  58. msgmsg 'Test Release.gpg with' "$1"
  59. rm -rf rootdir/var/lib/apt/lists
  60. find aptarchive/dists -name 'InRelease' -delete
  61. # get our cache populated
  62. testsuccess aptget update
  63. listcurrentlistsdirectory > listsdir.lst
  64. # hit again with a good cache
  65. testsuccessequal "Ign:1 $1 unstable InRelease
  66. 404 Not Found
  67. Hit:2 $1 unstable Release
  68. Reading package lists..." aptget update
  69. testfileequal 'listsdir.lst' "$(listcurrentlistsdirectory)"
  70. # drop an architecture, which means the file should be gone now
  71. configarchitecture 'i386'
  72. sed '/_binary-amd64_Packages/ d' listsdir.lst > listsdir-without-amd64.lst
  73. testsuccessequal "Ign:1 $1 unstable InRelease
  74. 404 Not Found
  75. Hit:2 $1 unstable Release
  76. Reading package lists..." aptget update
  77. testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
  78. # readd arch so its downloaded again…
  79. configarchitecture 'amd64' 'i386'
  80. # … but oh noes, hashsum mismatch!
  81. SIZE=$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz')
  82. find aptarchive/dists/unstable/main/binary-amd64/ -type f -delete
  83. cat >> aptarchive/dists/unstable/main/binary-amd64/Packages <<EOF
  84. Package: thisisbad
  85. Architecture: amd64
  86. Version: 1
  87. EOF
  88. compressfile aptarchive/dists/unstable/main/binary-amd64/Packages
  89. testfailureequal "Ign:1 $1 unstable InRelease
  90. 404 Not Found
  91. Hit:2 $1 unstable Release
  92. Get:4 $1 unstable/main amd64 Packages [$SIZE B]
  93. Err:4 $1 unstable/main amd64 Packages
  94. Hash Sum mismatch
  95. Reading package lists...
  96. W: Failed to fetch $1/dists/unstable/main/binary-amd64/Packages.gz Hash Sum mismatch
  97. E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update
  98. testfileequal 'listsdir-without-amd64.lst' "$(listcurrentlistsdirectory)"
  99. rm -rf aptarchive/dists
  100. cp -a aptarchive/dists.good aptarchive/dists
  101. find aptarchive/dists -name 'InRelease' -delete
  102. # … now everything is fine again
  103. testsuccessequal "Ign:1 $1 unstable InRelease
  104. 404 Not Found
  105. Hit:2 $1 unstable Release
  106. Get:4 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz') B]
  107. Reading package lists..." aptget update
  108. testfileequal 'listsdir.lst' "$(listcurrentlistsdirectory)"
  109. webserverconfig 'aptwebserver::support::modified-since' 'false'
  110. webserverconfig 'aptwebserver::support::last-modified' 'false'
  111. testsuccessequal "Ign:1 $1 unstable InRelease
  112. 404 Not Found
  113. Get:2 $1 unstable Release [$(stat -c '%s' 'aptarchive/dists/unstable/Release') B]
  114. Reading package lists..." aptget update
  115. webserverconfig 'aptwebserver::support::modified-since' 'true'
  116. webserverconfig 'aptwebserver::support::last-modified' 'true'
  117. rm -rf aptarchive/dists
  118. cp -a aptarchive/dists.good aptarchive/dists
  119. # new release file, but the indexes are the same
  120. redatereleasefiles '+2 hours'
  121. rm -rf rootdir/var/lib/apt/lists.good
  122. cp -a rootdir/var/lib/apt/lists rootdir/var/lib/apt/lists.good
  123. testsuccessequal "Get:1 $1 unstable InRelease [$(stat -c '%s' 'aptarchive/dists/unstable/InRelease') B]
  124. Reading package lists..." aptget update
  125. rm -rf rootdir/var/lib/apt/lists
  126. cp -a rootdir/var/lib/apt/lists.good rootdir/var/lib/apt/lists
  127. find rootdir/var/lib/apt/lists -name '*_Packages*' -delete
  128. testsuccessequal "Get:1 $1 unstable InRelease [$(stat -c '%s' 'aptarchive/dists/unstable/InRelease') B]
  129. Get:2 $1 unstable/main amd64 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-amd64/Packages.gz') B]
  130. Get:3 $1 unstable/main i386 Packages [$(stat -c '%s' 'aptarchive/dists/unstable/main/binary-i386/Packages.gz') B]
  131. Reading package lists..." aptget update
  132. rm -rf aptarchive/dists
  133. cp -a aptarchive/dists.good aptarchive/dists
  134. }
  135. changetowebserver
  136. methodtest "http://localhost:${APTHTTPPORT}"
  137. changetohttpswebserver
  138. methodtest "https://localhost:${APTHTTPSPORT}"