Mercurial > hg > nginx-tests
annotate sub_filter_ssi.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 882267679006 |
children |
rev | line source |
---|---|
406
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Tests for sub filter and subrequests. |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 BEGIN { use FindBin; chdir($FindBin::Bin); } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 use lib 'lib'; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 use Test::Nginx; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ############################################################################### |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 select STDERR; $| = 1; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 select STDOUT; $| = 1; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http sub ssi xslt/)->plan(2) |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ->write_file_expand('nginx.conf', <<'EOF'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 %%TEST_GLOBALS%% |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 daemon off; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 events { |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 http { |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 %%TEST_GLOBALS_HTTP%% |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 types { |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 text/html html; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 text/xml xml; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
43 listen 127.0.0.1:8080; |
406
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 server_name localhost; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 location / { |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 ssi on; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 sub_filter notfoo bar; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 location /xslt { |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 ssi on; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 sub_filter_types *; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 sub_filter root>foo bar; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 xslt_stylesheet test.xslt; |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 } |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 EOF |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 $t->write_file('index.html', '<!--#include virtual="/not.html" --> truncated'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 $t->write_file('not.html', 'response is not'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 $t->write_file('xslt.html', '<!--#include virtual="/xslt.xml" --> truncated'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 $t->write_file('xslt.xml', '<root>test</root>'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 $t->write_file('test.xslt', <<'EOF'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 <xsl:stylesheet version="1.0" |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 <xsl:output method="html"/> |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 <xsl:strip-space elements="*"/> |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 <xsl:template match="/">response is not</xsl:template> |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 </xsl:stylesheet> |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 EOF |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 $t->run(); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 ############################################################################### |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 like(http_get('/index.html'), qr/not truncated/, 'subrequest partial match'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 like(http_get('/xslt.html'), qr/not.*truncated/ms, 'partial match and xslt'); |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 |
811fbc213fd8
Tests: sub filter tests with subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 ############################################################################### |