dispose http(s) 416 error page as non-content
[ntk/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
92e8c1ff
DK
27 sed -e '/^ <- / s#%20# #g' -e '/^ <- / s#%0a#\n#g' "$DOWNLOADLOG" | grep '^.*-Hash: ' > receivedhashes.log
28 testsuccess test -s receivedhashes.log
29 local HASHES_OK=0
30 local HASHES_BAD=0
31 while read field hash; do
fd46d305
DK
32 local EXPECTED
33 case "$field" in
34 'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
35 'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
36 'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
37 'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
92e8c1ff
DK
38 'Checksum-FileSize-Hash:')
39 #filesize is too weak to check for !=
40 if [ "$4" = '=' ]; then
41 EXPECTED="$(stat -c '%s' "$TESTFILE")"
42 else
43 continue
44 fi
45 ;;
fd46d305
DK
46 *) continue;;
47 esac
48 if [ "$4" = '=' ]; then
49 msgtest 'Test downloaded file for correct' "$field"
50 else
51 msgtest 'Test downloaded file does not match in' "$field"
52 fi
53 if [ "$EXPECTED" "$4" "$hash" ]; then
54 msgpass
92e8c1ff 55 HASHES_OK=$((HASHES_OK+1));
fd46d305 56 else
fd46d305 57 msgfail "expected: $EXPECTED ; got: $hash"
92e8c1ff 58 HASHES_BAD=$((HASHES_BAD+1));
fd46d305 59 fi
92e8c1ff
DK
60 done < receivedhashes.log
61 msgtest 'At least one good hash and no bad ones'
62 if [ $HASHES_OK -eq 0 ] || [ $HASHES_BAD -ne 0 ]; then
63 cat >&2 "$DOWNLOADLOG"
64 msgfail
65 else
66 msgpass
67 fi
fd46d305
DK
68}
69
fd46d305
DK
70TESTFILE='aptarchive/testfile'
71cp -a ${TESTDIR}/framework $TESTFILE
92e8c1ff
DK
72cp -a ${TESTDIR}/framework "${TESTFILE}2"
73
74followuprequest() {
75 local DOWN='./testfile'
76
77 copysource $TESTFILE 1M $DOWN
78 testdownloadfile 'completely downloaded file' "${1}/testfile" "$DOWN" '='
79 testwebserverlaststatuscode '416' "$DOWNLOADLOG"
80
81 copysource $TESTFILE 1M $DOWN
82 copysource "${TESTFILE}2" 20 "${DOWN}2"
83 msgtest 'Testing download of files with' 'completely downloaded file + partial file'
84 testsuccess --nomsg apthelper -o Debug::Acquire::${1%%:*}=1 -o Debug::pkgAcquire::Worker=1 \
85 download-file "$1/testfile" "$DOWN" '' "$1/testfile2" "${DOWN}2"
86 testwebserverlaststatuscode '206' 'rootdir/tmp/testsuccess.output'
87 testsuccess diff -u "$TESTFILE" "${DOWN}"
88 testsuccess diff -u "${DOWN}" "${DOWN}2"
89}
fd46d305
DK
90
91testrun() {
f2c0ec8b 92 webserverconfig 'aptwebserver::support::range' 'true'
fd46d305
DK
93
94 copysource $TESTFILE 0 ./testfile
95 testdownloadfile 'no data' "${1}/testfile" './testfile' '='
0d58c26a 96 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305
DK
97
98 copysource $TESTFILE 20 ./testfile
99 testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
0d58c26a 100 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
fd46d305
DK
101
102 copysource /dev/zero 20 ./testfile
103 testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
0d58c26a 104 testwebserverlaststatuscode '206' "$DOWNLOADLOG"
fd46d305 105
92e8c1ff
DK
106 webserverconfig 'aptwebserver::closeOnError' 'false'
107 followuprequest "$1"
108 webserverconfig 'aptwebserver::closeOnError' 'true'
109 followuprequest "$1"
110 webserverconfig 'aptwebserver::closeOnError' 'false'
fd46d305
DK
111
112 copysource /dev/zero 1M ./testfile
113 testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
0d58c26a 114 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305
DK
115
116 copysource /dev/zero 20 ./testfile
117 touch ./testfile
118 testdownloadfile 'old data' "${1}/testfile" './testfile' '='
0d58c26a 119 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305 120
f2c0ec8b 121 webserverconfig 'aptwebserver::support::range' 'false'
fd46d305
DK
122
123 copysource $TESTFILE 20 ./testfile
124 testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
0d58c26a 125 testwebserverlaststatuscode '200' "$DOWNLOADLOG"
fd46d305
DK
126}
127
92e8c1ff
DK
128msgmsg 'http: Test with Content-Length'
129webserverconfig 'aptwebserver::chunked-transfer-encoding' 'false'
130testrun 'http://localhost:8080'
131msgmsg 'http: Test with Transfer-Encoding: chunked'
132webserverconfig 'aptwebserver::chunked-transfer-encoding' 'true'
fd46d305
DK
133testrun 'http://localhost:8080'
134
135changetohttpswebserver
136
92e8c1ff
DK
137msgmsg 'https: Test with Content-Length'
138webserverconfig 'aptwebserver::chunked-transfer-encoding' 'false'
139testrun 'https://localhost:4433'
140msgmsg 'https: Test with Transfer-Encoding: chunked'
141webserverconfig 'aptwebserver::chunked-transfer-encoding' 'true'
fd46d305 142testrun 'https://localhost:4433'