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