Mercurial > hg > nginx-tests
annotate proxy_protocol_ipv6.t @ 1982:fb25cbe9d4ec
Tests: explicit Valgrind support.
Valgrind logging is done to a separate file, as it is not able to
follow stderr redirection within nginx or append to a file without
corrupting it. Further, Valgrind logging seems to interfere with
error suppression in tests, and catches various startup errors and
warnings, so the log is additionally filtered.
Since startup under Valgrind can be really slow, timeout in waitforfile()
was changed to 10 seconds.
Prodded by Robert Mueller.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 31 May 2024 06:23:00 +0300 |
parents | f3ba4c74de31 |
children |
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 { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1190
diff
changeset
|
56 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1190
diff
changeset
|
57 |
811
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
59 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
60 proxy_pass [::1]:%%PORT_8080%%; |
811
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 proxy_protocol on; |
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 } |
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 EOF |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $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
|
69 $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
|
70 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 ############################################################################### |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 my $r = http_get('/t'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 like($r, qr/X-IP: ::1/, 'realip'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 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
|
76 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 $r = http_get('/pp'); |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 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
|
79 |
dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 ############################################################################### |