Mercurial > hg > nginx-tests
annotate range.t @ 671:0c70eb166a3a
Tests: in HTTP/2 tests, always access a dynamic table by reference.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 02 Sep 2015 13:57:46 +0300 |
parents | dc2f8aac0553 |
children | e9064d691790 |
rev | line source |
---|---|
33 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for range filter module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
13 | |
14 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
15 | |
16 use lib 'lib'; | |
17 use Test::Nginx; | |
18 | |
19 ############################################################################### | |
20 | |
21 select STDERR; $| = 1; | |
22 select STDOUT; $| = 1; | |
23 | |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http charset/)->plan(41); |
33 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
179
diff
changeset
|
30 daemon off; |
33 | 31 |
32 events { | |
33 } | |
34 | |
35 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
35
7bf0e8a1d66c
Tests: always define temp paths.
Maxim Dounin <mdounin@mdounin.ru>
parents:
33
diff
changeset
|
37 |
33 | 38 charset_map B A { |
39 58 59; # X -> Y | |
40 } | |
41 | |
42 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
35
diff
changeset
|
43 listen 127.0.0.1:8080; |
33 | 44 server_name localhost; |
45 | |
46 location /t2.html { | |
47 charset A; | |
48 source_charset B; | |
49 } | |
344
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
50 |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
51 location /t3.html { |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
52 max_ranges 2; |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
53 } |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
54 |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
55 location /t4.html { |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
56 max_ranges 0; |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
57 } |
33 | 58 } |
59 } | |
60 | |
61 EOF | |
62 | |
63 $t->write_file('t1.html', | |
64 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
65 $t->write_file('t2.html', | |
66 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); | |
344
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
67 $t->write_file('t3.html', |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
68 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
69 $t->write_file('t4.html', |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
70 join('', map { sprintf "X%03dXXXXXX", $_ } (0 .. 99))); |
33 | 71 $t->run(); |
72 | |
73 ############################################################################### | |
74 | |
75 my $t1; | |
76 | |
77 $t1 = http_get_range('/t1.html', 'Range: bytes=0-8'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
78 like($t1, qr/ 206 /, 'range request - 206 partial reply'); |
33 | 79 like($t1, qr/Content-Length: 9/, 'range request - correct length'); |
80 like($t1, qr/Content-Range: bytes 0-8\/1000/, 'range request - content range'); | |
81 like($t1, qr/^X000XXXXX$/m, 'range request - correct content'); | |
82 | |
83 $t1 = http_get_range('/t1.html', 'Range: bytes=-10'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
84 like($t1, qr/ 206 /, 'final bytes - 206 partial reply'); |
33 | 85 like($t1, qr/Content-Length: 10/, 'final bytes - content length'); |
86 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
87 'final bytes - content range'); | |
88 like($t1, qr/^X099XXXXXX$/m, 'final bytes - correct content'); | |
89 | |
90 $t1 = http_get_range('/t1.html', 'Range: bytes=990-'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
91 like($t1, qr/ 206 /, 'final bytes explicit - 206 partial reply'); |
33 | 92 like($t1, qr/Content-Length: 10/, 'final bytes explicit - content length'); |
93 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
94 'final bytes explicit - content range'); | |
95 like($t1, qr/^X099XXXXXX$/m, 'final bytes explicit - correct content'); | |
96 | |
97 $t1 = http_get_range('/t1.html', 'Range: bytes=990-1990'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
98 like($t1, qr/ 206 /, 'more than length - 206 partial reply'); |
33 | 99 like($t1, qr/Content-Length: 10/, 'more than length - content length'); |
100 like($t1, qr/Content-Range: bytes 990-999\/1000/, | |
101 'more than length - content range'); | |
102 like($t1, qr/^X099XXXXXX$/m, 'more than length - correct content'); | |
103 | |
104 $t1 = http_get_range('/t2.html', 'Range: bytes=990-1990'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
105 like($t1, qr/ 206 /, 'recoded - 206 partial reply'); |
33 | 106 like($t1, qr/Content-Length: 10/, 'recoded - content length'); |
107 like($t1, qr/Content-Range: bytes 990-999\/1000/, 'recoded - content range'); | |
108 like($t1, qr/^Y099YYYYYY$/m, 'recoded - correct content'); | |
109 | |
110 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 10-19'); | |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
111 like($t1, qr/ 206 /, 'multipart - 206 partial reply'); |
33 | 112 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, |
113 'multipart - content type'); | |
114 like($t1, qr/X000XXXXXX/m, 'multipart - content 0-9'); | |
115 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart - content -10 aka 990-999'); | |
116 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart - content 10-19'); | |
117 | |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
118 $t1 = http_get_range('/t1.html', 'Range: bytes=0-9, -10, 100000-, 10-19'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
119 like($t1, qr/ 206 /, 'multipart big - 206 partial reply'); |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
120 like($t1, qr/Content-Type: multipart\/byteranges; boundary=/, |
590
dc2f8aac0553
Tests: whitespace fixes.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
491
diff
changeset
|
121 'multipart big - content type'); |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
122 like($t1, qr/X000XXXXXX/m, 'multipart big - content 0-9'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
123 like($t1, qr/^X099XXXXXX\x0d?$/m, 'multipart big - content -10 aka 990-999'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
124 like($t1, qr/X001XXXXXX\x0d?$/m, 'multipart big - content 10-19'); |
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
125 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
126 like(http_get_range('/t1.html', 'Range: bytes=100000-'), qr/ 416 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
127 'not satisfiable - too big first byte pos'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
128 like(http_get_range('/t1.html', 'Range: bytes=alpha'), qr/ 416 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
129 'not satisfiable - alpha in first byte pos'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
130 like(http_get_range('/t1.html', 'Range: bytes=10-alpha'), qr/ 416 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
131 'not satisfiable - alpha in last byte pos'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
132 like(http_get_range('/t1.html', 'Range: bytes=10'), qr/ 416 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
133 'not satisfiable - no hyphen'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
134 like(http_get_range('/t1.html', 'Range: bytes=10-11 12-'), qr/ 416 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
135 'not satisfiable - no comma'); |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
136 |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
137 # last-byte-pos is taken to be equal to one less than the current length |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
138 # of the entity-body in bytes -- rfc2616 sec 14.35. |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
139 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
140 like(http_get_range('/t1.html', 'Range: bytes=0-10001'), qr/ 206 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
141 'satisfiable - last byte pos adjusted'); |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
142 |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
143 # total size of all ranges is greater than source response size |
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
144 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
145 like(http_get_range('/t1.html', 'Range: bytes=0-10001, 0-0'), qr/ 200 /, |
345
8e8636a4fe61
Tests: more range filter tests for satisfiable ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
344
diff
changeset
|
146 'not satisfiable - malicious byte ranges'); |
170
c5696c97c735
Tests: range not satisfiable tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
147 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
148 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10'), qr/ 206 /, |
344
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
149 'max_ranges not reached'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
150 like(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10000-'), qr/ 206 /, |
344
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
151 'max_ranges not reached bad range'); |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
152 unlike(http_get_range('/t3.html', 'Range: bytes=0-9, -10, 10-19'), |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
153 qr/ 206 /, 'max_ranges reached'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
345
diff
changeset
|
154 unlike(http_get_range('/t4.html', 'Range: bytes=0-9'), qr/ 206 /, |
344
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
155 'max_ranges zero'); |
b6d566531746
Tests: tests for range filter bound with "max_ranges".
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
156 |
33 | 157 ############################################################################### |
158 | |
159 sub http_get_range { | |
160 my ($url, $extra) = @_; | |
161 return http(<<EOF); | |
162 GET $url HTTP/1.1 | |
163 Host: localhost | |
164 Connection: close | |
165 $extra | |
166 | |
167 EOF | |
168 } | |
169 | |
170 ############################################################################### |