Mercurial > hg > nginx-tests
annotate 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 | ea796652fcdc |
children |
rev | line source |
---|---|
1017
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for geo module with IPv6. |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
1417
ea796652fcdc
Tests: added missing proxy prerequisites.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1190
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http geo proxy/) |
1017
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 http { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 geo $geo { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 ::1/128 loopback; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 2001:0db8::/32 test; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 ::/0 world; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 geo $geo_delete { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 ::1/128 loopback; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 2001:0db8::/32 test; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 ::/0 world; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 delete ::1/128; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 geo $geo_proxy { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 ranges; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 proxy ::1; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 default default; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 192.0.2.1-192.0.2.1 test; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 geo $arg_ip $geo_arg { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 default default; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 ::1/128 loopback; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 192.0.2.0/24 test; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 server { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 listen 127.0.0.1:8080; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 server_name localhost; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 location / { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 proxy_pass http://[::1]:%%PORT_8080%%/; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 server { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 listen [::1]:%%PORT_8080%%; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 server_name localhost; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 location / { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 add_header X-Geo $geo; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 add_header X-Del $geo_delete; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 add_header X-XFF $geo_proxy; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 add_header X-Arg $geo_arg; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 location /addr { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 add_header X-IP $remote_addr; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 EOF |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 $t->write_file('index.html', ''); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 $t->write_file('addr', ''); |
1190
fcd65708672d
Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1171
diff
changeset
|
94 $t->try_run('no inet6 support'); |
1017
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 plan(skip_all => 'no ::1 on host') |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 if http_get('/addr') !~ /X-IP: ::1/m; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 $t->plan(4); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 ############################################################################### |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 like(http_get('/'), qr/^X-Geo: loopback/m, 'geo ipv6'); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 like(http_get('/'), qr/^X-Del: world/m, 'geo ipv6 delete'); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 like(http_xff('::ffff:192.0.2.1'), qr/^X-XFF: test/m, 'geo ipv6 ipv4-mapped'); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 like(http_get('/?ip=::ffff:192.0.2.1'), qr/^X-Arg: test/m, |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 'geo ipv6 ipv4-mapped from variable'); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 sub http_xff { |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 my ($xff) = @_; |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 return http(<<EOF); |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 GET / HTTP/1.0 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 Host: localhost |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 X-Forwarded-For: $xff |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 EOF |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 } |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 |
82bdc838ba94
Tests: added geo IPv6 tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 ############################################################################### |