Mercurial > hg > nginx-tests
annotate limit_req_delay.t @ 1851:0351dee227a8
Tests: unbreak tests with dynamic certificates on stable.
In 74cffa9d4c43, ticket based session reuse is enabled in addition to
using a shared SSL session cache. This changed how a session can be
resumed in a different server:
- for a session ID based resumption, it is resumed in the same context
- when using session tickets, a key name is also checked for matching
- with a ticket callback, this is skipped in favor of callback's logic
This makes 'session id context match' tests fail with session tickets
on stable since ticket key names are unique in distinct SSL contexts.
On the other hand, tests pass on 1.23.2+ due to automatic ticket keys
rotation that installs ticket callback, and using a common shared SSL
session cache.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 28 Mar 2023 01:36:32 +0400 |
parents | 144c6ce732e4 |
children |
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 ############################################################################### |