Mercurial > hg > nginx-tests
annotate sub_filter_perl.t @ 1896:8b74936ff2ac
Tests: added has_feature() test for CryptX.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 29 May 2023 17:04:36 +0400 |
parents | 882267679006 |
children |
rev | line source |
---|---|
304 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for sub filter, extended tests using embedded perl. | |
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 | |
314
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http sub perl/)->plan(22) |
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 { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
38 listen 127.0.0.1:8080; |
304 | 39 server_name localhost; |
40 | |
41 sub_filter_types *; | |
42 sub_filter foobarbaz replaced; | |
43 | |
44 location / { | |
45 perl 'sub { | |
46 my $r = shift; | |
47 $r->send_http_header("text/html"); | |
48 return OK if $r->header_only; | |
49 $r->print("foo"); | |
50 $r->flush(); | |
51 $r->print("bar"); | |
52 $r->flush(); | |
53 $r->print("baz"); | |
54 return OK; | |
55 }'; | |
56 } | |
57 | |
58 location /multi { | |
59 sub_filter aab _replaced; | |
60 perl 'sub { | |
61 my $r = shift; | |
62 $r->send_http_header("text/html"); | |
63 return OK if $r->header_only; | |
64 $r->print($r->variable("arg_a")); | |
65 $r->print($r->variable("arg_b")); | |
66 return OK; | |
67 }'; | |
68 } | |
314
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
69 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
70 location /short { |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
71 sub_filter ab _replaced; |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
72 perl 'sub { |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
73 my $r = shift; |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
74 $r->send_http_header("text/html"); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
75 return OK if $r->header_only; |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
76 $r->print($r->variable("arg_a")); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
77 $r->print($r->variable("arg_b")); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
78 return OK; |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
79 }'; |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
80 } |
304 | 81 } |
82 } | |
83 | |
84 EOF | |
85 | |
86 $t->run(); | |
87 | |
88 ############################################################################### | |
89 | |
90 like(http_get('/flush'), qr/^replaced$/m, 'flush'); | |
91 | |
92 like(http_get('/multi?a=a&b=ab'), qr/^_replaced$/m, 'aab in a + ab'); | |
93 like(http_get('/multi?a=a&b=aaab'), qr/^aa_replaced$/m, 'aab in a + aaab'); | |
314
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
94 like(http_get('/multi?a=a&b=aab'), qr/^a_replaced$/m, 'aab in a + aab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
95 like(http_get('/multi?a=a&b=aaaab'), qr/^aaa_replaced$/m, 'aab in a + aaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
96 like(http_get('/multi?a=aa&b=ab'), qr/^a_replaced$/m, 'aab in aa + ab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
97 like(http_get('/multi?a=aa&b=aab'), qr/^aa_replaced$/m, 'aab in aa + aab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
98 like(http_get('/multi?a=aa&b=aaab'), qr/^aaa_replaced$/m, 'aab in aa + aaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
99 like(http_get('/multi?a=aa&b=aaaab'), qr/^aaaa_replaced$/m, 'aab in aa + aaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
100 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
101 # full backtracking |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
102 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
103 like(http_get('/multi?a=aa&b=xaaab'), qr/^aaxa_replaced$/m, 'aab in aa + xaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
104 like(http_get('/multi?a=aa&b=axaaab'), qr/^aaaxa_replaced$/m, |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
105 'aab in aa + axaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
106 like(http_get('/multi?a=aa&b=aaxaaab'), qr/^aaaaxa_replaced$/m, |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
107 'aab in aa + aaxaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
108 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
109 # short pattern |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
110 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
111 like(http_get('/short?a=a&b=b'), qr/^_replaced$/m, 'ab in a + b'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
112 like(http_get('/short?a=a&b=ab'), qr/^a_replaced$/m, 'ab in a + ab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
113 like(http_get('/short?a=a&b=aab'), qr/^aa_replaced$/m, 'ab in a + aab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
114 like(http_get('/short?a=a&b=aaab'), qr/^aaa_replaced$/m, 'ab in a + aaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
115 like(http_get('/short?a=a&b=aaaab'), qr/^aaaa_replaced$/m, 'ab in a + aaaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
116 |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
117 like(http_get('/short?a=aa&b=b'), qr/^a_replaced$/m, 'ab in aa + b'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
118 like(http_get('/short?a=aa&b=ab'), qr/^aa_replaced$/m, 'ab in aa + ab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
119 like(http_get('/short?a=aa&b=aab'), qr/^aaa_replaced$/m, 'ab in aa + aab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
120 like(http_get('/short?a=aa&b=aaab'), qr/^aaaa_replaced$/m, 'ab in aa + aaab'); |
eb6f293b512b
Tests: improve sub_filter tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
304
diff
changeset
|
121 like(http_get('/short?a=aa&b=aaaab'), qr/^aaaaa_replaced$/m, 'ab in aa + aaaab'); |
304 | 122 |
123 ############################################################################### |