test-apt-update-rollback 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/bin/sh
  2. #
  3. # test that apt-get update is transactional
  4. #
  5. set -e
  6. avoid_ims_hit() {
  7. touch -d '+1hour' aptarchive/dists/unstable/main/binary-i386/Packages*
  8. touch -d '+1hour' aptarchive/dists/unstable/main/source/Sources*
  9. touch -d '+1hour' aptarchive/dists/unstable/*Release*
  10. touch -d '-1hour' rootdir/var/lib/apt/lists/*
  11. }
  12. create_fresh_archive()
  13. {
  14. rm -rf aptarchive/*
  15. rm -f rootdir/var/lib/apt/lists/_* rootdir/var/lib/apt/lists/partial/*
  16. insertpackage 'unstable' 'old' 'all' '1.0'
  17. setupaptarchive
  18. }
  19. add_new_package() {
  20. insertpackage "unstable" "new" "all" "1.0"
  21. insertsource "unstable" "new" "all" "1.0"
  22. setupaptarchive --no-update
  23. avoid_ims_hit
  24. }
  25. break_repository_sources_index() {
  26. printf "xxx" > $APTARCHIVE/dists/unstable/main/source/Sources
  27. gzip -c $APTARCHIVE/dists/unstable/main/source/Sources > \
  28. $APTARCHIVE/dists/unstable/main/source/Sources.gz
  29. avoid_ims_hit
  30. }
  31. test_inrelease_to_new_inrelease() {
  32. msgmsg "Test InRelease to new InRelease works fine"
  33. create_fresh_archive
  34. testequal "old/unstable 1.0 all" apt list -q
  35. add_new_package
  36. testsuccess aptget update -o Debug::Acquire::Transaction=1
  37. testequal "new/unstable 1.0 all
  38. old/unstable 1.0 all" apt list -q
  39. }
  40. test_inrelease_to_broken_hash_reverts_all() {
  41. msgmsg "Test InRelease to broken InRelease reverts everything"
  42. create_fresh_archive
  43. add_new_package
  44. # break the Sources file
  45. break_repository_sources_index
  46. # test the error condition
  47. testequal "W: Failed to fetch file:${APTARCHIVE}/dists/unstable/main/source/Sources Hash Sum mismatch
  48. E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
  49. # ensure that the Packages file is also rolled back
  50. testequal "E: Unable to locate package new" aptget install new -s -qq
  51. }
  52. test_inreleae_to_valid_release() {
  53. msgmsg "Test InRelease to valid Release"
  54. create_fresh_archive
  55. add_new_package
  56. # switch to a unsinged repo now
  57. rm $APTARCHIVE/dists/unstable/InRelease
  58. rm $APTARCHIVE/dists/unstable/Release.gpg
  59. avoid_ims_hit
  60. # update fails
  61. testequal "E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update -qq
  62. # test that we can install the new packages but do no longer have a sig
  63. testsuccess aptget install old -s
  64. testfailure aptget install new -s
  65. testsuccess ls $ROOTDIR/var/lib/apt/lists/*_InRelease
  66. testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release
  67. }
  68. test_inreleae_to_release_reverts_all() {
  69. msgmsg "Test InRelease to broken Release reverts everything"
  70. create_fresh_archive
  71. # switch to a unsinged repo now
  72. add_new_package
  73. rm $APTARCHIVE/dists/unstable/InRelease
  74. rm $APTARCHIVE/dists/unstable/Release.gpg
  75. # break it
  76. break_repository_sources_index
  77. # ensure error
  78. testequal "E: The repository 'file: unstable Release.gpg' is no longer signed." aptget update -qq # -o Debug::acquire::transaction=1
  79. # ensure that the Packages file is also rolled back
  80. testsuccess aptget install old -s
  81. testfailure aptget install new -s
  82. testsuccess ls $ROOTDIR/var/lib/apt/lists/*_InRelease
  83. testfailure ls $ROOTDIR/var/lib/apt/lists/*_Release
  84. }
  85. test_unauthenticated_to_invalid_inrelease() {
  86. msgmsg "Test UnAuthenticated to invalid InRelease reverts everything"
  87. create_fresh_archive
  88. rm -rf rootdir/var/lib/apt/lists/*
  89. rm $APTARCHIVE/dists/unstable/InRelease
  90. rm $APTARCHIVE/dists/unstable/Release.gpg
  91. avoid_ims_hit
  92. testsuccess aptget update -qq --allow-unauthenticated
  93. testequal "WARNING: The following packages cannot be authenticated!
  94. old
  95. E: There are problems and -y was used without --force-yes" aptget install -qq -y old
  96. # go to authenticated but not correct
  97. add_new_package
  98. break_repository_sources_index
  99. testequal "W: Failed to fetch file:$APTARCHIVE/dists/unstable/main/source/Sources Hash Sum mismatch
  100. E: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
  101. testfailure ls rootdir/var/lib/apt/lists/*_InRelease
  102. testequal "WARNING: The following packages cannot be authenticated!
  103. old
  104. E: There are problems and -y was used without --force-yes" aptget install -qq -y old
  105. }
  106. test_inrelease_to_unauth_inrelease() {
  107. msgmsg "Test InRelease to InRelease without sig"
  108. create_fresh_archive
  109. signreleasefiles 'Marvin Paranoid'
  110. avoid_ims_hit
  111. testequal "W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: file: unstable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY E8525D47528144E2
  112. W: Failed to fetch file:$APTARCHIVE/dists/unstable/InRelease
  113. W: Some index files failed to download. They have been ignored, or old ones used instead." aptget update -qq
  114. testsuccess ls rootdir/var/lib/apt/lists/*_InRelease
  115. }
  116. test_inrelease_to_broken_gzip() {
  117. msgmsg "Test InRelease to broken gzip"
  118. create_fresh_archive
  119. # append junk at the end of the gzip, this
  120. echo "lala" >> $APTARCHIVE/dists/unstable/main/source/Sources.gz
  121. # remove uncompressed file, otherwise apt will just fallback fetching
  122. # that
  123. rm $APTARCHIVE/dists/unstable/main/source/Sources
  124. avoid_ims_hit
  125. testfailure aptget update
  126. }
  127. TESTDIR=$(readlink -f $(dirname $0))
  128. . $TESTDIR/framework
  129. setupenvironment
  130. configarchitecture "i386"
  131. # setup the archive and ensure we have a single package that installs fine
  132. setupaptarchive
  133. APTARCHIVE=$(readlink -f ./aptarchive)
  134. ROOTDIR=${TMPWORKINGDIRECTORY}/rootdir
  135. APTARCHIVE_LISTS="$(echo $APTARCHIVE | tr "/" "_" )"
  136. # test the following cases:
  137. # - InRelease -> broken InRelease revert to previous state
  138. # - empty lists dir and broken remote leaves nothing on the system
  139. # - InRelease -> hashsum mismatch for one file reverts all files to previous state
  140. # - Release/Release.gpg -> hashsum mismatch
  141. # - InRelease -> Release with hashsum mismatch revert entire state and kills Release
  142. # - Release -> InRelease with broken Sig/Hash removes InRelease
  143. # going from Release/Release.gpg -> InRelease and vice versa
  144. # - unauthenticated -> invalid InRelease
  145. # stuff to do:
  146. # - ims-hit
  147. # - gzip-index tests
  148. test_inrelease_to_new_inrelease
  149. test_inrelease_to_broken_hash_reverts_all
  150. test_inreleae_to_valid_release
  151. test_inreleae_to_release_reverts_all
  152. test_unauthenticated_to_invalid_inrelease
  153. test_inrelease_to_unauth_inrelease
  154. test_inrelease_to_broken_gzip