Mercurial > hg > nginx-tests
annotate proxy_protocol_ipv6.t @ 1427:eb1d883305ea
Tests: avoid edge cases in upstream random two test.
Unavailable servers contribute to the number of attempts, if selected,
before the balancer would fall back to the default round-robin method.
This means that it's quite possible to get server with more connections.
To facilitate with selecting two alive servers, down server was removed
from the upstream configuration at the cost of slightly worse coverage.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 10 Jan 2019 17:42:34 +0300 |
parents | fcd65708672d |
children | f3ba4c74de31 |
rev | line source |
---|---|
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for haproxy protocol on IPv6 listening socket. |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http realip stream/); |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen [::1]:%%PORT_8080%% proxy_protocol; |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server_name localhost; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 add_header X-IP $remote_addr; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 add_header X-PP $proxy_protocol_addr; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 real_ip_header proxy_protocol; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 location / { } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /pp { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 set_real_ip_from ::1/128; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 error_page 404 =200 /t; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 stream { |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
57 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
58 proxy_pass [::1]:%%PORT_8080%%; |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 proxy_protocol on; |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 EOF |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $t->write_file('t', 'SEE-THIS'); |
1190
fcd65708672d
Tests: let tests pass on travis-ci VMs with disabled IPv6 loopback.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1171
diff
changeset
|
67 $t->try_run('no inet6 support')->plan(3); |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $r = http_get('/t'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 like($r, qr/X-IP: ::1/, 'realip'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 like($r, qr/X-PP: 127.0.0.1/, 'proxy protocol'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $r = http_get('/pp'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like($r, qr/X-IP: 127.0.0.1/, 'proxy protocol realip'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 ############################################################################### |