test-apt-helper 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. Hashes of expected file:
  28. - MD5Sum:aabbcc [weak]
  29. Hashes of received file:
  30. - SHA512:0cf9180a764aba863a67b6d72f0918bc131c6772642cb2dce5a34f0a702f9470ddc2bf125c12198b1995c233c34b4afd346c54a2334c350a948a51b6e8b4e6b6
  31. - SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
  32. - SHA1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15 [weak]
  33. - MD5Sum:d3b07384d113edec49eaa6238ad5ff00 [weak]
  34. - Filesize:4 [weak]
  35. Last modification reported: $(lastmodification 'aptarchive/foo')
  36. E: Download Failed"
  37. testfileequal ./downloaded/foo5.FAILED 'foo'
  38. msgtest 'apt-file download-file' 'wrong sha256'
  39. testfailure --nomsg apthelper -qq download-file "${1}/foo" './downloaded/foo6' 'SHA256:aabbcc'
  40. testfileequal rootdir/tmp/testfailure.output "E: Failed to fetch ${1}/foo Hash Sum mismatch
  41. Hashes of expected file:
  42. - SHA256:aabbcc
  43. Hashes of received file:
  44. - SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
  45. - Filesize:4 [weak]
  46. Last modification reported: $(lastmodification 'aptarchive/foo')
  47. E: Download Failed"
  48. testfileequal './downloaded/foo6.FAILED' 'foo'
  49. msgtest 'apt-file download-file' 'sha256 sha1'
  50. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo8' 'SHA256:b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' \
  51. "${1}/foo2" './downloaded/foo7' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
  52. testfileequal './downloaded/foo8' 'foo'
  53. testfileequal './downloaded/foo7' 'bar'
  54. msgtest 'apt-file download-file' 'md5sum sha1'
  55. testsuccess --nomsg apthelper download-file "${1}/foo" './downloaded/foo9' 'MD5Sum:d3b07384d113edec49eaa6238ad5ff00' \
  56. "${1}/foo2" './downloaded/foo10' 'SHA1:e242ed3bffccdf271b7fbaf34ed72d089537b42f'
  57. testfileequal './downloaded/foo9' 'foo'
  58. testfileequal './downloaded/foo10' 'bar'
  59. }
  60. setupproxydetect() {
  61. local METH="$1"
  62. shift
  63. {
  64. echo '#!/bin/sh -e'
  65. echo "$@"
  66. } > "${TMPWORKINGDIRECTORY}/apt-proxy-detect"
  67. chmod 755 "${TMPWORKINGDIRECTORY}/apt-proxy-detect"
  68. echo "Acquire::${METH}::Proxy-Auto-Detect \"${TMPWORKINGDIRECTORY}/apt-proxy-detect\";" > rootdir/etc/apt/apt.conf.d/02proxy-detect
  69. }
  70. test_apt_helper_detect_proxy() {
  71. msgmsg 'apt-helper auto-detect-proxy' 'no proxy'
  72. testsuccessequal "Using proxy '' for URL 'http://example.com/'" apthelper auto-detect-proxy http://example.com/
  73. setupproxydetect 'http' 'exit 0'
  74. testsuccessequal "Using proxy '' for URL 'http://example.com/'" apthelper auto-detect-proxy http://example.com/
  75. setupproxydetect 'http' 'exit 1'
  76. testfailureequal 'E: Sub-process ProxyAutoDetect returned an error code (1)' apthelper auto-detect-proxy http://example.com/
  77. setupproxydetect 'http' 'echo'
  78. testwarningequal "Using proxy '' for URL 'http://example.com/'
  79. W: ProxyAutoDetect command returned an empty line" apthelper auto-detect-proxy http://example.com/
  80. setupproxydetect 'http' 'echo DIRECT'
  81. testsuccessequal "Using proxy 'DIRECT' for URL 'http://example.com/'" apthelper auto-detect-proxy http://example.com/
  82. msgmsg 'apt-helper auto-detect-proxy' 'http proxy'
  83. setupproxydetect 'http' 'echo "http://some-proxy"'
  84. testsuccessequal "Using proxy 'http://some-proxy' for URL 'http://www.example.com/'" apthelper auto-detect-proxy http://www.example.com
  85. msgmsg 'apt-helper auto-detect-proxy' 'https proxy'
  86. setupproxydetect 'https' 'echo "https://https-proxy"'
  87. testsuccessequal "Using proxy 'https://https-proxy' for URL 'https://ssl.example.com/'" apthelper auto-detect-proxy https://ssl.example.com
  88. }
  89. test_apt_helper_download "http://localhost:${APTHTTPPORT}"
  90. test_apt_helper_download "https://localhost:${APTHTTPSPORT}"
  91. test_apt_helper_detect_proxy
  92. msgmsg 'test various failure modes'
  93. testfailureequal 'E: Invalid operation download' apthelper download
  94. testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file
  95. testfailureequal 'E: Must specify at least one pair url/filename' apthelper download-file 'http://example.org/'
  96. testfailureequal 'E: Need one URL as argument' apthelper auto-detect-proxy
  97. testfailureequal 'E: Must specify at least one SRV record' apthelper srv-lookup
  98. testfailureequal 'E: GetSrvRec failed for localhost' apthelper -q=1 srv-lookup 'localhost'
  99. testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPPORT}"
  100. testfailureequal "E: GetSrvRec failed for localhost:${APTHTTPSPORT}" apthelper -q=1 srv-lookup "localhost:${APTHTTPSPORT}"