test-bug-738785-switch-protocol 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture "i386"
  7. buildsimplenativepackage 'apt' 'all' '1.0' 'stable'
  8. # setup http redirecting to https
  9. setupaptarchive --no-update
  10. changetowebserver -o 'aptwebserver::redirect::replace::/redirectme/=https://localhost:4433/' \
  11. -o 'aptwebserver::redirect::replace::/downgrademe/=http://localhost:8080/' \
  12. -o 'aptwebserver::support::http=false'
  13. changetohttpswebserver
  14. sed -i -e 's#:4433/#:8080/redirectme#' -e 's# https:# http:#' rootdir/etc/apt/sources.list.d/*
  15. testsuccess aptget update -o Debug::Acquire::http=1 -o Debug::Acquire::https=1 -o Debug::pkgAcquire::Worker=1
  16. msgtest 'Test that the webserver does not answer' 'http requests'
  17. downloadfile 'http://localhost:8080/pool/apt_1.0/changelog' changelog >/dev/null 2>&1 && msgfail || msgpass
  18. echo 'Apt::Changelogs::Server "http://localhost:8080/redirectme";' > rootdir/etc/apt/apt.conf.d/changelog.conf
  19. testsuccessequal "'http://localhost:8080/redirectme/pool/apt_1.0/changelog'" aptget changelog apt --print-uris
  20. cd downloaded
  21. testsuccess aptget changelog apt -d
  22. testsuccess test -s apt.changelog
  23. rm -f apt.changelog
  24. testsuccess aptget download apt
  25. testsuccess test -s apt_1.0_all.deb
  26. rm apt_1.0_all.deb
  27. cd - >/dev/null
  28. testsuccess aptget install apt -y
  29. testdpkginstalled 'apt'
  30. # create a copy of all methods, expect https
  31. eval `aptconfig shell METHODS Dir::Bin::Methods/d`
  32. COPYMETHODS='usr/lib/apt/methods'
  33. mv rootdir/${COPYMETHODS} rootdir/${COPYMETHODS}.bak
  34. mkdir -p rootdir/$COPYMETHODS
  35. cd rootdir/$COPYMETHODS
  36. find $METHODS \! -type d | while read meth; do
  37. ln -s $meth
  38. done
  39. rm https
  40. cd - >/dev/null
  41. echo "Dir::Bin::Methods \"${COPYMETHODS}\";" >> aptconfig.conf
  42. cd downloaded
  43. testfailureequal "E: The method driver $(readlink -f './../')/rootdir/usr/lib/apt/methods/https could not be found.
  44. N: Is the package apt-transport-https installed?" aptget download apt -q=0
  45. testfailure test -e apt_1.0_all.deb
  46. cd - >/dev/null
  47. # revert to all methods
  48. rm -rf rootdir/$COPYMETHODS
  49. mv rootdir/${COPYMETHODS}.bak rootdir/${COPYMETHODS}
  50. # check that downgrades from https to http are not allowed
  51. webserverconfig 'aptwebserver::support::http' 'true'
  52. sed -i -e 's#:8080/redirectme#:4433/downgrademe#' -e 's# http:# https:#' rootdir/etc/apt/sources.list.d/*
  53. testfailure aptget update --allow-insecure-repositories