Mercurial > hg > nginx-tests
annotate xslt.t @ 1606:e4e0695552ed
Tests: fixed stream_proxy_ssl_conf_command.t.
The stream_proxy_ssl_conf_command.t test used stream return module
to return the response. Since this ignores actual request, but the
perl test code used http_get(). This might result in the request being
sent after the response is returned and the connection closed by the server,
resulting in RST being generated and no response seen by the client at all.
Fix is to use "stream(...)->read()" instead of http_get(), so
no request is sent at all, eliminating possibility of RST being
generated.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 10 Nov 2020 05:03:29 +0300 |
parents | b4014b3e8495 |
children | 5ac6efbe5552 |
rev | line source |
---|---|
208 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Maxim Dounin | |
4 | |
5 # Tests for nginx xslt filter module. | |
6 | |
7 ############################################################################### | |
8 | |
9 use warnings; | |
10 use strict; | |
11 | |
12 use Test::More; | |
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 | |
1584
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
24 my $t = Test::Nginx->new()->has(qw/http xslt/)->plan(8); |
208 | 25 |
26 $t->write_file_expand('nginx.conf', <<'EOF'); | |
27 | |
28 %%TEST_GLOBALS%% | |
29 | |
249
6a0d934950bc
Tests: remove extra spaces in "daemon off".
Maxim Dounin <mdounin@mdounin.ru>
parents:
224
diff
changeset
|
30 daemon off; |
208 | 31 |
32 events { | |
33 } | |
34 | |
35 http { | |
36 %%TEST_GLOBALS_HTTP%% | |
37 | |
38 server { | |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:8080; |
208 | 40 server_name localhost; |
41 | |
42 default_type text/xml; | |
43 | |
44 location /x1 { | |
45 xslt_stylesheet %%TESTDIR%%/test.xslt; | |
46 } | |
47 location /x2 { | |
48 xslt_stylesheet %%TESTDIR%%/test.xslt | |
211
ee8fee3c4ae8
Tests: fix xslt tests for CentOS 5.
Maxim Dounin <mdounin@mdounin.ru>
parents:
208
diff
changeset
|
49 param1='value1':param2=/root param3='value%33'; |
208 | 50 } |
51 location /x3 { | |
52 xml_entities %%TESTDIR%%/entities.dtd; | |
53 xslt_stylesheet %%TESTDIR%%/test.xslt; | |
54 } | |
55 location /x4 { | |
56 xslt_stylesheet %%TESTDIR%%/first.xslt; | |
57 xslt_stylesheet %%TESTDIR%%/test.xslt; | |
58 } | |
1493
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
59 location /x5 { |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
60 xslt_stylesheet %%TESTDIR%%/test.xslt |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
61 param1='$server_name'; |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
62 } |
208 | 63 } |
64 } | |
65 | |
66 EOF | |
67 | |
68 $t->write_file('test.xslt', <<'EOF'); | |
69 | |
70 <xsl:stylesheet version="1.0" | |
71 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
72 | |
73 <xsl:output method="html"/> | |
74 | |
75 <xsl:param name="param1"/> | |
76 <xsl:param name="param2"/> | |
77 <xsl:param name="param3"/> | |
78 | |
79 <xsl:template match="/"> | |
80 test xslt result | |
81 param1=<xsl:value-of select="$param1"/> | |
82 param2=<xsl:value-of select="$param2"/> | |
83 param3=<xsl:value-of select="$param3"/> | |
211
ee8fee3c4ae8
Tests: fix xslt tests for CentOS 5.
Maxim Dounin <mdounin@mdounin.ru>
parents:
208
diff
changeset
|
84 data=<xsl:value-of select="/root"/> |
208 | 85 </xsl:template> |
86 | |
87 </xsl:stylesheet> | |
88 | |
89 EOF | |
90 | |
91 $t->write_file('first.xslt', <<'EOF'); | |
92 | |
93 <xsl:stylesheet version="1.0" | |
94 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
95 | |
96 <xsl:template match="/"> | |
211
ee8fee3c4ae8
Tests: fix xslt tests for CentOS 5.
Maxim Dounin <mdounin@mdounin.ru>
parents:
208
diff
changeset
|
97 <root>other <xsl:value-of select="/root"/></root> |
208 | 98 </xsl:template> |
99 | |
100 </xsl:stylesheet> | |
101 | |
102 EOF | |
103 | |
104 $t->write_file('entities.dtd', '<!ENTITY test "test entity">' . "\n"); | |
105 $t->write_file('x1', '<empty/>'); | |
106 $t->write_file('x2', '<root>data</root>'); | |
107 $t->write_file('x3', '<!DOCTYPE root><root>&test;</root>'); | |
108 $t->write_file('x4', '<root>data</root>'); | |
1493
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
109 $t->write_file('x5', '<root>data</root>'); |
208 | 110 |
111 $t->run(); | |
112 | |
113 ############################################################################### | |
114 | |
115 like(http_get("/x1"), qr!200 OK.*test xslt result!ms, 'simple'); | |
116 like(http_get("/x1"), qr!200 OK.*Content-Type: text/html!ms, 'content type'); | |
117 like(http_get("/x2"), qr!200 OK.*param1=value1.*param2=data.*param3=value3!ms, | |
118 'params'); | |
119 like(http_get("/x3"), qr!200 OK.*data=test entity!ms, 'entities'); | |
120 like(http_get("/x4"), qr!200 OK.*data=other data!ms, 'several stylesheets'); | |
121 | |
1493
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
122 TODO: { |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
123 todo_skip 'heap-buffer-overflow', 1 unless $t->has_version('1.17.2') |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
124 or $ENV{TEST_NGINX_UNSAFE}; |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
125 |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
126 like(http_get("/x5"), qr!200 OK.*param1=localhost!ms, 'params variable'); |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
127 |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
128 } |
829467f8d696
Tests: xslt_stylesheet parameter from variable.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
129 |
1584
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
130 # xslt and ranges |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
131 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
132 TODO: { |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
133 local $TODO = 'not yet' unless $t->has_version('1.19.2'); |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
134 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
135 unlike(http_get("/x1"), qr!Accept-Ranges!, 'no Accept-Ranges'); |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
136 like(http(<<EOF), qr!200 OK.*test xslt result!ms, 'no ranges'); |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
137 GET /x1 HTTP/1.1 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
138 Host: localhost |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
139 Connection: close |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
140 Range: bytes=-10 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
141 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
142 EOF |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
143 |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
144 } |
b4014b3e8495
Tests: added xslt filter tests with ranges.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1493
diff
changeset
|
145 |
208 | 146 ############################################################################### |