X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Ftest_filter_rewrite.cpp;h=430e7846dfd2911fdfc3c952923675737579702c;hb=0ce322844494022dc85a9c776d9ff041aad17520;hp=29bc5ca31ea58d613281fb6ddb6f657196fff73b;hpb=c26efced52c043f96c6560b453975d77ebde1b0f;p=metaproxy-moved-to-github.git diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 29bc5ca..430e784 100644 --- a/src/test_filter_rewrite.cpp +++ b/src/test_filter_rewrite.cpp @@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include + #define BOOST_AUTO_TEST_MAIN #define BOOST_TEST_DYN_LINK @@ -37,26 +39,29 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using namespace boost::unit_test; namespace mp = metaproxy_1; - -BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) -{ - try +struct TestConfig { + TestConfig() { - mp::filter::HttpRewrite fhr; + std::cout << "global setup\n"; + yaz_log_init_level(YLOG_ALL); } - catch ( ... ) { - BOOST_CHECK (false); + ~TestConfig() + { + std::cout << "global teardown\n"; } -} +}; -BOOST_AUTO_TEST_CASE( test_filter_rewrite_2 ) +BOOST_GLOBAL_FIXTURE( TestConfig ); + +BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { 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?)(?[^\\/?#]+)\\/(?[^\\/]+)" @@ -65,42 +70,125 @@ 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?)(?[^\\/?#]+)\\/(?[^ >]+)", - "http://${pxhost}/${pxpath}/${host}/${path}" + "(?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 + + 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; @@ -139,36 +232,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" + "