X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ftest_filter_rewrite.cpp;h=b16768f11f9bd832145772db7801cda08792984e;hb=213d7bae1233185595186f881a150ee238dac64f;hp=d266274baf328ed1fe7860f518717173dcdcb786;hpb=2c08da821832998446e5fe92acf4d1e87fe531d4;p=metaproxy-moved-to-github.git diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index d266274..b16768f 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -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,6 +54,7 @@ struct TestConfig { }; BOOST_GLOBAL_FIXTURE( TestConfig ); +*/ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { @@ -60,27 +63,43 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) 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?)(?[^\\/?#]+)\\/(?[^\\/]+)" - "\\/(?[^\\/]+)(?.*)", - "${proto}${host}${path}" - )); - vec_req.push_back(std::make_pair( - "(?:Host\\: )(.*)", - "Host: ${host}" - )); - - mp::filter::HttpRewrite::spair_vec vec_res; - vec_res.push_back(std::make_pair( - "(?http\\:\\/\\/s?)(?[^\\/?# \"'>]+)\\/(?[^ \"'>]+)", - "${proto}${pxhost}/${pxpath}/${host}/${path}" - )); - - 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" + "\n" + ; + + 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); // create an http request @@ -179,10 +198,11 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) resp_result = odr_getbuf(enc, &resp_result_len, 0); BOOST_CHECK(resp_result); - BOOST_CHECK_EQUAL(resp_result_len, strlen(resp_expected)); + BOOST_CHECK_EQUAL((size_t) resp_result_len, strlen(resp_expected)); - std::cout << "Rewriten result:\n" << resp_result << std::endl; - std::cout << "Rewriten result buf len: " << resp_result_len + std::cout << "Rewritten result:\n" << std::endl; + fwrite(resp_result, 1, resp_result_len, stdout); + std::cout << "\nRewritten result buf len: " << resp_result_len << std::endl; BOOST_CHECK(memcmp(resp_result, resp_expected, resp_result_len) == 0); @@ -197,143 +217,6 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) } } -/* -BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) -{ - try - { - std::cout << "Running xml config test case" << std::endl; - mp::RouterChain router; - mp::filter::HttpRewrite fhr; - - std::string xmlconf = - "\n" - "\n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - " \n" - "\n" - ; - - 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); - - // create an http request - mp::Package pack; - - mp::odr odr; - Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, - "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" - "