Mercurial > hg > nginx-tests
comparison geo.t @ 230:9d7805b05f0f
Tests: geo ranges minimal testing.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 16 Aug 2012 16:59:47 +0400 |
parents | ea574aae77cb |
children | a675a0d1d19d |
comparison
equal
deleted
inserted
replaced
229:9969fcf1f27e | 230:9d7805b05f0f |
---|---|
53 proxy 127.0.0.1/32; | 53 proxy 127.0.0.1/32; |
54 127.0.0.0/8 loopback; | 54 127.0.0.0/8 loopback; |
55 192.0.2.0/24 test; | 55 192.0.2.0/24 test; |
56 } | 56 } |
57 | 57 |
58 geo $geo_ranges { | |
59 ranges; | |
60 default default; | |
61 127.0.0.0-127.255.255.255 loopback; | |
62 192.0.2.0-192.0.2.255 test; | |
63 } | |
64 | |
58 server { | 65 server { |
59 listen 127.0.0.1:8080; | 66 listen 127.0.0.1:8080; |
60 server_name localhost; | 67 server_name localhost; |
61 | 68 |
62 location / { | 69 location / { |
63 add_header X-IP $remote_addr; | 70 add_header X-IP $remote_addr; |
64 add_header X-Geo $geo; | 71 add_header X-Geo $geo; |
65 add_header X-Arg $geo_from_arg; | 72 add_header X-Arg $geo_from_arg; |
66 add_header X-XFF $geo_proxy; | 73 add_header X-XFF $geo_proxy; |
74 add_header X-Ran $geo_ranges; | |
67 } | 75 } |
68 } | 76 } |
69 } | 77 } |
70 | 78 |
71 EOF | 79 EOF |
74 $t->run(); | 82 $t->run(); |
75 | 83 |
76 plan(skip_all => 'no 127.0.0.1 on host') | 84 plan(skip_all => 'no 127.0.0.1 on host') |
77 if http_get('/1') !~ /X-IP: 127.0.0.1/m; | 85 if http_get('/1') !~ /X-IP: 127.0.0.1/m; |
78 | 86 |
79 $t->plan(6); | 87 $t->plan(7); |
80 | 88 |
81 ############################################################################### | 89 ############################################################################### |
82 | 90 |
83 like(http_get('/1'), qr/^X-Geo: loopback/m, 'geo'); | 91 like(http_get('/1'), qr/^X-Geo: loopback/m, 'geo'); |
84 | 92 |
86 like(http_get('/1?ip=10.0.0.1'), qr/^X-Arg: default/m, 'geo default'); | 94 like(http_get('/1?ip=10.0.0.1'), qr/^X-Arg: default/m, 'geo default'); |
87 | 95 |
88 like(http_xff('192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy'); | 96 like(http_xff('192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy'); |
89 like(http_xff('10.0.0.1'), qr/^X-XFF: default/m, 'geo proxy default'); | 97 like(http_xff('10.0.0.1'), qr/^X-XFF: default/m, 'geo proxy default'); |
90 like(http_xff('10.0.0.1, 192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy long'); | 98 like(http_xff('10.0.0.1, 192.0.2.1'), qr/^X-XFF: test/m, 'geo proxy long'); |
99 | |
100 like(http_get('/1'), qr/^X-Ran: loopback/m, 'geo ranges'); | |
91 | 101 |
92 ############################################################################### | 102 ############################################################################### |
93 | 103 |
94 sub http_xff { | 104 sub http_xff { |
95 my ($xff) = @_; | 105 my ($xff) = @_; |