Mercurial > hg > nginx-tests
annotate limit_req.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 62e2baa3bc60 |
children |
rev | line source |
---|---|
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for nginx limit_req module. |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
1364
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(6); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 $t->write_file_expand('nginx.conf', <<'EOF'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
223
diff
changeset
|
30 daemon off; |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
103
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
503
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
38 limit_req_zone $binary_remote_addr zone=one:1m rate=2r/s; |
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
39 limit_req_zone $binary_remote_addr zone=long:1m rate=2r/s; |
071e8941e3bf
Tests: reduce shared memory zone sizes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
40 limit_req_zone $binary_remote_addr zone=fast:1m rate=1000r/s; |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location / { |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 limit_req zone=one burst=1 nodelay; |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
1364
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
48 location /status { |
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
49 limit_req zone=one burst=1 nodelay; |
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
50 |
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
51 limit_req_status 501; |
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
52 } |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
53 location /long { |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
54 limit_req zone=long burst=5; |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
55 } |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
56 location /fast { |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
57 limit_req zone=fast burst=1; |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
58 } |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 } |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 EOF |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 $t->write_file('test1.html', 'XtestX'); |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
65 $t->write_file('long.html', "1234567890\n" x (1 << 16)); |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
66 $t->write_file('fast.html', 'XtestX'); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 $t->run(); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 ############################################################################### |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'request'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 http_get('/test1.html'); |
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 like(http_get('/test1.html'), qr/^HTTP\/1.. 503 /m, 'request rejected'); |
1364
62e2baa3bc60
Tests: added limit_req_status test.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1020
diff
changeset
|
74 like(http_get('/status.html'), qr/^HTTP\/1.. 501 /m, 'request rejected status'); |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
75 http_get('/test1.html'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
76 http_get('/test1.html'); |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
78 # Second request will be delayed by limit_req, make sure it isn't truncated. |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
79 # The bug only manifests itself if buffer will be filled, so sleep for a while |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
80 # before reading response. |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
81 |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
82 my $l1 = length(http_get('/long.html')); |
172
d099e407fff5
Tests: tune sleep in limit_req.t to avoid spurious timeouts.
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
83 my $l2 = length(http_get('/long.html', sleep => 0.6)); |
79
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
84 is($l2, $l1, 'delayed big request not truncated'); |
d5330d926fac
Tests: add test for limit_req not clearing write timeout on delay.
Maxim Dounin <mdounin@mdounin.ru>
parents:
78
diff
changeset
|
85 |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
86 # make sure rejected requests are not counted, and access is again allowed |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
87 # after 1/rate seconds |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
88 |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
89 like(http_get('/test1.html'), qr/^HTTP\/1.. 200 /m, 'rejects not counted'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
90 |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
91 # make sure negative excess values are handled properly |
113
5d31f920eda9
Tests: whitespace cleanup, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
92 |
103
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
93 http_get('/fast.html'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
94 select undef, undef, undef, 0.1; |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
95 like(http_get('/fast.html'), qr/^HTTP\/1.. 200 /m, 'negative excess'); |
4ae2198b97ec
Tests: limit_req tests for 0.8.18 changes and bug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
97
diff
changeset
|
96 |
78
c893908c1a44
Tests: add some limit_req module tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 ############################################################################### |