Mercurial > hg > nginx-tests
annotate not_modified.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for not modified filter module. |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
446
37a46774e307
Tests: entity tags test for unsuccessful response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
419
diff
changeset
|
24 my $t = Test::Nginx->new()->has('http')->plan(15) |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
226
diff
changeset
|
29 daemon off; |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 listen 127.0.0.1:8080; |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location / { |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 if_modified_since before; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 EOF |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 $t->write_file('t', ''); |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 $t->run(); |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 ############################################################################### |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
55 like(http_get_ims('/t', 'Wed, 08 Jul 2037 22:53:52 GMT'), qr/ 304 /, |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 '0x7F000000'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
57 like(http_get_ims('/t', 'Tue, 19 Jan 2038 03:14:07 GMT'), qr/ 304 /, |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 '0x7FFFFFFF'); |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 SKIP: { |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 skip "only for 32-bit time_t", 2 if (gmtime(0xFFFFFFFF))[5] == 206; |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
63 like(http_get_ims('/t', 'Tue, 19 Jan 2038 03:14:08 GMT'), qr/ 200 /, |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 '0x7FFFFFFF + 1'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
65 like(http_get_ims('/t', 'Fri, 25 Feb 2174 09:42:23 GMT'), qr/ 200 /, |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 '0x17FFFFFFF'); |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
69 # If-Match, If-None-Match tests |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
70 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
71 my ($t1, $etag); |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
72 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
73 $t1 = http_get('/t'); |
416
5c25acbc870a
Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
74 $t1 =~ /ETag: (".*")/; |
5c25acbc870a
Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
75 $etag = $1; |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
76 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
77 like(http_get_inm('/t', $etag), qr/ 304 /, 'if-none-match'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
78 like(http_get_inm('/t', '"foo"'), qr/ 200 /, 'if-none-match fail'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
79 like(http_get_inm('/t', '"foo", "bar", ' . $etag . ' , "baz"'), qr/ 304 /, |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
80 'if-none-match with complex list'); |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
81 like(http_get_inm('/t', '*'), qr/ 304 /, 'if-none-match all'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
82 like(http_get_inm('/t', 'W/' . $etag), qr/ 304 /, 'if-none-match weak'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
83 like(http_get_im('/t', $etag), qr/ 200 /, 'if-match'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
84 like(http_get_im('/t', '"foo"'), qr/ 412 /, 'if-match fail'); |
416
5c25acbc870a
Tests: etags support is present in all supported branches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
85 like(http_get_im('/t', '"foo", "bar", ' . "\t" . $etag . ' , "baz"'), |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
86 qr/ 200 /, 'if-match with complex list'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
87 like(http_get_im('/t', '*'), qr/ 200 /, 'if-match all'); |
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
88 like(http_get_im('/t', 'W/' . $etag), qr/ 412 /, 'if-match weak fail'); |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
89 |
446
37a46774e307
Tests: entity tags test for unsuccessful response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
419
diff
changeset
|
90 # server MUST ignore precondition if its response wouldn't be 2xx or 412 |
37a46774e307
Tests: entity tags test for unsuccessful response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
419
diff
changeset
|
91 |
491
d5bf5942a8b2
Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents:
446
diff
changeset
|
92 like(http_get_im('/nx', '"foo"'), qr/ 404 /, 'if-match ignored with 404'); |
446
37a46774e307
Tests: entity tags test for unsuccessful response.
Sergey Kandaurov <pluknet@nginx.com>
parents:
419
diff
changeset
|
93 |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 ############################################################################### |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 sub http_get_ims { |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
97 my ($url, $ims) = @_; |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
98 return http(<<EOF); |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 GET $url HTTP/1.0 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 Host: localhost |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 If-Modified-Since: $ims |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 EOF |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 } |
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
226
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
106 sub http_get_inm { |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
107 my ($url, $inm) = @_; |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
108 return http(<<EOF); |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
109 GET $url HTTP/1.0 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
110 Host: localhost |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
111 If-None-Match: $inm |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
112 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
113 EOF |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
114 } |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
115 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
116 sub http_get_im { |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
117 my ($url, $inm) = @_; |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
118 return http(<<EOF); |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
119 GET $url HTTP/1.0 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
120 Host: localhost |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
121 If-Match: $inm |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
122 |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
123 EOF |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
124 } |
e7a01be387ad
Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
125 |
111
02838a17ba9a
Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 ############################################################################### |