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