Mercurial > hg > nginx-tests
annotate geo.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
4 # (C) Andrey Zelenkov |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
5 # (C) Nginx, Inc. |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 # Tests for nginx geo module. |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 ############################################################################### |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 use warnings; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use strict; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 use Test::More; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use lib 'lib'; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 ############################################################################### |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
217
ea574aae77cb
Tests: unbreak geo and realip tests in jails.
Maxim Dounin <mdounin@mdounin.ru>
parents:
216
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http geo/); |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 $t->write_file_expand('nginx.conf', <<'EOF'); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
244
diff
changeset
|
32 daemon off; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 events { |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 http { |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 geo $geo { |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
41 127.0.0.0/8 loopback; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
42 192.0.2.0/24 test; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
43 0.0.0.0/0 world; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
46 geo $geo_include { |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
47 include geo.conf; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
48 192.0.2.0/24 test; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
49 0.0.0.0/0 world; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
50 } |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
51 |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
52 geo $geo_delete { |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
53 127.0.0.0/8 loopback; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
54 192.0.2.0/24 test; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
55 0.0.0.0/0 world; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
56 delete 127.0.0.0/8; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
57 } |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
58 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 geo $arg_ip $geo_from_arg { |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
60 default default; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
61 127.0.0.0/8 loopback; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
62 192.0.2.0/24 test; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
65 geo $arg_ip $geo_arg_ranges { |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
66 ranges; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
67 default default; |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
68 127.0.0.0-127.0.0.1 loopback; |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
69 |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
70 # ranges with two /16 networks |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
71 # the latter network has greater two least octets |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
72 # (see 1301a58b5dac for details) |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
73 10.10.3.0-10.11.2.255 foo; |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
74 10.12.3.0-10.13.2.255 foo2; |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
75 delete 10.10.3.0-10.11.2.255; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
76 } |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
77 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 geo $geo_proxy { |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
79 default default; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
80 proxy 127.0.0.1; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
81 127.0.0.0/8 loopback; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
82 192.0.2.0/24 test; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
244
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
85 geo $geo_proxy_recursive { |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
86 proxy_recursive; |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
87 default default; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
88 proxy 127.0.0.1; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
89 127.0.0.0/8 loopback; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
90 192.0.2.0/24 test; |
244
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
91 } |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
92 |
230
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
93 geo $geo_ranges { |
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
94 ranges; |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
95 default default; |
230
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
96 127.0.0.0-127.255.255.255 loopback; |
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
97 192.0.2.0-192.0.2.255 test; |
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
98 } |
9d7805b05f0f
Tests: geo ranges minimal testing.
Maxim Dounin <mdounin@mdounin.ru>
parents:
217
diff
changeset
|
99 |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
100 geo $geo_ranges_include { |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
101 ranges; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
102 default default; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
103 include geo-ranges.conf; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
104 192.0.2.0-192.0.2.255 test; |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
105 } |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
106 |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
107 geo $geo_ranges_delete { |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
108 ranges; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
109 default default; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
110 127.0.0.0-127.0.0.255 test; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
111 127.0.0.1-127.0.0.1 loopback; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
112 delete 127.0.0.0-127.0.0.0; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
113 delete 127.0.0.2-127.0.0.255; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
114 delete 127.0.0.1-127.0.0.1; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
115 } |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
116 |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
117 # delete range with two /16 |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
118 geo $geo_ranges_delete_2 { |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
119 ranges; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
120 default default; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
121 127.0.0.0-127.1.0.0 loopback; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
122 delete 127.0.0.0-127.1.0.0; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
123 } |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
124 |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
125 geo $geo_before { |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
126 ranges; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
127 default default; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
128 127.0.0.1-127.0.0.255 loopback; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
129 127.0.0.0-127.0.0.0 test; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
130 } |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
131 |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
132 geo $geo_after { |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
133 ranges; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
134 default default; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
135 127.0.0.0-127.0.0.1 loopback; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
136 127.0.0.2-127.0.0.255 test; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
137 } |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
138 |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
139 geo $geo_insert { |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
140 ranges; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
141 default default; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
142 127.0.0.0-127.0.0.255 test; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
143 127.0.0.1-127.0.0.2 test2; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
144 127.0.0.1-127.0.0.1 loopback; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
145 } |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
146 |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
147 geo $geo_insert_before { |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
148 ranges; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
149 default default; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
150 127.0.0.0-127.0.0.255 test; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
151 127.0.0.0-127.0.0.1 loopback; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
152 } |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
153 |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
154 geo $geo_insert_after { |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
155 ranges; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
156 default default; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
157 127.0.0.0-127.0.0.255 test; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
158 127.0.0.1-127.0.0.255 loopback; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
159 } |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
160 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
162 listen 127.0.0.1:8080; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 server_name localhost; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 location / { |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
166 add_header X-IP $remote_addr; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
167 add_header X-Geo $geo; |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
168 add_header X-Inc $geo_include; |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
169 add_header X-Del $geo_delete; |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
170 add_header X-Ran $geo_ranges; |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
171 add_header X-RIn $geo_ranges_include; |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
172 add_header X-ABe $geo_before; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
173 add_header X-AAf $geo_after; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
174 add_header X-Ins $geo_insert; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
175 add_header X-IBe $geo_insert_before; |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
176 add_header X-IAf $geo_insert_after; |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
177 add_header X-Arg $geo_from_arg; |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
178 add_header X-ARa $geo_arg_ranges; |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
179 add_header X-XFF $geo_proxy; |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
180 add_header X-XFR $geo_proxy_recursive; |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 } |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
182 |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
183 location /2 { |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
184 add_header X-RDe $geo_ranges_delete; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
185 add_header X-RD2 $geo_ranges_delete_2; |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
186 } |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 EOF |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 $t->write_file('1', ''); |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
193 $t->write_file('2', ''); |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
194 $t->write_file('geo.conf', '127.0.0.0/8 loopback;'); |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
195 $t->write_file('geo-ranges.conf', '127.0.0.0-127.255.255.255 loopback;'); |
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
196 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
197 $t->run(); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 |
217
ea574aae77cb
Tests: unbreak geo and realip tests in jails.
Maxim Dounin <mdounin@mdounin.ru>
parents:
216
diff
changeset
|
199 plan(skip_all => 'no 127.0.0.1 on host') |
ea574aae77cb
Tests: unbreak geo and realip tests in jails.
Maxim Dounin <mdounin@mdounin.ru>
parents:
216
diff
changeset
|
200 if http_get('/1') !~ /X-IP: 127.0.0.1/m; |
ea574aae77cb
Tests: unbreak geo and realip tests in jails.
Maxim Dounin <mdounin@mdounin.ru>
parents:
216
diff
changeset
|
201 |
1044
1fe8d33f75ad
Tests: split out geo tests with binary base and skip by default.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1016
diff
changeset
|
202 $t->plan(22); |
217
ea574aae77cb
Tests: unbreak geo and realip tests in jails.
Maxim Dounin <mdounin@mdounin.ru>
parents:
216
diff
changeset
|
203 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
204 ############################################################################### |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
205 |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
206 my $r = http_get('/1'); |
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
207 like($r, qr/^X-Geo: loopback/m, 'geo'); |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
208 like($r, qr/^X-Inc: loopback/m, 'geo include'); |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
209 like($r, qr/^X-Del: world/m, 'geo delete'); |
1012
a0758fe11465
Tests: style and rearrangements in geo tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
210 like($r, qr/^X-Ran: loopback/m, 'geo ranges'); |
1013
8f92d97cf40e
Tests: geo include tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1012
diff
changeset
|
211 like($r, qr/^X-RIn: loopback/m, 'geo ranges include'); |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
212 |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
213 like(http_get('/2'), qr/^X-RDe: default/m, 'geo ranges delete'); |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
214 like(http_get('/2'), qr/^X-RD2: default/m, 'geo ranges delete 2'); |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
215 |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
216 like($r, qr/^X-ABe: loopback/m, 'geo ranges add before'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
217 like($r, qr/^X-AAf: loopback/m, 'geo ranges add after'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
218 like($r, qr/^X-Ins: loopback/m, 'geo ranges insert'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
219 like($r, qr/^X-IBe: loopback/m, 'geo ranges insert before'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
220 like($r, qr/^X-IAf: loopback/m, 'geo ranges insert after'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
221 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
222 like(http_get('/1?ip=192.0.2.1'), qr/^X-Arg: test/m, 'geo from variable'); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
223 like(http_get('/1?ip=10.0.0.1'), qr/^X-Arg: default/m, 'geo default'); |
1015
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
224 like(http_get('/1?ip=10.0.0.1'), qr/^X-ARa: default/m, 'geo ranges default'); |
1d205c07ef59
Tests: more geo ranges tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1014
diff
changeset
|
225 like(http_get('/1?ip=10.13.2.1'), qr/^X-ARa: foo2/m, 'geo ranges add'); |
1014
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
226 like(http_get('/1?ip=10.11.2.1'), qr/^X-ARa: default/m, |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
227 'geo delete range from variable'); |
61fbb879446a
Tests: geo delete tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1013
diff
changeset
|
228 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
229 like(http_xff('192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy'); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
230 like(http_xff('10.0.0.1'), qr/^X-XFF: default/m, 'geo proxy default'); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
231 like(http_xff('10.0.0.1, 192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy long'); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
232 |
244
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
233 like(http_xff('192.0.2.1, 127.0.0.1'), qr/^X-XFF: loopback/m, |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
234 'geo proxy_recursive off'); |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
235 like(http_xff('192.0.2.1, 127.0.0.1'), qr/^X-XFR: test/m, |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
236 'geo proxy_recursive on'); |
a675a0d1d19d
Tests: geo proxy_recursive test.
Ruslan Ermilov <ru@nginx.com>
parents:
230
diff
changeset
|
237 |
216
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
238 ############################################################################### |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
239 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
240 sub http_xff { |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
241 my ($xff) = @_; |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
242 return http(<<EOF); |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
243 GET /1 HTTP/1.0 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
244 Host: localhost |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
245 X-Forwarded-For: $xff |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
246 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
247 EOF |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
248 } |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
249 |
f2f37a52e42e
Tests: basic tests for geo and realip modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
250 ############################################################################### |