You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
4.3 KiB

  1. #!/bin/sh
  2. set -e
  3. TESTDIR="$(readlink -f "$(dirname "$0")")"
  4. . "$TESTDIR/framework"
  5. setupenvironment
  6. configarchitecture 'i386'
  7. changetohttpswebserver
  8. echo 'foo' > aptarchive/foo
  9. echo 'bar' > aptarchive/foo2
  10. test_apt_helper_download() {
  11. msgmsg 'Test with' "$1"
  12. msgtest 'apt-file download-file' 'md5sum'
  13. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo2' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00'
  14. testfileequal ./downloaded/foo2 'foo'
  15. msgtest 'apt-file download-file' 'sha1'
  16. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo1' 'SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15'
  17. testfileequal ./downloaded/foo1 'foo'
  18. msgtest 'apt-file download-file' 'sha256'
  19. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo3' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'
  20. testfileequal ./downloaded/foo3 'foo'
  21. msgtest 'apt-file download-file' 'no-hash'
  22. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo4'
  23. testfileequal ./downloaded/foo4 'foo'
  24. msgtest 'apt-file download-file' 'wrong md5sum'
  25. testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo5' 'MD5Sum:aabbcc'
  26. testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
  27. E: Download Failed"
  28. testfileequal ./downloaded/foo5.FAILED 'foo'
  29. msgtest 'apt-file download-file' 'wrong sha256'
  30. testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo6' 'SHA256:aabbcc'
  31. testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
  32. E: Download Failed"
  33. testfileequal './downloaded/foo6.FAILED' 'foo'
  34. msgtest 'apt-file download-file' 'sha256 sha1'
  35. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo8' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' \
  36. "${1}/foo2" './downloaded/foo7' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
  37. testfileequal './downloaded/foo8' 'foo'
  38. testfileequal './downloaded/foo7' 'bar'
  39. msgtest 'apt-file download-file' 'md5sum sha1'
  40. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo9' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00' \
  41. "${1}/foo2" './downloaded/foo10' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
  42. testfileequal './downloaded/foo9' 'foo'
  43. testfileequal './downloaded/foo10' 'bar'
  44. }
  45. test_apt_helper_detect_proxy() {
  46. # no proxy
  47. testsuccessequal "Using proxy '' for URL 'http://example.com/'" apthelper auto-detect-proxy http://example.com/
  48. # http auto detect proxy script
  49. cat > apt-proxy-detect <<'EOF'
  50. #!/bin/sh -e
  51. echo "http://some-proxy"
  52. EOF
  53. chmod 755 apt-proxy-detect
  54. echo "Acquire::http::Proxy-Auto-Detect \"$(pwd)/apt-proxy-detect\";" > rootdir/etc/apt/apt.conf.d/02proxy-detect
  55. testsuccessequal "Using proxy 'http://some-proxy' for URL 'http://www.example.com/'" apthelper auto-detect-proxy http://www.example.com
  56. # https auto detect proxy script
  57. cat > apt-proxy-detect <<'EOF'
  58. #!/bin/sh -e
  59. echo "https://https-proxy"
  60. EOF
  61. chmod 755 apt-proxy-detect
  62. echo "Acquire::https::Proxy-Auto-Detect \"$(pwd)/apt-proxy-detect\";" > rootdir/etc/apt/apt.conf.d/02proxy-detect
  63. testsuccessequal "Using proxy 'https://https-proxy' for URL 'https://ssl.example.com/'" apthelper auto-detect-proxy https://ssl.example.com
  64. }
  65. test_apt_helper_download "http://localhost:${APTHTTPPORT}"
  66. test_apt_helper_download "https://localhost:${APTHTTPSPORT}"
  67. test_apt_helper_detect_proxy
  68. # test failure modes
  69. testfailureequal 'E: Invalid operation download' apthelper download
  70. testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file
  71. testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file 'http://example.org/'
  72. testfailureequal 'E: Need one URL as argument' apthelper auto-detect-proxy
  73. testfailureequal 'E: Must specify at least one SRV record' apthelper srv-lookup
  74. testfailureequal 'E: GetSrvRec failed for localhost' apthelper -q=1 srv-lookup 'localhost'
  75. testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPPORT}"
  76. testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPSPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPSPORT}"