comparison proxy_intercept_errors.t @ 1771:83ec64929612

Tests: tests for multiple WWW-Authenticate headers (ticket #485).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:37:05 +0300
parents
children
comparison
equal deleted inserted replaced
1770:ce4419d32383 1771:83ec64929612
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 ###############################################################################