Mercurial > hg > nginx-tests
comparison proxy_protocol_ipv6.t @ 811:dba758c045ed
Tests: proxy protocol tests on IPv6 socket.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 17 Dec 2015 17:18:07 +0300 |
parents | |
children | 9f5f604a840e |
comparison
equal
deleted
inserted
replaced
810:a4f806eb4426 | 811:dba758c045ed |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for haproxy protocol on IPv6 listening socket. | |
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 ipv6 realip stream/)->plan(3); | |
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 [::1]:8080 proxy_protocol; | |
41 server_name localhost; | |
42 | |
43 add_header X-IP $remote_addr; | |
44 add_header X-PP $proxy_protocol_addr; | |
45 real_ip_header proxy_protocol; | |
46 | |
47 location / { } | |
48 location /pp { | |
49 set_real_ip_from ::1/128; | |
50 error_page 404 =200 /t; | |
51 } | |
52 } | |
53 } | |
54 | |
55 stream { | |
56 server { | |
57 listen 127.0.0.1:8080; | |
58 proxy_pass [::1]:8080; | |
59 | |
60 proxy_protocol on; | |
61 } | |
62 } | |
63 | |
64 EOF | |
65 | |
66 $t->write_file('t', 'SEE-THIS'); | |
67 $t->run(); | |
68 | |
69 ############################################################################### | |
70 | |
71 TODO: { | |
72 local $TODO = 'not yet' unless $t->has_version('1.9.10'); | |
73 | |
74 my $r = http_get('/t'); | |
75 like($r, qr/X-IP: ::1/, 'realip'); | |
76 like($r, qr/X-PP: 127.0.0.1/, 'proxy protocol'); | |
77 | |
78 $r = http_get('/pp'); | |
79 like($r, qr/X-IP: 127.0.0.1/, 'proxy protocol realip'); | |
80 | |
81 } | |
82 | |
83 ############################################################################### |