comparison realip.t @ 245:7189255c1b91

Tests: added real_ip_recursive test.
author Andrei Belov <defan@nginx.com>
date Mon, 14 Jan 2013 19:49:41 +0400
parents ea574aae77cb
children bf6b05f03458
comparison
equal deleted inserted replaced
244:a675a0d1d19d 245:7189255c1b91
33 } 33 }
34 34
35 http { 35 http {
36 %%TEST_GLOBALS_HTTP%% 36 %%TEST_GLOBALS_HTTP%%
37 37
38 set_real_ip_from 127.0.0.1/32; 38 add_header X-IP $remote_addr;
39 real_ip_header X-Forwarded-For; 39 real_ip_header X-Forwarded-For;
40 40
41 server { 41 server {
42 listen 127.0.0.1:8080; 42 listen 127.0.0.1:8080;
43 server_name localhost; 43 server_name localhost;
44 44
45 location / { 45 location /1 {
46 add_header X-IP $remote_addr; 46 set_real_ip_from 127.0.0.1/32;
47 set_real_ip_from 10.0.1.0/24;
48 real_ip_recursive off;
49 }
50
51 location /2 {
52 set_real_ip_from 127.0.0.1/32;
53 set_real_ip_from 10.0.1.0/24;
54 real_ip_recursive on;
47 } 55 }
48 } 56 }
49 } 57 }
50 58
51 EOF 59 EOF
52 60
53 $t->write_file('1', ''); 61 $t->write_file('1', '');
62 $t->write_file('2', '');
54 $t->run(); 63 $t->run();
55 64
56 plan(skip_all => 'no 127.0.0.1 on host') 65 plan(skip_all => 'no 127.0.0.1 on host')
57 if http_get('/1') !~ /X-IP: 127.0.0.1/m; 66 if http_get('/1') !~ /X-IP: 127.0.0.1/m;
58 67
59 $t->plan(2); 68 $t->plan(4);
60 69
61 ############################################################################### 70 ###############################################################################
62 71
63 like(http_xff('192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip'); 72 like(http_xff('/1', '192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip');
64 like(http_xff('10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip multi'); 73 like(http_xff('/1', '10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m,
74 'realip multi');
75 like(http_xff('/1', '192.0.2.1, 10.0.1.1, 127.0.0.1'),
76 qr/^X-IP: 127.0.0.1/m, 'realip recursive off');
77 like(http_xff('/2', '192.0.2.1, 10.0.1.1, 127.0.0.1'),
78 qr/^X-IP: 192.0.2.1/m, 'realip recursive on');
65 79
66 ############################################################################### 80 ###############################################################################
67 81
68 sub http_xff { 82 sub http_xff {
69 my ($xff) = @_; 83 my ($uri, $xff) = @_;
70 return http(<<EOF); 84 return http(<<EOF);
71 GET /1 HTTP/1.0 85 GET $uri HTTP/1.0
72 Host: localhost 86 Host: localhost
73 X-Forwarded-For: $xff 87 X-Forwarded-For: $xff
74 88
75 EOF 89 EOF
76 } 90 }