]> git.saurik.com Git - apt.git/blame - test/integration/test-partial-file-support
always run 'dpkg --configure -a' at the end of our dpkg callings
[apt.git] / test / integration / test-partial-file-support
CommitLineData
fd46d305
DK
1#!/bin/sh
2set -e
3
4TESTDIR=$(readlink -f $(dirname $0))
5. $TESTDIR/framework
6setupenvironment
7configarchitecture 'amd64'
8
9changetowebserver
10
11copysource() {
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
16DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'
17
fd46d305 18testdownloadfile() {
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
50TESTFILE='aptarchive/testfile'
51cp -a ${TESTDIR}/framework $TESTFILE
52
53testrun() {
f2c0ec8b 54 webserverconfig 'aptwebserver::support::range' 'true'
03aa0847 55 local DOWN='./downloaded/testfile'
fd46d305 56
03aa0847
DK
57 copysource $TESTFILE 0 $DOWN
58 testdownloadfile 'no data' "${1}/testfile" "$DOWN" '='
0d58c26a 59 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305 60
03aa0847
DK
61 copysource $TESTFILE 20 $DOWN
62 testdownloadfile 'valid partial data' "${1}/testfile" "$DOWN" '='
0d58c26a 63 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
fd46d305 64
03aa0847
DK
65 copysource /dev/zero 20 $DOWN
66 testdownloadfile 'invalid partial data' "${1}/testfile" "$DOWN" '!='
0d58c26a 67 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
fd46d305 68
03aa0847
DK
69 copysource $TESTFILE 1M $DOWN
70 testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '='
0d58c26a 71 testwebserverlaststatuscode '416' "$DOWNLOADLOG"
fd46d305 72
03aa0847
DK
73 copysource /dev/zero 1M $DOWN
74 testdownloadfile 'too-big partial file' "${1}/testfile" "$DOWN" '='
0d58c26a 75 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305 76
03aa0847
DK
77 copysource /dev/zero 20 $DOWN
78 touch $DOWN
79 testdownloadfile 'old data' "${1}/testfile" "$DOWN" '='
0d58c26a 80 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305 81
f2c0ec8b 82 webserverconfig 'aptwebserver::support::range' 'false'
fd46d305 83
03aa0847
DK
84 copysource $TESTFILE 20 $DOWN
85 testdownloadfile 'no server support' "${1}/testfile" "$DOWN" '='
0d58c26a 86 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305
DK
87}
88
89testrun 'http://localhost:8080'
90
91changetohttpswebserver
92
93testrun 'https://localhost:4433'