test-partial-file-support 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. copysource $TESTFILE 0 ./testfile
  49. testdownloadfile 'no data' "${1}/testfile" './testfile' '='
  50. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  51. copysource $TESTFILE 20 ./testfile
  52. testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
  53. testwebserverlaststatuscode '206' "$DOWNLOADLOG"
  54. copysource /dev/zero 20 ./testfile
  55. testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
  56. testwebserverlaststatuscode '206' "$DOWNLOADLOG"
  57. copysource $TESTFILE 1M ./testfile
  58. testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
  59. testwebserverlaststatuscode '416' "$DOWNLOADLOG"
  60. copysource /dev/zero 1M ./testfile
  61. testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
  62. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  63. copysource /dev/zero 20 ./testfile
  64. touch ./testfile
  65. testdownloadfile 'old data' "${1}/testfile" './testfile' '='
  66. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  67. webserverconfig 'aptwebserver::support::range' 'false'
  68. copysource $TESTFILE 20 ./testfile
  69. testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
  70. testwebserverlaststatuscode '200' "$DOWNLOADLOG"
  71. }
  72. testrun 'http://localhost:8080'
  73. changetohttpswebserver
  74. testrun 'https://localhost:4433'