Mercurial > hg > nginx-tests
annotate stream_proxy.t @ 1836:74cffa9d4c43
Tests: enabled session reuse via TLS session tickets.
This fixes tests with TLSv1.3 enabled when using BoringSSL, since
for TLSv1.3 it only supports session reuse via TLS session tickets,
and not server-side session cache.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Mar 2023 19:50:02 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream proxy module. |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use IO::Select; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
21 use Test::Nginx::Stream qw/ stream /; |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDERR; $| = 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDOUT; $| = 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
28 my $t = Test::Nginx->new()->has(qw/stream/)->plan(5) |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 ->write_file_expand('nginx.conf', <<'EOF'); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1235
diff
changeset
|
39 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1235
diff
changeset
|
40 |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 proxy_pass 127.0.0.1:8081; |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
44 proxy_connect_timeout 2s; |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 EOF |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 $t->run_daemon(\&stream_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
51 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
55 my $s = stream('127.0.0.1:' . port(8080)); |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
57 is($s->io('foo1', length => 4), 'bar1', 'proxy connection'); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
58 is($s->io('foo3', length => 4), 'bar3', 'proxy connection again'); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
59 is($s->io('close'), 'close', 'proxy connection close'); |
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
60 is($s->io('test'), '', 'proxy connection closed'); |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
1235
3fc6817cd84a
Tests: explicit peer port in stream tests now required.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
974
diff
changeset
|
62 $s = stream('127.0.0.1:' . port(8080)); |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
63 |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
64 sleep 3; |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
711
diff
changeset
|
65 |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
795
diff
changeset
|
66 is($s->io('foo', length => 3), 'bar', 'proxy connect timeout'); |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 ############################################################################### |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 sub stream_daemon { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 my $server = IO::Socket::INET->new( |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
73 LocalAddr => '127.0.0.1:' . port(8081), |
555
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 Listen => 5, |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 Reuse => 1 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 ) |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 or die "Can't create listening socket: $!\n"; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 my $sel = IO::Select->new($server); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 local $SIG{PIPE} = 'IGNORE'; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 while (my @ready = $sel->can_read) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 foreach my $fh (@ready) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 if ($server == $fh) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 my $new = $fh->accept; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $new->autoflush(1); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 $sel->add($new); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } elsif (stream_handle_client($fh)) { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 $sel->remove($fh); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 $fh->close; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 sub stream_handle_client { |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 my ($client) = @_; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 log2c("(new connection $client)"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 $client->sysread(my $buffer, 65536) or return 1; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 log2i("$client $buffer"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 $buffer =~ s/foo/bar/g; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 log2o("$client $buffer"); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 $client->syswrite($buffer); |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
113 return $buffer =~ /close/; |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
118 sub log2c { Test::Nginx::log_core('||', @_); } |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 |
ba6cc90e3d67
Tests: basic stream proxy tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 ############################################################################### |