Mercurial > hg > nginx-tests
annotate stream_tcp_nodelay.t @ 1974:b5036a0f9ae0
Tests: improved compatibility when using recent "openssl" app.
Starting with OpenSSL 3.0, "openssl genrsa" generates encrypted keys
in PKCS#8 format instead of previously used PKCS#1 format. Further,
since OpenSSL 1.1.0 such keys are using PBKDF2 hmacWithSHA256.
Such keys are not supported by old SSL libraries, notably by OpenSSL
before 1.0.0 (OpenSSL 0.9.8 only supports hmacWithSHA1) and by BoringSSL
before May 21, 2019 (support for hmacWithSHA256 was added in 302a4dee6c),
and trying to load such keys into nginx compiled with an old SSL library
results in "unsupported prf" errors.
To facilitate testing with old SSL libraries, keys are now generated
with "openssl genrsa -traditional" if the flag is available.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 May 2024 00:04:26 +0300 |
parents | f3ba4c74de31 |
children |
rev | line source |
---|---|
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Sergey Kandaurov |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 # (C) Nginx, Inc. |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 # Stream tests for tcp_nodelay. |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use warnings; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 use strict; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use Test::More; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 use IO::Select; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 BEGIN { use FindBin; chdir($FindBin::Bin); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use lib 'lib'; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 use Test::Nginx; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
812
diff
changeset
|
22 use Test::Nginx::Stream qw/ stream /; |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 select STDERR; $| = 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 select STDOUT; $| = 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 my $t = Test::Nginx->new()->has(qw/stream/); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 $t->plan(2)->write_file_expand('nginx.conf', <<'EOF'); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 %%TEST_GLOBALS%% |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 daemon off; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 events { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1020
diff
changeset
|
41 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1020
diff
changeset
|
42 |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 proxy_buffer_size 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 tcp_nodelay off; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
47 listen 127.0.0.1:8081; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
48 proxy_pass 127.0.0.1:8080; |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 server { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 tcp_nodelay on; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
53 listen 127.0.0.1:8082; |
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
54 proxy_pass 127.0.0.1:8080; |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 EOF |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 $t->run_daemon(\&stream_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
61 $t->run()->waitforsocket('127.0.0.1:' . port(8080)); |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
812
acec03d44976
Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
711
diff
changeset
|
65 my $str = '1234567890' x 10 . 'F'; |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
812
diff
changeset
|
66 my $length = length($str); |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
68 is(stream('127.0.0.1:' . port(8081))->io($str, length => $length), $str, |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
812
diff
changeset
|
69 'tcp_nodelay off'); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 is(stream('127.0.0.1:' . port(8082))->io($str, length => $length), $str, |
816
77359b849cd5
Tests: stream package.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
812
diff
changeset
|
71 'tcp_nodelay on'); |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 ############################################################################### |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 sub stream_daemon { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 my $server = IO::Socket::INET->new( |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
78 LocalAddr => '127.0.0.1:' . port(8080), |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 Listen => 5, |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 Reuse => 1 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 ) |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 or die "Can't create listening socket: $!\n"; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 my $sel = IO::Select->new($server); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 local $SIG{PIPE} = 'IGNORE'; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 while (my @ready = $sel->can_read) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 foreach my $fh (@ready) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 if ($server == $fh) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my $new = $fh->accept; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 $new->autoflush(1); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 $sel->add($new); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 } elsif (stream_handle_client($fh)) { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $sel->remove($fh); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 $fh->close; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 sub stream_handle_client { |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 my ($client) = @_; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 log2c("(new connection $client)"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 $client->sysread(my $buffer, 65536) or return 1; |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 log2i("$client $buffer"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
812
acec03d44976
Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
711
diff
changeset
|
112 my $close = $buffer =~ /F/; |
acec03d44976
Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
711
diff
changeset
|
113 |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
114 log2o("$client $buffer"); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
115 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
116 $client->syswrite($buffer); |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
117 |
812
acec03d44976
Tests: close connection on last write in stream_tcp_nodelay.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
711
diff
changeset
|
118 return $close; |
642
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
119 } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 sub log2i { Test::Nginx::log_core('|| <<', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 sub log2o { Test::Nginx::log_core('|| >>', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 sub log2c { Test::Nginx::log_core('||', @_); } |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 |
555e718a70a5
Tests: basic stream tests for tcp_nodelay.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
125 ############################################################################### |