X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Ftest_filter_rewrite.cpp;h=374950975b1354882aed8fd423324e613a49a2f0;hb=9c5a788489d7fc2bb6796b87ffe6d631f5ef0c90;hp=430e7846dfd2911fdfc3c952923675737579702c;hpb=7611584ef0d15383d61c9a0fca5b4cc6aedb6f48;p=metaproxy-moved-to-github.git diff --git a/src/test_filter_rewrite.cpp b/src/test_filter_rewrite.cpp index 430e784..3749509 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,20 +38,23 @@ 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() + TestConfig() { - std::cout << "global setup\n"; + std::cout << "global setup\n"; yaz_log_init_level(YLOG_ALL); } - ~TestConfig() - { - std::cout << "global teardown\n"; + ~TestConfig() + { + std::cout << "global teardown\n"; } }; BOOST_GLOBAL_FIXTURE( TestConfig ); +*/ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) { @@ -60,34 +63,58 @@ 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" + " \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, + Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, "http://proxyhost/proxypath/targetsite/page1.html", 0, 1); pack.request() = gdu_req; @@ -108,20 +135,24 @@ BOOST_AUTO_TEST_CASE( test_filter_rewrite_1 ) "}" "" "" - "" + "" "" "

Welcome to our website. It doesn't make it easy to get pro" "xified" "" " An absolute link" - "" " An absolute link" - "\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" - "