diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:41:55 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-10 23:41:55 -0400 |
commit | e07206afea28d110a0a7b74d4e230db3b0fe3120 (patch) | |
tree | 8f251f9c27bdfbe94e0a3d97b7e4b21a2b5fa9f0 /src/test/test_pt.c | |
parent | 5474d8ae05da1a7b896a12e5857b2dbe0b0b8ce6 (diff) | |
parent | cae44838fecc550f2df16de44b0ef297ecb509a6 (diff) | |
download | tor-e07206afea28d110a0a7b74d4e230db3b0fe3120.tar.gz tor-e07206afea28d110a0a7b74d4e230db3b0fe3120.zip |
Merge remote-tracking branch 'yawning/bug_8402'
Diffstat (limited to 'src/test/test_pt.c')
-rw-r--r-- | src/test/test_pt.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/test/test_pt.c b/src/test/test_pt.c index f55c059580..b45151e8b7 100644 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@ -450,6 +450,85 @@ test_pt_configure_proxy(void *arg) tor_free(mp); } +/* Test the get_pt_proxy_uri() function. */ +static void +test_get_pt_proxy_uri(void *arg) +{ + or_options_t *options = get_options_mutable(); + char *uri = NULL; + int ret; + (void) arg; + + /* Test with no proxy. */ + uri = get_pt_proxy_uri(); + tt_assert(uri == NULL); + + /* Test with a SOCKS4 proxy. */ + options->Socks4Proxy = tor_strdup("192.0.2.1:1080"); + ret = tor_addr_port_lookup(options->Socks4Proxy, + &options->Socks4ProxyAddr, + &options->Socks4ProxyPort); + tt_assert(ret == 0); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "socks4a://192.0.2.1:1080"); + tor_free(uri); + tor_free(options->Socks4Proxy); + + /* Test with a SOCKS5 proxy, no username/password. */ + options->Socks5Proxy = tor_strdup("192.0.2.1:1080"); + ret = tor_addr_port_lookup(options->Socks5Proxy, + &options->Socks5ProxyAddr, + &options->Socks5ProxyPort); + tt_assert(ret == 0); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "socks5://192.0.2.1:1080"); + tor_free(uri); + + /* Test with a SOCKS5 proxy, with username/password. */ + options->Socks5ProxyUsername = tor_strdup("hwest"); + options->Socks5ProxyPassword = tor_strdup("r34n1m470r"); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "socks5://hwest:r34n1m470r@192.0.2.1:1080"); + tor_free(uri); + tor_free(options->Socks5Proxy); + tor_free(options->Socks5ProxyUsername); + tor_free(options->Socks5ProxyPassword); + + /* Test with a HTTPS proxy, no authenticator. */ + options->HTTPSProxy = tor_strdup("192.0.2.1:80"); + ret = tor_addr_port_lookup(options->HTTPSProxy, + &options->HTTPSProxyAddr, + &options->HTTPSProxyPort); + tt_assert(ret == 0); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "http://192.0.2.1:80"); + tor_free(uri); + + /* Test with a HTTPS proxy, with authenticator. */ + options->HTTPSProxyAuthenticator = tor_strdup("hwest:r34n1m470r"); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "http://hwest:r34n1m470r@192.0.2.1:80"); + tor_free(uri); + tor_free(options->HTTPSProxy); + tor_free(options->HTTPSProxyAuthenticator); + + /* Token nod to the fact that IPv6 exists. */ + options->Socks4Proxy = tor_strdup("[2001:db8::1]:1080"); + ret = tor_addr_port_lookup(options->Socks4Proxy, + &options->Socks4ProxyAddr, + &options->Socks4ProxyPort); + tt_assert(ret == 0); + uri = get_pt_proxy_uri(); + tt_str_op(uri, ==, "socks4a://[2001:db8::1]:1080"); + tor_free(uri); + tor_free(options->Socks4Proxy); + + done: + if (uri) + tor_free(uri); +} + + #define PT_LEGACY(name) \ { #name, legacy_test_helper, 0, &legacy_setup, test_pt_ ## name } @@ -462,6 +541,8 @@ struct testcase_t pt_tests[] = { NULL, NULL }, { "configure_proxy",test_pt_configure_proxy, TT_FORK, NULL, NULL }, + { "get_pt_proxy_uri", test_get_pt_proxy_uri, TT_FORK, + NULL, NULL }, END_OF_TESTCASES }; |