test-ubuntu-bug-346386-apt-get-update-paywall 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'native'
  7. insertpackage 'unstable' 'unrelated' 'all' '1.0' 'stable'
  8. insertsource 'unstable' 'unrelated' 'all' '1.0' 'stable'
  9. echo 'ni ni ni' > aptarchive/knights
  10. setupaptarchive
  11. changetowebserver -o 'aptwebserver::overwrite::.*InRelease::filename=/knights' -o 'aptwebserver::overwrite::.*::filename=/knights'
  12. msgtest 'Acquire test file from the webserver to check' 'overwrite'
  13. if downloadfile http://localhost:${APTHTTPPORT}/holygrail ./knights-talking >/dev/null; then
  14. msgpass
  15. else
  16. msgfail
  17. fi
  18. testfileequal knights-talking 'ni ni ni'
  19. ensure_n_canary_strings_in_dir() {
  20. local DIR="$1"
  21. local CANARY_STRING="$2"
  22. local EXPECTED_N="$3"
  23. msgtest "Testing in $DIR for $EXPECTED_N canary" "$CANARY_STRING"
  24. local N=$(grep "$CANARY_STRING" $DIR/* 2>/dev/null |wc -l )
  25. test "$N" = "$EXPECTED_N" && msgpass || msgfail "Expected $EXPECTED_N canaries, got $N"
  26. }
  27. runtests() {
  28. LISTS='rootdir/var/lib/apt/lists'
  29. rm -rf "$LISTS"
  30. testfailure aptget update
  31. testsuccess grep "$1" rootdir/tmp/testfailure.output
  32. ensure_n_canary_strings_in_dir "$LISTS" 'ni ni ni' 0
  33. testequal 'lock
  34. partial' ls "$LISTS"
  35. # and again with pre-existing files with "valid data" which should remain
  36. for f in Release Release.gpg main_binary-amd64_Packages main_source_Sources; do
  37. echo 'peng neee-wom' > "$LISTS/localhost:${APTHTTPPORT}_dists_stable_${f}"
  38. chmod 644 "$LISTS/localhost:${APTHTTPPORT}_dists_stable_${f}"
  39. done
  40. testfailure aptget update
  41. testsuccess grep "$1" rootdir/tmp/testfailure.output
  42. ensure_n_canary_strings_in_dir "$LISTS" 'peng neee-wom' 4
  43. ensure_n_canary_strings_in_dir "$LISTS" 'ni ni ni' 0
  44. # and now with a pre-existing InRelease file
  45. echo 'peng neee-wom' > "$LISTS/localhost:${APTHTTPPORT}_dists_stable_InRelease"
  46. chmod 644 "$LISTS/localhost:${APTHTTPPORT}_dists_stable_InRelease"
  47. rm -f "$LISTS/localhost:${APTHTTPPORT}_dists_stable_Release" "$LISTS/localhost:${APTHTTPPORT}_dists_stable_Release.gpg"
  48. msgtest 'excpected failure of' 'apt-get update'
  49. testfailure aptget update
  50. testsuccess grep "$1" rootdir/tmp/testfailure.output
  51. ensure_n_canary_strings_in_dir "$LISTS" 'peng neee-wom' 3
  52. ensure_n_canary_strings_in_dir "$LISTS" 'ni ni ni' 0
  53. }
  54. runtests '^E:.*Clearsigned file .*NOSPLIT.*'
  55. webserverconfig 'aptwebserver::overwrite::.*InRelease::filename' '/404'
  56. runtests '^E:.*Signed file .*NODATA.*'