test-partial-file-support 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. set -e
  3. TESTDIR=$(readlink -f $(dirname $0))
  4. . $TESTDIR/framework
  5. setupenvironment
  6. configarchitecture 'amd64'
  7. changetowebserver
  8. copysource() {
  9. dd if="$1" bs=1 count="$2" of="$3" 2>/dev/null
  10. touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
  11. }
  12. DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'
  13. testdownloadfile() {
  14. rm -f "$DOWNLOADLOG"
  15. msgtest "Testing download of file $2 with" "$1"
  16. if ! downloadfile "$2" "$3" > "$DOWNLOADLOG"; then
  17. cat >&2 "$DOWNLOADLOG"
  18. msgfail
  19. else
  20. msgpass
  21. fi
  22. cat "$DOWNLOADLOG" | while read field hash; do
  23. local EXPECTED
  24. case "$field" in
  25. 'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
  26. 'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
  27. 'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
  28. 'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
  29. *) continue;;
  30. esac
  31. if [ "$4" = '=' ]; then
  32. msgtest 'Test downloaded file for correct' "$field"
  33. else
  34. msgtest 'Test downloaded file does not match in' "$field"
  35. fi
  36. if [ "$EXPECTED" "$4" "$hash" ]; then
  37. msgpass
  38. else
  39. cat >&2 "$DOWNLOADLOG"
  40. msgfail "expected: $EXPECTED ; got: $hash"
  41. fi
  42. done
  43. }
  44. TESTFILE='aptarchive/testfile'
  45. cp -a ${TESTDIR}/framework $TESTFILE
  46. testrun() {
  47. webserverconfig 'aptwebserver::support::range' 'true'
  48. local DOWN='./downloaded/testfile'
  49. copysource $TESTFILE 0 $DOWN
  50. testdownloadfile 'no data' "${1}/testfile" "$DOWN" '='
  51. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  52. copysource $TESTFILE 20 $DOWN
  53. testdownloadfile 'valid partial data' "${1}/testfile" "$DOWN" '='
  54. testwebserverlaststatuscode '206' "$DOWNLOADLOG"
  55. copysource /dev/zero 20 $DOWN
  56. testdownloadfile 'invalid partial data' "${1}/testfile" "$DOWN" '!='
  57. testwebserverlaststatuscode '206' "$DOWNLOADLOG"
  58. copysource $TESTFILE 1M $DOWN
  59. testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '='
  60. testwebserverlaststatuscode '416' "$DOWNLOADLOG"
  61. copysource /dev/zero 1M $DOWN
  62. testdownloadfile 'too-big partial file' "${1}/testfile" "$DOWN" '='
  63. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  64. copysource /dev/zero 20 $DOWN
  65. touch $DOWN
  66. testdownloadfile 'old data' "${1}/testfile" "$DOWN" '='
  67. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  68. webserverconfig 'aptwebserver::support::range' 'false'
  69. copysource $TESTFILE 20 $DOWN
  70. testdownloadfile 'no server support' "${1}/testfile" "$DOWN" '='
  71. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  72. }
  73. testrun 'http://localhost:8080'
  74. changetohttpswebserver
  75. testrun 'https://localhost:4433'