Mercurial > hg > nginx-tests
annotate stream_proxy_protocol2_tlv.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | a095b971fbcc |
children | 6b1222de8286 |
rev | line source |
---|---|
1808
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
2 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
3 # (C) Roman Arutyunyan |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
4 # (C) Eugene Grebenschikov |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
6 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
7 # Tests for variables for proxy protocol v2 TLVs. |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
8 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
9 ############################################################################### |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
10 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
11 use warnings; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
12 use strict; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
13 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
14 use Test::More; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
15 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
17 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
18 use lib 'lib'; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
19 use Test::Nginx; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
20 use Test::Nginx::Stream qw/ stream /; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
21 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
22 ############################################################################### |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
23 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
26 |
1987
a095b971fbcc
Tests: removed TODO and try_run() checks for legacy versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1808
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/stream stream_return map/)->plan(14) |
1808
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
29 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
31 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
32 daemon off; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
33 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
34 events { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
35 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
36 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
37 stream { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_STREAM%% |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
39 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
40 map $proxy_protocol_tlv_ssl $binary_present { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
41 "~\\x00" "true"; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
42 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
43 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
44 server { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8080 proxy_protocol; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
46 return " |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
47 alpn:$proxy_protocol_tlv_alpn |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
48 authority:$proxy_protocol_tlv_authority |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
49 crc32c:$proxy_protocol_tlv_0x3 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
50 unique-id:$proxy_protocol_tlv_unique_id |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
51 netns:$proxy_protocol_tlv_netns |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
52 ssl-verify:$proxy_protocol_tlv_ssl_verify |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
53 ssl-version:$proxy_protocol_tlv_ssl_version |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
54 ssl-cn:$proxy_protocol_tlv_ssl_cn |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
55 ssl-cipher:$proxy_protocol_tlv_ssl_cipher |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
56 ssl-sig-alg:$proxy_protocol_tlv_ssl_sig_alg |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
57 ssl-key-alg:$proxy_protocol_tlv_ssl_key_alg |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
58 custom:$proxy_protocol_tlv_0x000ae |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
59 x:$proxy_protocol_tlv_0x000e |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
60 ssl-binary:$binary_present"; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
61 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
62 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
63 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
64 EOF |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
65 |
1987
a095b971fbcc
Tests: removed TODO and try_run() checks for legacy versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1808
diff
changeset
|
66 $t->run(); |
1808
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
67 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
68 ############################################################################### |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
69 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
70 my $tlv = pp2_create_tlv(0x1, "ALPN1"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
71 $tlv .= pp2_create_tlv(0x2, "localhost"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
72 $tlv .= pp2_create_tlv(0x3, "4321"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
73 $tlv .= pp2_create_tlv(0x5, "UNIQQ"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
74 $tlv .= pp2_create_tlv(0x30, "NETNS"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
75 $tlv .= pp2_create_tlv(0xae, "12345"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
76 my $p = pp2_create($tlv); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
77 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
78 my $r = pp_get(8080, $p); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
79 like($r, qr/alpn:ALPN1\x0d?$/m, 'ALPN'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
80 like($r, qr/authority:localhost\x0d?$/m, 'AUTHORITY'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
81 like($r, qr/crc32c:4321\x0d?$/m, 'CRC32C'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
82 like($r, qr/unique-id:UNIQQ\x0d?$/m, 'UNIQUE_ID'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
83 like($r, qr/netns:NETNS\x0d?$/m, 'NETNS'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
84 like($r, qr/custom:12345\x0d?$/m, 'custom'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
85 like($r, qr/x:\x0d?$/m, 'non-existent'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
86 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
87 # big proxy protocol header with TLVs |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
88 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
89 my $sub = pp2_create_tlv(0x21, "TLSv1.2"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
90 $sub .= pp2_create_tlv(0x22, "example.com"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
91 $sub .= pp2_create_tlv(0x23, "AES256-SHA"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
92 $sub .= pp2_create_tlv(0x24, "SHA1"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
93 $sub .= pp2_create_tlv(0x25, "RSA512"); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
94 my $ssl = pp2_create_ssl(0x01, 255, $sub); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
95 $tlv .= pp2_create_tlv(0x20, $ssl); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
96 $p = pp2_create($tlv); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
97 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
98 $r = pp_get(8080, $p); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
99 like($r, qr/ssl-verify:255\x0d?$/m, 'SSL_VERIFY'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
100 like($r, qr/ssl-version:TLSv1.2\x0d?$/m, 'SSL_VERSION'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
101 like($r, qr/ssl-cn:example.com\x0d?$/m, 'SSL_CN'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
102 like($r, qr/ssl-cipher:AES256-SHA\x0d?$/m, 'SSL_CIPHER'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
103 like($r, qr/ssl-sig-alg:SHA1\x0d?$/m, 'SSL_SIG_ALG'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
104 like($r, qr/ssl-key-alg:RSA512\x0d?$/m, 'SSL_KEY_ALG'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
105 like($r, qr/ssl-binary:true/, 'SSL_BINARY'); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
106 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
107 ############################################################################### |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
108 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
109 sub pp_get { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
110 my ($port, $proxy) = @_; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
111 stream(PeerPort => port($port))->io($proxy); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
112 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
113 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
114 sub pp2_create { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
115 my ($tlv) = @_; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
116 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
117 my $pp2_sig = pack("N3", 0x0D0A0D0A, 0x000D0A51, 0x5549540A); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
118 my $ver_cmd = pack('C', 0x21); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
119 my $family = pack('C', 0x11); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
120 my $packet = $pp2_sig . $ver_cmd . $family; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
121 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
122 my $ip1 = pack('N', 0xc0000201); # 192.0.2.1 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
123 my $ip2 = pack('N', 0xc0000202); # 192.0.2.2 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
124 my $port1 = pack('n', 123); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
125 my $port2 = pack('n', 5678); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
126 my $addrs = $ip1 . $ip2 . $port1 . $port2; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
127 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
128 my $len = length($addrs) + length($tlv); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
129 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
130 $packet .= pack('n', $len) . $addrs . $tlv; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
131 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
132 return $packet; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
133 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
134 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
135 sub pp2_create_tlv { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
136 my ($type, $content) = @_; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
137 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
138 my $len = length($content); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
139 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
140 return pack("CnA*", $type, $len, $content); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
141 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
142 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
143 sub pp2_create_ssl { |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
144 my ($client, $verify, $content) = @_; |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
145 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
146 return pack("CNA*", $client, $verify, $content); |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
147 } |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
148 |
6040bfd6acbd
Tests: proxy protocol v2 TLVs tests for stream module.
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff
changeset
|
149 ############################################################################### |