summaryrefslogtreecommitdiffstats
path: root/test/integration/test-http-if-range
blob: 462d731cfeadf681105c89bcc08cb0a748fcd1be (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
#!/bin/sh
set -e

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

changetowebserver

TESTFILE='aptarchive/testfile'
HTTPFILE="http://localhost:${APTHTTPPORT}/testfile"
DOWNFILE='./downloaded/testfile'
DOWNLOADLOG='rootdir/tmp/testdownloadfile.log'

testdownloadfile() {
	rm -f "$DOWNLOADLOG"
	msgtest "Testing download of file with" "$1"
	if ! downloadfile "$HTTPFILE" "$DOWNFILE" > "$DOWNLOADLOG"; then
		cat >&2 "$DOWNLOADLOG"
		msgfail
	else
		msgpass
	fi
}

nopartialfile() {
	rm -f "$DOWNFILE"
}
validpartialfile() {
	head -n 5 "$TESTFILE" > "$DOWNFILE"
	touch -d "$(stat --format '%y' "${TESTFILE}")" "$DOWNFILE"
}
badolderpartialfile() {
	head -n 5 "$TESTFILE" > "$DOWNFILE"
	touch -d "$(stat --format '%y' "${TESTFILE}") - 1sec" "$DOWNFILE"
}
badnewerpartialfile() {
	head -n 5 "$TESTFILE" > "$DOWNFILE"
	touch -d 'now + 1hour' "$DOWNFILE"
}
fullfile() {
	cp -a "$TESTFILE" "$DOWNFILE"
}

cp -a "${TESTDIR}/framework" "$TESTFILE"

testrun() {
	nopartialfile
	testdownloadfile "no file $1"
	testwebserverlaststatuscode "$2" "$DOWNLOADLOG"
	testsuccess cmp "$TESTFILE" "$DOWNFILE"

	validpartialfile
	testdownloadfile "good partial file $1"
	testwebserverlaststatuscode "$3" "$DOWNLOADLOG"
	testsuccess cmp "$TESTFILE" "$DOWNFILE"

	badolderpartialfile
	testdownloadfile "bad old partial file $1"
	testwebserverlaststatuscode "$4" "$DOWNLOADLOG"
	testsuccess cmp "$TESTFILE" "$DOWNFILE"

	badnewerpartialfile
	testdownloadfile "bad new partial file $1"
	testwebserverlaststatuscode "$4" "$DOWNLOADLOG"
	testsuccess cmp "$TESTFILE" "$DOWNFILE"

	fullfile
	testdownloadfile "complete file $1"
	testwebserverlaststatuscode "$5" "$DOWNLOADLOG"
	testsuccess cmp "$TESTFILE" "$DOWNFILE"
}

testrun 'defaults' '200' '206' '200' '416'

webserverconfig 'aptwebserver::support::range' 'false'
testrun 'no ranges' '200' '200' '200' '200'
webserverconfig 'aptwebserver::support::range' 'true'

webserverconfig 'aptwebserver::support::if-range' 'false'
# the second 206 is bad, but we are unable to detect this
testrun 'buggy server' '200' '206' '206' '416'
echo 'Acquire::http::localhost::AllowRanges "false";' > rootdir/etc/apt/apt.conf.d/noallowranges
testrun 'range disabled by conf' '200' '200' '200' '200'
rm rootdir/etc/apt/apt.conf.d/noallowranges
# detect varnish < 6.4 automatically
webserverconfig 'aptwebserver::response-header::Via' '1.1 varnish (Varnish/6.1)'
testrun 'bad varnish' '200' '200' '200' '200'
webserverconfig 'aptwebserver::response-header::Via' '1.1 varnish (Varnish/6.4)'
testrun 'good varnish' '200' '206' '206' '416'