annotate limit_req2.t @ 1974:b5036a0f9ae0 default tip

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 e91d80dd2527
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1363
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for nginx limit_req module, multiple limits.
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(14);
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 limit_req_zone $arg_a zone=slow:1m rate=1r/m;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 limit_req_zone $arg_b zone=fast:1m rate=1000r/s;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 server {
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 listen 127.0.0.1:8080;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 server_name localhost;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 location / {
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 limit_req zone=fast;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 limit_req zone=slow;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 location /t2.html {
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 limit_req zone=fast nodelay;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 limit_req zone=slow nodelay;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 alias %%TESTDIR%%/t1.html;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56 }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 }
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 EOF
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 $t->write_file('t1.html', 'XtestX');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 $t->run();
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 ###############################################################################
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 like(http_get('/t1.html?b=1'), qr/^HTTP\/1.. 200 /m, 'fast');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 like(http_get('/t1.html?b=1'), qr/^HTTP\/1.. 200 /m, 'fast - passed');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 like(http_get('/t1.html?a=1'), qr/^HTTP\/1.. 200 /m, 'slow');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 like(http_get('/t1.html?a=1'), qr/^HTTP\/1.. 503 /m, 'slow - rejected');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 like(http_get('/t1.html?a=2&b=2'), qr/^HTTP\/1.. 200 /m, 'both');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 like(http_get('/t1.html?a=2&b=2'), qr/^HTTP\/1.. 503 /m, 'both - rejected');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 like(http_get('/t1.html'), qr/^HTTP\/1.. 200 /m, 'no key');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 like(http_get('/t1.html'), qr/^HTTP\/1.. 200 /m, 'no key - passed');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82 # nodelay
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 like(http_get('/t2.html?b=3'), qr/^HTTP\/1.. 200 /m, 'nodelay fast');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 like(http_get('/t2.html?b=3'), qr/^HTTP\/1.. 200 /m, 'nodelay fast - passed');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 like(http_get('/t2.html?a=3'), qr/^HTTP\/1.. 200 /m, 'nodelay slow');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 like(http_get('/t2.html?a=3'), qr/^HTTP\/1.. 503 /m, 'nodelay slow - rejected');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 like(http_get('/t2.html?a=4&b=4'), qr/^HTTP\/1.. 200 /m, 'nodelay both');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93 select undef, undef, undef, 0.1;
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 like(http_get('/t2.html?a=4&b=4'), qr/^HTTP\/1.. 503 /m,
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 'nodelay both - rejected');
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
e91d80dd2527 Tests: limit_req basic tests with multiple limits.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 ###############################################################################