Mercurial > hg > nginx-tests
annotate http_location.t @ 1248:70192b1baf01
Tests: added exception test to stream_js.t using 'require'.
The stream js tests introduced in edf5a3c9e36a fail on njs 0.1.14. It doesn't
currently provide an easy way to check its version, whilst we are obligated to
gracefully handle such cases somehow. With such an addition of 'require', now
the tests are skipped instead on the previous versions.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 21 Nov 2017 13:16:39 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for location selection. |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
335
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http rewrite/)->plan(14) |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
218
diff
changeset
|
29 daemon off; |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
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; |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location = / { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 add_header X-Location exactlyroot; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 add_header X-Location root; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 location ^~ /images/ { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 add_header X-Location images; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location ~* \.(gif|jpg|jpeg)$ { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 add_header X-Location regex; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 location ~ casefull { |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 add_header X-Location casefull; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 return 204; |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 } |
329
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
65 |
335
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
66 location = /foo { |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
67 add_header X-Location "/foo exact"; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
68 return 204; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
69 } |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
70 |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
71 location /foo { |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
72 add_header X-Location "/foo prefix"; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
73 return 204; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
74 } |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
75 |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
76 location = /foo/ { |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
77 add_header X-Location "/foo/ exact"; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
78 return 204; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
79 } |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
80 |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
81 location /foo/ { |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
82 add_header X-Location "/foo/ prefix"; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
83 return 204; |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
84 } |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
85 |
329
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
86 location /lowercase { |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
87 add_header X-Location lowercase; |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
88 return 204; |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
89 } |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
90 |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
91 location /UPPERCASE { |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
92 add_header X-Location uppercase; |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
93 return 204; |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
94 } |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 EOF |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 $t->run(); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 ############################################################################### |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 like(http_get('/'), qr/X-Location: exactlyroot/, 'exactlyroot'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 like(http_get('/x'), qr/X-Location: root/, 'root'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 like(http_get('/images/t.gif'), qr/X-Location: images/, 'images'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 like(http_get('/t.gif'), qr/X-Location: regex/, 'regex'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 like(http_get('/t.GIF'), qr/X-Location: regex/, 'regex with mungled case'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 like(http_get('/casefull/t.gif'), qr/X-Location: regex/, 'first regex wins'); |
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 like(http_get('/casefull/'), qr/X-Location: casefull/, 'casefull regex'); |
218
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
111 |
335
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
112 like(http_get('/foo'), qr!X-Location: /foo exact!, '/foo exact'); |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
113 like(http_get('/foobar'), qr!X-Location: /foo prefix!, '/foo prefix'); |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
114 like(http_get('/foo/'), qr!X-Location: /foo/ exact!, '/foo/ exact'); |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
115 like(http_get('/foo/bar'), qr!X-Location: /foo/ prefix!, '/foo/ prefix'); |
433be52171d5
Tests: more location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
329
diff
changeset
|
116 |
218
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
117 SKIP: { |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
118 skip 'caseless os', 1 |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
119 if $^O eq 'MSWin32' or $^O eq 'darwin'; |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
120 |
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
121 like(http_get('/CASEFULL/'), qr/X-Location: root/, |
343
e7dc8f4d0a4b
Tests: whitespace and spelling fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
341
diff
changeset
|
122 'casefull regex do not match wrong case'); |
218
7f4a913d7504
Tests: skip casefull location test on caseless OSes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
123 } |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 |
397
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
343
diff
changeset
|
125 # on case-insensitive systems a request to "/UPPERCASE" might fail, |
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
343
diff
changeset
|
126 # if location search tree is incorrectly sorted and uppercase |
329
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
127 # characters are used in location directives (ticket #90) |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
128 |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
129 like(http_get('/lowercase'), qr/X-Location: lowercase/, 'lowercase'); |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
130 like(http_get('/UPPERCASE'), qr/X-Location: uppercase/, 'uppercase'); |
98c6af2a5138
Tests: location on caseless systems (ticket #90).
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
131 |
117
f2b8d86438ee
Tests: add location matching tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 ############################################################################### |