Mercurial > hg > nginx-tests
annotate proxy.t @ 540:481d705b8610
Tests: SSL support in mail backends.
Socket is now embedded into every mail module.
Socket methods are wrapped where appropriate.
The new "SSL" extra flag specifies to accept connection over SSL.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 03 Apr 2015 00:11:38 +0300 |
parents | a8596c7b33cc |
children | 3b6ff3b7367d |
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 | |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy/)->plan(4); |
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 |
38 server { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
39 listen 127.0.0.1:8080; |
42 | 40 server_name localhost; |
41 | |
42 location / { | |
45
d68b85def521
Tests: use 127.0.0.1 instead of localhost.
Maxim Dounin <mdounin@mdounin.ru>
parents:
43
diff
changeset
|
43 proxy_pass http://127.0.0.1:8081; |
42 | 44 proxy_read_timeout 1s; |
45 } | |
434 | 46 |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
47 location /var { |
434 | 48 proxy_pass http://$arg_b; |
49 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
|
50 } |
42 | 51 } |
52 } | |
53 | |
54 EOF | |
55 | |
56 $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
|
57 $t->run()->waitforsocket('127.0.0.1:8081'); |
42 | 58 |
59 ############################################################################### | |
60 | |
61 like(http_get('/'), qr/SEE-THIS/, 'proxy request'); | |
62 like(http_get('/multi'), qr/AND-THIS/, 'proxy request with multiple packets'); | |
63 | |
64 unlike(http_head('/'), qr/SEE-THIS/, 'proxy head request'); | |
65 | |
434 | 66 like(http_get('/var?b=127.0.0.1:8081/'), qr/SEE-THIS/, 'proxy with variables'); |
432
c1269426585d
Tests: test for implicit upstream with IP literal and variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
295
diff
changeset
|
67 |
42 | 68 ############################################################################### |
69 | |
70 sub http_daemon { | |
71 my $server = IO::Socket::INET->new( | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
72 Proto => 'tcp', |
42 | 73 LocalHost => '127.0.0.1:8081', |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
74 Listen => 5, |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
75 Reuse => 1 |
42 | 76 ) |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
77 or die "Can't create listening socket: $!\n"; |
42 | 78 |
295
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
79 local $SIG{PIPE} = 'IGNORE'; |
6fe0459b6668
Tests: eliminate startup races in proxy and fastcgi tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
249
diff
changeset
|
80 |
42 | 81 while (my $client = $server->accept()) { |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
82 $client->autoflush(1); |
42 | 83 |
84 my $headers = ''; | |
85 my $uri = ''; | |
86 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
87 while (<$client>) { |
42 | 88 $headers .= $_; |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
89 last if (/^\x0d?\x0a?$/); |
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
90 } |
42 | 91 |
92 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; | |
93 | |
94 if ($uri eq '/') { | |
95 print $client <<'EOF'; | |
96 HTTP/1.1 200 OK | |
97 Connection: close | |
98 | |
99 EOF | |
100 print $client "TEST-OK-IF-YOU-SEE-THIS" | |
101 unless $headers =~ /^HEAD/i; | |
102 | |
103 } elsif ($uri eq '/multi') { | |
104 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
105 print $client <<"EOF"; |
42 | 106 HTTP/1.1 200 OK |
107 Connection: close | |
108 | |
109 TEST-OK-IF-YOU-SEE-THIS | |
110 EOF | |
111 | |
112 select undef, undef, undef, 0.1; | |
113 print $client 'AND-THIS'; | |
114 | |
115 } else { | |
116 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
117 print $client <<"EOF"; |
42 | 118 HTTP/1.1 404 Not Found |
119 Connection: close | |
120 | |
121 Oops, '$uri' not found | |
122 EOF | |
123 } | |
124 | |
83
6e5884419e4a
Tests: whitespace cleanup.
Maxim Dounin <mdounin@mdounin.ru>
parents:
64
diff
changeset
|
125 close $client; |
42 | 126 } |
127 } | |
128 | |
129 ############################################################################### |