Mercurial > hg > nginx-tests
changeset 690:a894f041244e
Tests: corrected simple realip tests.
First realip test was changed to real_ip_header directive test with default
value. Added real_ip_header test with custom string value.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Fri, 11 Sep 2015 18:36:08 +0300 |
parents | 26f58787c6b4 |
children | 3f4a132c6463 |
files | realip.t |
diffstat | 1 files changed, 27 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/realip.t +++ b/realip.t @@ -36,21 +36,25 @@ http { %%TEST_GLOBALS_HTTP%% add_header X-IP $remote_addr; - real_ip_header X-Forwarded-For; + set_real_ip_from 127.0.0.1/32; + set_real_ip_from 10.0.1.0/24; server { listen 127.0.0.1:8080; server_name localhost; + location / { } + location /custom { + real_ip_header X-Real-IP-Custom; + } + location /1 { - set_real_ip_from 127.0.0.1/32; - set_real_ip_from 10.0.1.0/24; + real_ip_header X-Forwarded-For; real_ip_recursive off; } location /2 { - set_real_ip_from 127.0.0.1/32; - set_real_ip_from 10.0.1.0/24; + real_ip_header X-Forwarded-For; real_ip_recursive on; } } @@ -58,18 +62,33 @@ http { EOF +$t->write_file('index.html', ''); +$t->write_file('custom', ''); $t->write_file('1', ''); $t->write_file('2', ''); $t->run(); plan(skip_all => 'no 127.0.0.1 on host') - if http_get('/1') !~ /X-IP: 127.0.0.1/m; + if http_get('/') !~ /X-IP: 127.0.0.1/m; -$t->plan(6); +$t->plan(7); ############################################################################### -like(http_xff('/1', '192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip'); +like(http(<<EOF), qr/^X-IP: 192.0.2.1/m, 'realip'); +GET / HTTP/1.0 +Host: localhost +X-Real-IP: 192.0.2.1 + +EOF + +like(http(<<EOF), qr/^X-IP: 192.0.2.1/m, 'realip custom'); +GET /custom HTTP/1.0 +Host: localhost +X-Real-IP-Custom: 192.0.2.1 + +EOF + like(http_xff('/1', '10.0.0.1, 192.0.2.1'), qr/^X-IP: 192.0.2.1/m, 'realip multi'); like(http_xff('/1', '192.0.2.1, 10.0.1.1, 127.0.0.1'),