Mercurial > hg > nginx-tests
annotate ssi_stub.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | |
children |
rev | line source |
---|---|
1990
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for nginx ssi module, stub output. |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http proxy ssi/)->plan(4) |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 listen 127.0.0.1:8080; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 server_name localhost; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 location / { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 ssi on; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 location = /empty { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 # static |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 location = /error404 { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 # static 404 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 location = /proxy404 { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 proxy_pass http://127.0.0.1:8081; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 proxy_intercept_errors on; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 error_page 404 /error404; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 location = /not_empty { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 proxy_pass http://127.0.0.1:8081; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 server { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 listen 127.0.0.1:8081; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 server_name localhost; |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 EOF |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 $t->write_file('empty.html', |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 '<!--#block name="fallback" -->fallback<!--#endblock -->' . |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 ':<!--#include virtual="/empty" stub="fallback" -->:'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 $t->write_file('error.html', |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 '<!--#block name="fallback" -->fallback<!--#endblock -->' . |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 ':<!--#include virtual="/error404" stub="fallback" -->:'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 $t->write_file('proxy_error.html', |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 '<!--#block name="fallback" -->fallback<!--#endblock -->' . |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 ':<!--#include virtual="/proxy404" stub="fallback" -->:'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 $t->write_file('postponed.html', |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 '<!--#block name="fallback" -->fallback<!--#endblock -->' . |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 ':<!--#include virtual="/not_empty" -->' . |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 ':<!--#include virtual="/empty" stub="fallback" -->:'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 $t->write_file('empty', ''); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 $t->write_file('not_empty', 'not empty'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 $t->run(); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 ############################################################################### |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 like(http_get('/empty.html'), qr/:fallback:/, 'ssi stub empty'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 like(http_get('/error.html'), qr/:fallback:/, 'ssi stub error'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 like(http_get('/proxy_error.html'), qr/:fallback:/, 'ssi stub proxied error'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 TODO: { |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 local $TODO = 'not yet' unless $t->has_version('1.27.2'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 like(http_get('/postponed.html'), qr/:not empty:fallback:/s, |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 'ssi stub postponed'); |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 } |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 |
85d88cd5091c
Tests: SSI include stub tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 ############################################################################### |