Mercurial > hg > nginx-tests
annotate stream_limit_conn_dry_run.t @ 1841:db6fd9184fa0
Tests: fixed ssl_sni.t with LibreSSL and TLSv1.3.
LibreSSL does not support session reuse with TLSv1.3.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Mar 2023 19:50:15 +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 use Test::Nginx::Stream qw/ stream /; |
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 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_limit_conn http/); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 $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
|
29 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
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 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 stream { |
1609
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1532
diff
changeset
|
38 %%TEST_GLOBALS_STREAM%% |
f3ba4c74de31
Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents:
1532
diff
changeset
|
39 |
1532
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 $server_port:$limit_conn_status; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 access_log %%TESTDIR%%/test.log test; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8080; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 proxy_timeout 5s; |
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:8081; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 limit_conn zone 1; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 listen 127.0.0.1:8082; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 proxy_pass 127.0.0.1:8084; |
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 limit_conn_dry_run on; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 listen 127.0.0.1:8083; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 proxy_pass 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 } |
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 http { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 %%TEST_GLOBALS_HTTP%% |
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 server { |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 listen 127.0.0.1:8084; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 server_name localhost; |
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 location / { } |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 } |
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 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 EOF |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 $t->write_file('index.html', 'OK'); |
1693
5ac6efbe5552
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1609
diff
changeset
|
87 $t->run()->plan(9); |
1532
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
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 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my ($p, $p1, $p2, $p3) = (port(8080), port(8081), port(8082), port(8083)); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 is(stream("127.0.0.1:$p")->io("GET /\n"), 'OK', 'passed'); |
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 my $s = stream('127.0.0.1:' . port(8080)); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $s->write("GET"); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 is(stream("127.0.0.1:$p1")->io("GET /\n"), '', 'rejected'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 is(stream("127.0.0.1:$p2")->io("GET /\n"), 'OK', 'rejected dry run'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 is(stream("127.0.0.1:$p3")->io("GET /\n"), 'OK', 'no limit'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 undef $s; |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 $t->stop(); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 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
|
107 like($t->read_file('test.log'), qr|$p:PASSED|, 'log passed'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 like($t->read_file('test.log'), qr|$p1:REJECTED$|m, 'log rejected'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 like($t->read_file('test.log'), qr|$p2:REJECTED_DRY_RUN|, 'log rejected dry'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 like($t->read_file('test.log'), qr|$p3:-|, 'log not found'); |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 |
9d5996c3f5b8
Tests: limit_conn_dry_run, $limit_conn_status tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
112 ############################################################################### |