Mercurial > hg > nginx-tests
annotate proxy_xar.t @ 572:ca54b445d982
Tests: masked nginx bug in proxy next upstream.
When iterating through several next upstreams per a worker cycle,
a previously reported event about upstream connection error may
be improperly applied to the next upstream, thus leading to the
invalid connection error. E.g., in kqueue, where the problem is
visible, this is caused by "ev->instance" that does not tolerate
more than one next upstream at once, and kevents placed on the
kqueue separately for read and write events.
The change is to limit test case to the only one next upstream.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 14 May 2015 11:54:24 +0300 |
parents | 907e89fba9c3 |
children | 9239393e73c8 |
rev | line source |
---|---|
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for proxy X-Accel-Redirect functionality. |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
495
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy rewrite/)->plan(15); |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 $t->write_file_expand('nginx.conf', <<'EOF'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
30 daemon off; |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 events { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 http { |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
82
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 server { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 listen 127.0.0.1:8080; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 server_name localhost; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
495
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
42 # catch safe and unhandled unsafe URIs, |
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
43 # bypassed with redirect to named location |
366
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
44 if ($upstream_http_x_accel_redirect) { |
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
45 return 200 "xar: $upstream_http_x_accel_redirect uri: $uri"; |
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
46 } |
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
47 |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 location /proxy { |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 proxy_pass http://127.0.0.1:8080/return-xar; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 location /return-xar { |
366
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
52 add_header X-Accel-Redirect $arg_xar; |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 # this headers will be preserved on |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 # X-Accel-Redirect |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 add_header Content-Type text/blah; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 add_header Set-Cookie blah=blah; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 add_header Content-Disposition attachment; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 add_header Cache-Control no-cache; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 add_header Expires fake; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 add_header Accept-Ranges parrots; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 # others won't be |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 add_header Something other; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 return 204; |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 } |
495
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
69 location @named { |
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
70 return 200 "named xar: $upstream_http_x_accel_redirect uri: $uri"; |
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
71 } |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 } |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 EOF |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 $t->run(); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 ############################################################################### |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
366
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
81 my $r = http_get('/proxy?xar=/index.html'); |
77c301be6c2d
Tests: preparations for escaped and unsafe URI tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
249
diff
changeset
|
82 like($r, qr/xar: \/index.html uri: \/index.html/, 'X-Accel-Redirect works'); |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 like($r, qr/^Content-Type: text\/blah/m, 'Content-Type preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 like($r, qr/^Set-Cookie: blah=blah/m, 'Set-Cookie preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 like($r, qr/^Content-Disposition: attachment/m, 'Content-Disposition preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 like($r, qr/^Cache-Control: no-cache/m, 'Cache-Control preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 like($r, qr/^Expires: fake/m, 'Expires preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 like($r, qr/^Accept-Ranges: parrots/m, 'Accept-Ranges preserved'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 unlike($r, qr/^Something/m, 'other headers stripped'); |
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 |
397
847ea345becb
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
367
diff
changeset
|
91 # escaped characters |
367
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
92 |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
93 like(http_get('/proxy?xar=/foo?bar'), qr/200 OK.*xar: \/foo\?bar/s, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
94 'X-Accel-Redirect value unchanged'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
95 unlike(http_get('/proxy?xar=..'), qr/200 OK/, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
96 'X-Accel-Redirect unsafe dotdot'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
97 unlike(http_get('/proxy?xar=../foo'), qr/200 OK/, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
98 'X-Accel-Redirect unsafe dotdotsep'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
99 unlike(http_get('/proxy?xar=/foo/..'), qr/200 OK/, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
100 'X-Accel-Redirect unsafe sepdotdot'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
101 unlike(http_get('/proxy?xar=/foo/.%2e'), qr/200 OK/, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
102 'X-Accel-Redirect unsafe unescaped'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
103 like(http_get('/proxy?xar=/foo%20bar'), qr/uri: \/foo bar/, |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
104 'X-Accel-Redirect unescaped'); |
0726521e42f3
Tests: added tests for escaped and unsafe URIs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
366
diff
changeset
|
105 |
495
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
106 like(http_get('/proxy?xar=@named'), |
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
107 qr!200 OK.*named xar: \@named uri: /proxy!s, 'in named location'); |
eaf287a41f08
Tests: added X-Accel-Redirect test with named location.
Sergey Kandaurov <pluknet@nginx.com>
parents:
397
diff
changeset
|
108 |
82
a2fc9b9e9a2b
Tests: add X-Accel-Redirect tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 ############################################################################### |