]> git.saurik.com Git - apt.git/blob - test/integration/test-partial-file-support
Merge remote-tracking branch 'upstream/debian/experimental' into feature/no-more...
[apt.git] / test / integration / test-partial-file-support
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 DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'
17
18 testdownloadfile() {
19 rm -f "$DOWNLOADLOG"
20 msgtest "Testing download of file $2 with" "$1"
21 if ! downloadfile "$2" "$3" > "$DOWNLOADLOG"; then
22 cat >&2 "$DOWNLOADLOG"
23 msgfail
24 else
25 msgpass
26 fi
27 cat "$DOWNLOADLOG" | while read field hash; do
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
44 cat >&2 "$DOWNLOADLOG"
45 msgfail "expected: $EXPECTED ; got: $hash"
46 fi
47 done
48 }
49
50 TESTFILE='aptarchive/testfile'
51 cp -a ${TESTDIR}/framework $TESTFILE
52
53 testrun() {
54 webserverconfig 'aptwebserver::support::range' 'true'
55 local DOWN='./downloaded/testfile'
56
57 copysource $TESTFILE 0 $DOWN
58 testdownloadfile 'no data' "${1}/testfile" "$DOWN" '='
59 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
60
61 copysource $TESTFILE 20 $DOWN
62 testdownloadfile 'valid partial data' "${1}/testfile" "$DOWN" '='
63 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
64
65 copysource /dev/zero 20 $DOWN
66 testdownloadfile 'invalid partial data' "${1}/testfile" "$DOWN" '!='
67 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
68
69 copysource $TESTFILE 1M $DOWN
70 testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '='
71 testwebserverlaststatuscode '416' "$DOWNLOADLOG"
72
73 copysource /dev/zero 1M $DOWN
74 testdownloadfile 'too-big partial file' "${1}/testfile" "$DOWN" '='
75 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
76
77 copysource /dev/zero 20 $DOWN
78 touch $DOWN
79 testdownloadfile 'old data' "${1}/testfile" "$DOWN" '='
80 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
81
82 webserverconfig 'aptwebserver::support::range' 'false'
83
84 copysource $TESTFILE 20 $DOWN
85 testdownloadfile 'no server support' "${1}/testfile" "$DOWN" '='
86 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
87 }
88
89 testrun 'http://localhost:8080'
90
91 changetohttpswebserver
92
93 testrun 'https://localhost:4433'