Mercurial > hg > nginx-tests
annotate limit_conn_dry_run.t @ 1965:84f4d4930835
Tests: relaxed mail_imap_ssl.t cipher matching.
Previously, exact match between cipher name in the log and the one from
IO::Socket:SSL was needed, which might not be the case if nginx and
Net::SSLeay are compiled with different SSL libraries, notably LibreSSL
(which uses names like AEAD-AES256-GCM-SHA384 till 3.5.0), and
OpenSSL or BoringSSL (which use TLS_AES_256_GCM_SHA384). In particular,
this affects macOS, where Net::SSLeay compiled with LibreSSL 3.3.6 is
shipped with the OS, while nginx is likely to be compiled with OpenSSL.
Fix is to not require exact match but instead accept properly looking names
as checked by a regular expression, similarly to how it is already tested
in ssl.t and stream_ssl_variables.t.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 May 2024 00:01:40 +0300 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
1532
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for limit_conn_dry_run directive, limit_conn_status variable. |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy limit_conn limit_req/); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 limit_req_zone $binary_remote_addr zone=req:1m rate=30r/m; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 limit_conn_zone $binary_remote_addr zone=zone:1m; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 log_format test $uri:$limit_conn_status; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 listen 127.0.0.1:8081; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 server_name localhost; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /w { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 limit_req zone=req burst=10; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 listen 127.0.0.1:8080; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 server_name localhost; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 add_header X-Status $limit_conn_status always; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 access_log %%TESTDIR%%/test.log test; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 location /reject { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_pass http://127.0.0.1:8081/w; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 location /dry { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 limit_conn_dry_run on; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 location / { } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 EOF |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 $t->write_file('w', ''); |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1532
diff
changeset
|
77 $t->run()->plan(6); |
1532
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 ############################################################################### |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 like(http_get('/reject'), qr/ 200 .*PASSED/s, 'passed'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 my $s = http_get('/reject', start => 1); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 like(http_get('/reject'), qr/ 503 .*REJECTED(?!_)/s, 'rejected'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 like(http_get('/dry'), qr/ 404 .*REJECTED_DRY_RUN/s, 'rejected dry run'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 unlike(http_get('/'), qr/X-Status/, 'no limit'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 close $s; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 $t->stop(); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like($t->read_file('error.log'), qr/limiting connections, dry/, 'log dry run'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 like($t->read_file('test.log'), qr|^/:-|m, 'log not found'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 ############################################################################### |