Mercurial > hg > nginx-tests
annotate http_try_files.t @ 431:05c46688b54b
Tests: ssl_password_file.t fixes.
Make sure to always specify listen socket in all servers as the
default vary (under root, nginx will try to listen on 80). Make sure
to detect if an https request was processed by http.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 09 Jul 2014 05:19:51 +0400 |
parents | 25f2ba615000 |
children | 64eabe6aa1f2 |
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 | |
310
25f2ba615000
Tests: added missing proxy prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4) |
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 |
189 | 53 location /fallback { |
54 proxy_pass http://127.0.0.1:8081/fallback; | |
55 } | |
56 location /fallback_nouri { | |
57 proxy_pass http://127.0.0.1:8081; | |
58 } | |
59 } | |
60 | |
61 server { | |
62 listen 127.0.0.1:8081; | |
63 server_name localhost; | |
64 | |
65 location / { | |
66 add_header X-URI $request_uri; | |
67 return 204; | |
68 } | |
69 } | |
70 } | |
71 | |
72 EOF | |
73 | |
74 $t->write_file('found.html', 'SEE THIS'); | |
75 $t->run(); | |
76 | |
77 ############################################################################### | |
78 | |
79 like(http_get('/found.html'), qr!SEE THIS!, 'found'); | |
80 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
|
81 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
|
82 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files'); |
189 | 83 |
84 ############################################################################### |