http_rewrite: content areas
[metaproxy-moved-to-github.git] / src / test_filter_rewrite.cpp
index 65cb4c0..0050b40 100644 (file)
@@ -68,30 +68,39 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "<?xml version='1.0'?>\n"
             "<filter xmlns='http://indexdata.com/metaproxy'\n"
             "        id='rewrite1' type='http_rewrite'>\n"
-            " <request>\n"
-            "   <rule name=\"null\"/>\n"
-            "   <rule name=\"url\">\n"
+            " <request verbose=\"1\">\n"
+            "  <rule name=\"null\"/>\n"
+            "  <rule name=\"url\">\n"
             "     <rewrite from='"
     "(?&lt;proto>https?://)(?&lt;pxhost>[^ /?#]+)/(?&lt;pxpath>[^ /]+)"
     "/(?&lt;host>[^ /]+)(?&lt;path>[^ ]*)'\n"
             "            to='${proto}${host}${path}' />\n"
             "     <rewrite from='(?:Host: )(.*)'\n"
             "            to='Host: ${host}' />\n"
-            "   </rule>\n"
-            "  <within header=\"link\" rule=\"null\"/>\n"
-            "  <within reqline=\"1\" rule=\"url\"/>\n"
+            "  </rule>\n"
+            "  <content type=\"headers\">\n"
+            "    <within header=\"link\" rule=\"null\"/>\n"
+            "    <within reqline=\"1\" rule=\"url\"/>\n"
+            "  </content>\n"
             " </request>\n"
-            " <response>\n"
-            "   <rule name=\"null\"/>\n"
-            "   <rule name=\"url\">\n"
+            " <response verbose=\"1\">\n"
+            "  <rule name=\"null\"/>\n"
+            "  <rule name=\"url\">\n"
+            "     <rewrite from='foo' to='bar'/>\n"
+            "     <rewrite from='^cx' to='cy'/>\n"
             "     <rewrite from='"
     "(?&lt;proto>https?://)(?&lt;host>[^/?# &quot;&apos;>]+)/(?&lt;path>[^  &quot;&apos;>]+)'\n"
             "            to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n"
             "  </rule>\n"
-            "  <within header=\"link\" rule=\"url\"/>\n"
-            "  <within tag=\"script\" attr=\"src,#text\" rule=\"url\"/>\n"
-            "  <within tag=\"style\" rule=\"url\"/>\n"
-            "  <within attr=\"href,src\" rule=\"url\"/>\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"
             " </response>\n"
             "</filter>\n"
         ;
@@ -132,7 +141,9 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "}"
             "</style>"
             "</head>"
-            "<script>var jslink=\"http://targetsite/webservice.xml\";</script>"
+            "<script>var jslink=\"http://targetsite/webservice.xml\";"
+            "var some=foo;"
+            "</script>"
             "<body>"
             "<p>Welcome to our website. It doesn't make it easy to get pro"
             "xified"
@@ -141,11 +152,13 @@ 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 href=\"cxcx\" />"
+            "<a href=\"cx \" />"
             "</body></html>";
 
         const char *resp_expected =
             "HTTP/1.1 200 OK\r\n"
-            "Content-Length: 522\r\n"
+            "Content-Length: 564\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"
@@ -157,15 +170,19 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
             "}"
             "</style>"
             "</head>"
-            "<script>var jslink=\"http://proxyhost/proxypath/targetsite/webservice.xml\";</script>"
+            "<script>var jslink=\"http://proxyhost/proxypath/targetsite/webservice.xml\";"
+            "var some=bar;"
+            "</script>"
             "<body>"
             "<p>Welcome to our website. It doesn't make it easy to get pro"
             "xified"
             "<a href=\"http://proxyhost/proxypath/targetsite/page2.html\">"
             "  An absolute link</a>"
-            "<a target=\"_blank\" href=\"http://proxyhost/proxypath/targetsite/page3.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 \"/>"
             "</body></html>";
 
         int r;
@@ -205,11 +222,11 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 )
         BOOST_CHECK(resp_result);
         BOOST_CHECK_EQUAL((size_t) resp_result_len, strlen(resp_expected));
 
-        std::cout << "Rewritten result:\n" << std::endl;
+        std::cout << "Got result:\n" << std::endl;
         fflush(stdout);
         fwrite(resp_result, 1, resp_result_len, stdout);
         fflush(stdout);
-        std::cout << "\nRewritten result buf len: " << resp_result_len
+        std::cout << "\nGot result buf len: " << resp_result_len
             << std::endl;
 
         BOOST_CHECK(memcmp(resp_result, resp_expected, resp_result_len) == 0);