Mercurial > hg > nginx-tests
annotate map.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
4 # (C) Andrey Zelenkov |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
5 # (C) Nginx, Inc. |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # Tests for map module. |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Test::More; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use lib 'lib'; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
926
16b5438e3da4
Tests: added map test with matching hash key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
681
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http map rewrite/)->plan(19); |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
241
diff
changeset
|
32 daemon off; |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 map $args $x { |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
41 default 0; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
42 foo bar; |
926
16b5438e3da4
Tests: added map test with matching hash key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
681
diff
changeset
|
43 foo2 bar; |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 map $args $y { |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 hostnames; |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
48 default 0; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
49 example.com foo; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
50 example.* right-wildcard; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
51 *.example.com left-wildcard; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
52 .dot.example.com special-wildcard; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
53 ~^REGEX.EXAMPLE\.ORG$ regex-sensitive; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
54 ~*^www.regex.example\.org$ regex-insensitive; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
55 \include include; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
56 server $server_name; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
57 var $z; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
58 } |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
59 |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
60 map $args $z { |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
61 default 0; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
62 var baz; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
63 include map.conf; |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
67 listen 127.0.0.1:8080; |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 server_name localhost; |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 location / { |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 add_header X-Foo "x:$x y:$y\n"; |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
72 return 204; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
73 } |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
74 location /z { |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
75 add_header X-Foo "z:$z\n"; |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
76 return 204; |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 } |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 EOF |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
83 $t->write_file('map.conf', "foo bar;"); |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 $t->run(); |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 ############################################################################### |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 like(http_get('/?1'), qr/x:0 y:0/, 'map default'); |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 like(http_get('/?foo'), qr/x:bar y:0/, 'map foo bar'); |
926
16b5438e3da4
Tests: added map test with matching hash key.
Sergey Kandaurov <pluknet@nginx.com>
parents:
681
diff
changeset
|
90 like(http_get('/?foo2'), qr/x:bar y:0/, 'map foo bar key'); |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 like(http_get('/?example.com'), qr/x:0 y:foo/, 'map example.com foo'); |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
92 like(http_get('/?EXAMPLE.COM'), qr/x:0 y:foo/, 'map EXAMPLE.COM foo'); |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 like(http_get('/?example.com.'), qr/x:0 y:foo/, 'map example.com. foo'); |
681
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
94 like(http_get('/?example.org'), qr/x:0 y:right-wildcard/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
95 'map example.org wildcard'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
96 like(http_get('/?foo.example.com'), qr/x:0 y:left-wildcard/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
97 'map foo.example.com wildcard'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
98 like(http_get('/?foo.example.com.'), qr/x:0 y:left-wildcard/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
99 'map foo.example.com. wildcard'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
100 like(http_get('/?dot.example.com'), qr/x:0 y:special-wildcard/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
101 'map dot.example.com special wildcard'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
102 like(http_get('/?www.dot.example.com'), qr/x:0 y:special-wildcard/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
103 'map www.dot.example.com special wildcard'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
104 like(http_get('/?REGEX.EXAMPLE.ORG'), qr/x:0 y:regex-sensitive/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
105 'map REGEX.EXAMPLE.ORG'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
106 like(http_get('/?regex.example.org'), qr/x:0 y:0/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
107 'map regex.example.org'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
108 like(http_get('/?www.regex.example.org'), qr/x:0 y:regex-insensitive/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
109 'map www.regex.example.org insensitive'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
110 like(http_get('/?WWW.REGEX.EXAMPLE.ORG'), qr/x:0 y:regex-insensitive/, |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
111 'map WWW.REGEX.EXAMPLE.ORG insensitive'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
112 like(http_get('/?include'), qr/x:0 y:include/, 'map special parameter'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
113 like(http_get('/?server'), qr/x:0 y:localhost/, 'map server_name variable'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
114 like(http_get('/?var'), qr/x:0 y:baz/, 'map z variable'); |
1f8e15e1899a
Tests: more tests for map module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
249
diff
changeset
|
115 like(http_get('/z?foo'), qr/z:bar/, 'include foo bar'); |
227
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 |
16371849bd07
Tests: map module basic tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 ############################################################################### |