From 197ca4e06d1ed18bbb6865d98de227abec070937 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 22 Dec 2015 00:44:03 -0500 Subject: [PATCH 1/2] transition http proxy test for http_connection to the sim --- simulation/libsimulator | 2 +- simulation/make_proxy_settings.hpp | 3 +- simulation/test_http_connection.cpp | 68 ++++++++++++++++++++--------- test/test_http_connection.cpp | 10 +---- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index a6129b416..36752ab36 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit a6129b41688ae3caa667f0ac766080fbee28eb37 +Subproject commit 36752ab36697b922c2c7deabd1ac661df19f7d25 diff --git a/simulation/make_proxy_settings.hpp b/simulation/make_proxy_settings.hpp index 67bd3f942..712591549 100644 --- a/simulation/make_proxy_settings.hpp +++ b/simulation/make_proxy_settings.hpp @@ -43,10 +43,11 @@ inline libtorrent::aux::proxy_settings make_proxy_settings( aux::proxy_settings ps; ps.type = proxy_type; ps.proxy_hostnames = false; + // this IP and ports are specific to test_http_connection.cpp if (proxy_type != settings_pack::none) { ps.hostname = "50.50.50.50"; - ps.port = 4444; + ps.port = proxy_type == settings_pack::http ? 4445 : 4444; ps.username = "testuser"; ps.password = "testpass"; } diff --git a/simulation/test_http_connection.cpp b/simulation/test_http_connection.cpp index 4be255ca7..186280e54 100644 --- a/simulation/test_http_connection.cpp +++ b/simulation/test_http_connection.cpp @@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "setup_swarm.hpp" #include "simulator/simulator.hpp" #include "simulator/http_server.hpp" +#include "simulator/http_proxy.hpp" #include "simulator/socks_server.hpp" #include "libtorrent/alert_types.hpp" #include "libtorrent/aux_/proxy_settings.hpp" @@ -221,7 +222,8 @@ void run_suite(lt::aux::proxy_settings ps) // with socks5 we would be able to do this, assuming the socks server // supported it, but the current socks implementation in libsimulator does // not support IPv6 - if (ps.type != settings_pack::socks5) + if (ps.type != settings_pack::socks5 + && ps.type != settings_pack::http) { run_test(ps, "http://[ff::dead:beef]:8080/test_file", 0, -1 , error_condition(boost::system::errc::address_family_not_supported, generic_category()) @@ -229,9 +231,17 @@ void run_suite(lt::aux::proxy_settings ps) } // there is no node at 10.0.0.10, this should fail with connection refused - run_test(ps, "http://10.0.0.10:8080/test_file", 0, -1, - error_condition(boost::system::errc::connection_refused, generic_category()) - , {0,1}); + if (ps.type != settings_pack::http) + { + run_test(ps, "http://10.0.0.10:8080/test_file", 0, -1, + error_condition(boost::system::errc::connection_refused, generic_category()) + , {0,1}); + } + else + { + run_test(ps, "http://10.0.0.10:8080/test_file", 0, 503, + error_condition(), {1,1}); + } // the try-next test in his case would test the socks proxy itself, whether // it has robust retry behavior (which the simple test proxy that comes with @@ -246,20 +256,23 @@ void run_suite(lt::aux::proxy_settings ps) , error_condition(), { 1, 1, 1}); } - const error_condition expected_error = ps.proxy_hostnames - ? error_condition(boost::system::errc::host_unreachable, generic_category()) - : error_condition(asio::error::host_not_found, boost::asio::error::get_netdb_category()); + // the http proxy does not support hostname lookups yet + if (ps.type != settings_pack::http) + { + const error_condition expected_error = ps.proxy_hostnames + ? error_condition(boost::system::errc::host_unreachable, generic_category()) + : error_condition(asio::error::host_not_found, boost::asio::error::get_netdb_category()); - // make sure hostname lookup failures are passed through correctly - run_test(ps, "http://non-existent.com/test_file", 0, -1 - , expected_error, { 0, 1}); + // make sure hostname lookup failures are passed through correctly + run_test(ps, "http://non-existent.com/test_file", 0, -1 + , expected_error, { 0, 1 }); + } // make sure we handle gzipped content correctly run_test(ps, url_base + "/test_file.gz", 1337, 200, error_condition(), { 1, 1, 0, 0, 0, 0, 0, 1}); // TODO: 2 test basic-auth // TODO: 2 test https - } void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int expect_status @@ -279,6 +292,7 @@ void run_test(lt::aux::proxy_settings ps, std::string url, int expect_size, int sim::http_server http(web_server, 8080); sim::socks_server socks(proxy_ios, 4444, ps.type == settings_pack::socks4 ? 4 : 5); + sim::http_proxy http_p(proxy_ios, 4445); char data_buffer[4000]; std::generate(data_buffer, data_buffer + sizeof(data_buffer), &std::rand); @@ -398,6 +412,13 @@ TORRENT_TEST(http_connection) run_suite(ps); } +TORRENT_TEST(http_connection_http) +{ + lt::aux::proxy_settings ps = make_proxy_settings(settings_pack::http); + ps.proxy_hostnames = true; + run_suite(ps); +} + TORRENT_TEST(http_connection_socks4) { lt::aux::proxy_settings ps = make_proxy_settings(settings_pack::socks4); @@ -417,9 +438,8 @@ TORRENT_TEST(http_connection_socks5_proxy_names) run_suite(ps); } -TORRENT_TEST(http_connection_socks_error) +void test_proxy_failure(lt::settings_pack::proxy_type_t proxy_type) { - // if we set up to user a proxy that does not exist, expect failure! using sim::asio::ip::address_v4; sim_config network_cfg; sim::simulation sim{network_cfg}; @@ -430,12 +450,7 @@ TORRENT_TEST(http_connection_socks_error) sim::http_server http(web_server, 8080); - lt::aux::proxy_settings ps; - ps.hostname = "50.50.50.50"; - ps.port = 4444; - ps.username = "testuser"; - ps.password = "testpass"; - ps.type = settings_pack::socks5; + lt::aux::proxy_settings ps = make_proxy_settings(proxy_type); char data_buffer[4000]; std::generate(data_buffer, data_buffer + sizeof(data_buffer), &std::rand); @@ -463,7 +478,20 @@ TORRENT_TEST(http_connection_socks_error) TEST_EQUAL(e, error_code()); } -// TODO: test http proxy +// if we set up to user a proxy that does not exist, expect failure! +// if this doesn't fail, the other tests are invalid because the proxy may not +// be exercised! +TORRENT_TEST(http_connection_socks_error) +{ + test_proxy_failure(settings_pack::socks5); +} + +TORRENT_TEST(http_connection_http_error) +{ + test_proxy_failure(settings_pack::http); +} + +// TODO: test http proxy with password // TODO: test socks5 with password // TODO: test SSL // TODO: test keepalive diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index 5a0b0ceb6..e5de2bac6 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -207,21 +207,13 @@ void run_suite(std::string const& protocol printf("gethostbyname(\"non-existent-domain.se\") = %p. h_errno = %d\n", h, h_errno); if (h == 0 && h_errno == HOST_NOT_FOUND) { - // if we're going through an http proxy, we won't get the same error as if the hostname - // resolution failed - if ((ps.type == settings_pack::http || ps.type == settings_pack::http_pw) && protocol != "https") - run_test(protocol + "://non-existent-domain.se/non-existing-file", -1, 502, 1, err(), ps); - else - run_test(protocol + "://non-existent-domain.se/non-existing-file", -1, -1, 0, err(), ps); + run_test(protocol + "://non-existent-domain.se/non-existing-file", -1, -1, 0, err(), ps); } if (ps.type != settings_pack::none) stop_proxy(ps.port); stop_web_server(); } -TORRENT_TEST(http) { run_suite("http", settings_pack::http); } -TORRENT_TEST(http_pw) { run_suite("http", settings_pack::http_pw); } - #ifdef TORRENT_USE_OPENSSL TORRENT_TEST(no_proxy_ssl) { run_suite("https", settings_pack::none); } TORRENT_TEST(http_ssl) { run_suite("https", settings_pack::http); } From 63c3ff61e2825e02c6f963efe09ba43ed00832d0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 22 Dec 2015 01:26:49 -0500 Subject: [PATCH 2/2] update submodule --- simulation/libsimulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simulation/libsimulator b/simulation/libsimulator index 36752ab36..d55d7fe1e 160000 --- a/simulation/libsimulator +++ b/simulation/libsimulator @@ -1 +1 @@ -Subproject commit 36752ab36697b922c2c7deabd1ac661df19f7d25 +Subproject commit d55d7fe1ef1bf3a42ba3d21013cd7e952dc454bf