]> git.saurik.com Git - apt.git/blame - test/integration/test-partial-file-support
Fix conffile prompt regression (LP: #1260297)
[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
16testdownloadfile() {
17 local DOWNLOG='download-testfile.log'
18 rm -f "$DOWNLOG"
19 msgtest "Testing download of file $2 with" "$1"
20 if ! downloadfile "$2" "$3" > "$DOWNLOG"; then
23af9f40 21 cat >&2 "$DOWNLOG"
fd46d305
DK
22 msgfail
23 else
24 msgpass
25 fi
26 cat "$DOWNLOG" | while read field hash; do
27 local EXPECTED
28 case "$field" in
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)";;
33 *) continue;;
34 esac
35 if [ "$4" = '=' ]; then
36 msgtest 'Test downloaded file for correct' "$field"
37 else
38 msgtest 'Test downloaded file does not match in' "$field"
39 fi
40 if [ "$EXPECTED" "$4" "$hash" ]; then
41 msgpass
42 else
23af9f40 43 cat >&2 "$DOWNLOG"
fd46d305
DK
44 msgfail "expected: $EXPECTED ; got: $hash"
45 fi
46 done
47}
48
49testwebserverlaststatuscode() {
23af9f40
DK
50 local DOWNLOG='download-testfile.log'
51 rm -f "$DOWNLOG"
52 local STATUS="$(mktemp)"
fd46d305
DK
53 addtrap "rm $STATUS;"
54 msgtest 'Test last status code from the webserver was' "$1"
23af9f40 55 downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG"
fd46d305
DK
56 if [ "$(cat "$STATUS")" = "$1" ]; then
57 msgpass
58 else
23af9f40 59 cat >&2 "$DOWNLOG"
fd46d305
DK
60 msgfail "Status was $(cat "$STATUS")"
61 fi
62}
63
64
65TESTFILE='aptarchive/testfile'
66cp -a ${TESTDIR}/framework $TESTFILE
67
68testrun() {
f2c0ec8b 69 webserverconfig 'aptwebserver::support::range' 'true'
fd46d305
DK
70
71 copysource $TESTFILE 0 ./testfile
72 testdownloadfile 'no data' "${1}/testfile" './testfile' '='
73 testwebserverlaststatuscode '200'
74
75 copysource $TESTFILE 20 ./testfile
76 testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
77 testwebserverlaststatuscode '206'
78
79 copysource /dev/zero 20 ./testfile
80 testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
81 testwebserverlaststatuscode '206'
82
83 copysource $TESTFILE 1M ./testfile
84 testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
85 testwebserverlaststatuscode '416'
86
87 copysource /dev/zero 1M ./testfile
88 testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
89 testwebserverlaststatuscode '200'
90
91 copysource /dev/zero 20 ./testfile
92 touch ./testfile
93 testdownloadfile 'old data' "${1}/testfile" './testfile' '='
94 testwebserverlaststatuscode '200'
95
f2c0ec8b 96 webserverconfig 'aptwebserver::support::range' 'false'
fd46d305
DK
97
98 copysource $TESTFILE 20 ./testfile
99 testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
100 testwebserverlaststatuscode '200'
101}
102
103testrun 'http://localhost:8080'
104
105changetohttpswebserver
106
107testrun 'https://localhost:4433'