From 2b862fc3e525e3d53854e9825ae2e22683e8a03c Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Wed, 8 May 2013 16:04:30 +0200 Subject: [PATCH] More self-contained test --- src/test_filter_rewrite.cpp | 215 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 174 insertions(+), 41 deletions(-) diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 7753f0e..68b63f7 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -57,21 +57,11 @@ 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; + //configure the filter mp::filter::HttpRewrite::spair_vec vec_req; vec_req.push_back(std::make_pair( "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^\\/]+)" @@ -80,42 +70,112 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) )); vec_req.push_back(std::make_pair( "(?:Host\\: )(.*)", - "Host: localhost" + "Host: ${host}" )); mp::filter::HttpRewrite::spair_vec vec_res; vec_res.push_back(std::make_pair( - "(?http\\:\\/\\/s?)(?[^\\/?#]+)\\/(?[^ >]+)", - "THAT WAS MATCHED" + "(?http\\:\\/\\/s?)(?[^\\/?# \"'>]+)\\/(?[^ \"'>]+)", + "${proto}${pxhost}/${pxpath}/${host}/${path}" )); fhr.configure(vec_req, vec_res); - - mp::filter::HTTPClient hc; 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 + + /* response, content */ + const char *resp_buf = + /*123456789012345678 */ + "HTTP/1.1 200 OK\r\n" + "Content-Length: 3000\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\r" + "Link: ; rel=relative\r\r" + "\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 +218,104 @@ 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 + + /* response, content */ + const char *resp_buf = + /*123456789012345678 */ + "HTTP/1.1 200 OK\r\n" + "Content-Length: 3000\r\n" + "Content-Type: text/html\r\n" + "Link: ; rel=absolute\r\r" + "Link: ; rel=relative\r\r" + "\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" + "