Mercurial > hg > nginx-tests
annotate proxy_ssi_body.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 97c8280de681 |
children |
rev | line source |
---|---|
422
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Test for proxied subrequest with request body in file. |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use Socket qw/ CRLF /; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(1); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 $t->write_file_expand('nginx.conf', <<'EOF'); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 %%TEST_GLOBALS%% |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 daemon off; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 events { |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 http { |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 %%TEST_GLOBALS_HTTP%% |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
42 listen 127.0.0.1:8080; |
422
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /proxy { |
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:8080/; |
422
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 client_body_in_file_only on; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 ssi on; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 EOF |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 $t->write_file('ssi.html', 'X<!--# include virtual="test.html" -->X'); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 $t->write_file('test.html', 'YY'); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 $t->run(); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 # Request body cache file is released once a response is got. |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 # If later a subrequest tries to use body, it fails. |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 like(http_get_body('/proxy/ssi.html', "1234567890"), qr/^XYYX$/m, |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 'body in file in proxied subrequest'); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 ############################################################################### |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 sub http_get_body { |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 my ($url, $body, %extra) = @_; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 my $p = "GET $url HTTP/1.0" . CRLF |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 . "Host: localhost" . CRLF |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 . "Content-Length: " . (length $body) . CRLF . CRLF |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 . $body; |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 return http($p, %extra); |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 } |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
ddc4b1011333
Tests: test for proxied subrequest with request body in file.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 ############################################################################### |