Mercurial > hg > nginx-tests
comparison realip_remote_addr.t @ 786:4e6d21192037
Tests: realip module tests with realip_remote_addr variable.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 16 Nov 2015 18:14:52 +0300 |
parents | |
children | e9064d691790 |
comparison
equal
deleted
inserted
replaced
785:91e23e0c923a | 786:4e6d21192037 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for nginx realip module, realip_remote_addr variable. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 | |
20 ############################################################################### | |
21 | |
22 select STDERR; $| = 1; | |
23 select STDOUT; $| = 1; | |
24 | |
25 my $t = Test::Nginx->new()->has(qw/http realip/); | |
26 | |
27 $t->write_file_expand('nginx.conf', <<'EOF'); | |
28 | |
29 %%TEST_GLOBALS%% | |
30 | |
31 daemon off; | |
32 | |
33 events { | |
34 } | |
35 | |
36 http { | |
37 %%TEST_GLOBALS_HTTP%% | |
38 | |
39 set_real_ip_from 127.0.0.1/32; | |
40 real_ip_header X-Forwarded-For; | |
41 | |
42 server { | |
43 listen 127.0.0.1:8080; | |
44 server_name localhost; | |
45 | |
46 location / { | |
47 add_header X-IP $remote_addr; | |
48 add_header X-Real-IP $realip_remote_addr; | |
49 } | |
50 } | |
51 } | |
52 | |
53 EOF | |
54 | |
55 $t->write_file('index.html', ''); | |
56 $t->write_file('1', ''); | |
57 $t->try_run('no realip_remote_addr'); | |
58 | |
59 plan(skip_all => 'no 127.0.0.1 on host') | |
60 if http_get('/') !~ /X-IP: 127.0.0.1/m; | |
61 | |
62 $t->plan(4); | |
63 | |
64 ############################################################################### | |
65 | |
66 like(http_get('/1'), qr/X-Real-IP: 127.0.0.1/m, 'request'); | |
67 like(http_get('/'), qr/X-Real-IP: 127.0.0.1/m, 'request redirect'); | |
68 | |
69 like(http_xff('/1', '192.0.2.1'), qr/X-Real-IP: 127.0.0.1/m, 'realip'); | |
70 like(http_xff('/', '192.0.2.1'), qr/X-Real-IP: 127.0.0.1/m, 'realip redirect'); | |
71 | |
72 ############################################################################### | |
73 | |
74 sub http_xff { | |
75 my ($uri, $xff) = @_; | |
76 return http(<<EOF); | |
77 GET $uri HTTP/1.0 | |
78 Host: localhost | |
79 X-Forwarded-For: $xff | |
80 | |
81 EOF | |
82 } | |
83 | |
84 ############################################################################### |