Mercurial > hg > nginx-tests
annotate http_try_files.t @ 635:bc91b86a71ee
Tests: added test for try_files in regex location with alias.
It was broken by c985d90a8d1f.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 27 Jul 2015 13:01:41 +0300 |
parents | 907e89fba9c3 |
children | 68a95e3195f1 |
rev | line source |
---|---|
189 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for try_files 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 | |
635
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(9) |
189 | 25 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
224
diff
changeset
|
29 daemon off; |
189 | 30 |
31 events { | |
32 } | |
33 | |
34 http { | |
35 %%TEST_GLOBALS_HTTP%% | |
36 | |
37 server { | |
38 listen 127.0.0.1:8080; | |
39 server_name localhost; | |
40 | |
41 location / { | |
42 try_files $uri /fallback; | |
43 } | |
44 | |
45 location /nouri/ { | |
46 try_files $uri /fallback_nouri; | |
47 } | |
48 | |
214
35d050d7d5f1
Tests: add try_files test with short uri (ticket #152).
Maxim Dounin <mdounin@mdounin.ru>
parents:
189
diff
changeset
|
49 location /short/ { |
35d050d7d5f1
Tests: add try_files test with short uri (ticket #152).
Maxim Dounin <mdounin@mdounin.ru>
parents:
189
diff
changeset
|
50 try_files /short $uri =404; |
35d050d7d5f1
Tests: add try_files test with short uri (ticket #152).
Maxim Dounin <mdounin@mdounin.ru>
parents:
189
diff
changeset
|
51 } |
35d050d7d5f1
Tests: add try_files test with short uri (ticket #152).
Maxim Dounin <mdounin@mdounin.ru>
parents:
189
diff
changeset
|
52 |
523
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
53 location /file-file/ { |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
54 try_files /found.html =404; |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
55 } |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
56 |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
57 location /file-dir/ { |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
58 try_files /found.html/ =404; |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
59 } |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
60 |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
61 location /dir-dir/ { |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
62 try_files /directory/ =404; |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
63 } |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
64 |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
65 location /dir-file/ { |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
66 try_files /directory =404; |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
67 } |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
68 |
635
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
69 location ~ /alias_re.html { |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
70 alias %%TESTDIR%%/directory; |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
71 try_files $uri =404; |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
72 } |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
73 |
189 | 74 location /fallback { |
75 proxy_pass http://127.0.0.1:8081/fallback; | |
76 } | |
77 location /fallback_nouri { | |
78 proxy_pass http://127.0.0.1:8081; | |
79 } | |
80 } | |
81 | |
82 server { | |
83 listen 127.0.0.1:8081; | |
84 server_name localhost; | |
85 | |
86 location / { | |
87 add_header X-URI $request_uri; | |
88 return 204; | |
89 } | |
90 } | |
91 } | |
92 | |
93 EOF | |
94 | |
523
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
95 mkdir($t->testdir() . '/directory'); |
635
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
96 $t->write_file('directory/alias_re.html', 'SEE THIS'); |
189 | 97 $t->write_file('found.html', 'SEE THIS'); |
98 $t->run(); | |
99 | |
100 ############################################################################### | |
101 | |
102 like(http_get('/found.html'), qr!SEE THIS!, 'found'); | |
103 like(http_get('/uri/notfound'), qr!X-URI: /fallback!, 'not found uri'); | |
224
ba992cfdc606
Tests: remove TODO from tests which pass in 1.2.x.
Maxim Dounin <mdounin@mdounin.ru>
parents:
214
diff
changeset
|
104 like(http_get('/nouri/notfound'), qr!X-URI: /fallback!, 'not found nouri'); |
214
35d050d7d5f1
Tests: add try_files test with short uri (ticket #152).
Maxim Dounin <mdounin@mdounin.ru>
parents:
189
diff
changeset
|
105 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files'); |
189 | 106 |
523
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
107 like(http_get('/file-file/'), qr!SEE THIS!, 'file matches file'); |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
108 like(http_get('/file-dir/'), qr!404 Not!, 'file does not match dir'); |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
109 like(http_get('/dir-dir/'), qr!301 Moved Permanently!, 'dir matches dir'); |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
110 like(http_get('/dir-file/'), qr!404 Not!, 'dir does not match file'); |
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
111 |
635
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
112 SKIP: { |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
113 skip 'leaves coredump', 1 unless $ENV{TEST_NGINX_UNSAFE}; |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
114 |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
115 like(http_get('/alias_re.html'), qr!SEE THIS!, 'alias in regex location'); |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
116 |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
117 } |
bc91b86a71ee
Tests: added test for try_files in regex location with alias.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
118 |
189 | 119 ############################################################################### |