test-apt-update-transactions 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/sh
  2. set -e
  3. # ensure that an update will only succeed entirely or not at all
  4. TESTDIR="$(readlink -f "$(dirname "$0")")"
  5. . "$TESTDIR/framework"
  6. setupenvironment
  7. configarchitecture 'i386'
  8. configcompression '.' 'gz'
  9. insertpackage 'unstable' 'foo' 'i386' '1.0'
  10. insertsource 'unstable' 'foo' 'i386' '1.0'
  11. setupaptarchive --no-update
  12. breakfile() {
  13. mv "${1}" "${1}.bak"
  14. mv "${1}.gz" "${1}.gz.bak"
  15. cat > "$1" <<EOF
  16. Package: bar
  17. EOF
  18. compressfile "$1"
  19. }
  20. restorefile() {
  21. mv "${1}.bak" "$1"
  22. mv "${1}.gz.bak" "${1}.gz"
  23. }
  24. testrun() {
  25. rm -rf aptarchive/dists.good
  26. cp -a aptarchive/dists aptarchive/dists.good
  27. insertpackage 'unstable' 'bar' 'i386' '1.0'
  28. insertsource 'unstable' 'bar' 'i386' '1.0'
  29. buildaptarchivefromfiles '+1 hour'
  30. # produce an unsigned repository
  31. find aptarchive \( -name 'Release.gpg' -o -name 'InRelease' \) -delete
  32. testfailure aptget update --no-allow-insecure-repositories
  33. testfileequal "$1" "$(listcurrentlistsdirectory)"
  34. # signed but broken
  35. signreleasefiles
  36. onehashbroken() {
  37. rm -rf rootdir/var/lib/apt/lists/partial
  38. testfailure aptget update -o Debug::pkgAcquire::Worker=1 -o Debug::Acquire::http=1
  39. # each file generates two messages with this string
  40. testequal '2' grep --count 'Hash Sum mismatch' rootdir/tmp/testfailure.output
  41. testfileequal "$1" "$(listcurrentlistsdirectory)"
  42. }
  43. breakfile aptarchive/dists/unstable/main/binary-i386/Packages
  44. onehashbroken "$1"
  45. restorefile aptarchive/dists/unstable/main/binary-i386/Packages
  46. breakfile aptarchive/dists/unstable/main/source/Sources
  47. onehashbroken "$1"
  48. restorefile aptarchive/dists/unstable/main/source/Sources
  49. rm -rf aptarchive/dists
  50. cp -a aptarchive/dists.good aptarchive/dists
  51. }
  52. testsetup() {
  53. msgmsg 'Test with no initial data over' "$1"
  54. rm -rf rootdir/var/lib/apt/lists
  55. mkdir -p rootdir/var/lib/apt/lists/partial
  56. listcurrentlistsdirectory > listsdir.lst
  57. testrun 'listsdir.lst'
  58. msgmsg 'Test with initial data over' "$1"
  59. rm -rf rootdir/var/lib/apt/lists
  60. testsuccess aptget update -o Debug::pkgAcquire::Worker=1
  61. listcurrentlistsdirectory > listsdir.lst
  62. testrun 'listsdir.lst'
  63. }
  64. testsetup 'file'
  65. changetowebserver
  66. webserverconfig 'aptwebserver::support::modified-since' 'false' "$1"
  67. webserverconfig 'aptwebserver::support::last-modified' 'false' "$1" # curl is clever and sees hits here also
  68. webserverconfig 'aptwebserver::response-header::Accept-Ranges' 'none' "$1"
  69. testsetup 'http'
  70. changetohttpswebserver
  71. testsetup 'https'