annotate limit_req_delay.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 144c6ce732e4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1404
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for nginx limit_req module, delay parameter.
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 use lib 'lib';
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18 use Test::Nginx qw/ :DEFAULT http_end /;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 ###############################################################################
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 select STDERR; $| = 1;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23 select STDOUT; $| = 1;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24
1535
144c6ce732e4 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1416
diff changeset
25 my $t = Test::Nginx->new()->has(qw/http limit_req/)->plan(4);
1404
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 $t->write_file_expand('nginx.conf', <<'EOF');
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 daemon off;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 events {
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 }
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36 http {
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38
1416
d22717fcabdb Tests: adjusted rate in limit_req_delay.t for slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1404
diff changeset
39 limit_req_zone $binary_remote_addr zone=one:1m rate=30r/m;
1404
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 server {
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 listen 127.0.0.1:8080;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43 server_name localhost;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45 location / {
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 limit_req zone=one delay=1 burst=2;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47 add_header X-Time $request_time;
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 }
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 }
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 }
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 EOF
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 $t->write_file('delay.html', 'XtestX');
1535
144c6ce732e4 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1416
diff changeset
55 $t->run();
1404
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 ###############################################################################
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 like(http_get('/delay.html'), qr/^HTTP\/1.. 200 /m, 'request');
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 like(http_get('/delay.html'), qr/X-Time: 0.000/, 'not yet delayed');
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 my $s = http_get('/delay.html', start => 1, sleep => 0.2);
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 like(http_get('/delay.html'), qr/^HTTP\/1.. 503 /m, 'rejected');
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 like(http_end($s), qr/^HTTP\/1.. 200 .*X-Time: (?!0.000)/ms, 'delayed');
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
d316f1aff10a Tests: "limit_req .. delay" tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 ###############################################################################