annotate proxy_protocol2_tlv.t @ 1976:4e79bd25642f default tip

Tests: added test for headers without a colon.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 11 May 2024 18:56:23 +0300
parents 76fdf5ede7c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
1 #!/usr/bin/perl
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
2
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
3 # (C) Roman Arutyunyan
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
4 # (C) Eugene Grebenschikov
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
6
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
7 # Tests for variables for proxy protocol v2 TLVs.
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
8
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
9 ###############################################################################
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
10
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
11 use warnings;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
12 use strict;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
13
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
14 use Test::More;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
15
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
17
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
18 use lib 'lib';
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
19 use Test::Nginx;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
20
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
21 ###############################################################################
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
22
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
23 select STDERR; $| = 1;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
25
1803
4627e750efdd Tests: removed rewrite dependency in proxy_protocol2_tlv.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1802
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http map/)
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
27 ->write_file_expand('nginx.conf', <<'EOF');
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
28
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
30
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
31 daemon off;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
32
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
33 events {
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
34 }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
35
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
36 http {
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
38
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
39 map $proxy_protocol_tlv_ssl $binary_present {
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
40 "~\\x00" "true";
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
41 }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
42
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
43 add_header X-ALPN
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
44 $proxy_protocol_tlv_alpn-$proxy_protocol_tlv_0x01;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
45 add_header X-AUTHORITY
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
46 $proxy_protocol_tlv_authority-$proxy_protocol_tlv_0x02;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
47 add_header X-UNIQUE-ID
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
48 $proxy_protocol_tlv_unique_id-$proxy_protocol_tlv_0x05;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
49 add_header X-NETNS
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
50 $proxy_protocol_tlv_netns-$proxy_protocol_tlv_0x30;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
51 add_header X-SSL-VERIFY
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
52 $proxy_protocol_tlv_ssl_verify;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
53 add_header X-SSL-VERSION
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
54 $proxy_protocol_tlv_ssl_version-$proxy_protocol_tlv_ssl_0x21;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
55 add_header X-SSL-CN
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
56 $proxy_protocol_tlv_ssl_cn-$proxy_protocol_tlv_ssl_0x22;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
57 add_header X-SSL-CIPHER
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
58 $proxy_protocol_tlv_ssl_cipher-$proxy_protocol_tlv_ssl_0x23;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
59 add_header X-SSL-SIG-ALG
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
60 $proxy_protocol_tlv_ssl_sig_alg-$proxy_protocol_tlv_ssl_0x24;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
61 add_header X-SSL-KEY-ALG
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
62 $proxy_protocol_tlv_ssl_key_alg-$proxy_protocol_tlv_ssl_0x25;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
63 add_header X-TLV-CRC32C
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
64 $proxy_protocol_tlv_0x3;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
65 add_header X-TLV-CUSTOM
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
66 $proxy_protocol_tlv_0x000ae;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
67 add_header X-TLV-X
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
68 $proxy_protocol_tlv_0x000e-$proxy_protocol_tlv_0x0f;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
69 add_header X-SSL-BINARY
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
70 $binary_present;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
71
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
72 server {
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
73 listen 127.0.0.1:8080 proxy_protocol;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
74 server_name localhost;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
75
1803
4627e750efdd Tests: removed rewrite dependency in proxy_protocol2_tlv.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1802
diff changeset
76 location / { }
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
77 }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
78 }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
79
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
80 EOF
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
81
1803
4627e750efdd Tests: removed rewrite dependency in proxy_protocol2_tlv.t.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1802
diff changeset
82 $t->write_file('t1', 'SEE-THIS');
1805
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
83 $t->try_run('no proxy_protocol tlv')->plan(14);
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
84
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
85 ###############################################################################
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
86
1805
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
87 my $tlv = pp2_create_tlv(0x1, "ALPN1");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
88 $tlv .= pp2_create_tlv(0x2, "localhost");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
89 $tlv .= pp2_create_tlv(0x3, "4321");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
90 $tlv .= pp2_create_tlv(0x5, "UNIQQ");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
91
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
92 my $sub = pp2_create_tlv(0x21, "TLSv1.2");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
93 $sub .= pp2_create_tlv(0x22, "example.com");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
94 $sub .= pp2_create_tlv(0x23, "AES256-SHA");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
95 $sub .= pp2_create_tlv(0x24, "SHA1");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
96 $sub .= pp2_create_tlv(0x25, "RSA512");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
97 my $ssl = pp2_create_ssl(0x01, 255, $sub);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
98 $tlv .= pp2_create_tlv(0x20, $ssl);
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
99
1805
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
100 $tlv .= pp2_create_tlv(0x30, "NETNS");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
101 $tlv .= pp2_create_tlv(0xae, "12345");
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
102 my $p = pp2_create($tlv);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
103
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
104 my $r = pp_get('/t1', $p);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
105 like($r, qr/X-ALPN: ALPN1-ALPN1\x0d?$/m, 'ALPN');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
106 like($r, qr/X-AUTHORITY: localhost-localhost\x0d?$/m, 'AUTHORITY');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
107 like($r, qr/X-TLV-CRC32C: 4321\x0d?$/m, 'CRC32C');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
108 like($r, qr/X-UNIQUE-ID: UNIQQ-UNIQQ\x0d?$/m, 'UNIQUE_ID');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
109 like($r, qr/X-SSL-BINARY: true/, 'SSL_BINARY');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
110 like($r, qr/X-SSL-VERIFY: 255\x0d?$/m, 'SSL_VERIFY');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
111 like($r, qr/X-SSL-VERSION: TLSv1.2-TLSv1.2\x0d?$/m, 'SSL_VERSION');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
112 like($r, qr/X-SSL-CN: example.com-example.com\x0d?$/m, 'SSL_CN');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
113 like($r, qr/X-SSL-CIPHER: AES256-SHA-AES256-SHA\x0d?$/m, 'SSL_CIPHER');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
114 like($r, qr/X-SSL-SIG-ALG: SHA1-SHA1\x0d?$/m, 'SSL_SIG_ALG');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
115 like($r, qr/X-SSL-KEY-ALG: RSA512-RSA512\x0d?$/m, 'SSL_KEY_ALG');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
116 like($r, qr/X-NETNS: NETNS-NETNS\x0d?$/m, 'NETNS');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
117 like($r, qr/X-TLV-CUSTOM: 12345\x0d?$/m, 'custom');
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
118 like($r, qr/X-TLV-X: -\x0d?$/m, 'non-existent');
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
119
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
120 ###############################################################################
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
121
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
122 sub pp_get {
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
123 my ($url, $proxy) = @_;
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
124 return http($proxy . <<EOF);
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
125 GET $url HTTP/1.0
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
126 Host: localhost
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
127
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
128 EOF
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
129 }
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
130
1805
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
131 sub pp2_create {
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
132 my ($tlv) = @_;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
133
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
134 my $pp2_sig = pack("N3", 0x0D0A0D0A, 0x000D0A51, 0x5549540A);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
135 my $ver_cmd = pack('C', 0x21);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
136 my $family = pack('C', 0x11);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
137 my $packet = $pp2_sig . $ver_cmd . $family;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
138
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
139 my $ip1 = pack('N', 0xc0000201); # 192.0.2.1
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
140 my $ip2 = pack('N', 0xc0000202); # 192.0.2.2
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
141 my $port1 = pack('n', 123);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
142 my $port2 = pack('n', 5678);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
143 my $addrs = $ip1 . $ip2 . $port1 . $port2;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
144
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
145 my $len = length($addrs) + length($tlv);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
146
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
147 $packet .= pack('n', $len) . $addrs . $tlv;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
148
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
149 return $packet;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
150 }
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
151
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
152 sub pp2_create_tlv {
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
153 my ($type, $content) = @_;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
154
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
155 my $len = length($content);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
156
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
157 return pack("CnA*", $type, $len, $content);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
158 }
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
159
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
160 sub pp2_create_ssl {
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
161 my ($client, $verify, $content) = @_;
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
162
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
163 return pack("CNA*", $client, $verify, $content);
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
164 }
76fdf5ede7c0 Tests: improved readability in PROXY protocol v2 TLV tests.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1804
diff changeset
165
1800
074974eb9182 Tests: variables for proxy protocol v2 TLVs
Eugene Grebenschikov <e.grebenshchikov@f5.com>
parents:
diff changeset
166 ###############################################################################