Skip to content

Commit a48a2f3

Browse files
committed
Tests: tests for multiple WWW-Authenticate headers (ticket #485).
1 parent e23beaa commit a48a2f3

File tree

2 files changed

+130
-1
lines changed

2 files changed

+130
-1
lines changed

auth_request.t

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ select STDOUT; $| = 1;
2525

2626
my $t = Test::Nginx->new()
2727
->has(qw/http rewrite proxy cache fastcgi auth_basic auth_request/)
28-
->plan(19);
28+
->plan(20);
2929

3030
$t->write_file_expand('nginx.conf', <<'EOF');
3131
@@ -129,6 +129,20 @@ http {
129129
proxy_cache_valid 1m;
130130
}
131131
132+
location /proxy-multi {
133+
auth_request /auth-proxy-multi;
134+
}
135+
location = /auth-proxy-multi {
136+
proxy_pass http://127.0.0.1:8080/auth-multi;
137+
proxy_pass_request_body off;
138+
proxy_set_header Content-Length "";
139+
}
140+
location = /auth-multi {
141+
add_header WWW-Authenticate foo always;
142+
add_header WWW-Authenticate bar always;
143+
return 401;
144+
}
145+
132146
location /fastcgi {
133147
auth_request /auth-fastcgi;
134148
}
@@ -187,6 +201,16 @@ like(http_get('/proxy-cache'), qr/ 404 /, 'proxy auth cached');
187201

188202
like(http_post_big('/proxy-double'), qr/ 204 /, 'proxy auth with body read');
189203

204+
# Multiple WWW-Authenticate headers (ticket #485).
205+
206+
TODO: {
207+
local $TODO = 'not yet' unless $t->has_version('1.23.0');
208+
209+
like(http_get('/proxy-multi-auth'), qr/WWW-Authenticate: foo.*bar/s,
210+
'multiple www-authenticate headers');
211+
212+
}
213+
190214
SKIP: {
191215
eval { require FCGI; };
192216
skip 'FCGI not installed', 2 if $@;

proxy_intercept_errors.t

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Maxim Dounin
4+
5+
# Tests for http proxy module, proxy_intercept_errors directive.
6+
7+
###############################################################################
8+
9+
use warnings;
10+
use strict;
11+
12+
use Test::More;
13+
14+
BEGIN { use FindBin; chdir($FindBin::Bin); }
15+
16+
use lib 'lib';
17+
use Test::Nginx;
18+
19+
###############################################################################
20+
21+
select STDERR; $| = 1;
22+
select STDOUT; $| = 1;
23+
24+
my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(4);
25+
26+
$t->write_file_expand('nginx.conf', <<'EOF');
27+
28+
%%TEST_GLOBALS%%
29+
30+
daemon off;
31+
32+
events {
33+
}
34+
35+
http {
36+
%%TEST_GLOBALS_HTTP%%
37+
38+
server {
39+
listen 127.0.0.1:8080;
40+
server_name localhost;
41+
42+
location / {
43+
proxy_pass http://127.0.0.1:8081;
44+
proxy_intercept_errors on;
45+
error_page 401 500 /intercepted;
46+
}
47+
48+
location = /intercepted {
49+
return 200 "intercepted\n";
50+
}
51+
}
52+
53+
server {
54+
listen 127.0.0.1:8081;
55+
server_name localhost;
56+
57+
location / {
58+
return 404 "SEE-THIS";
59+
}
60+
61+
location /500 {
62+
return 500;
63+
}
64+
65+
location /auth {
66+
add_header WWW-Authenticate foo always;
67+
return 401;
68+
}
69+
70+
location /auth-multi {
71+
add_header WWW-Authenticate foo always;
72+
add_header WWW-Authenticate bar always;
73+
return 401;
74+
}
75+
}
76+
}
77+
78+
EOF
79+
80+
$t->run();
81+
82+
###############################################################################
83+
84+
# make sure errors without error_page set are not intercepted
85+
86+
like(http_get('/'), qr/SEE-THIS/, 'not intercepted');
87+
88+
# make sure errors with error_page are intercepted
89+
90+
like(http_get('/500'), qr/500.*intercepted/s, 'intercepted 500');
91+
like(http_get('/auth'), qr/401.*WWW-Authenticate.*intercepted/s,
92+
'intercepted 401');
93+
94+
# make sure multiple WWW-Authenticate headers are returned
95+
# along with intercepted response (ticket #485)
96+
97+
TODO: {
98+
local $TODO = 'not yet' unless $t->has_version('1.23.0');
99+
100+
like(http_get('/auth-multi'), qr/401.*WWW-Authenticate: foo.*bar.*intercept/s,
101+
'intercepted 401 multi');
102+
103+
}
104+
105+
###############################################################################

0 commit comments

Comments
 (0)