Mercurial > hg > nginx-tests
annotate proxy.t @ 1021:ebdf239722b9
Tests: relaxed proxy_cache_lock.t nolock tests to fix on Solaris.
Assumed that the order of responses being arrived in nolock case may be ignored.
An important part of such case is that the only last response should be cached.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 02 Sep 2016 12:17:35 +0300 |
parents | e4d5e7afb6e0 |
children | cbc8641a204e |
rev | line source |
---|---|
42 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for http proxy module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
121
8ac1faaddd2c
Tests: better handle various configure arguments.
Maxim Dounin <mdounin@mdounin.ru>
parents:
107
diff
changeset
|
12 use Test::More; |
42 | 13 |
924
54680c434afa
Tests: fixed proxy.t on platforms without IPv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
922
diff
changeset
|
14 use Socket; |
54680c434afa
Tests: fixed proxy.t on platforms without IPv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
922
diff
changeset
|
15 |
42 | 16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
17 | |
18 use lib 'lib'; | |
19 use Test::Nginx; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(7); |
42 | 27 |
28 $t->write_file_expand('nginx.conf', <<'EOF'); | |
29 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
30 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
31 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
32 daemon off; |
42 | 33 |
34 events { | |
35 } | |
36 | |
37 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
42 | 39 |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
40 upstream u { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 server 127.0.0.1:8081; |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
42 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
43 |
42 | 44 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
45 listen 127.0.0.1:8080; |
42 | 46 server_name localhost; |
731
cf9183219c59
Tests: removed debugging leftover.
Sergey Kandaurov <pluknet@nginx.com>
parents:
717
diff
changeset
|
47 |
42 | 48 location / { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
49 proxy_pass http://127.0.0.1:8081; |
42 | 50 proxy_read_timeout 1s; |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
51 proxy_connect_timeout 2s; |
42 | 52 } |
434 | 53 |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
54 location /var { |
434 | 55 proxy_pass http://$arg_b; |
56 proxy_read_timeout 1s; | |
1006
e4d5e7afb6e0
Tests: speed up proxy.t on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
57 proxy_connect_timeout 2s; |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
58 } |
42 | 59 } |
60 } | |
61 | |
62 EOF | |
63 | |
64 $t->run_daemon(\&http_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
65 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
42 | 66 |
67 ############################################################################### | |
68 | |
69 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
70 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
71 | |
72 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
73 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
74 like(http_get('/var?b=127.0.0.1:' . port(8081) . '/'), qr/SEE-THIS/, |
952
e9064d691790
Tests: converted tests to run in parallel.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
924
diff
changeset
|
75 'proxy with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
76 like(http_get('/var?b=u/'), qr/SEE-THIS/, 'proxy with variables to upstream'); |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
77 |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
78 SKIP: { |
924
54680c434afa
Tests: fixed proxy.t on platforms without IPv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
922
diff
changeset
|
79 skip 'no ipv6', 1 unless $t->has_module('ipv6') |
54680c434afa
Tests: fixed proxy.t on platforms without IPv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
922
diff
changeset
|
80 and socket(my $s, &AF_INET6, &SOCK_STREAM, 0); |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
81 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
82 TODO: { |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
83 todo_skip 'heap-buffer-overflow', 1 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
84 unless $ENV{TEST_NGINX_UNSAFE} or $t->has_version('1.11.0'); |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
85 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
86 ok(http_get("/var?b=[::]"), 'proxy with variables - no ipv6 port'); |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
87 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
88 } |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
89 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
90 } |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
91 |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
92 my $s = http('', start => 1); |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
93 |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
94 sleep 3; |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
95 |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
96 like(http_get('/', socket => $s), qr/200 OK/, 'proxy connect timeout'); |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
97 |
42 | 98 ############################################################################### |
99 | |
100 sub http_daemon { | |
101 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
102 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
103 LocalHost => '127.0.0.1:' . port(8081), |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
104 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
105 Reuse => 1 |
42 | 106 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
107 or die "Can't create listening socket: $!\n"; |
42 | 108 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
109 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
110 |
42 | 111 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
112 $client->autoflush(1); |
42 | 113 |
114 my $headers = ''; | |
115 my $uri = ''; | |
116 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
117 while (<$client>) { |
42 | 118 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
119 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
120 } |
42 | 121 |
122 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
123 | |
124 if ($uri eq '/') { | |
125 print $client <<'EOF'; | |
126 HTTP/1.1 200 OK | |
127 Connection: close | |
128 | |
129 EOF | |
130 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
131 unless $headers =~ /^HEAD/i; | |
132 | |
133 } elsif ($uri eq '/multi') { | |
134 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
135 print $client <<"EOF"; |
42 | 136 HTTP/1.1 200 OK |
137 Connection: close | |
138 | |
139 TEST-OK-IF-YOU-SEE-THIS | |
140 EOF | |
141 | |
142 select undef, undef, undef, 0.1; | |
143 print $client 'AND-THIS'; | |
144 | |
145 } else { | |
146 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
147 print $client <<"EOF"; |
42 | 148 HTTP/1.1 404 Not Found |
149 Connection: close | |
150 | |
151 Oops, '$uri' not found | |
152 EOF | |
153 } | |
154 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
155 close $client; |
42 | 156 } |
157 } | |
158 | |
159 ############################################################################### |