Mercurial > hg > nginx-tests
annotate auth_request.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | a095b971fbcc |
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. |
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 |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
12 use Test::More; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
14 use Socket qw/ CRLF /; |
322
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 BEGIN { use FindBin; chdir($FindBin::Bin); } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 use lib 'lib'; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 use Test::Nginx; |
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 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new() |
508
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
27 ->has(qw/http rewrite proxy cache fastcgi auth_basic auth_request/) |
1771
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
28 ->plan(20); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 $t->write_file_expand('nginx.conf', <<'EOF'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 %%TEST_GLOBALS%% |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
34 daemon off; |
322
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 events { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 } |
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 http { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 %%TEST_GLOBALS_HTTP%% |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
508
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
42 proxy_cache_path %%TESTDIR%%/cache levels=1:2 |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
43 keys_zone=NAME:1m; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
44 |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
46 listen 127.0.0.1:8080; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 server_name localhost; |
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 / { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 return 444; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 location /open { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 auth_request /auth-open; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 location = /auth-open { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 return 204; |
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 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 location /open-static { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 auth_request /auth-open-static; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 location = /auth-open-static { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 # nothing, use static file |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 location /unauthorized { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 auth_request /auth-unauthorized; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 location = /auth-unauthorized { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 return 401; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 } |
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 /forbidden { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 auth_request /auth-forbidden; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 location = /auth-forbidden { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 return 403; |
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 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 location /error { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 auth_request /auth-error; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 location = /auth-error { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 return 404; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 location /off { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 auth_request off; |
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 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 location /proxy { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 auth_request /auth-proxy; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 location = /auth-proxy { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
96 proxy_pass http://127.0.0.1:8080/auth-basic; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 proxy_pass_request_body off; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 proxy_set_header Content-Length ""; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 location = /auth-basic { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 auth_basic "restricted"; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 auth_basic_user_file %%TESTDIR%%/htpasswd; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 location = /proxy-double { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
106 proxy_pass http://127.0.0.1:8080/auth-error; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 proxy_intercept_errors on; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 error_page 404 = /proxy-double-fallback; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 client_body_buffer_size 4k; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 location = /proxy-double-fallback { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 auth_request /auth-proxy-double; |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
113 proxy_pass http://127.0.0.1:8080/auth-open; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 location = /auth-proxy-double { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
116 proxy_pass http://127.0.0.1:8080/auth-open; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 proxy_pass_request_body off; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 proxy_set_header Content-Length ""; |
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 |
508
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
121 location /proxy-cache { |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
122 auth_request /auth-proxy-cache; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
123 } |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
124 location = /auth-proxy-cache { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
125 proxy_pass http://127.0.0.1:8080/auth-basic; |
508
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
126 proxy_pass_request_body off; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
127 proxy_set_header Content-Length ""; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
128 proxy_cache NAME; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
129 proxy_cache_valid 1m; |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
130 } |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
131 |
1771
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
132 location /proxy-multi { |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
133 auth_request /auth-proxy-multi; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
134 } |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
135 location = /auth-proxy-multi { |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
136 proxy_pass http://127.0.0.1:8080/auth-multi; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
137 proxy_pass_request_body off; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
138 proxy_set_header Content-Length ""; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
139 } |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
140 location = /auth-multi { |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
141 add_header WWW-Authenticate foo always; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
142 add_header WWW-Authenticate bar always; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
143 return 401; |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
144 } |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
145 |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 location /fastcgi { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 auth_request /auth-fastcgi; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 location = /auth-fastcgi { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
150 fastcgi_pass 127.0.0.1:8081; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 fastcgi_pass_request_body off; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 EOF |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 |
333
e7647a966212
Tests: use {PLAIN} passwords on win32 to unbreak auth_request.t.
Maxim Dounin <mdounin@mdounin.ru>
parents:
331
diff
changeset
|
158 $t->write_file('htpasswd', 'user:{PLAIN}secret' . "\n"); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
159 $t->write_file('auth-basic', 'INVISIBLE'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
160 $t->write_file('auth-open-static', 'INVISIBLE'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 $t->run(); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 like(http_get('/open'), qr/ 404 /, 'auth open'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 like(http_get('/unauthorized'), qr/ 401 /, 'auth unauthorized'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 like(http_get('/forbidden'), qr/ 403 /, 'auth forbidden'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 like(http_get('/error'), qr/ 500 /, 'auth error'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 like(http_get('/off'), qr/ 404 /, 'auth off'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 like(http_post('/open'), qr/ 404 /, 'auth post open'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 like(http_post('/unauthorized'), qr/ 401 /, 'auth post unauthorized'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 like(http_get('/open-static'), qr/ 404 /, 'auth open static'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 unlike(http_get('/open-static'), qr/INVISIBLE/, 'auth static no content'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 like(http_get('/proxy'), qr/ 401 /, 'proxy auth unauthorized'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 like(http_get('/proxy'), qr/WWW-Authenticate: Basic realm="restricted"/, |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 'proxy auth has www-authenticate'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 like(http_post('/proxy'), qr/ 401 /, 'proxy auth post'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 |
508
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
185 like(http_get_auth('/proxy-cache'), qr/ 404 /, 'proxy auth with cache'); |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
186 like(http_get('/proxy-cache'), qr/ 404 /, 'proxy auth cached'); |
4ac60aad723e
Tests: test for auth request with proxy cache.
Sergey Kandaurov <pluknet@nginx.com>
parents:
333
diff
changeset
|
187 |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 # Consider the following scenario: |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 # |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 # 1. proxy_pass reads request body, then goes to fallback via error_page |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 # 2. auth request uses proxy_pass, and upstream module closes request body file |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 # in ngx_http_upstream_send_response() |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
193 # 3. oops: fallback has no body |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 # |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 # To prevent this we always allocate fake request body for auth request. |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
196 # |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
197 # Note that this doesn't happen when using header_only as relevant code |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 # in ngx_http_upstream_send_response() isn't reached. It may be reached |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
199 # with proxy_cache or proxy_store, but they will shutdown client connection |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 # in case of header_only and hence do not work for us at all. |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
202 like(http_post_big('/proxy-double'), qr/ 204 /, 'proxy auth with body read'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 |
1771
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
204 # Multiple WWW-Authenticate headers (ticket #485). |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
205 |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
206 like(http_get('/proxy-multi-auth'), qr/WWW-Authenticate: foo.*bar/s, |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
207 'multiple www-authenticate headers'); |
83ec64929612
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
Maxim Dounin <mdounin@mdounin.ru>
parents:
1344
diff
changeset
|
208 |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
209 SKIP: { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
210 eval { require FCGI; }; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
211 skip 'FCGI not installed', 2 if $@; |
331
241acee85fd1
Tests: skip FCGI use on win32.
Maxim Dounin <mdounin@mdounin.ru>
parents:
323
diff
changeset
|
212 skip 'win32', 2 if $^O eq 'MSWin32'; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
213 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
214 $t->run_daemon(\&fastcgi_daemon); |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
215 $t->waitforsocket('127.0.0.1:' . port(8081)); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
216 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
217 like(http_get('/fastcgi'), qr/ 404 /, 'fastcgi auth open'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
218 unlike(http_get('/fastcgi'), qr/INVISIBLE/, 'fastcgi auth no content'); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
219 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
220 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
221 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
222 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
223 sub http_get_auth { |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
224 my ($url, %extra) = @_; |
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
225 return http(<<EOF, %extra); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
226 GET $url HTTP/1.0 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
227 Host: localhost |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
228 Authorization: Basic dXNlcjpzZWNyZXQ= |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
229 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
230 EOF |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
231 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
232 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
233 sub http_post { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
234 my ($url, %extra) = @_; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
235 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
236 my $p = "POST $url HTTP/1.0" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
237 "Host: localhost" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
238 "Content-Length: 10" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
239 CRLF . |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
240 "1234567890"; |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
241 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
242 return http($p, %extra); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
243 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
244 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
245 sub http_post_big { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
246 my ($url, %extra) = @_; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
247 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
248 my $p = "POST $url HTTP/1.0" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
249 "Host: localhost" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
250 "Content-Length: 10240" . CRLF . |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
251 CRLF . |
323
d48de852157c
Tests: auth_request assorted fixes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
322
diff
changeset
|
252 ("1234567890" x 1024); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
253 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
254 return http($p, %extra); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
255 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
256 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
257 ############################################################################### |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
258 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
259 sub fastcgi_daemon { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
260 my $socket = FCGI::OpenSocket('127.0.0.1:' . port(8081), 5); |
322
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
261 my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
262 $socket); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
263 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
264 while ($request->Accept() >= 0) { |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
265 print <<EOF; |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
266 Content-Type: text/html |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
267 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
268 INVISIBLE |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
269 EOF |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
270 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
271 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
272 FCGI::CloseSocket($socket); |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
273 } |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
274 |
67c348ba1768
Tests: auth request tests import.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
275 ############################################################################### |