comparison realip.t @ 247:bf6b05f03458

Tests: add realip tests for multiple X-Forwarded-For headers.
author Andrei Belov <defan@nginx.com>
date Thu, 17 Jan 2013 12:02:08 +0400
parents 7189255c1b91
children 6a0d934950bc
comparison
equal deleted inserted replaced
246:6072306b7924 247:bf6b05f03458
63 $t->run(); 63 $t->run();
64 64
65 plan(skip_all => 'no 127.0.0.1 on host') 65 plan(skip_all => 'no 127.0.0.1 on host')
66 if http_get('/1') !~ /X-IP: 127.0.0.1/m; 66 if http_get('/1') !~ /X-IP: 127.0.0.1/m;
67 67
68 $t->plan(4); 68 $t->plan(6);
69 69
70 ############################################################################### 70 ###############################################################################
71 71
72 like(http_xff('/1', '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');
73 like(http_xff('/1', '10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 73 like(http_xff('/1', '10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m,
74 'realip multi'); 74 'realip multi');
75 like(http_xff('/1', '192.0.2.1, 10.0.1.1, 127.0.0.1'), 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'); 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'), 77 like(http_xff('/2', '10.0.1.1, 192.0.2.1, 127.0.0.1'),
78 qr/^X-IP: 192.0.2.1/m, 'realip recursive on'); 78 qr/^X-IP: 192.0.2.1/m, 'realip recursive on');
79
80 TODO: {
81
82 local $TODO = 'not yet';
83
84 like(http(<<EOF), qr/^X-IP: 10.0.1.1/m, 'realip multi xff recursive off');
85 GET /1 HTTP/1.0
86 Host: localhost
87 X-Forwarded-For: 192.0.2.1
88 X-Forwarded-For: 127.0.0.1, 10.0.1.1
89
90 EOF
91
92 like(http(<<EOF), qr/^X-IP: 192.0.2.1/m, 'realip multi xff recursive on');
93 GET /2 HTTP/1.0
94 Host: localhost
95 X-Forwarded-For: 10.0.1.1
96 X-Forwarded-For: 192.0.2.1
97 X-Forwarded-For: 127.0.0.1
98
99 EOF
100
101 }
79 102
80 ############################################################################### 103 ###############################################################################
81 104
82 sub http_xff { 105 sub http_xff {
83 my ($uri, $xff) = @_; 106 my ($uri, $xff) = @_;