Mercurial > hg > nginx-tests
comparison stream_proxy_protocol_ipv6.t @ 613:36a267631e03
Tests: added stream IPv6 haproxy protocol tests.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Tue, 23 Jun 2015 19:22:48 +0300 |
parents | |
children | 2d9f5f439598 |
comparison
equal
deleted
inserted
replaced
612:bae9850e566c | 613:36a267631e03 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Andrey Zelenkov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for stream proxy module with IPv6 haproxy protocol. | |
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 proxy stream ipv6/) | |
26 ->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
30 daemon off; | |
31 | |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 server { | |
39 listen 127.0.0.1:8080; | |
40 server_name localhost; | |
41 | |
42 location /on { | |
43 proxy_pass http://[::1]:8080; | |
44 } | |
45 | |
46 location /off { | |
47 proxy_pass http://[::1]:8081; | |
48 } | |
49 } | |
50 } | |
51 | |
52 stream { | |
53 proxy_protocol on; | |
54 | |
55 server { | |
56 listen [::1]:8080; | |
57 proxy_pass 127.0.0.1:8082; | |
58 } | |
59 | |
60 server { | |
61 listen [::1]:8081; | |
62 proxy_pass 127.0.0.1:8082; | |
63 proxy_protocol off; | |
64 } | |
65 } | |
66 | |
67 EOF | |
68 | |
69 $t->run_daemon(\&stream_daemon); | |
70 $t->try_run('no inet6 support')->plan(2); | |
71 $t->waitforsocket('127.0.0.1:8082'); | |
72 | |
73 ############################################################################### | |
74 | |
75 like(http_get('/on'), qr/PROXY TCP6 ::1 ::1 [0-9]+ 8080/, 'protocol on'); | |
76 unlike(http_get('/off'), qr/PROXY/, 'protocol off'); | |
77 | |
78 ############################################################################### | |
79 | |
80 sub stream_daemon { | |
81 my $d = shift; | |
82 my $server = IO::Socket::INET->new( | |
83 Proto => 'tcp', | |
84 LocalHost => '127.0.0.1:8082', | |
85 Listen => 5, | |
86 Reuse => 1 | |
87 ) | |
88 or die "Can't create listening socket: $!\n"; | |
89 | |
90 local $SIG{PIPE} = 'IGNORE'; | |
91 | |
92 while (my $client = $server->accept()) { | |
93 $client->autoflush(1); | |
94 | |
95 log2c("(new connection $client)"); | |
96 | |
97 $client->sysread(my $buffer, 65536) or next; | |
98 | |
99 log2i("$client $buffer"); | |
100 | |
101 $buffer =~ /(.*?)\x0d\x0a?/ms; | |
102 $buffer = $1; | |
103 | |
104 log2o("$client $buffer"); | |
105 | |
106 $client->syswrite($buffer); | |
107 | |
108 close $client; | |
109 } | |
110 } | |
111 | |
112 sub log2i { Test::Nginx::log_core('|| <<', @_); } | |
113 sub log2o { Test::Nginx::log_core('|| >>', @_); } | |
114 sub log2c { Test::Nginx::log_core('||', @_); } | |
115 | |
116 ############################################################################### |