]>
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 | ||
16 | testdownloadfile() { | |
17 | local DOWNLOG='download-testfile.log' | |
18 | rm -f "$DOWNLOG" | |
19 | msgtest "Testing download of file $2 with" "$1" | |
20 | if ! downloadfile "$2" "$3" > "$DOWNLOG"; then | |
21 | cat "$DOWNLOG" | |
22 | msgfail | |
23 | else | |
24 | msgpass | |
25 | fi | |
26 | cat "$DOWNLOG" | while read field hash; do | |
27 | local EXPECTED | |
28 | case "$field" in | |
29 | 'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";; | |
30 | 'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";; | |
31 | 'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";; | |
32 | 'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";; | |
33 | *) continue;; | |
34 | esac | |
35 | if [ "$4" = '=' ]; then | |
36 | msgtest 'Test downloaded file for correct' "$field" | |
37 | else | |
38 | msgtest 'Test downloaded file does not match in' "$field" | |
39 | fi | |
40 | if [ "$EXPECTED" "$4" "$hash" ]; then | |
41 | msgpass | |
42 | else | |
43 | cat "$DOWNLOG" | |
44 | msgfail "expected: $EXPECTED ; got: $hash" | |
45 | fi | |
46 | done | |
47 | } | |
48 | ||
49 | testwebserverlaststatuscode() { | |
50 | STATUS="$(mktemp)" | |
51 | addtrap "rm $STATUS;" | |
52 | msgtest 'Test last status code from the webserver was' "$1" | |
53 | downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" >/dev/null | |
54 | if [ "$(cat "$STATUS")" = "$1" ]; then | |
55 | msgpass | |
56 | else | |
57 | cat download-testfile.log | |
58 | msgfail "Status was $(cat "$STATUS")" | |
59 | fi | |
60 | } | |
61 | ||
62 | ||
63 | TESTFILE='aptarchive/testfile' | |
64 | cp -a ${TESTDIR}/framework $TESTFILE | |
65 | ||
66 | testrun() { | |
67 | downloadfile "$1/_config/set/aptwebserver::support::range/true" '/dev/null' >/dev/null | |
68 | testwebserverlaststatuscode '200' | |
69 | ||
70 | copysource $TESTFILE 0 ./testfile | |
71 | testdownloadfile 'no data' "${1}/testfile" './testfile' '=' | |
72 | testwebserverlaststatuscode '200' | |
73 | ||
74 | copysource $TESTFILE 20 ./testfile | |
75 | testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '=' | |
76 | testwebserverlaststatuscode '206' | |
77 | ||
78 | copysource /dev/zero 20 ./testfile | |
79 | testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!=' | |
80 | testwebserverlaststatuscode '206' | |
81 | ||
82 | copysource $TESTFILE 1M ./testfile | |
83 | testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '=' | |
84 | testwebserverlaststatuscode '416' | |
85 | ||
86 | copysource /dev/zero 1M ./testfile | |
87 | testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '=' | |
88 | testwebserverlaststatuscode '200' | |
89 | ||
90 | copysource /dev/zero 20 ./testfile | |
91 | touch ./testfile | |
92 | testdownloadfile 'old data' "${1}/testfile" './testfile' '=' | |
93 | testwebserverlaststatuscode '200' | |
94 | ||
95 | downloadfile "$1/_config/set/aptwebserver::support::range/false" '/dev/null' >/dev/null | |
96 | testwebserverlaststatuscode '200' | |
97 | ||
98 | copysource $TESTFILE 20 ./testfile | |
99 | testdownloadfile 'no server support' "${1}/testfile" './testfile' '=' | |
100 | testwebserverlaststatuscode '200' | |
101 | } | |
102 | ||
103 | testrun 'http://localhost:8080' | |
104 | ||
105 | changetohttpswebserver | |
106 | ||
107 | testrun 'https://localhost:4433' |