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"
17 local DOWNLOG
='download-testfile.log'
19 msgtest
"Testing download of file $2 with" "$1"
20 if ! downloadfile
"$2" "$3" > "$DOWNLOG"; then
26 cat "$DOWNLOG" | while read field
hash; do
29 'MD5Sum-Hash:') EXPECTED
="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
30 'SHA1-Hash:') EXPECTED
="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
31 'SHA256-Hash:') EXPECTED
="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
32 'SHA512-Hash:') EXPECTED
="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
35 if [ "$4" = '=' ]; then
36 msgtest
'Test downloaded file for correct' "$field"
38 msgtest
'Test downloaded file does not match in' "$field"
40 if [ "$EXPECTED" "$4" "$hash" ]; then
44 msgfail
"expected: $EXPECTED ; got: $hash"
49 testwebserverlaststatuscode
() {
50 local DOWNLOG
='download-testfile.log'
52 local STATUS
="$(mktemp)"
54 msgtest
'Test last status code from the webserver was' "$1"
55 downloadfile
"http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
56 if [ "$(cat "$STATUS")" = "$1" ]; then
60 msgfail
"Status was $(cat "$STATUS")"
65 TESTFILE
='aptarchive/testfile'
66 cp -a ${TESTDIR}/framework
$TESTFILE
69 webserverconfig
'aptwebserver::support::range' 'true'
71 copysource
$TESTFILE 0 .
/testfile
72 testdownloadfile
'no data' "${1}/testfile" './testfile' '='
73 testwebserverlaststatuscode
'200'
75 copysource
$TESTFILE 20 .
/testfile
76 testdownloadfile
'valid partial data' "${1}/testfile" './testfile' '='
77 testwebserverlaststatuscode
'206'
79 copysource
/dev
/zero
20 .
/testfile
80 testdownloadfile
'invalid partial data' "${1}/testfile" './testfile' '!='
81 testwebserverlaststatuscode
'206'
83 copysource
$TESTFILE 1M .
/testfile
84 testdownloadfile
'completely downloaded file' "${1}/testfile" './testfile' '='
85 testwebserverlaststatuscode
'416'
87 copysource
/dev
/zero
1M .
/testfile
88 testdownloadfile
'too-big partial file' "${1}/testfile" './testfile' '='
89 testwebserverlaststatuscode
'200'
91 copysource
/dev
/zero
20 .
/testfile
93 testdownloadfile
'old data' "${1}/testfile" './testfile' '='
94 testwebserverlaststatuscode
'200'
96 webserverconfig
'aptwebserver::support::range' 'false'
98 copysource
$TESTFILE 20 .
/testfile
99 testdownloadfile
'no server support' "${1}/testfile" './testfile' '='
100 testwebserverlaststatuscode
'200'
103 testrun
'http://localhost:8080'
105 changetohttpswebserver
107 testrun
'https://localhost:4433'