Mercurial > hg > nginx-tests
annotate http_variables.t @ 1904:c04134b0290b
Tests: removed deprecated "ssl" directive tests.
In preparation for the directive removal.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 05 Jun 2023 18:55:36 +0400 |
parents | 5ac6efbe5552 |
children |
rev | line source |
---|---|
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
2 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
4 # (C) Valentin Bartenev |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
5 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
6 # Tests for http variables. |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
7 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
8 ############################################################################### |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
9 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
10 use warnings; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
11 use strict; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
12 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
13 use Test::More; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
14 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
16 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
17 use lib 'lib'; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
18 use Test::Nginx; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
19 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
20 ############################################################################### |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
21 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
24 |
1569
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite proxy/)->plan(7); |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
26 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
28 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
30 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
31 daemon off; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
32 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
33 events { |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
34 } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
35 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
36 http { |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
38 |
192
f2a48c528b3b
Tests: fixed http variables test, log entries order may differ.
Valentin Bartenev <ne@vbart.ru>
parents:
185
diff
changeset
|
39 log_format cc "$uri: $sent_http_cache_control"; |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
40 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080; |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
43 server_name localhost; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
44 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
45 access_log %%TESTDIR%%/cc.log cc; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
46 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
47 location / { |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
48 return 200 OK; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
49 } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
50 |
1569
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
51 location /arg { |
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
52 return 200 $arg_l:$arg_; |
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
53 } |
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
54 |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
55 location /set { |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
56 add_header Cache-Control max-age=3600; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
57 add_header Cache-Control private; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
58 add_header Cache-Control must-revalidate; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
59 return 200 OK; |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
60 } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
61 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
62 location /redefine { |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
63 expires epoch; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
64 proxy_pass http://127.0.0.1:8080/set; |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
65 } |
999
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
66 |
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
67 location /limit_rate { |
1464
4bc1490cedbc
Tests: added $limit_rate test with invalid empty value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1130
diff
changeset
|
68 set $limit_rate $arg_l; |
999
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
69 add_header X-Rate $limit_rate; |
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
70 return 200 OK; |
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
71 } |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
72 } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
73 } |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
74 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
75 EOF |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
76 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
77 $t->run(); |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
78 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
79 ############################################################################### |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
80 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
81 http_get('/'); |
441
cd61bacbbfe0
Tests: ensure that $uri is reset on URI parsing errors.
Sergey Kandaurov <pluknet@nginx.com>
parents:
264
diff
changeset
|
82 http_get('/../bad_uri'); |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
83 http_get('/redefine'); |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
84 |
1569
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
85 like(http_get('/arg?l=42'), qr/42:$/, 'arg'); |
cd6abbe0f989
Tests: added generic tests for $arg_ variables.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1464
diff
changeset
|
86 |
999
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
87 # $limit_rate is a special variable that has its own set_handler / get_handler |
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
88 |
1464
4bc1490cedbc
Tests: added $limit_rate test with invalid empty value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1130
diff
changeset
|
89 like(http_get('/limit_rate?l=40k'), qr/X-Rate: 40960/, 'limit_rate handlers'); |
4bc1490cedbc
Tests: added $limit_rate test with invalid empty value.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1130
diff
changeset
|
90 like(http_get('/limit_rate'), qr/X-Rate: 0/, 'limit_rate invalid'); |
999
ff12dfdb0cda
Tests: added test for the $limit_rate variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
91 |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
92 $t->stop(); |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
93 |
908
adf5671391ac
Tests: use read_file subroutine in several tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
447
diff
changeset
|
94 my $log = $t->read_file('cc.log'); |
441
cd61bacbbfe0
Tests: ensure that $uri is reset on URI parsing errors.
Sergey Kandaurov <pluknet@nginx.com>
parents:
264
diff
changeset
|
95 like($log, qr!^: -$!m, 'no uri'); |
192
f2a48c528b3b
Tests: fixed http variables test, log entries order may differ.
Valentin Bartenev <ne@vbart.ru>
parents:
185
diff
changeset
|
96 like($log, qr!^/: -$!m, 'no header'); |
1130
cb46ac65d50e
Tests: fixed expected value for multiple Cache-Control headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1000
diff
changeset
|
97 like($log, qr!^/set: max-age=3600, private, must-revalidate$!m, |
192
f2a48c528b3b
Tests: fixed http variables test, log entries order may differ.
Valentin Bartenev <ne@vbart.ru>
parents:
185
diff
changeset
|
98 'multi headers'); |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
99 |
192
f2a48c528b3b
Tests: fixed http variables test, log entries order may differ.
Valentin Bartenev <ne@vbart.ru>
parents:
185
diff
changeset
|
100 like($log, qr!^/redefine: no-cache$!m, 'ignoring headers with (hash == 0)'); |
185
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
101 |
43fe964de06a
Tests: added tests for the $sent_http_cache_control variable.
Valentin Bartenev <ne@vbart.ru>
parents:
diff
changeset
|
102 ############################################################################### |