Mercurial > hg > nginx-tests
annotate stream_geo_ipv6.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
1018
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Stream tests for geo module with IPv6. |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_map stream_geo/) |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1018
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
1018
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 events { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1251
diff
changeset
|
38 |
1018
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 geo $geo { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 ::1/128 loopback; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 2001:0db8::/32 test; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 ::/0 world; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 geo $geo_delete { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 ::1/128 loopback; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 2001:0db8::/32 test; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 ::/0 world; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 delete ::1/128; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 map $server_port $var { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 %%PORT_8080%% "::1"; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 %%PORT_8081%% "::ffff:192.0.2.1"; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 geo $var $geo_var { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 default default; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 192.0.2.1 test; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 geo $var $geo_var_ranges { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 ranges; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 default default; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 127.0.0.1-127.0.0.2 loopback; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 192.0.2.0-192.0.2.1 test; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 server { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 listen 127.0.0.1:8080; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 proxy_pass [::1]:%%PORT_8080%%; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 server { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 listen [::1]:%%PORT_8080%%; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 return "geo:$geo |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 geo_delete:$geo_delete |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 geo_var:$geo_var |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 geo_var_ranges:$geo_var_ranges"; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 server { |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 listen 127.0.0.1:8081; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 return "geo_var:$geo_var |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 geo_var_ranges:$geo_var_ranges"; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 } |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 EOF |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1235
diff
changeset
|
91 $t->try_run('no inet6 support')->plan(6); |
1018
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 ############################################################################### |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
95 my %data = stream('127.0.0.1:' . port(8080))->read() =~ /(\w+):(\w+)/g; |
1018
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 is($data{geo}, 'loopback', 'geo ipv6'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 is($data{geo_delete}, 'world', 'geo ipv6 delete'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 is($data{geo_var}, 'default', 'geo ipv6 from variable'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 is($data{geo_var_ranges}, 'default', 'geo ipv6 from variable range'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 %data = stream('127.0.0.1:' . port(8081))->read() =~ /(\w+):(\w+)/g; |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 is($data{geo_var}, 'test', 'geo ipv6 ipv4-mapped from variable'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 is($data{geo_var_ranges}, 'test', 'geo ipv6 ipv4-mapped from variable range'); |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 |
2120f5808c32
Tests: added stream geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 ############################################################################### |