X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Ftest_filter_rewrite.cpp;h=36e1a15f1dfb938e32cc9e3fdaaedd5b420664f4;hb=4a14f732154658bbd097d833089f968d77568ebd;hp=7753f0e8bef60558e378e26441c6f7eea2a4eab4;hpb=1933e4904a95ec7c430b61a2dcc0e907cbac75de;p=metaproxy-moved-to-github.git diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 7753f0e..36e1a15 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "filter_http_client.hpp" #include "filter_http_rewrite.hpp" #include -#include "router_chain.hpp" +#include #include #include @@ -38,7 +38,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using namespace boost::unit_test; namespace mp = metaproxy_1; - +/* + * The global testconfig is commented out, as it won't even compile + * on old Centos5 machines struct TestConfig { TestConfig() { @@ -52,70 +54,159 @@ struct TestConfig { }; BOOST_GLOBAL_FIXTURE( TestConfig ); +*/ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { try { - mp::filter::HttpRewrite fhr; - } - catch ( ... ) { - BOOST_CHECK (false); - } -} - -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::filter::HttpRewrite::spair_vec vec_req; - vec_req.push_back(std::make_pair( - "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^\\/]+)" - "\\/(?[^\\/]+)(?.*)", - "${proto}${host}${path}" - )); - vec_req.push_back(std::make_pair( - "(?:Host\\: )(.*)", - "Host: localhost" - )); - - mp::filter::HttpRewrite::spair_vec vec_res; - vec_res.push_back(std::make_pair( - "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^ >]+)", - "THAT WAS MATCHED" - )); - - fhr.configure(vec_req, vec_res); + + std::string xmlconf = + "\n" + "\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n" + ; - mp::filter::HTTPClient hc; - + std::cout << xmlconf; + + // reading and parsing XML conf + xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); + BOOST_CHECK(doc); + xmlNode *root_element = xmlDocGetRootElement(doc); + fhr.configure(root_element, true, ""); + xmlFreeDoc(doc); + router.append(fhr); - router.append(hc); // create an http request mp::Package pack; mp::odr odr; Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1); + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); 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: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "\n" "\n" " \n" " https?://)(?<pxhost>[^ /?#]+)/(?<pxpath>[^ /]+)" + "/(?<host>[^ /]+)(?<path>[^ ]*)'\n" " to='${proto}${host}${path}' />\n" - " \n" + " \n" " \n" " \n" " \n" + "(?<proto>https?://)(?<host>[^/?# "'>]+)/(?<path>[^ "'>]+)'\n" + " to='${proto}${pxhost}/${pxpath}/${host}/${path}' />\n" " \n" "\n" - ; + ; std::cout << xmlconf; @@ -154,36 +250,100 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_3 ) xmlDocPtr doc = xmlParseMemory(xmlconf.c_str(), xmlconf.size()); BOOST_CHECK(doc); xmlNode *root_element = xmlDocGetRootElement(doc); - mp::filter::HttpRewrite fhr; fhr.configure(root_element, true, ""); xmlFreeDoc(doc); - - mp::filter::HTTPClient hc; - mp::RouterChain router; router.append(fhr); - router.append(hc); // create an http request mp::Package pack; mp::odr odr; Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "http://proxyhost/proxypath/localhost:80/~jakub/targetsite.php", 0, 1); + "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); pack.request() = gdu_req; + //create the http response + + const char *resp_buf = + "HTTP/1.1 200 OK\r\n" + "Content-Length: 50\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\n" + "Link: ; rel=relative\r\n" + "\r\n" + "Hello proxy!" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "" + "" + "" + "" + "

Welcome to our website. It doesn't make it easy to get pro" + "xified" + "" + " An absolute link" + "