|
@@ -5,9 +5,11 @@
|
|
|
|
|
|
#include "orconfig.h"
|
|
|
#define PT_PRIVATE
|
|
|
+#define UTIL_PRIVATE
|
|
|
#include "or.h"
|
|
|
#include "transports.h"
|
|
|
#include "circuitbuild.h"
|
|
|
+#include "util.h"
|
|
|
#include "test.h"
|
|
|
|
|
|
static void
|
|
@@ -153,12 +155,81 @@ test_pt_protocol(void)
|
|
|
tor_free(mp);
|
|
|
}
|
|
|
|
|
|
+#ifdef _WIN32
|
|
|
+static smartlist_t *
|
|
|
+tor_get_lines_from_handle_replacement(HANDLE *handle,
|
|
|
+ enum stream_status *stream_status_out)
|
|
|
+#else
|
|
|
+static smartlist_t *
|
|
|
+tor_get_lines_from_handle_replacement(FILE *handle,
|
|
|
+ enum stream_status *stream_status_out)
|
|
|
+#endif
|
|
|
+{
|
|
|
+ (void) handle;
|
|
|
+ (void) stream_status_out;
|
|
|
+ static int times_called = 0;
|
|
|
+
|
|
|
+ smartlist_t *retval_sl = smartlist_new();
|
|
|
+
|
|
|
+ /* 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)
|
|
|
+{
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+/* Test the configure_proxy() function. */
|
|
|
+static void
|
|
|
+test_pt_configure_proxy(void *arg)
|
|
|
+{
|
|
|
+ (void) arg;
|
|
|
+ int i;
|
|
|
+ managed_proxy_t *mp = NULL;
|
|
|
+
|
|
|
+ MOCK(tor_get_lines_from_handle,
|
|
|
+ tor_get_lines_from_handle_replacement);
|
|
|
+ MOCK(tor_process_handle_destroy,
|
|
|
+ tor_process_handle_destroy_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));
|
|
|
+
|
|
|
+ /* 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:
|
|
|
+ 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),
|
|
|
+ { "configure_proxy",test_pt_configure_proxy, TT_FORK,
|
|
|
+ NULL, NULL },
|
|
|
END_OF_TESTCASES
|
|
|
};
|
|
|
|