Mercurial > hg > nginx-tests
annotate limit_req_dry_run.t @ 1606:e4e0695552ed
Tests: fixed stream_proxy_ssl_conf_command.t.
The stream_proxy_ssl_conf_command.t test used stream return module
to return the response. Since this ignores actual request, but the
perl test code used http_get(). This might result in the request being
sent after the response is returned and the connection closed by the server,
resulting in RST being generated and no response seen by the client at all.
Fix is to use "stream(...)->read()" instead of http_get(), so
no request is sent at all, eliminating possibility of RST being
generated.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 10 Nov 2020 05:03:29 +0300 |
parents | 65eb942993ad |
children | 5ac6efbe5552 |
rev | line source |
---|---|
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for nginx limit_req module, limit_req_dry_run directive. |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http limit_req/); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 limit_req_zone $binary_remote_addr zone=one:1m rate=1r/m; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
41 log_format test $uri:$limit_req_status; |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
42 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 listen 127.0.0.1:8080; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server_name localhost; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 limit_req_dry_run on; |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
48 add_header X-Status $limit_req_status always; |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
49 access_log %%TESTDIR%%/test.log test; |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 location /delay { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 limit_req zone=one burst=2; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 location /reject { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 limit_req zone=one; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 location /reject/off { |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 limit_req zone=one; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 limit_req_dry_run off; |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
64 |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
65 location / { } |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 } |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 EOF |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $t->write_file('delay', 'SEE-THIS'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $t->write_file('reject', 'SEE-THIS'); |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
73 $t->try_run('no limit_req_dry_run/limit_req_status')->plan(8); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 ############################################################################### |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
77 like(http_get('/delay'), qr/ 200 .*PASSED/ms, 'dry run - passed'); |
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
78 like(http_get('/delay'), qr/ 200 .*DELAYED_DRY_RUN/ms, 'dry run - delayed'); |
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
79 like(http_get('/reject'), qr/ 200 .*REJECTED_DRY_RUN/ms, 'dry run - rejected'); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
1530
c1cdd7c73a73
Tests: $limit_req_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1486
diff
changeset
|
81 like(http_get('/reject/off'), qr/ 503 .*REJECTED/ms, 'dry run off - rejected'); |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
83 unlike(http_get('/'), qr/X-Status/, 'no limit'); |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
84 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $t->stop(); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like($t->read_file('error.log'), qr/delaying request, dry/, 'log - delay'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 like($t->read_file('error.log'), qr/limiting requests, dry/, 'log - reject'); |
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
1531
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
90 like($t->read_file('test.log'), qr|^/:-|m, 'log - not found'); |
65eb942993ad
Tests: added $limit_req_status not found tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1530
diff
changeset
|
91 |
1486
723c7e08eec7
Tests: limit_req_dry_run tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 ############################################################################### |