Mercurial > hg > nginx-tests
annotate sub_filter.t @ 575:eea2b0158b51
Tests: sub filter tests for complex variable.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 May 2015 17:04:42 +0300 |
parents | 907e89fba9c3 |
children | 8504a62496df |
rev | line source |
---|---|
304 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for sub filter. | |
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 | |
575
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http rewrite sub/)->plan(25) |
304 | 25 ->write_file_expand('nginx.conf', <<'EOF'); |
26 | |
27 %%TEST_GLOBALS%% | |
28 | |
29 daemon off; | |
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 sub_filter_types *; | |
42 sub_filter foo bar; | |
43 | |
44 location / { | |
45 } | |
46 | |
47 location /once { | |
48 return 200 $arg_b; | |
49 } | |
50 | |
51 location /many { | |
52 sub_filter_once off; | |
53 return 200 $arg_b; | |
54 } | |
55 | |
56 location /complex { | |
57 sub_filter abac _replaced; | |
58 return 200 $arg_b; | |
59 } | |
60 | |
61 location /complex2 { | |
62 sub_filter ababX _replaced; | |
63 return 200 $arg_b; | |
64 } | |
65 | |
66 location /complex3 { | |
67 sub_filter aab _replaced; | |
68 return 200 $arg_b; | |
69 } | |
452
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
70 |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
71 location /single { |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
72 sub_filter A B; |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
73 return 200 $arg_b; |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
74 } |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
75 |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
76 location /single/many { |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
77 sub_filter A B; |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
78 sub_filter_once off; |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
79 return 200 $arg_b; |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
80 } |
575
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
81 |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
82 location /var/string { |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
83 sub_filter X$arg_a _replaced; |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
84 return 200 $arg_b; |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
85 } |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
86 |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
87 location /var/replacement { |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
88 sub_filter aab '${arg_a}_replaced'; |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
89 return 200 $arg_b; |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
90 } |
304 | 91 } |
92 } | |
93 | |
94 EOF | |
95 | |
96 $t->write_file('foo.html', 'foo'); | |
97 $t->write_file('foofoo.html', 'foofoo'); | |
98 $t->run(); | |
99 | |
100 ############################################################################### | |
101 | |
102 like(http_get('/foo.html'), qr/bar/, 'sub_filter'); | |
103 like(http_get('/foofoo.html'), qr/barfoo/, 'once default'); | |
104 | |
105 like(http_get('/once?b=foofoo'), qr/barfoo/, 'once'); | |
106 like(http_get('/many?b=foofoo'), qr/barbar/, 'many'); | |
107 like(http_get('/many?b=fo'), qr/fo/, 'incomplete'); | |
108 like(http_get('/many?b=foofo'), qr/barfo/, 'incomplete long'); | |
109 | |
110 like(http_get('/complex?b=abac'), qr/_replaced/, 'complex'); | |
111 like(http_get('/complex?b=abaabac'), qr/aba_replaced/, 'complex 1st char'); | |
112 like(http_get('/complex?b=ababac'), qr/replaced/, 'complex 2nd char'); | |
113 like(http_get('/complex2?b=ababX'), qr/_replaced/, 'complex2'); | |
114 like(http_get('/complex2?b=abababX'), qr/ab_replaced/, 'complex2 long'); | |
115 like(http_get('/complex3?b=aab'), qr/_replaced/, 'complex3 aab in aab'); | |
116 like(http_get('/complex3?b=aaab'), qr/a_replaced/, 'complex3 aab in aaab'); | |
117 like(http_get('/complex3?b=aaaab'), qr/aa_replaced/, 'complex3 aab in aaaab'); | |
118 | |
452
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
119 like(http_get('/single?b=A'), qr/B/, 'single only'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
120 like(http_get('/single?b=AA'), qr/BA/, 'single begin'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
121 like(http_get('/single?b=CAAC'), qr/CBAC/, 'single middle'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
122 like(http_get('/single?b=CA'), qr/CB/, 'single end'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
123 |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
124 like(http_get('/single/many?b=A'), qr/B/, 'single many only'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
125 like(http_get('/single/many?b=AA'), qr/BB/, 'single many begin'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
126 like(http_get('/single/many?b=CAAC'), qr/CBBC/, 'single many middle'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
127 like(http_get('/single/many?b=CA'), qr/CB/, 'single many end'); |
4465c1cf6f75
Tests: sub filter tests for single character matching.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
128 |
575
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
129 TODO: { |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
130 local $TODO = 'not yet'; |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
131 |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
132 like(http_get('/var/string?a=foo&b=Xfoo'), qr/_replaced/, 'complex string'); |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
133 like(http_get('/var/string?a=abcdefghijklmnopq&b=Xabcdefghijklmnopq'), |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
134 qr/_replaced/, 'complex string long'); |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
135 |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
136 } |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
137 |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
138 like(http_get('/var/replacement?a=ee&b=aaab'), qr/aee_replaced/, |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
139 'complex replacement'); |
eea2b0158b51
Tests: sub filter tests for complex variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
568
diff
changeset
|
140 |
304 | 141 ############################################################################### |