commit 904a58d10f144b95a689b35c88f6780371243da8 Merge: d5a5a6a 8a0eedb Author: Nick Mathewson nickm@torproject.org Date: Wed Jul 31 13:51:15 2013 -0400
Merge branch 'bug9288_rebased'
Conflicts: src/test/test_pt.c
changes/bug9288 | 4 +++ src/common/util.c | 10 +++--- src/common/util.h | 21 ++++++------ src/or/statefile.c | 4 +-- src/or/statefile.h | 2 +- src/or/transports.c | 28 +++++++++------- src/or/transports.h | 2 ++ src/test/test_pt.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 131 insertions(+), 29 deletions(-)
diff --cc src/or/transports.c index 15faa98,0bd024f..62cc1a8 --- a/src/or/transports.c +++ b/src/or/transports.c @@@ -102,9 -102,10 +102,7 @@@ create_managed_proxy_environment(const
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); - static void parse_method_error(const char *line, int is_server_method); #define parse_server_method_error(l) parse_method_error(l, 1) #define parse_client_method_error(l) parse_method_error(l, 0) diff --cc src/or/transports.h index 1c6fc41,7f180a6..7b524f2 --- a/src/or/transports.h +++ b/src/or/transports.h @@@ -113,14 -110,9 +113,16 @@@ STATIC int parse_smethod_line(const cha 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);
+ STATIC int configure_proxy(managed_proxy_t *mp); + #endif
#endif diff --cc src/test/test_pt.c index ac97cf9,afa4917..f969457 --- a/src/test/test_pt.c +++ b/src/test/test_pt.c @@@ -5,11 -5,12 +5,14 @@@
#include "orconfig.h" #define PT_PRIVATE + #define UTIL_PRIVATE #include "or.h" +#include "config.h" +#include "confparse.h" #include "transports.h" #include "circuitbuild.h" + #include "util.h" + #include "statefile.h" #include "test.h"
static void @@@ -224,61 -156,98 +227,147 @@@ test_pt_protocol(void tor_free(mp); }
+static void +test_pt_get_extrainfo_string(void *arg) +{ + managed_proxy_t *mp1 = NULL, *mp2 = NULL; + char **argv1, **argv2; + smartlist_t *t1 = smartlist_new(), *t2 = smartlist_new(); + int r; + char *s = NULL; + (void) arg; + + argv1 = tor_malloc_zero(sizeof(char*)*3); + argv1[0] = tor_strdup("ewige"); + argv1[1] = tor_strdup("Blumenkraft"); + argv1[2] = NULL; + argv2 = tor_malloc_zero(sizeof(char*)*4); + argv2[0] = tor_strdup("und"); + argv2[1] = tor_strdup("ewige"); + argv2[2] = tor_strdup("Schlangenkraft"); + argv2[3] = NULL; + + mp1 = managed_proxy_create(t1, argv1, 1); + mp2 = managed_proxy_create(t2, argv2, 1); + + r = parse_smethod_line("SMETHOD hagbard 127.0.0.1:5555", mp1); + tt_int_op(r, ==, 0); + r = parse_smethod_line("SMETHOD celine 127.0.0.1:1723 ARGS:card=no-enemy", + mp2); + tt_int_op(r, ==, 0); + + /* Force these proxies to look "completed" or they won't generate output. */ + mp1->conf_state = mp2->conf_state = PT_PROTO_COMPLETED; + + s = pt_get_extra_info_descriptor_string(); + tt_assert(s); + tt_str_op(s, ==, + "transport hagbard 127.0.0.1:5555\n" + "transport celine 127.0.0.1:1723 card=no-enemy\n"); + + done: + /* XXXX clean up better */ + smartlist_free(t1); + smartlist_free(t2); + tor_free(s); +} + + #ifdef _WIN32 + #define STDIN_HANDLE HANDLE + #else + #define STDIN_HANDLE FILE + #endif + + static smartlist_t * + tor_get_lines_from_handle_replacement(STDIN_HANDLE *handle, + enum stream_status *stream_status_out) + { + static int times_called = 0; + smartlist_t *retval_sl = smartlist_new(); + + (void) handle; + (void) stream_status_out; + + /* Generate some dummy CMETHOD lines the first 5 times. The 6th + time, send 'CMETHODS DONE' to finish configuring the proxy. */ + if (times_called++ != 5) { + smartlist_add_asprintf(retval_sl, "CMETHOD mock%d socks5 127.0.0.1:555%d", + times_called, times_called); + } else { + smartlist_add(retval_sl, tor_strdup("CMETHODS DONE")); + } + + return retval_sl; + } + + /* NOP mock */ + static void + tor_process_handle_destroy_replacement(process_handle_t *process_handle, + int also_terminate_process) + { + (void) process_handle; + (void) also_terminate_process; + } + + static or_state_t *dummy_state = NULL; + + static or_state_t * + get_or_state_replacement(void) + { + return dummy_state; + } + + /* Test the configure_proxy() function. */ + static void + test_pt_configure_proxy(void *arg) + { + int i; + managed_proxy_t *mp = NULL; + (void) arg; + + dummy_state = tor_malloc_zero(sizeof(or_state_t)); + + MOCK(tor_get_lines_from_handle, + tor_get_lines_from_handle_replacement); + MOCK(tor_process_handle_destroy, + tor_process_handle_destroy_replacement); + MOCK(get_or_state, + get_or_state_replacement); + + mp = tor_malloc(sizeof(managed_proxy_t)); + mp->conf_state = PT_PROTO_ACCEPTING_METHODS; + mp->transports = smartlist_new(); + mp->transports_to_launch = smartlist_new(); + mp->process_handle = tor_malloc_zero(sizeof(process_handle_t)); + mp->argv = tor_malloc_zero(sizeof(char*)*2); + mp->argv[0] = tor_strdup("<testcase>"); + + /* Test the return value of configure_proxy() by calling it some + times while it is uninitialized and then finally finalizing its + configuration. */ + for (i = 0 ; i < 5 ; i++) { + test_assert(configure_proxy(mp) == 0); + } + test_assert(configure_proxy(mp) == 1); + + done: + tor_free(dummy_state); + UNMOCK(tor_get_lines_from_handle); + UNMOCK(tor_process_handle_destroy); + } + #define PT_LEGACY(name) \ { #name, legacy_test_helper, 0, &legacy_setup, test_pt_ ## name }
struct testcase_t pt_tests[] = { PT_LEGACY(parsing), PT_LEGACY(protocol), + { "get_transport_options", test_pt_get_transport_options, TT_FORK, + NULL, NULL }, + { "get_extrainfo_string", test_pt_get_extrainfo_string, TT_FORK, + NULL, NULL }, + { "configure_proxy",test_pt_configure_proxy, TT_FORK, + NULL, NULL }, END_OF_TESTCASES };
tor-commits@lists.torproject.org