Mercurial > hg > nginx-tests
annotate proxy.t @ 1260:eadd24ccfda1
Tests: postponed startup in certain ssl certificate tests on win32.
At least, some win32 hosts exhibit a round-off error or some such in the
notBefore field of the certificate generated before starting nginx, such
that it can be set to the value one second ahead of the current time.
This manifests in spurious test failures due to certificate verify error
with a failure reason "certificate is not yet valid".
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 12 Dec 2017 12:53:53 +0300 |
parents | 766bcbb632ee |
children | 16a8962ff246 |
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 } |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
59 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
60 location /timeout { |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
61 proxy_pass http://127.0.0.1:8081; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
62 proxy_connect_timeout 2s; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
63 } |
42 | 64 } |
65 } | |
66 | |
67 EOF | |
68 | |
69 $t->run_daemon(\&http_daemon); | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
70 $t->run()->waitforsocket('127.0.0.1:' . port(8081)); |
42 | 71 |
72 ############################################################################### | |
73 | |
74 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
75 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
76 | |
77 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
78 | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
79 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
|
80 'proxy with variables'); |
802
eca9b1d19021
Tests: tests for host expansion to an explicit upstream.
Sergey Kandaurov <pluknet@nginx.com>
parents:
795
diff
changeset
|
81 like(http_get('/var?b=u/'), qr/SEE-THIS/, 'proxy with variables to upstream'); |
922
93d900bac201
Tests: added regression test for proxy with no IPv6 port specified.
Sergey Kandaurov <pluknet@nginx.com>
parents:
802
diff
changeset
|
82 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
|
83 |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
84 like(http_get('/timeout'), qr/200 OK/, 'proxy connect timeout'); |
732
984bfe661cce
Tests: stream and http proxy_connect_timeout tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
731
diff
changeset
|
85 |
42 | 86 ############################################################################### |
87 | |
88 sub http_daemon { | |
89 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
90 Proto => 'tcp', |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
91 LocalHost => '127.0.0.1:' . port(8081), |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
92 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
93 Reuse => 1 |
42 | 94 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
95 or die "Can't create listening socket: $!\n"; |
42 | 96 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
97 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
98 |
42 | 99 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
100 $client->autoflush(1); |
42 | 101 |
102 my $headers = ''; | |
103 my $uri = ''; | |
104 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
105 while (<$client>) { |
42 | 106 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
107 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
108 } |
42 | 109 |
110 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
111 | |
112 if ($uri eq '/') { | |
113 print $client <<'EOF'; | |
114 HTTP/1.1 200 OK | |
115 Connection: close | |
116 | |
117 EOF | |
118 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
119 unless $headers =~ /^HEAD/i; | |
120 | |
121 } elsif ($uri eq '/multi') { | |
122 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
123 print $client <<"EOF"; |
42 | 124 HTTP/1.1 200 OK |
125 Connection: close | |
126 | |
127 TEST-OK-IF-YOU-SEE-THIS | |
128 EOF | |
129 | |
130 select undef, undef, undef, 0.1; | |
131 print $client 'AND-THIS'; | |
132 | |
1079
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
133 } elsif ($uri eq '/timeout') { |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
134 sleep 3; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
135 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
136 print $client <<"EOF"; |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
137 HTTP/1.1 200 OK |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
138 Connection: close |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
139 |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
140 EOF |
cbc8641a204e
Tests: fixed "proxy connect timeout" http tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
1006
diff
changeset
|
141 |
42 | 142 } else { |
143 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
144 print $client <<"EOF"; |
42 | 145 HTTP/1.1 404 Not Found |
146 Connection: close | |
147 | |
148 Oops, '$uri' not found | |
149 EOF | |
150 } | |
151 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
152 close $client; |
42 | 153 } |
154 } | |
155 | |
156 ############################################################################### |