4 TESTDIR
=$(readlink -f $(dirname $0))
7 configarchitecture
'amd64'
12 dd if="$1" bs
=1 count
="$2" of
="$3" 2>/dev
/null
13 touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
16 DOWNLOADLOG
='rootdir/tmp/testdownloadfile.log'
20 msgtest
"Testing download of file $2 with" "$1"
21 if ! downloadfile
"$2" "$3" > "$DOWNLOADLOG"; then
22 cat >&2 "$DOWNLOADLOG"
27 sed -e '/^ <- / s#%20# #g' -e '/^ <- / s#%0a#\n#g' "$DOWNLOADLOG" | grep '^.*-Hash: ' > receivedhashes.log
28 testsuccess
test -s receivedhashes.log
31 while read field
hash; do
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)";;
38 'Checksum-FileSize-Hash:')
39 #filesize is too weak to check for !=
40 if [ "$4" = '=' ]; then
41 EXPECTED
="$(stat -c '%s' "$TESTFILE")"
48 if [ "$4" = '=' ]; then
49 msgtest
'Test downloaded file for correct' "$field"
51 msgtest
'Test downloaded file does not match in' "$field"
53 if [ "$EXPECTED" "$4" "$hash" ]; then
55 HASHES_OK
=$((HASHES_OK+1));
57 msgfail
"expected: $EXPECTED ; got: $hash"
58 HASHES_BAD
=$((HASHES_BAD+1));
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"
70 TESTFILE
='aptarchive/testfile'
71 cp -a ${TESTDIR}/framework
$TESTFILE
72 cp -a ${TESTDIR}/framework
"${TESTFILE}2"
75 local DOWN
='./testfile'
77 copysource
$TESTFILE 1M
$DOWN
78 testdownloadfile
'completely downloaded file' "${1}/testfile" "$DOWN" '='
79 testwebserverlaststatuscode
'416' "$DOWNLOADLOG"
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"
92 webserverconfig
'aptwebserver::support::range' 'true'
94 copysource
$TESTFILE 0 .
/testfile
95 testdownloadfile
'no data' "${1}/testfile" './testfile' '='
96 testwebserverlaststatuscode
'200' "$DOWNLOADLOG"
98 copysource
$TESTFILE 20 .
/testfile
99 testdownloadfile
'valid partial data' "${1}/testfile" './testfile' '='
100 testwebserverlaststatuscode
'206' "$DOWNLOADLOG"
102 copysource
/dev
/zero
20 .
/testfile
103 testdownloadfile
'invalid partial data' "${1}/testfile" './testfile' '!='
104 testwebserverlaststatuscode
'206' "$DOWNLOADLOG"
106 webserverconfig
'aptwebserver::closeOnError' 'false'
108 webserverconfig
'aptwebserver::closeOnError' 'true'
110 webserverconfig
'aptwebserver::closeOnError' 'false'
112 copysource
/dev
/zero
1M .
/testfile
113 testdownloadfile
'too-big partial file' "${1}/testfile" './testfile' '='
114 testwebserverlaststatuscode
'200' "$DOWNLOADLOG"
116 copysource
/dev
/zero
20 .
/testfile
118 testdownloadfile
'old data' "${1}/testfile" './testfile' '='
119 testwebserverlaststatuscode
'200' "$DOWNLOADLOG"
121 webserverconfig
'aptwebserver::support::range' 'false'
123 copysource
$TESTFILE 20 .
/testfile
124 testdownloadfile
'no server support' "${1}/testfile" './testfile' '='
125 testwebserverlaststatuscode
'200' "$DOWNLOADLOG"
128 msgmsg
'http: Test with Content-Length'
129 webserverconfig
'aptwebserver::chunked-transfer-encoding' 'false'
130 testrun
'http://localhost:8080'
131 msgmsg
'http: Test with Transfer-Encoding: chunked'
132 webserverconfig
'aptwebserver::chunked-transfer-encoding' 'true'
133 testrun
'http://localhost:8080'
135 changetohttpswebserver
137 msgmsg
'https: Test with Content-Length'
138 webserverconfig
'aptwebserver::chunked-transfer-encoding' 'false'
139 testrun
'https://localhost:4433'
140 msgmsg
'https: Test with Transfer-Encoding: chunked'
141 webserverconfig
'aptwebserver::chunked-transfer-encoding' 'true'
142 testrun
'https://localhost:4433'