Mercurial > hg > nginx-tests
annotate http_try_files.t @ 1260:eadd24ccfda1
Tests: postponed startup in certain ssl certificate tests on win32.
At least, some win32 hosts exhibit a round-off error or some such in the
notBefore field of the certificate generated before starting nginx, such
that it can be set to the value one second ahead of the current time.
This manifests in spurious test failures due to certificate verify error
with a failure reason "certificate is not yet valid".
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Dec 2017 12:53:53 +0300 |
parents | 882267679006 |
children |
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 | |
658
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(10) |
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 { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 listen 127.0.0.1:8080; |
189 | 39 server_name localhost; |
40 | |
41 location / { | |
42 try_files $uri /fallback; | |
43 } | |
44 | |
45 location /nouri/ { | |
659
f3b5bee3a14e
Tests: replaced underscores by hyphens in http_try_files.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
658
diff
changeset
|
46 try_files $uri /fallback-nouri; |
189 | 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 |
659
f3b5bee3a14e
Tests: replaced underscores by hyphens in http_try_files.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
658
diff
changeset
|
69 location ~ /alias-re.html { |
635
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 |
658
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
74 location /alias-nested/ { |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
75 alias %%TESTDIR%%/; |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
76 location ~ html { |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
77 try_files $uri =404; |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
78 } |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
79 } |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
80 |
189 | 81 location /fallback { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
82 proxy_pass http://127.0.0.1:8081/fallback; |
189 | 83 } |
659
f3b5bee3a14e
Tests: replaced underscores by hyphens in http_try_files.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
658
diff
changeset
|
84 location /fallback-nouri { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
85 proxy_pass http://127.0.0.1:8081; |
189 | 86 } |
87 } | |
88 | |
89 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
90 listen 127.0.0.1:8081; |
189 | 91 server_name localhost; |
92 | |
93 location / { | |
94 add_header X-URI $request_uri; | |
95 return 204; | |
96 } | |
97 } | |
98 } | |
99 | |
100 EOF | |
101 | |
523
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
102 mkdir($t->testdir() . '/directory'); |
659
f3b5bee3a14e
Tests: replaced underscores by hyphens in http_try_files.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
658
diff
changeset
|
103 $t->write_file('directory/alias-re.html', 'SEE THIS'); |
189 | 104 $t->write_file('found.html', 'SEE THIS'); |
105 $t->run(); | |
106 | |
107 ############################################################################### | |
108 | |
109 like(http_get('/found.html'), qr!SEE THIS!, 'found'); | |
110 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
|
111 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
|
112 like(http_get('/short/long'), qr!404 Not!, 'short uri in try_files'); |
189 | 113 |
523
64eabe6aa1f2
Tests: try_files tests for files and directory matching.
Damien Tournoud <damien@commerceguys.com>
parents:
310
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 |
659
f3b5bee3a14e
Tests: replaced underscores by hyphens in http_try_files.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
658
diff
changeset
|
119 like(http_get('/alias-re.html'), qr!SEE THIS!, 'alias in regex location'); |
658
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
120 like(http_get('/alias-nested/found.html'), qr!SEE THIS!, |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
121 'alias with nested location'); |
b9eb462d8973
Tests: added try_files test for alias with nested location.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
657
diff
changeset
|
122 |
189 | 123 ############################################################################### |