summaryrefslogtreecommitdiff
path: root/src/test/test_pt.c
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-03-25 07:21:22 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-05-21 08:14:38 +0000
commit41d2b4d3af01b34beb2951028cdbc45b5f41e08e (patch)
tree118ea32e411d735e71b93069479bb898d3791c67 /src/test/test_pt.c
parentfef65fa64341fb70df0e7b34d91d3b08a74e7aad (diff)
downloadtor-41d2b4d3af01b34beb2951028cdbc45b5f41e08e.tar.gz
tor-41d2b4d3af01b34beb2951028cdbc45b5f41e08e.zip
Allow ClientTransportPlugins to use proxies
This change allows using Socks4Proxy, Socks5Proxy and HTTPSProxy with ClientTransportPlugins via the TOR_PT_PROXY extension to the pluggable transport specification. This fixes bug #8402.
Diffstat (limited to 'src/test/test_pt.c')
-rw-r--r--src/test/test_pt.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index f71627df1e..788d4205cc 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 = "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);
+
+ options->Socks4Proxy = NULL;
+
+ /* Test with a SOCKS5 proxy, no username/password. */
+ options->Socks5Proxy = "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 = "hwest";
+ options->Socks5ProxyPassword = "r34n1m470r";
+ uri = get_pt_proxy_uri();
+ tt_str_op(uri, ==, "socks5://hwest:r34n1m470r@192.0.2.1:1080");
+ tor_free(uri);
+
+ options->Socks5Proxy = NULL;
+
+ /* Test with a HTTPS proxy, no authenticator. */
+ options->HTTPSProxy = "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 = "hwest:r34n1m470r";
+ uri = get_pt_proxy_uri();
+ tt_str_op(uri, ==, "http://hwest:r34n1m470r@192.0.2.1:80");
+ tor_free(uri);
+
+ options->HTTPSProxy = NULL;
+
+ /* Token nod to the fact that IPv6 exists. */
+ options->Socks4Proxy = "[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);
+
+
+ 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
};