comparison rewrite.t @ 141:1e1975cd25ef

Tests: error_page and return related tests, dav tests.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 02 Nov 2010 06:49:42 +0300
parents 8ac1faaddd2c
children d732aaa5f370
comparison
equal deleted inserted replaced
140:3f246a1be2b0 141:1e1975cd25ef
19 ############################################################################### 19 ###############################################################################
20 20
21 select STDERR; $| = 1; 21 select STDERR; $| = 1;
22 select STDOUT; $| = 1; 22 select STDOUT; $| = 1;
23 23
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(5) 24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(17)
25 ->write_file_expand('nginx.conf', <<'EOF'); 25 ->write_file_expand('nginx.conf', <<'EOF');
26 26
27 %%TEST_GLOBALS%% 27 %%TEST_GLOBALS%%
28 28
29 master_process off; 29 master_process off;
48 } 48 }
49 49
50 location /no { 50 location /no {
51 rewrite ^ http://example.com/?c=d? redirect; 51 rewrite ^ http://example.com/?c=d? redirect;
52 } 52 }
53
54 location /return204 {
55 return 204;
56 }
57
58 location /return200 {
59 return 200;
60 }
61
62 location /error405return204 {
63 error_page 405 /return204;
64 return 405;
65 }
66
67 location /error405return200 {
68 error_page 405 /return200;
69 return 405;
70 }
71
72 location /file.html {
73 }
74
75 location /return200text {
76 return 200 "text";
77 }
78
79 location /return404text {
80 return 404 "text";
81 }
82
83 location /return302text {
84 return 302 "text";
85 }
86
87 location /error405return200text {
88 error_page 405 /return200text;
89 return 405;
90 }
91
92 location /error302return200text {
93 error_page 302 /return200text;
94 return 302 "text";
95 }
96
97 location /error405return302text {
98 error_page 405 /return302text;
99 return 405;
100 }
101
102 location /error405rewrite {
103 error_page 405 /;
104 return 405;
105 }
106
107 location /error405directory {
108 error_page 405 /directory;
109 return 405;
110 }
111
112 location /directory {
113 }
53 } 114 }
54 } 115 }
55 116
56 EOF 117 EOF
118
119 mkdir($t->testdir() . '/directory');
57 120
58 $t->run(); 121 $t->run();
59 122
60 ############################################################################### 123 ###############################################################################
61 124
69 'add args with args'); 132 'add args with args');
70 133
71 like(http_get('/no?a=b'), qr!^Location: http://example.com/\?c=d\x0d?$!ms, 134 like(http_get('/no?a=b'), qr!^Location: http://example.com/\?c=d\x0d?$!ms,
72 'no args with args'); 135 'no args with args');
73 136
74 ############################################################################### 137 like(http_get('/return204'), qr!204 No Content!, 'return 204');
138 like(http_get('/return200'), qr!200 OK!, 'return 200');
139
140 TODO: {
141 local $TODO = 'not yet';
142
143 # status code should be 405, and entity body is expected (vs. normal 204
144 # replies which doesn't expect to have body); use HTTP/1.1 for test
145 # to make problem clear
146
147 my $r = http(<<EOF);
148 GET /error405return204 HTTP/1.1
149 Host: localhost
150 Connection: close
151
152 EOF
153
154 like($r, qr/HTTP\/1.1 405.*(Content-Length|\x0d\0a0\x0d\x0a)/ms,
155 'error 405 return 204');
156
157 # the same test, but with return 200. this doesn't have special
158 # handling and returns builtin error page body (the same problem as
159 # in /error405return200text below)
160
161 like(http_get('/error405return200'), qr/HTTP\/1.1 405(?!.*body)/ms,
162 'error 405 return 200');
163
164 }
165
166 # tests involving return with two arguments, as introduced in
167 # 0.8.42
168
169 like(http_get('/return200text'), qr!text\z!, 'return 200 text');
170 like(http_get('/return404text'), qr!text\z!, 'return 404 text');
171
172 TODO: {
173 local $TODO = 'not yet';
174
175 like(http_get('/error405return200text'), qr!HTTP/1.1 405.*text\z!ms,
176 'error 405 to return 200 text');
177
178 }
179
180 # return 302 is somewhat special: it adds Location header instead of
181 # body text. additionally it doesn't sent reply directly (as it's done for
182 # other returns since 0.8.42) but instead returns NGX_HTTP_* code
183
184 like(http_get('/return302text'), qr!HTTP/1.1 302.*Location: text!ms,
185 'return 302 text');
186
187 TODO: {
188 local $TODO = 'not yet';
189
190 like(http_get('/error302return200text'),
191 qr!HTTP/1.1 302.*Location: text.*text\z!ms,
192 'error 302 return 200 text');
193
194 }
195
196 TODO: {
197 local $TODO = 'not yet';
198
199 # in contrast to other return's this shouldn't preserve original status code
200 # from error, and the same applies to "rewrite ... redirect" as an error
201 # handler; both should in line with e.g. directory redirect as well
202
203 like(http_get('/error405return302text'),
204 qr!HTTP/1.1 302.*Location: text!ms,
205 'error 405 return 302 text');
206
207 like(http_get('/error405rewrite'),
208 qr!HTTP/1.1 302.*Location: http://example.com/!ms,
209 'error 405 rewrite redirect');
210
211 }
212
213 like(http_get('/error405directory'),
214 qr!HTTP/1.1 301.*Location: http://!ms,
215 'error 405 directory redirect');
216
217 ###############################################################################