comparison http-error-page.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
children fd865ada95c8
comparison
equal deleted inserted replaced
140:3f246a1be2b0 141:1e1975cd25ef
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Tests for error_page directive.
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
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(7)
25 ->write_file_expand('nginx.conf', <<'EOF');
26
27 %%TEST_GLOBALS%%
28
29 master_process off;
30 daemon off;
31
32 events {
33 }
34
35 http {
36 %%TEST_GLOBALS_HTTP%%
37
38 server {
39 listen 127.0.0.1:8080;
40 server_name localhost;
41
42 location /redirect200 {
43 error_page 404 =200 http://example.com/;
44 return 404;
45 }
46
47 location /redirect497 {
48 # 497 implies implicit status code change
49 error_page 497 https://example.com/;
50 return 497;
51 }
52
53 location /error302redirect {
54 error_page 302 http://example.com/;
55 return 302 "first";
56 }
57
58 location /error302return302text {
59 error_page 302 /return302text;
60 return 302 "first";
61 }
62
63 location /return302text {
64 return 302 "http://example.com/";
65 }
66
67 location /error302rewrite {
68 error_page 302 /rewrite;
69 return 302 "first";
70 }
71
72 location /rewrite {
73 rewrite ^ http://example.com/;
74 }
75
76 location /error302directory {
77 error_page 302 /directory;
78 return 302 "first";
79 }
80
81 location /directory {
82 }
83
84 location /error302auto {
85 error_page 302 /auto;
86 return 302 "first";
87 }
88
89 location /auto/ {
90 proxy_pass http://127.0.0.1:8081;
91 }
92 }
93 }
94
95 EOF
96
97 mkdir($t->testdir() . '/directory');
98
99 $t->run();
100
101 ###############################################################################
102
103 TODO: {
104 local $TODO = 'not yet';
105
106 # tests for error_page status code change for redirects. problems
107 # introduced in 0.8.53.
108
109 like(http_get('/redirect200'), qr!HTTP!, 'redirect 200');
110 like(http_get('/redirect497'), qr!HTTP/1.1 302!, 'redirect 497');
111
112 # various tests to see if old location cleared if we happen to redirect
113 # again in error_page 302
114
115 like(http_get('/error302redirect'),
116 qr{HTTP/1.1 302(?!.*Location: first).*Location: http://example.com/}ms,
117 'error 302 redirect - old location cleared');
118
119 like(http_get('/error302return302text'),
120 qr{HTTP/1.1 302(?!.*Location: first).*Location: http://example.com/}ms,
121 'error 302 return 302 text - old location cleared');
122
123 like(http_get('/error302rewrite'),
124 qr{HTTP/1.1 302(?!.*Location: first).*Location: http://example.com/}ms,
125 'error 302 rewrite - old location cleared');
126
127 like(http_get('/error302directory'),
128 qr{HTTP/1.1 301(?!.*Location: first).*Location: http://}ms,
129 'error 302 directory redirect - old location cleared');
130
131 like(http_get('/error302auto'),
132 qr{HTTP/1.1 301(?!.*Location: first).*Location: http://}ms,
133 'error 302 auto redirect - old location cleared');
134
135 }
136
137 ###############################################################################