Mercurial > hg > nginx-tests
annotate proxy.t @ 939:cfddaf316233
Tests: restored proxy_temp_path access bits in proxy_unfinished.t.
Useful when removing that directory by hand.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 03 Jun 2016 14:31:52 +0300 |
parents | 54680c434afa |
children | e9064d691790 |
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 { |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
41 server 127.0.0.1:8081; |
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 { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
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 / { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
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; | |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
57 } |
42 | 58 } |
59 } | |
60 | |
61 EOF | |
62 | |
63 $t->run_daemon(\&http_daemon); | |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
64 $t->run()->waitforsocket('127.0.0.1:8081'); |
42 | 65 |
66 ############################################################################### | |
67 | |
68 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
69 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
70 | |
71 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
72 | |
434 | 73 like(http_get('/var?b=127.0.0.1:8081/'), qr/SEE-THIS/, 'proxy with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
74 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
|
75 |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
76 SKIP: { |
924
54680c434afa
Tests: fixed proxy.t on platforms without IPv6 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
922
diff
changeset
|
77 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
|
78 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
|
79 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
80 TODO: { |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
81 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
|
82 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
|
83 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
84 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
|
85 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
86 } |
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 |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
90 my $s = http('', start => 1); |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
91 |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
92 sleep 3; |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
93 |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
94 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
|
95 |
42 | 96 ############################################################################### |
97 | |
98 sub http_daemon { | |
99 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
100 Proto => 'tcp', |
42 | 101 LocalHost => '127.0.0.1:8081', |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
102 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
103 Reuse => 1 |
42 | 104 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
105 or die "Can't create listening socket: $!\n"; |
42 | 106 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
107 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
108 |
42 | 109 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
110 $client->autoflush(1); |
42 | 111 |
112 my $headers = ''; | |
113 my $uri = ''; | |
114 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
115 while (<$client>) { |
42 | 116 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
117 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
118 } |
42 | 119 |
120 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
121 | |
122 if ($uri eq '/') { | |
123 print $client <<'EOF'; | |
124 HTTP/1.1 200 OK | |
125 Connection: close | |
126 | |
127 EOF | |
128 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
129 unless $headers =~ /^HEAD/i; | |
130 | |
131 } elsif ($uri eq '/multi') { | |
132 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
133 print $client <<"EOF"; |
42 | 134 HTTP/1.1 200 OK |
135 Connection: close | |
136 | |
137 TEST-OK-IF-YOU-SEE-THIS | |
138 EOF | |
139 | |
140 select undef, undef, undef, 0.1; | |
141 print $client 'AND-THIS'; | |
142 | |
143 } else { | |
144 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
145 print $client <<"EOF"; |
42 | 146 HTTP/1.1 404 Not Found |
147 Connection: close | |
148 | |
149 Oops, '$uri' not found | |
150 EOF | |
151 } | |
152 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
153 close $client; |
42 | 154 } |
155 } | |
156 | |
157 ############################################################################### |