]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Improve test coverage of 8929 code
authorNick Mathewson <nickm@torproject.org>
Mon, 15 Jul 2013 21:32:08 +0000 (17:32 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 18 Jul 2013 12:45:03 +0000 (08:45 -0400)
src/or/transports.c
src/or/transports.h
src/test/test_pt.c

index 39cb872c234e4e734f906c7701f3c5f85a35db53..5941560cc7105c1cb671da647dfc4f835ca8650d 100644 (file)
@@ -102,9 +102,6 @@ create_managed_proxy_environment(const managed_proxy_t *mp);
 
 static INLINE int proxy_configuration_finished(const managed_proxy_t *mp);
 
-static void managed_proxy_destroy(managed_proxy_t *mp,
-                                  int also_terminate_process);
-
 static void handle_finished_proxy(managed_proxy_t *mp);
 static void configure_proxy(managed_proxy_t *mp);
 
@@ -694,7 +691,7 @@ register_proxy(const managed_proxy_t *mp)
 }
 
 /** Free memory allocated by managed proxy <b>mp</b>. */
-static void
+STATIC void
 managed_proxy_destroy(managed_proxy_t *mp,
                       int also_terminate_process)
 {
@@ -1103,7 +1100,7 @@ parse_cmethod_line(const char *line, managed_proxy_t *mp)
 /** Return a newly allocated string that tor should place in
  * TOR_PT_SERVER_TRANSPORT_OPTIONS while configuring the server
  * manged proxy in <b>mp</b>. Return NULL if no such options are found. */
-static char *
+STATIC char *
 get_transport_options_for_server_proxy(const managed_proxy_t *mp)
 {
   char *options_string = NULL;
@@ -1265,7 +1262,7 @@ create_managed_proxy_environment(const managed_proxy_t *mp)
  *  <b>proxy_argv</b>.
  *
  * Requires that proxy_argv have at least one element. */
-static managed_proxy_t *
+STATIC managed_proxy_t *
 managed_proxy_create(const smartlist_t *transport_list,
                      char **proxy_argv, int is_server)
 {
index cc3e018d6d8b8bea23ec66baf1413f1da948da95..dc68e946f23b9135cd3fe40a9d470d3fd79cdb0f 100644 (file)
@@ -110,6 +110,12 @@ STATIC int parse_smethod_line(const char *line, managed_proxy_t *mp);
 STATIC int parse_version(const char *line, managed_proxy_t *mp);
 STATIC void parse_env_error(const char *line);
 STATIC void handle_proxy_line(const char *line, managed_proxy_t *mp);
+STATIC char *get_transport_options_for_server_proxy(const managed_proxy_t *mp);
+
+STATIC void managed_proxy_destroy(managed_proxy_t *mp,
+                                  int also_terminate_process);
+STATIC managed_proxy_t *managed_proxy_create(const smartlist_t *transport_list,
+                                             char **proxy_argv, int is_server);
 
 #endif
 
index d4cc0ae97b5d622b68d87ed24d498b4b9331e5dc..6aa345d56868605f3645315d45394626a02bfc29 100644 (file)
@@ -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"
@@ -86,6 +88,58 @@ test_pt_parsing(void)
   tor_free(mp);
 }
 
+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)
 {
@@ -138,6 +192,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
 };