]> git.saurik.com Git - apt.git/blob - test/integration/test-partial-file-support
Use _apt as our unprivileged user name
[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
56 copysource $TESTFILE 0 ./testfile
57 testdownloadfile 'no data' "${1}/testfile" './testfile' '='
58 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
59
60 copysource $TESTFILE 20 ./testfile
61 testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
62 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
63
64 copysource /dev/zero 20 ./testfile
65 testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
66 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
67
68 copysource $TESTFILE 1M ./testfile
69 testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
70 testwebserverlaststatuscode '416' "$DOWNLOADLOG"
71
72 copysource /dev/zero 1M ./testfile
73 testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
74 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
75
76 copysource /dev/zero 20 ./testfile
77 touch ./testfile
78 testdownloadfile 'old data' "${1}/testfile" './testfile' '='
79 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
80
81 webserverconfig 'aptwebserver::support::range' 'false'
82
83 copysource $TESTFILE 20 ./testfile
84 testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
85 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
86 }
87
88 testrun 'http://localhost:8080'
89
90 changetohttpswebserver
91
92 testrun 'https://localhost:4433'