annotate not_modified.t @ 540:481d705b8610

Tests: SSL support in mail backends. Socket is now embedded into every mail module. Socket methods are wrapped where appropriate. The new "SSL" extra flag specifies to accept connection over SSL.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 03 Apr 2015 00:11:38 +0300
parents d5bf5942a8b2
children 907e89fba9c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 {
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
38 listen 127.0.0.1:8080;
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');
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
82
417
1bdd58f388f6 Tests: weak etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 416
diff changeset
83 TODO: {
419
f5f2a66853a9 Tests: adjust entity tag TODOs.
Maxim Dounin <mdounin@mdounin.ru>
parents: 417
diff changeset
84 local $TODO = 'not yet' unless $t->has_version('1.7.3');
417
1bdd58f388f6 Tests: weak etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 416
diff changeset
85
491
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 446
diff changeset
86 like(http_get_inm('/t', 'W/' . $etag), qr/ 304 /, 'if-none-match weak');
417
1bdd58f388f6 Tests: weak etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 416
diff changeset
87
1bdd58f388f6 Tests: weak etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 416
diff changeset
88 }
1bdd58f388f6 Tests: weak etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 416
diff changeset
89
491
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 446
diff changeset
90 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
91 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
92 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
93 qr/ 200 /, 'if-match with complex list');
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 446
diff changeset
94 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
95 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
96
446
37a46774e307 Tests: entity tags test for unsuccessful response.
Sergey Kandaurov <pluknet@nginx.com>
parents: 419
diff changeset
97 # 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
98
491
d5bf5942a8b2 Tests: disambiguated parsing of the status code.
Sergey Kandaurov <pluknet@nginx.com>
parents: 446
diff changeset
99 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
100
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
101 ###############################################################################
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 sub http_get_ims {
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
104 my ($url, $ims) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
105 return http(<<EOF);
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
106 GET $url HTTP/1.0
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
107 Host: localhost
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
108 If-Modified-Since: $ims
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
109
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
110 EOF
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
111 }
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
112
226
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
113 sub http_get_inm {
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
114 my ($url, $inm) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
115 return http(<<EOF);
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
116 GET $url HTTP/1.0
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
117 Host: localhost
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
118 If-None-Match: $inm
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
119
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
120 EOF
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
121 }
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 sub http_get_im {
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
124 my ($url, $inm) = @_;
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
125 return http(<<EOF);
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
126 GET $url HTTP/1.0
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
127 Host: localhost
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
128 If-Match: $inm
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
129
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
130 EOF
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
131 }
e7a01be387ad Tests: added some etag tests.
Maxim Dounin <mdounin@mdounin.ru>
parents: 166
diff changeset
132
111
02838a17ba9a Tests: add not modified filter (parse time, actually) tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
133 ###############################################################################