Mercurial > hg > nginx-tests
annotate stream_variables.t @ 1689:dbd19195df8a
Tests: adjusted mail_smtp.t "long pipelined" TODO.
Prior to fixed reading with fully filled buffer in 2851e4c7de03 (1.21.0),
test for long pipelined commands leads to connection close by nginx, which
can result in RST and no response seen by the client, notably on win32.
While here, cleaned up permitted smtp_auth methods in that particular server.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 24 May 2021 22:09:54 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream variables. |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
15 use Sys::Hostname; |
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
16 |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
1010
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream dgram /; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
1170
cf14cfe9ec8c
Tests: dropped obsolete ipv6 prerequisite.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1047
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream stream_return udp/); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 daemon off; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 events { |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
40 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1600
diff
changeset
|
41 |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
43 listen 127.0.0.1:8080; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 return $connection:$nginx_version:$hostname:$pid:$bytes_sent; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
48 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
49 listen [::1]:%%PORT_8081%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 return $remote_addr:$remote_port:$server_addr:$server_port; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
54 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
55 proxy_pass [::1]:%%PORT_8081%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
59 listen 127.0.0.1:8083; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
60 listen [::1]:%%PORT_8083%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 return $binary_remote_addr; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
65 listen 127.0.0.1:8084; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
66 proxy_pass [::1]:%%PORT_8083%%; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
70 listen 127.0.0.1:8085; |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 return $msec!$time_local!$time_iso8601; |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
1010
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
73 |
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
74 server { |
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
75 listen 127.0.0.1:8086; |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
76 listen 127.0.0.1:%%PORT_8987_UDP%% udp; |
1010
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
77 return $protocol; |
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
78 } |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 } |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 EOF |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1237
diff
changeset
|
83 $t->try_run('no inet6 support')->plan(8); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 ############################################################################### |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
1600
b61e820caa83
Tests: using Sys::Hostname to get hostname in a portable way.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1251
diff
changeset
|
87 my $hostname = lc hostname(); |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
88 like(stream('127.0.0.1:' . port(8080))->read(), |
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1190
diff
changeset
|
89 qr/^\d+:[\d.]+:$hostname:\d+:0$/, 'vars'); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
91 my $dport = port(8081); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 my $s = stream("127.0.0.1:$dport"); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 my $lport = $s->sockport(); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 is($s->read(), "127.0.0.1:$lport:127.0.0.1:$dport", 'addr'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
96 my $data = stream('127.0.0.1:' . port(8082))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 like($data, qr/^::1:\d+:::1:\d+$/, 'addr ipv6'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
99 $data = stream('127.0.0.1:' . port(8083))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 is(unpack("H*", $data), '7f000001', 'binary addr'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
102 $data = stream('127.0.0.1:' . port(8084))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 is(unpack("H*", $data), '0' x 31 . '1', 'binary addr ipv6'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
964
diff
changeset
|
105 $data = stream('127.0.0.1:' . port(8085))->read(); |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 like($data, qr#^\d+.\d+![-+\w/: ]+![-+\dT:]+$#, 'time'); |
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
1010
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
108 is(stream('127.0.0.1:' . port(8086))->read(), 'TCP', 'protocol TCP'); |
1237
e4974af3fb12
Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1235
diff
changeset
|
109 is(dgram('127.0.0.1:' . port(8987))->io('.'), 'UDP', 'protocol UDP'); |
1010
4f739c15069e
Tests: stream $protocol tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1004
diff
changeset
|
110 |
964
cca37c930b29
Tests: stream tests with variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 ############################################################################### |