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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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::.*::filename=/knights'
  12. msgtest 'Acquire test file from the webserver to check' 'overwrite'
  13. if downloadfile http://localhost:8080/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. LISTS='rootdir/var/lib/apt/lists'
  28. rm -rf rootdir/var/lib/apt/lists
  29. msgtest 'Got expected NODATA failure in' 'apt-get update'
  30. aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
  31. ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0
  32. testequal 'partial' ls $LISTS
  33. # and again with pre-existing files with "valid data" which should remain
  34. for f in Release Release.gpg main_binary-amd64_Packages main_source_Sources; do
  35. echo 'peng neee-wom' > $LISTS/localhost:8080_dists_stable_${f}
  36. done
  37. msgtest 'Got expected NODATA failure in' 'apt-get update'
  38. aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
  39. ensure_n_canary_strings_in_dir $LISTS 'peng neee-wom' 4
  40. ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0
  41. # and now with a pre-existing InRelease file
  42. echo 'peng neee-wom' > $LISTS/localhost:8080_dists_stable_InRelease
  43. rm -f $LISTS/localhost:8080_dists_stable_Release $LISTS/localhost:8080_dists_stable_Release.gpg
  44. msgtest 'excpected failure of' 'apt-get update'
  45. aptget update -qq 2>&1 | grep -q 'E: GPG error.*NODATA' && msgpass || msgfail
  46. ensure_n_canary_strings_in_dir $LISTS 'peng neee-wom' 3
  47. ensure_n_canary_strings_in_dir $LISTS 'ni ni ni' 0