comparison auth_request.t @ 508:4ac60aad723e

Tests: test for auth request with proxy cache.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 04 Dec 2014 19:18:45 +0300
parents e7647a966212
children 907e89fba9c3
comparison
equal deleted inserted replaced
507:34280f6b0bc6 508:4ac60aad723e
22 22
23 select STDERR; $| = 1; 23 select STDERR; $| = 1;
24 select STDOUT; $| = 1; 24 select STDOUT; $| = 1;
25 25
26 my $t = Test::Nginx->new() 26 my $t = Test::Nginx->new()
27 ->has(qw/http rewrite proxy fastcgi auth_basic auth_request/) 27 ->has(qw/http rewrite proxy cache fastcgi auth_basic auth_request/)
28 ->plan(17); 28 ->plan(19);
29 29
30 $t->write_file_expand('nginx.conf', <<'EOF'); 30 $t->write_file_expand('nginx.conf', <<'EOF');
31 31
32 %%TEST_GLOBALS%% 32 %%TEST_GLOBALS%%
33 33
36 events { 36 events {
37 } 37 }
38 38
39 http { 39 http {
40 %%TEST_GLOBALS_HTTP%% 40 %%TEST_GLOBALS_HTTP%%
41
42 proxy_cache_path %%TESTDIR%%/cache levels=1:2
43 keys_zone=NAME:1m;
41 44
42 server { 45 server {
43 listen 127.0.0.1:8080; 46 listen 127.0.0.1:8080;
44 server_name localhost; 47 server_name localhost;
45 48
113 proxy_pass http://127.0.0.1:8080/auth-open; 116 proxy_pass http://127.0.0.1:8080/auth-open;
114 proxy_pass_request_body off; 117 proxy_pass_request_body off;
115 proxy_set_header Content-Length ""; 118 proxy_set_header Content-Length "";
116 } 119 }
117 120
121 location /proxy-cache {
122 auth_request /auth-proxy-cache;
123 }
124 location = /auth-proxy-cache {
125 proxy_pass http://127.0.0.1:8080/auth-basic;
126 proxy_pass_request_body off;
127 proxy_set_header Content-Length "";
128 proxy_cache NAME;
129 proxy_cache_valid 1m;
130 }
131
118 location /fastcgi { 132 location /fastcgi {
119 auth_request /auth-fastcgi; 133 auth_request /auth-fastcgi;
120 } 134 }
121 location = /auth-fastcgi { 135 location = /auth-fastcgi {
122 fastcgi_pass 127.0.0.1:8081; 136 fastcgi_pass 127.0.0.1:8081;
151 'proxy auth has www-authenticate'); 165 'proxy auth has www-authenticate');
152 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass'); 166 like(http_get_auth('/proxy'), qr/ 404 /, 'proxy auth pass');
153 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content'); 167 unlike(http_get_auth('/proxy'), qr/INVISIBLE/, 'proxy auth no content');
154 168
155 like(http_post('/proxy'), qr/ 401 /, 'proxy auth post'); 169 like(http_post('/proxy'), qr/ 401 /, 'proxy auth post');
170
171 TODO: {
172 local $TODO = 'not yet' unless $t->has_version('1.7.3');
173
174 like(http_get_auth('/proxy-cache'), qr/ 404 /, 'proxy auth with cache');
175
176 }
177
178 like(http_get('/proxy-cache'), qr/ 404 /, 'proxy auth cached');
156 179
157 # Consider the following scenario: 180 # Consider the following scenario:
158 # 181 #
159 # 1. proxy_pass reads request body, then goes to fallback via error_page 182 # 1. proxy_pass reads request body, then goes to fallback via error_page
160 # 2. auth request uses proxy_pass, and upstream module closes request body file 183 # 2. auth request uses proxy_pass, and upstream module closes request body file