comparison realip_hostname.t @ 1176:eaa92d810bbb

Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 16 May 2017 15:45:10 +0300
parents
children 97c8280de681
comparison
equal deleted inserted replaced
1175:717030fd5a94 1176:eaa92d810bbb
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for nginx realip module, 'unix:' and hostname in set_real_ip_from.
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 proxy unix/);
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 server {
40 listen 127.0.0.1:8080;
41 listen unix:%%TESTDIR%%/unix.sock;
42 server_name localhost;
43
44 location /1 {
45 set_real_ip_from localhost;
46 add_header X-IP $remote_addr;
47 }
48
49 location /2 {
50 set_real_ip_from unix:;
51 add_header X-IP $remote_addr;
52 }
53
54 location /unix {
55 proxy_pass http://unix:%%TESTDIR%%/unix.sock:/;
56 proxy_set_header X-Real-IP 192.0.2.1;
57 }
58
59 location /ip {
60 proxy_pass http://127.0.0.1:8080/;
61 proxy_set_header X-Real-IP 192.0.2.1;
62 }
63 }
64 }
65
66 EOF
67
68 $t->write_file('1', '');
69 $t->write_file('2', '');
70 $t->try_run('no realip hostnames support');
71
72 plan(skip_all => 'no 127.0.0.1 on host')
73 if http_get('/1') !~ /X-IP: 127.0.0.1/m;
74
75 $t->plan(4);
76
77 ###############################################################################
78
79 like(http_get('/unix/2'), qr/X-IP: 192.0.2.1/, 'realip unix');
80 unlike(http_get('/unix/1'), qr/X-IP: 192.0.2.1/, 'realip unix - no match');
81
82 like(http_get('/ip/1'), qr/X-IP: 192.0.2.1/, 'realip hostname');
83 unlike(http_get('/ip/2'), qr/X-IP: 192.0.2.1/, 'realip hostname - no match');
84
85 ###############################################################################