Mercurial > hg > nginx-tests
annotate proxy.t @ 922:93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 12 May 2016 13:08:43 +0300 |
parents | eca9b1d19021 |
children | 54680c434afa |
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 |
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 | |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(7); |
42 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
28 %%TEST_GLOBALS%% |
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
29 |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
166
diff
changeset
|
30 daemon off; |
42 | 31 |
32 events { | |
33 } | |
34 | |
35 http { | |
107
1c0ec30614c6
Tests: add TEST_GLOBALS and TEST_GLOBALS_HTTP config chunks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
83
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
42 | 37 |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
38 upstream u { |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
39 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
|
40 } |
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
41 |
42 | 42 server { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
43 listen 127.0.0.1:8080; |
42 | 44 server_name localhost; |
731
cf9183219c59
Tests: removed debugging leftover.
Sergey Kandaurov <pluknet@nginx.com>
parents:
717
diff
changeset
|
45 |
42 | 46 location / { |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
42 | 48 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
|
49 proxy_connect_timeout 2s; |
42 | 50 } |
434 | 51 |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
52 location /var { |
434 | 53 proxy_pass http://$arg_b; |
54 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
|
55 } |
42 | 56 } |
57 } | |
58 | |
59 EOF | |
60 | |
61 $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
|
62 $t->run()->waitforsocket('127.0.0.1:8081'); |
42 | 63 |
64 ############################################################################### | |
65 | |
66 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
67 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
68 | |
69 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
70 | |
434 | 71 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
|
72 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
|
73 |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
74 SKIP: { |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
75 skip 'no ipv6', 1 unless $t->has_module('ipv6'); |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
76 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
77 TODO: { |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
78 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
|
79 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
|
80 |
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
81 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
|
82 |
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 |
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 |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
87 my $s = http('', start => 1); |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
88 |
795
122cd3a82367
Tests: fixed 'proxy connect timeout' test timeouts on slow hosts.
Sergey Kandaurov <pluknet@nginx.com>
parents:
732
diff
changeset
|
89 sleep 3; |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
90 |
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
91 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
|
92 |
42 | 93 ############################################################################### |
94 | |
95 sub http_daemon { | |
96 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
97 Proto => 'tcp', |
42 | 98 LocalHost => '127.0.0.1:8081', |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
99 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
100 Reuse => 1 |
42 | 101 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
102 or die "Can't create listening socket: $!\n"; |
42 | 103 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
104 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
105 |
42 | 106 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
107 $client->autoflush(1); |
42 | 108 |
109 my $headers = ''; | |
110 my $uri = ''; | |
111 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
112 while (<$client>) { |
42 | 113 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
114 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
115 } |
42 | 116 |
117 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
118 | |
119 if ($uri eq '/') { | |
120 print $client <<'EOF'; | |
121 HTTP/1.1 200 OK | |
122 Connection: close | |
123 | |
124 EOF | |
125 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
126 unless $headers =~ /^HEAD/i; | |
127 | |
128 } elsif ($uri eq '/multi') { | |
129 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
130 print $client <<"EOF"; |
42 | 131 HTTP/1.1 200 OK |
132 Connection: close | |
133 | |
134 TEST-OK-IF-YOU-SEE-THIS | |
135 EOF | |
136 | |
137 select undef, undef, undef, 0.1; | |
138 print $client 'AND-THIS'; | |
139 | |
140 } else { | |
141 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
142 print $client <<"EOF"; |
42 | 143 HTTP/1.1 404 Not Found |
144 Connection: close | |
145 | |
146 Oops, '$uri' not found | |
147 EOF | |
148 } | |
149 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
150 close $client; |
42 | 151 } |
152 } | |
153 | |
154 ############################################################################### |