Mercurial > hg > nginx-tests
annotate auth_request_set.t @ 1587:17b227c271a2
Tests: 4xx and 5xx codes with stale-while-revalidate.
Now these codes do not fall under stale-if-error (enabled by
stale-while-revalidate).
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Fri, 14 Aug 2020 13:32:27 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for auth request module, auth_request_set. |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http rewrite proxy auth_request/) |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->plan(6); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
31 daemon off; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 events { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 http { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
40 listen 127.0.0.1:8080; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server_name localhost; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 location = /t1.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 auth_request /auth; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 auth_request_set $username $upstream_http_x_username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 add_header X-Set-Username $username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 location = /t2.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 auth_request /auth; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 auth_request_set $username $upstream_http_x_username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 error_page 404 = /fallback; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 location = /fallback { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 add_header X-Set-Username $username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 location = /t3.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 auth_request /auth; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 auth_request_set $username $upstream_http_x_username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 error_page 404 = @fallback; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 location @fallback { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 add_header X-Set-Username $username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 location = /t4.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 auth_request /auth; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 auth_request_set $username $upstream_http_x_username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 error_page 404 = /t4-fallback.html; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 location = /t4-fallback.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 auth_request /auth2; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 auth_request_set $username $upstream_http_x_username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 add_header X-Set-Username $username; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 location = /t5.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 auth_request /auth; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 auth_request_set $args "setargs"; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
83 proxy_pass http://127.0.0.1:8081/t5.html; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 location = /t6.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 add_header X-Unset-Username "x${username}x"; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 location = /auth { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
92 proxy_pass http://127.0.0.1:8081; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 location = /auth2 { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
95 proxy_pass http://127.0.0.1:8081; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
100 listen 127.0.0.1:8081; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 server_name localhost; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 location = /auth { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 add_header X-Username "username"; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 location = /auth2 { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 add_header X-Username "username2"; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 location = /t5.html { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 add_header X-Args $args; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 return 204; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 EOF |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 $t->write_file('t1.html', ''); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 $t->write_file('t4-fallback.html', ''); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 $t->run(); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 like(http_get('/t1.html'), qr/X-Set-Username: username/, 'set normal'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 like(http_get('/t2.html'), qr/X-Set-Username: username/, 'set after redirect'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 like(http_get('/t3.html'), qr/X-Set-Username: username/, |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 'set after named location'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 like(http_get('/t4.html'), qr/X-Set-Username: username2/, |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
133 'set on second auth'); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 # there are two variables with set_handler: $args and $limit_rate |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 # we do test $args as it's a bit more simple thing to do |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
138 like(http_get('/t5.html'), qr/X-Args: setargs/, 'variable with set_handler'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 # check that using variable without setting it returns empty content |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 like(http_get('/t6.html'), qr/X-Unset-Username: xx/, 'unset variable'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 ############################################################################### |