Mercurial > hg > nginx-tests
annotate mirror_proxy.t @ 1323:6eb3dd2d4d5a
Tests: postponed grpc_ssl.t startup on win32, see eadd24ccfda1.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 03 May 2018 13:08:22 +0300 |
parents | a6453cf5786a |
children | e16eecc84b49 |
rev | line source |
---|---|
1208
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http mirror module and it's interaction with proxy. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http proxy mirror rewrite/); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 log_format test $uri:$request_body; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 mirror /mirror; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 proxy_pass http://127.0.0.1:8081; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 location /off { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 mirror /mirror/off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 mirror_request_body off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 proxy_pass http://127.0.0.1:8081; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 location /mirror { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 internal; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 proxy_pass http://127.0.0.1:8082; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 server { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 listen 127.0.0.1:8081; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 listen 127.0.0.1:8082; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 server_name localhost; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 location / { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 client_body_timeout 1s; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 proxy_pass http://127.0.0.1:$server_port/return204; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 access_log %%TESTDIR%%/test.log test; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 add_header X-Body $request_body; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 location /return204 { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 return 204; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 EOF |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $t->try_run('no mirror')->plan(6); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 like(http_post('/'), qr/X-Body: 1234567890\x0d?$/m, 'mirror proxy'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 like(http_post('/off'), qr/X-Body: 1234567890\x0d?$/m, 'mirror_request_body'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $t->stop(); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 my $log = $t->read_file('test.log'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 like($log, qr!^/:1234567890$!m, 'log - request body'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
93 like($log, qr!^/mirror:1234567890$!m, 'log - request body in mirror'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 like($log, qr!^/off:1234567890$!m, 'log - mirror_request_body off'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 like($log, qr!^/mirror/off:-$!m,, 'log - mirror_request_body off in mirror'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 sub http_post { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 my ($url) = @_; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
102 http(<<EOF); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
103 POST $url HTTP/1.0 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
104 Host: localhost |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
105 Content-Length: 10 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
106 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
107 1234567890 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
108 EOF |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
109 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
110 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
111 ############################################################################### |