summaryrefslogtreecommitdiff
path: root/test/integration/test-partial-file-support
blob: 5ab326defce3efaa056e8c0fe136245c6b54bb59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/sh
set -e

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework
setupenvironment
configarchitecture 'amd64'

changetowebserver

copysource() {
	dd if="$1" bs=1 count="$2" of="$3" 2>/dev/null
	touch -d "$(stat --format '%y' "${TESTFILE}")" "$3"
}

DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'

testdownloadfile() {
	rm -f "$DOWNLOADLOG"
	msgtest "Testing download of file $2 with" "$1"
	if ! downloadfile "$2" "$3" > "$DOWNLOADLOG"; then
		cat >&2 "$DOWNLOADLOG"
		msgfail
	else
		msgpass
	fi
	cat "$DOWNLOADLOG" | while read field hash; do
		local EXPECTED
		case "$field" in
		'MD5Sum-Hash:') EXPECTED="$(md5sum "$TESTFILE" | cut -d' ' -f 1)";;
		'SHA1-Hash:') EXPECTED="$(sha1sum "$TESTFILE" | cut -d' ' -f 1)";;
		'SHA256-Hash:') EXPECTED="$(sha256sum "$TESTFILE" | cut -d' ' -f 1)";;
		'SHA512-Hash:') EXPECTED="$(sha512sum "$TESTFILE" | cut -d' ' -f 1)";;
		*) continue;;
		esac
		if [ "$4" = '=' ]; then
			msgtest 'Test downloaded file for correct' "$field"
		else
			msgtest 'Test downloaded file does not match in' "$field"
		fi
		if [ "$EXPECTED" "$4" "$hash" ]; then
			msgpass
		else
			cat >&2 "$DOWNLOADLOG"
			msgfail "expected: $EXPECTED ; got: $hash"
		fi
	done
}

TESTFILE='aptarchive/testfile'
cp -a ${TESTDIR}/framework $TESTFILE

testrun() {
	webserverconfig 'aptwebserver::support::range' 'true'

	copysource $TESTFILE 0 ./testfile
	testdownloadfile 'no data' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '200' "$DOWNLOADLOG"

	copysource $TESTFILE 20 ./testfile
	testdownloadfile 'valid partial data' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '206' "$DOWNLOADLOG"

	copysource /dev/zero 20 ./testfile
	testdownloadfile 'invalid partial data' "${1}/testfile" './testfile' '!='
	testwebserverlaststatuscode '206' "$DOWNLOADLOG"

	copysource $TESTFILE 1M ./testfile
	testdownloadfile 'completely downloaded file' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '416' "$DOWNLOADLOG"

	copysource /dev/zero 1M ./testfile
	testdownloadfile 'too-big partial file' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '200' "$DOWNLOADLOG"

	copysource /dev/zero 20 ./testfile
	touch ./testfile
	testdownloadfile 'old data' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '200' "$DOWNLOADLOG"

	webserverconfig 'aptwebserver::support::range' 'false'

	copysource $TESTFILE 20 ./testfile
	testdownloadfile 'no server support' "${1}/testfile" './testfile' '='
	testwebserverlaststatuscode '200' "$DOWNLOADLOG"
}

testrun 'http://localhost:8080'

changetohttpswebserver

testrun 'https://localhost:4433'