Mercurial > hg > nginx-tests
annotate geoip.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | cf14cfe9ec8c |
children |
rev | line source |
---|---|
1061
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for geoip module. |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1064
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http http_geoip/) |
1061
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 http { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 geoip_proxy 127.0.0.1/32; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 geoip_country %%TESTDIR%%/country.dat; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 geoip_city %%TESTDIR%%/city.dat; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 geoip_org %%TESTDIR%%/org.dat; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 server { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8080; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 location / { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 add_header X-Country-Code $geoip_country_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 add_header X-Country-Code3 $geoip_country_code3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 add_header X-Country-Name $geoip_country_name; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 add_header X-Area-Code $geoip_area_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 add_header X-C-Continent-Code $geoip_city_continent_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 add_header X-C-Country-Code $geoip_city_country_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 add_header X-C-Country-Code3 $geoip_city_country_code3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 add_header X-C-Country-Name $geoip_city_country_name; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 add_header X-Dma-Code $geoip_dma_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 add_header X-Latitude $geoip_latitude; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 add_header X-Longitude $geoip_longitude; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 add_header X-Region $geoip_region; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 add_header X-Region-Name $geoip_region_name; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 add_header X-City $geoip_city; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 add_header X-Postal-Code $geoip_postal_code; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 add_header X-Org $geoip_org; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 EOF |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 my $d = $t->testdir(); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 # country database: |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 # |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 # "10.0.0.1","10.0.0.1","RU","Russian Federation" |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 # "2001:db8::","2001:db8::","US","United States" |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 my $data = ''; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 for my $i (0 .. 156) { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 # skip to offset 32 if 1st bit set in ipv6 address wins |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 $data .= pack_node($i + 1) . pack_node(32), next if $i == 2; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 # otherwise default to RU |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 $data .= pack_node(0xffffb9) . pack_node(0xffff00), next if $i == 31; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 # continue checking bits set in ipv6 address |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 $data .= pack_node(0xffff00) . pack_node($i + 1), next |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 if grep $_ == $i, (44, 49, 50, 52, 53, 55, 56, 57); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 # last bit set in ipv6 address |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 $data .= pack_node(0xffffe1) . pack_node(0xffff00), next if $i == 156; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 $data .= pack_node($i + 1) . pack_node(0xffff00); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 $data .= chr(0x00) x 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 $data .= chr(0xFF) x 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 $data .= chr(12); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 $t->write_file('country.dat', $data); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 # city database: |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 # |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 # "167772161","167772161","RU","48","Moscow","119034","55.7543",37.6202",, |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 $data = ''; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 for my $i (0 .. 31) { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 $data .= pack_node(32) . pack_node($i + 1), next if $i == 4 or $i == 6; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 $data .= pack_node(32) . pack_node($i + 2), next if $i == 31; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 $data .= pack_node($i + 1) . pack_node(32); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
111 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
112 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
113 $data .= chr(42); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 $data .= chr(185); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 $data .= pack('Z*', 48); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 $data .= pack('Z*', 'Moscow'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 $data .= pack('Z*', 119034); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 $data .= pack_node(int((55.7543 + 180) * 10000)); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 $data .= pack_node(int((37.6202 + 180) * 10000)); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 $data .= chr(0) x 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
121 $data .= chr(0xFF) x 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
122 $data .= chr(2); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
123 $data .= pack_node(32); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
124 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
125 $t->write_file('city.dat', $data); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
126 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
127 # organization database: |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
128 # |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
129 # "167772161","167772161","Nginx" |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
130 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
131 $data = ''; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
132 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
133 for my $i (0 .. 31) { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
134 $data .= pack_org(32) . pack_org($i + 1), next if $i == 4 or $i == 6; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
135 $data .= pack_org(32) . pack_org($i + 2), next if $i == 31; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
136 $data .= pack_org($i + 1) . pack_org(32); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
137 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
138 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
139 $data .= chr(42); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
140 $data .= pack('Z*', 'Nginx'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
141 $data .= chr(0xFF) x 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
142 $data .= chr(5); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
143 $data .= pack_node(32); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
144 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
145 $t->write_file('org.dat', $data); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
146 $t->write_file('index.html', ''); |
1064
6508aa1cf9cb
Tests: skip geoip tests on hosts without GeoIP IPv6 support.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1061
diff
changeset
|
147 $t->try_run('no inet6 support')->plan(20); |
1061
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
148 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
149 ############################################################################### |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
150 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
151 my $r = http_xff('10.0.0.1'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
152 like($r, qr/X-Country-Code: RU/, 'geoip country code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
153 like($r, qr/X-Country-Code3: RUS/, 'geoip country code 3'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
154 like($r, qr/X-Country-Name: Russian Federation/, 'geoip country name'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
155 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
156 like($r, qr/X-Area-Code: 0/, 'geoip area code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
157 like($r, qr/X-C-Continent-Code: EU/, 'geoip city continent code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
158 like($r, qr/X-C-Country-Code: RU/, 'geoip city country code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
159 like($r, qr/X-C-Country-Code3: RUS/, 'geoip city country code 3'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
160 like($r, qr/X-C-Country-Name: Russian Federation/, 'geoip city country name'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
161 like($r, qr/X-Dma-Code: 0/, 'geoip dma code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
162 like($r, qr/X-Latitude: 55.7543/, 'geoip latitude'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
163 like($r, qr/X-Longitude: 37.6202/, 'geoip longitude'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
164 like($r, qr/X-Region: 48/, 'geoip region'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
165 like($r, qr/X-Region-Name: Moscow City/, 'geoip region name'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
166 like($r, qr/X-City: Moscow/, 'geoip city'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
167 like($r, qr/X-Postal-Code: 119034/, 'geoip postal code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
168 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
169 like($r, qr/X-Org: Nginx/, 'geoip org'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
170 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
171 like(http_xff('::ffff:10.0.0.1'), qr/X-Org: Nginx/, 'geoip ipv6 ipv4-mapped'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
172 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
173 $r = http_xff('2001:db8::'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
174 like($r, qr/X-Country-Code: US/, 'geoip ipv6 country code'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
175 like($r, qr/X-Country-Code3: USA/, 'geoip ipv6 country code 3'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
176 like($r, qr/X-Country-Name: United States/, 'geoip ipv6 country name'); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
177 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
178 ############################################################################### |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
179 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
180 sub http_xff { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
181 my ($xff) = @_; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
182 return http(<<EOF); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
183 GET / HTTP/1.0 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
184 Host: localhost |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
185 X-Forwarded-For: $xff |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
186 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
187 EOF |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
188 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
189 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
190 sub pack_node { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
191 substr pack('V', shift), 0, 3; |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
192 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
193 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
194 sub pack_org { |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
195 pack('V', shift); |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
196 } |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
197 |
83357211563e
Tests: basic tests for geoip module.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
198 ############################################################################### |