1: #!/usr/bin/env perl
2: BEGIN {
3: # add current source dir to the include-path
4: # we need this for make distcheck
5: (my $srcdir = $0) =~ s,/[^/]+$,/,;
6: unshift @INC, $srcdir;
7: }
8:
9: use strict;
10: use IO::Socket;
11: use Test::More tests => 25;
12: use LightyTest;
13:
14: my $tf = LightyTest->new();
15: my $t;
16:
17: $tf->{CONFIGFILE} = 'lighttpd.conf';
18:
19: ok($tf->start_proc == 0, "Starting lighttpd") or die();
20:
21: ## check if If-Modified-Since, If-None-Match works
22:
23: $t->{REQUEST} = ( <<EOF
24: GET / HTTP/1.0
25: If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
26: EOF
27: );
28: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
29: ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since');
30:
31: $t->{REQUEST} = ( <<EOF
32: GET / HTTP/1.0
33: If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
34: EOF
35: );
36: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Last-Modified' => ''} ];
37: ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since, comment');
38:
39: my $now = $t->{date};
40:
41: $t->{REQUEST} = ( <<EOF
42: GET / HTTP/1.0
43: If-Modified-Since: $now
44: EOF
45: );
46: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
47: ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since');
48:
49: $t->{REQUEST} = ( <<EOF
50: GET / HTTP/1.0
51: If-Modified-Since: $now; foo
52: EOF
53: );
54: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
55: ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since, comment');
56:
57: $t->{REQUEST} = ( <<EOF
58: GET / HTTP/1.0
59: If-None-Match: foo
60: EOF
61: );
62: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => ''} ];
63: ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
64:
65: my $etag = $t->{etag};
66:
67: $t->{REQUEST} = ( <<EOF
68: GET / HTTP/1.0
69: If-None-Match: $etag
70: EOF
71: );
72: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
73: ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
74:
75: $t->{REQUEST} = ( <<EOF
76: GET / HTTP/1.0
77: If-None-Match: $etag
78: If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
79: EOF
80: );
81: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
82: ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + old Last-Modified (which should be ignored)');
83:
84: $t->{REQUEST} = ( <<EOF
85: GET / HTTP/1.0
86: If-None-Match: $etag
87: If-Modified-Since: $now; foo
88: EOF
89: );
90: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
91: ok($tf->handle_http($t) == 0, 'Conditional GET - ETag, Last-Modified + comment (which should be ignored)');
92:
93: $t->{REQUEST} = ( <<EOF
94: GET / HTTP/1.0
95: If-None-Match: Foo
96: If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
97: EOF
98: );
99: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
100: ok($tf->handle_http($t) == 0, 'Conditional GET - old ETAG + old Last-Modified');
101:
102: $t->{REQUEST} = ( <<EOF
103: GET / HTTP/1.0
104: If-None-Match: $etag
105: If-Modified-Since: $now foo
106: EOF
107: );
108: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
109: ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + Last-Modified + overlong timestamp (which should be ignored)');
110:
111: $t->{REQUEST} = ( <<EOF
112: GET / HTTP/1.0
113: If-None-Match: $etag
114: Host: etag.example.org
115: EOF
116: );
117: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
118: ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + disabled etags on server side');
119:
120: ###############
121:
122: ok($etag =~ /^\"(.*)\"$/, "The server must quote ETags");
123:
124: $t->{REQUEST} = ( <<EOF
125: GET / HTTP/1.0
126: If-None-Match: $1
127: EOF
128: );
129: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
130: ok($tf->handle_http($t) == 0, 'The client must send a quoted ETag');
131:
132: $etag =~ /^(\".*)\"$/;
133: $t->{REQUEST} = ( <<EOF
134: GET / HTTP/1.0
135: If-None-Match: $1
136: EOF
137: );
138: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
139: ok($tf->handle_http($t) == 0, 'The ETag must be surrounded by quotes');
140:
141: $t->{REQUEST} = ( <<EOF
142: GET / HTTP/1.0
143: If-None-Match: *
144: EOF
145: );
146: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
147: ok($tf->handle_http($t) == 0, 'An unquoted star matches any ETag');
148:
149: $t->{REQUEST} = ( <<EOF
150: GET / HTTP/1.0
151: If-None-Match: "*"
152: EOF
153: );
154: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
155: ok($tf->handle_http($t) == 0, 'A quoted star is just a regular ETag');
156:
157: TODO: {
158: local $TODO = "weak etags not allowed yet";
159: $t->{REQUEST} = ( <<EOF
160: GET / HTTP/1.0
161: If-None-Match: W/$etag
162: EOF
163: );
164: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
165: ok($tf->handle_http($t) == 0, 'A weak etag matches like a regular ETag for HEAD and GET');
166: }
167:
168: $t->{REQUEST} = ( <<EOF
169: GET / HTTP/1.0
170: If-None-Match: W/$etag
171: Range: bytes=0-0
172: EOF
173: );
174: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '<' } ];
175: ok($tf->handle_http($t) == 0, 'A weak etag does not match for ranged requests');
176:
177: $t->{REQUEST} = ( <<EOF
178: GET / HTTP/1.0
179: If-None-Match: W/"12345"
180: EOF
181: );
182: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
183: ok($tf->handle_http($t) == 0, 'However, a weak ETag is not *');
184:
185: $t->{REQUEST} = ( <<EOF
186: GET / HTTP/1.0
187: If-None-Match: "12345", $etag
188: EOF
189: );
190: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
191: ok($tf->handle_http($t) == 0, 'Client sent a list of ETags, the second matches');
192:
193: TODO: {
194: local $TODO = "weak etags not allowed yet";
195: $t->{REQUEST} = ( <<EOF
196: GET / HTTP/1.0
197: If-None-Match: "12345", W/$etag
198: EOF
199: );
200: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
201: ok($tf->handle_http($t) == 0, 'The second provided ETag matches weakly');
202: }
203:
204: $t->{REQUEST} = ( <<EOF
205: GET / HTTP/1.0
206: If-None-Match: "12345",, ,, , $etag
207: EOF
208: );
209: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
210: ok($tf->handle_http($t) == 0, 'Broken client did get around to sending good data');
211:
212: $t->{REQUEST} = ( <<EOF
213: GET / HTTP/1.0
214: If-None-Match: "1234", $etag, "brokentrailing
215: EOF
216: );
217: $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
218: ok($tf->handle_http($t) == 0, 'Bad syntax *after* a matching ETag doesn\'t matter');
219:
220: ok($tf->stop_proc == 0, "Stopping lighttpd");
221:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>