Mercurial > hg > nginx-tests
annotate stream_realip_hostname.t @ 1547:2d747d967fc0
Tests: grpc_pass with variables.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 20 Jan 2020 16:30:56 +0300 |
parents | 97c8280de681 |
children | f3ba4c74de31 |
rev | line source |
---|---|
1176
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream realip module, 'unix:' and hostname in set_real_ip_from. |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ $CRLF /; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_return stream_realip unix/) |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 listen unix:%%TESTDIR%%/unix.sock proxy_protocol; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 listen 127.0.0.1:8080; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8082 proxy_protocol; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 return $remote_addr; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 set_real_ip_from unix:; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 listen 127.0.0.1:8081; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 proxy_pass unix:%%TESTDIR%%/unix.sock; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 listen 127.0.0.1:8085 proxy_protocol; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 listen unix:%%TESTDIR%%/unix2.sock proxy_protocol; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 return $remote_addr; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 set_real_ip_from localhost; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 listen 127.0.0.1:8083; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 proxy_pass 127.0.0.1:8085; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 server { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 listen 127.0.0.1:8084; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 proxy_pass unix:%%TESTDIR%%/unix2.sock; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 EOF |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1176
diff
changeset
|
74 $t->run(); |
1176
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 plan(skip_all => 'no 127.0.0.1 on host') |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 if http_get('/') ne '127.0.0.1'; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $t->plan(4); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 is(pp_get(8081, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"), |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 '192.0.2.1', 'realip unix'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 isnt(pp_get(8082, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"), |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 '192.0.2.1', 'realip unix - no match'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 is(pp_get(8083, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"), |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 '192.0.2.1', 'realip hostname'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 isnt(pp_get(8084, "PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678${CRLF}"), |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 '192.0.2.1', 'realip hostname - no match'); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 ############################################################################### |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 sub pp_get { |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 my ($port, $proxy) = @_; |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 stream(PeerPort => port($port))->io($proxy); |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 } |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 |
eaa92d810bbb
Tests: realip tests for 'unix:' and hostname in set_real_ip_from.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 ############################################################################### |