projects
/
metaproxy-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
DOCUMENT_ROOT, GATEWAY_INTERFACE MP-564
[metaproxy-moved-to-github.git]
/
src
/
test_filter_rewrite.cpp
diff --git
a/src/test_filter_rewrite.cpp
b/src/test_filter_rewrite.cpp
index
6a81559
..
110d614
100644
(file)
--- a/
src/test_filter_rewrite.cpp
+++ b/
src/test_filter_rewrite.cpp
@@
-1,5
+1,5
@@
/* This file is part of Metaproxy.
/* This file is part of Metaproxy.
- Copyright (C) 2005-2013 Index Data
+ Copyright (C) Index Data
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Metaproxy is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
@@
-43,7
+43,6
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
{
try
{
{
try
{
- std::cout << "Running non-xml config test case" << std::endl;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
@@
-68,9
+67,11
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
" </request>\n"
" <response verbose=\"1\">\n"
" <rule name=\"null\"/>\n"
" </request>\n"
" <response verbose=\"1\">\n"
" <rule name=\"null\"/>\n"
+ " <rule name=\"cx\">\n"
+ " <rewrite from='^cx' to='cy'/>\n"
+ " </rule>\n"
" <rule name=\"url\">\n"
" <rewrite from='foo' to='bar'/>\n"
" <rule name=\"url\">\n"
" <rewrite from='foo' to='bar'/>\n"
- " <rewrite from='^cx' to='cy'/>\n"
" <rewrite from='"
"(?<proto>https?://)(?<host>[^/?# "'>]+)/(?<path>[^ "'>]+)'\n"
" to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n"
" <rewrite from='"
"(?<proto>https?://)(?<host>[^/?# "'>]+)/(?<path>[^ "'>]+)'\n"
" to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n"
@@
-80,9
+81,13
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
" </content>\n"
" <content type=\"html\" mime=\"text/xml|text/html\">\n"
" <within tag=\"body\" attr=\"background\" rule=\"null\"/>\n"
" </content>\n"
" <content type=\"html\" mime=\"text/xml|text/html\">\n"
" <within tag=\"body\" attr=\"background\" rule=\"null\"/>\n"
- " <within tag=\"script\" attr=\"#text\" rule=\"url\"/>\n"
+ " <within tag=\"script\" attr=\"#text\" type=\"quoted-literal\" rule=\"url\"/>\n"
" <within tag=\"style\" attr=\"#text\" rule=\"url\"/>\n"
" <within tag=\"style\" attr=\"#text\" rule=\"url\"/>\n"
- " <within attr=\"href,src\" rule=\"url\"/>\n"
+ " <within attr=\"href|src\" rule=\"url,cx\"/>\n"
+ " <within attr=\"onclick\" type=\"quoted-literal\" rule=\"url\"/>\n"
+ " </content>\n"
+ " <content type=\"quoted-literal\" mime=\".*javascript\">\n"
+ " <within rule=\"url\"/>\n"
" </content>\n"
" </response>\n"
"</filter>\n"
" </content>\n"
" </response>\n"
"</filter>\n"
@@
-104,15
+109,17
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
mp::odr odr;
Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr,
mp::odr odr;
Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr,
- "http://proxyhost/proxypath/targetsite/page1.html", 0, 1);
-
+ "http://proxyhost/proxypath/targetsite/page1.html", 0, 1);
+
+ Z_HTTP_Request *hreq = gdu_req->u.HTTP_Request;
+ z_HTTP_header_set(odr, &hreq->headers,
+ "X-Metaproxy-SkipLink", ".* skiplink.com" );
pack.request() = gdu_req;
//create the http response
const char *resp_buf =
"HTTP/1.1 200 OK\r\n"
pack.request() = gdu_req;
//create the http response
const char *resp_buf =
"HTTP/1.1 200 OK\r\n"
- "Content-Length: 441\r\n"
"Content-Type: text/html\r\n"
"Link: <http://targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
"Content-Type: text/html\r\n"
"Link: <http://targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
@@
-125,7
+132,8
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
"</style>"
"</head>"
"<script>var jslink=\"http://targetsite/webservice.xml\";"
"</style>"
"</head>"
"<script>var jslink=\"http://targetsite/webservice.xml\";"
- "var some=foo;"
+ "for (i = 0; i<foo; i++) ;\n"
+ "var some=\"foo\"; foo=1;"
"</script>"
"<body>"
"<p>Welcome to our website. It doesn't make it easy to get pro"
"</script>"
"<body>"
"<p>Welcome to our website. It doesn't make it easy to get pro"
@@
-135,13
+143,14
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
"<a target=_blank href=\"http://targetsite/page3.html\">"
" Another abs link</a>"
"<a href=\"/docs/page4.html\" />"
"<a target=_blank href=\"http://targetsite/page3.html\">"
" Another abs link</a>"
"<a href=\"/docs/page4.html\" />"
- "<a href=\"cxcx\" />"
- "<a href=\"cx \" />"
+ "<A href=\"cxcx\" />"
+ "<a HREF=\"cx \" onclick=\"foo("foo");\"/>\n"
+ "<a href=\"http://www.skiplink.com/page5.html\">skip</a>\n"
"</body></html>";
const char *resp_expected =
"HTTP/1.1 200 OK\r\n"
"</body></html>";
const char *resp_expected =
"HTTP/1.1 200 OK\r\n"
- "Content-Length: 564\r\n"
+ "Content-Length: 686\r\n"
"Content-Type: text/html\r\n"
"Link: <http://proxyhost/proxypath/targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
"Content-Type: text/html\r\n"
"Link: <http://proxyhost/proxypath/targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
@@
-154,7
+163,8
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
"</style>"
"</head>"
"<script>var jslink=\"http://proxyhost/proxypath/targetsite/webservice.xml\";"
"</style>"
"</head>"
"<script>var jslink=\"http://proxyhost/proxypath/targetsite/webservice.xml\";"
- "var some=bar;"
+ "for (i = 0; i<foo; i++) ;\n"
+ "var some=\"bar\"; foo=1;"
"</script>"
"<body>"
"<p>Welcome to our website. It doesn't make it easy to get pro"
"</script>"
"<body>"
"<p>Welcome to our website. It doesn't make it easy to get pro"
@@
-164,8
+174,9
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
"<a target=_blank href=\"http://proxyhost/proxypath/targetsite/page3.html\">"
" Another abs link</a>"
"<a href=\"/docs/page4.html\"/>"
"<a target=_blank href=\"http://proxyhost/proxypath/targetsite/page3.html\">"
" Another abs link</a>"
"<a href=\"/docs/page4.html\"/>"
- "<a href=\"cycx\"/>"
- "<a href=\"cy \"/>"
+ "<A href=\"cycx\"/>"
+ "<a HREF=\"cy \" onclick=\"foo("bar");\"/>\n"
+ "<a href=\"http://www.skiplink.com/page5.html\">skip</a>\n"
"</body></html>";
Z_GDU *gdu_res;
"</body></html>";
Z_GDU *gdu_res;
@@
-205,7
+216,7
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
- std::cout << "Got result:\n" << "\n";
+ std::cout << "Got result:\n";
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);
@@
-221,12
+232,10
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
}
}
}
}
-
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
{
try
{
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
{
try
{
- std::cout << "Running non-xml config test case" << std::endl;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
mp::RouterChain router;
mp::filter::HttpRewrite fhr;
@@
-261,12
+270,6
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
" <content type=\"headers\">\n"
" <within header=\"link\" rule=\"url\"/>\n"
" </content>\n"
" <content type=\"headers\">\n"
" <within header=\"link\" rule=\"url\"/>\n"
" </content>\n"
- " <content type=\"html\" mime=\"text/xml|text/html\">\n"
- " <within tag=\"body\" attr=\"background\" rule=\"null\"/>\n"
- " <within tag=\"script\" attr=\"#text\" rule=\"url\"/>\n"
- " <within tag=\"style\" attr=\"#text\" rule=\"url\"/>\n"
- " <within attr=\"href,src\" rule=\"url\"/>\n"
- " </content>\n"
" <content type=\"quoted-literal\" mime=\".*javascript\">\n"
" <within rule=\"url\"/>\n"
" </content>\n"
" <content type=\"quoted-literal\" mime=\".*javascript\">\n"
" <within rule=\"url\"/>\n"
" </content>\n"
@@
-298,7
+301,6
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
const char *resp_buf =
"HTTP/1.1 200 OK\r\n"
const char *resp_buf =
"HTTP/1.1 200 OK\r\n"
- "Content-Length: 140\r\n"
"Content-Type: application/javascript\r\n"
"Link: <http://targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
"Content-Type: application/javascript\r\n"
"Link: <http://targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
@@
-307,11
+309,11
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
"my.location = 'http://targetsite/images/bg.png';\n"
"my.other = \"http://targetsite/images/fg.png\";\n"
"my.thrd = \"other\";\n"
"my.location = 'http://targetsite/images/bg.png';\n"
"my.other = \"http://targetsite/images/fg.png\";\n"
"my.thrd = \"other\";\n"
- "// http://targetsite/images/bg.png\n";
+ "// \"http://targetsite/images/bg.png\n";
const char *resp_expected =
"HTTP/1.1 200 OK\r\n"
const char *resp_expected =
"HTTP/1.1 200 OK\r\n"
- "Content-Length: 194\r\n"
+ "Content-Length: 195\r\n"
"Content-Type: application/javascript\r\n"
"Link: <http://proxyhost/proxypath/targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
"Content-Type: application/javascript\r\n"
"Link: <http://proxyhost/proxypath/targetsite/file.xml>; rel=absolute\r\n"
"Link: </dir/file.xml>; rel=relative\r\n"
@@
-320,7
+322,7
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
"my.location = 'http://proxyhost/proxypath/targetsite/images/bg.png';\n"
"my.other = \"http://proxyhost/proxypath/targetsite/images/fg.png\";\n"
"my.thrd = \"other\";\n"
"my.location = 'http://proxyhost/proxypath/targetsite/images/bg.png';\n"
"my.other = \"http://proxyhost/proxypath/targetsite/images/fg.png\";\n"
"my.thrd = \"other\";\n"
- "// http://targetsite/images/bg.png\n";
+ "// \"http://targetsite/images/bg.png\n";
Z_GDU *gdu_res;
mp::odr dec(ODR_DECODE);
Z_GDU *gdu_res;
mp::odr dec(ODR_DECODE);
@@
-359,7
+361,7
@@
BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 )
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
{
//compare buffers
std::cout << "Expected result:\n" << resp_expected << "\n";
- std::cout << "Got result:\n" << "\n";
+ std::cout << "Got result:\n";
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);
fflush(stdout);
fwrite(resp_result, 1, resp_result_len, stdout);
fflush(stdout);