aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-18 08:45:13 -0400
committerNick Mathewson <nickm@torproject.org>2013-07-18 08:45:13 -0400
commitb551988ef46ac29427a3bd8d8a76965b190623ab (patch)
treeebb700b59bc4e5f732514855b48b2b626db4312d /src/test
parentdd44ff663e074d07a8bf8b94dc5d8b9d8dc3fb32 (diff)
parent8a01a7c35b422a2c22fad2ee71f0268aa1b28b85 (diff)
downloadtor-b551988ef46ac29427a3bd8d8a76965b190623ab.tar
tor-b551988ef46ac29427a3bd8d8a76965b190623ab.tar.gz
Merge branch 'bug8929_rebase_2'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_config.c72
-rw-r--r--src/test/test_pt.c56
-rw-r--r--src/test/test_util.c14
3 files changed, 135 insertions, 7 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 4e9e13e47..3848d352d 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -438,12 +438,84 @@ test_config_parse_bridge_line(void *arg)
"aa=b");
}
+static void
+test_config_parse_transport_options_line(void *arg)
+{
+ smartlist_t *options_sl = NULL, *sl_tmp = NULL;
+
+ (void) arg;
+
+ { /* too small line */
+ options_sl = get_options_from_transport_options_line("valley", NULL);
+ test_assert(!options_sl);
+ }
+
+ { /* no k=v values */
+ options_sl = get_options_from_transport_options_line("hit it!", NULL);
+ test_assert(!options_sl);
+ }
+
+ { /* correct line, but wrong transport specified */
+ options_sl =
+ get_options_from_transport_options_line("trebuchet k=v", "rook");
+ test_assert(!options_sl);
+ }
+
+ { /* correct -- no transport specified */
+ sl_tmp = smartlist_new();
+ smartlist_add_asprintf(sl_tmp, "ladi=dadi");
+ smartlist_add_asprintf(sl_tmp, "weliketo=party");
+
+ options_sl =
+ get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
+ NULL);
+ test_assert(options_sl);
+ test_assert(smartlist_strings_eq(options_sl, sl_tmp));
+
+ SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
+ smartlist_free(sl_tmp);
+ sl_tmp = NULL;
+ SMARTLIST_FOREACH(options_sl, char *, s, tor_free(s));
+ smartlist_free(options_sl);
+ options_sl = NULL;
+ }
+
+ { /* correct -- correct transport specified */
+ sl_tmp = smartlist_new();
+ smartlist_add_asprintf(sl_tmp, "ladi=dadi");
+ smartlist_add_asprintf(sl_tmp, "weliketo=party");
+
+ options_sl =
+ get_options_from_transport_options_line("rook ladi=dadi weliketo=party",
+ "rook");
+ test_assert(options_sl);
+ test_assert(smartlist_strings_eq(options_sl, sl_tmp));
+ SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
+ smartlist_free(sl_tmp);
+ sl_tmp = NULL;
+ SMARTLIST_FOREACH(options_sl, char *, s, tor_free(s));
+ smartlist_free(options_sl);
+ options_sl = NULL;
+ }
+
+ done:
+ if (options_sl) {
+ SMARTLIST_FOREACH(options_sl, char *, s, tor_free(s));
+ smartlist_free(options_sl);
+ }
+ if (sl_tmp) {
+ SMARTLIST_FOREACH(sl_tmp, char *, s, tor_free(s));
+ smartlist_free(sl_tmp);
+ }
+}
+
#define CONFIG_TEST(name, flags) \
{ #name, test_config_ ## name, flags, NULL, NULL }
struct testcase_t config_tests[] = {
CONFIG_TEST(addressmap, 0),
CONFIG_TEST(parse_bridge_line, 0),
+ CONFIG_TEST(parse_transport_options_line, 0),
CONFIG_TEST(check_or_create_data_subdir, TT_FORK),
CONFIG_TEST(write_to_data_subdir, TT_FORK),
END_OF_TESTCASES
diff --git a/src/test/test_pt.c b/src/test/test_pt.c
index 16daa2836..4970cfff4 100644
--- a/src/test/test_pt.c
+++ b/src/test/test_pt.c
@@ -6,6 +6,8 @@
#include "orconfig.h"
#define PT_PRIVATE
#include "or.h"
+#include "config.h"
+#include "confparse.h"
#include "transports.h"
#include "circuitbuild.h"
#include "test.h"
@@ -108,6 +110,58 @@ test_pt_parsing(void)
}
static void
+test_pt_get_transport_options(void *arg)
+{
+ char **execve_args;
+ smartlist_t *transport_list = smartlist_new();
+ managed_proxy_t *mp;
+ or_options_t *options = get_options_mutable();
+ char *opt_str = NULL;
+ config_line_t *cl = NULL;
+ (void)arg;
+
+ execve_args = tor_malloc(sizeof(char*)*2);
+ execve_args[0] = tor_strdup("cheeseshop");
+ execve_args[1] = NULL;
+
+ mp = managed_proxy_create(transport_list, execve_args, 1);
+ tt_ptr_op(mp, !=, NULL);
+ opt_str = get_transport_options_for_server_proxy(mp);
+ tt_ptr_op(opt_str, ==, NULL);
+
+ smartlist_add(mp->transports_to_launch, tor_strdup("gruyere"));
+ smartlist_add(mp->transports_to_launch, tor_strdup("roquefort"));
+ smartlist_add(mp->transports_to_launch, tor_strdup("stnectaire"));
+
+ tt_assert(options);
+
+ cl = tor_malloc_zero(sizeof(config_line_t));
+ cl->value = tor_strdup("gruyere melty=10 hardness=se;ven");
+ options->ServerTransportOptions = cl;
+
+ cl = tor_malloc_zero(sizeof(config_line_t));
+ cl->value = tor_strdup("stnectaire melty=4 hardness=three");
+ cl->next = options->ServerTransportOptions;
+ options->ServerTransportOptions = cl;
+
+ cl = tor_malloc_zero(sizeof(config_line_t));
+ cl->value = tor_strdup("pepperjack melty=12 hardness=five");
+ cl->next = options->ServerTransportOptions;
+ options->ServerTransportOptions = cl;
+
+ opt_str = get_transport_options_for_server_proxy(mp);
+ tt_str_op(opt_str, ==,
+ "gruyere:melty=10;gruyere:hardness=se\\;ven;"
+ "stnectaire:melty=4;stnectaire:hardness=three");
+
+ done:
+ tor_free(opt_str);
+ config_free_lines(cl);
+ managed_proxy_destroy(mp, 0);
+ smartlist_free(transport_list);
+}
+
+static void
test_pt_protocol(void)
{
char line[200];
@@ -159,6 +213,8 @@ test_pt_protocol(void)
struct testcase_t pt_tests[] = {
PT_LEGACY(parsing),
PT_LEGACY(protocol),
+ { "get_transport_options", test_pt_get_transport_options, TT_FORK,
+ NULL, NULL },
END_OF_TESTCASES
};
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 2cc25e986..f7513c0f3 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -796,37 +796,37 @@ test_util_expand_filename(void)
}
#endif
-/** Test tor_escape_str_for_socks_arg(). */
+/** Test tor_escape_str_for_pt_args(). */
static void
test_util_escape_string_socks(void)
{
char *escaped_string = NULL;
/** Simple backslash escape. */
- escaped_string = tor_escape_str_for_socks_arg("This is a backslash: \\");
+ escaped_string = tor_escape_str_for_pt_args("This is a backslash: \\",";\\");
test_assert(escaped_string);
test_streq(escaped_string, "This is a backslash: \\\\");
tor_free(escaped_string);
/** Simple semicolon escape. */
- escaped_string = tor_escape_str_for_socks_arg("First rule: Do not use ;");
+ escaped_string = tor_escape_str_for_pt_args("First rule:Do not use ;",";\\");
test_assert(escaped_string);
- test_streq(escaped_string, "First rule: Do not use \\;");
+ test_streq(escaped_string, "First rule:Do not use \\;");
tor_free(escaped_string);
/** Empty string. */
- escaped_string = tor_escape_str_for_socks_arg("");
+ escaped_string = tor_escape_str_for_pt_args("", ";\\");
test_assert(escaped_string);
test_streq(escaped_string, "");
tor_free(escaped_string);
/** Escape all characters. */
- escaped_string = tor_escape_str_for_socks_arg(";\\;\\");
+ escaped_string = tor_escape_str_for_pt_args(";\\;\\", ";\\");
test_assert(escaped_string);
test_streq(escaped_string, "\\;\\\\\\;\\\\");
tor_free(escaped_string);
- escaped_string = tor_escape_str_for_socks_arg(";");
+ escaped_string = tor_escape_str_for_pt_args(";", ";\\");
test_assert(escaped_string);
test_streq(escaped_string, "\\;");
tor_free(escaped_string);