2011-07-13 19:06:14 +02:00
|
|
|
/* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2013-01-16 07:54:56 +01:00
|
|
|
* Copyright (c) 2007-2013, The Tor Project, Inc. */
|
2011-07-13 19:06:14 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
#include "orconfig.h"
|
|
|
|
#define PT_PRIVATE
|
2013-07-29 15:59:59 +02:00
|
|
|
#define UTIL_PRIVATE
|
2013-08-05 19:54:54 +02:00
|
|
|
#define STATEFILE_PRIVATE
|
2013-08-25 17:29:03 +02:00
|
|
|
#define CONTROL_PRIVATE
|
2011-07-13 19:06:14 +02:00
|
|
|
#include "or.h"
|
2013-07-15 23:32:08 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "confparse.h"
|
2013-08-25 17:29:03 +02:00
|
|
|
#include "control.h"
|
2011-07-18 02:33:31 +02:00
|
|
|
#include "transports.h"
|
2011-07-13 19:06:14 +02:00
|
|
|
#include "circuitbuild.h"
|
2013-07-29 15:59:59 +02:00
|
|
|
#include "util.h"
|
2013-07-29 17:37:39 +02:00
|
|
|
#include "statefile.h"
|
2011-07-13 19:06:14 +02:00
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
reset_mp(managed_proxy_t *mp)
|
|
|
|
{
|
2011-10-07 15:44:58 +02:00
|
|
|
mp->conf_state = PT_PROTO_LAUNCHED;
|
2011-07-13 19:06:14 +02:00
|
|
|
SMARTLIST_FOREACH(mp->transports, transport_t *, t, transport_free(t));
|
|
|
|
smartlist_clear(mp->transports);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_pt_parsing(void)
|
|
|
|
{
|
|
|
|
char line[200];
|
2013-07-16 13:07:03 +02:00
|
|
|
transport_t *transport = NULL;
|
|
|
|
tor_addr_t test_addr;
|
2011-07-13 19:06:14 +02:00
|
|
|
|
|
|
|
managed_proxy_t *mp = tor_malloc(sizeof(managed_proxy_t));
|
|
|
|
mp->conf_state = PT_PROTO_INFANT;
|
2012-01-18 21:53:30 +01:00
|
|
|
mp->transports = smartlist_new();
|
2011-07-13 19:06:14 +02:00
|
|
|
|
|
|
|
/* incomplete cmethod */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_cmethod_line(line, mp) < 0);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* wrong proxy type */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_cmethod_line(line, mp) < 0);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* wrong addrport */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet socks4 abcd",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_cmethod_line(line, mp) < 0);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* correct line */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_cmethod_line(line, mp) == 0);
|
2013-07-16 13:07:03 +02:00
|
|
|
test_assert(smartlist_len(mp->transports) == 1);
|
|
|
|
transport = smartlist_get(mp->transports, 0);
|
|
|
|
/* test registered address of transport */
|
|
|
|
tor_addr_parse(&test_addr, "127.0.0.1");
|
|
|
|
test_assert(tor_addr_eq(&test_addr, &transport->addr));
|
|
|
|
/* test registered port of transport */
|
|
|
|
test_assert(transport->port == 1999);
|
|
|
|
/* test registered SOCKS version of transport */
|
|
|
|
test_assert(transport->socks_version == PROXY_SOCKS5);
|
|
|
|
/* test registered name of transport */
|
|
|
|
test_streq(transport->name, "trebuchet");
|
2011-07-13 19:06:14 +02:00
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* incomplete smethod */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"SMETHOD trebuchet",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_smethod_line(line, mp) < 0);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* wrong addr type */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"SMETHOD trebuchet abcd",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_smethod_line(line, mp) < 0);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* cowwect */
|
2013-07-16 13:07:03 +02:00
|
|
|
strlcpy(line,"SMETHOD trebuchy 127.0.0.2:2999",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_smethod_line(line, mp) == 0);
|
2013-07-16 13:07:03 +02:00
|
|
|
test_assert(smartlist_len(mp->transports) == 1);
|
|
|
|
transport = smartlist_get(mp->transports, 0);
|
|
|
|
/* test registered address of transport */
|
|
|
|
tor_addr_parse(&test_addr, "127.0.0.2");
|
|
|
|
test_assert(tor_addr_eq(&test_addr, &transport->addr));
|
|
|
|
/* test registered port of transport */
|
|
|
|
test_assert(transport->port == 2999);
|
|
|
|
/* test registered name of transport */
|
|
|
|
test_streq(transport->name, "trebuchy");
|
2011-07-13 19:06:14 +02:00
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
2013-07-16 17:53:25 +02:00
|
|
|
/* Include some arguments. Good ones. */
|
2013-07-18 14:49:52 +02:00
|
|
|
strlcpy(line,"SMETHOD trebuchet 127.0.0.1:9999 "
|
|
|
|
"ARGS:counterweight=3,sling=snappy",
|
2013-07-16 17:53:25 +02:00
|
|
|
sizeof(line));
|
|
|
|
test_assert(parse_smethod_line(line, mp) == 0);
|
|
|
|
tt_int_op(1, ==, smartlist_len(mp->transports));
|
|
|
|
{
|
|
|
|
const transport_t *transport = smartlist_get(mp->transports, 0);
|
|
|
|
tt_assert(transport);
|
|
|
|
tt_str_op(transport->name, ==, "trebuchet");
|
|
|
|
tt_int_op(transport->port, ==, 9999);
|
|
|
|
tt_str_op(fmt_addr(&transport->addr), ==, "127.0.0.1");
|
|
|
|
tt_str_op(transport->extra_info_args, ==,
|
|
|
|
"counterweight=3,sling=snappy");
|
|
|
|
}
|
|
|
|
reset_mp(mp);
|
|
|
|
|
2011-07-13 19:06:14 +02:00
|
|
|
/* unsupported version */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION 666",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_version(line, mp) < 0);
|
|
|
|
|
|
|
|
/* incomplete VERSION */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION ",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_version(line, mp) < 0);
|
|
|
|
|
|
|
|
/* correct VERSION */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION 1",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
test_assert(parse_version(line, mp) == 0);
|
|
|
|
|
|
|
|
done:
|
2014-04-26 17:28:39 +02:00
|
|
|
reset_mp(mp);
|
|
|
|
smartlist_free(mp->transports);
|
2011-07-13 19:06:14 +02:00
|
|
|
tor_free(mp);
|
|
|
|
}
|
|
|
|
|
2013-07-15 23:32:08 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-07-13 19:06:14 +02:00
|
|
|
static void
|
|
|
|
test_pt_protocol(void)
|
|
|
|
{
|
|
|
|
char line[200];
|
|
|
|
|
2011-11-25 22:54:06 +01:00
|
|
|
managed_proxy_t *mp = tor_malloc_zero(sizeof(managed_proxy_t));
|
2011-10-07 15:44:58 +02:00
|
|
|
mp->conf_state = PT_PROTO_LAUNCHED;
|
2012-01-18 21:53:30 +01:00
|
|
|
mp->transports = smartlist_new();
|
2012-05-08 15:37:43 +02:00
|
|
|
mp->argv = tor_malloc_zero(sizeof(char*)*2);
|
|
|
|
mp->argv[0] = tor_strdup("<testcase>");
|
2011-07-13 19:06:14 +02:00
|
|
|
|
|
|
|
/* various wrong protocol runs: */
|
|
|
|
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION 1",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
|
|
|
|
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION 1",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_BROKEN);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_BROKEN);
|
|
|
|
|
|
|
|
reset_mp(mp);
|
|
|
|
|
|
|
|
/* correct protocol run: */
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"VERSION 1",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
|
|
|
|
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
|
|
|
|
|
2013-05-11 23:06:22 +02:00
|
|
|
strlcpy(line,"CMETHODS DONE",sizeof(line));
|
2011-07-13 19:06:14 +02:00
|
|
|
handle_proxy_line(line, mp);
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_CONFIGURED);
|
|
|
|
|
|
|
|
done:
|
2014-04-26 17:28:39 +02:00
|
|
|
reset_mp(mp);
|
|
|
|
smartlist_free(mp->transports);
|
|
|
|
tor_free(mp->argv[0]);
|
|
|
|
tor_free(mp->argv);
|
2011-07-13 19:06:14 +02:00
|
|
|
tor_free(mp);
|
|
|
|
}
|
|
|
|
|
2013-07-16 17:53:36 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
#ifdef _WIN32
|
2013-07-29 17:37:39 +02:00
|
|
|
#define STDIN_HANDLE HANDLE
|
2013-07-29 15:59:59 +02:00
|
|
|
#else
|
2013-07-29 17:37:39 +02:00
|
|
|
#define STDIN_HANDLE FILE
|
|
|
|
#endif
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
static smartlist_t *
|
2013-07-29 17:37:39 +02:00
|
|
|
tor_get_lines_from_handle_replacement(STDIN_HANDLE *handle,
|
2013-07-29 15:59:59 +02:00
|
|
|
enum stream_status *stream_status_out)
|
|
|
|
{
|
|
|
|
static int times_called = 0;
|
|
|
|
smartlist_t *retval_sl = smartlist_new();
|
|
|
|
|
2013-07-31 19:36:17 +02:00
|
|
|
(void) handle;
|
|
|
|
(void) stream_status_out;
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
/* Generate some dummy CMETHOD lines the first 5 times. The 6th
|
|
|
|
time, send 'CMETHODS DONE' to finish configuring the proxy. */
|
|
|
|
if (times_called++ != 5) {
|
2013-08-05 19:54:54 +02:00
|
|
|
smartlist_add_asprintf(retval_sl, "SMETHOD mock%d 127.0.0.1:555%d",
|
2013-07-29 15:59:59 +02:00
|
|
|
times_called, times_called);
|
|
|
|
} else {
|
2013-08-05 19:54:54 +02:00
|
|
|
smartlist_add(retval_sl, tor_strdup("SMETHODS DONE"));
|
2013-07-29 15:59:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval_sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOP mock */
|
|
|
|
static void
|
|
|
|
tor_process_handle_destroy_replacement(process_handle_t *process_handle,
|
|
|
|
int also_terminate_process)
|
|
|
|
{
|
2013-07-29 17:37:39 +02:00
|
|
|
(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;
|
2013-07-29 15:59:59 +02:00
|
|
|
}
|
|
|
|
|
2013-08-25 17:29:03 +02:00
|
|
|
static int controlevent_n = 0;
|
|
|
|
static uint16_t controlevent_event = 0;
|
|
|
|
static smartlist_t *controlevent_msgs = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_control_event_string_replacement(uint16_t event, event_format_t which,
|
|
|
|
const char *msg)
|
|
|
|
{
|
|
|
|
(void) which;
|
|
|
|
++controlevent_n;
|
|
|
|
controlevent_event = event;
|
|
|
|
if (!controlevent_msgs)
|
|
|
|
controlevent_msgs = smartlist_new();
|
|
|
|
smartlist_add(controlevent_msgs, tor_strdup(msg));
|
|
|
|
}
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
/* Test the configure_proxy() function. */
|
|
|
|
static void
|
|
|
|
test_pt_configure_proxy(void *arg)
|
|
|
|
{
|
2013-08-05 15:30:21 +02:00
|
|
|
int i, retval;
|
2013-07-29 15:59:59 +02:00
|
|
|
managed_proxy_t *mp = NULL;
|
2013-07-31 19:36:17 +02:00
|
|
|
(void) arg;
|
2013-07-29 15:59:59 +02:00
|
|
|
|
2013-07-29 17:37:39 +02:00
|
|
|
dummy_state = tor_malloc_zero(sizeof(or_state_t));
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
MOCK(tor_get_lines_from_handle,
|
|
|
|
tor_get_lines_from_handle_replacement);
|
|
|
|
MOCK(tor_process_handle_destroy,
|
|
|
|
tor_process_handle_destroy_replacement);
|
2013-07-29 17:37:39 +02:00
|
|
|
MOCK(get_or_state,
|
|
|
|
get_or_state_replacement);
|
2013-08-25 17:29:03 +02:00
|
|
|
MOCK(send_control_event_string,
|
|
|
|
send_control_event_string_replacement);
|
|
|
|
|
|
|
|
control_testing_set_global_event_mask(EVENT_TRANSPORT_LAUNCHED);
|
2013-07-29 15:59:59 +02:00
|
|
|
|
|
|
|
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));
|
2013-07-29 17:37:39 +02:00
|
|
|
mp->argv = tor_malloc_zero(sizeof(char*)*2);
|
|
|
|
mp->argv[0] = tor_strdup("<testcase>");
|
2013-08-05 19:54:54 +02:00
|
|
|
mp->is_server = 1;
|
2013-07-29 15:59:59 +02:00
|
|
|
|
|
|
|
/* 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++) {
|
2013-08-05 15:30:21 +02:00
|
|
|
retval = configure_proxy(mp);
|
|
|
|
/* retval should be zero because proxy hasn't finished configuring yet */
|
|
|
|
test_assert(retval == 0);
|
|
|
|
/* check the number of registered transports */
|
|
|
|
test_assert(smartlist_len(mp->transports) == i+1);
|
|
|
|
/* check that the mp is still waiting for transports */
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS);
|
2013-07-29 15:59:59 +02:00
|
|
|
}
|
2013-08-05 15:30:21 +02:00
|
|
|
|
|
|
|
/* this last configure_proxy() should finalize the proxy configuration. */
|
|
|
|
retval = configure_proxy(mp);
|
|
|
|
/* retval should be 1 since the proxy finished configuring */
|
|
|
|
test_assert(retval == 1);
|
|
|
|
/* check the mp state */
|
|
|
|
test_assert(mp->conf_state == PT_PROTO_COMPLETED);
|
2013-07-29 15:59:59 +02:00
|
|
|
|
2013-08-25 17:29:03 +02:00
|
|
|
tt_int_op(controlevent_n, ==, 5);
|
|
|
|
tt_int_op(controlevent_event, ==, EVENT_TRANSPORT_LAUNCHED);
|
|
|
|
tt_int_op(smartlist_len(controlevent_msgs), ==, 5);
|
|
|
|
smartlist_sort_strings(controlevent_msgs);
|
|
|
|
tt_str_op(smartlist_get(controlevent_msgs, 0), ==,
|
|
|
|
"650 TRANSPORT_LAUNCHED server mock1 127.0.0.1 5551\r\n");
|
|
|
|
tt_str_op(smartlist_get(controlevent_msgs, 1), ==,
|
|
|
|
"650 TRANSPORT_LAUNCHED server mock2 127.0.0.1 5552\r\n");
|
|
|
|
tt_str_op(smartlist_get(controlevent_msgs, 2), ==,
|
|
|
|
"650 TRANSPORT_LAUNCHED server mock3 127.0.0.1 5553\r\n");
|
|
|
|
tt_str_op(smartlist_get(controlevent_msgs, 3), ==,
|
|
|
|
"650 TRANSPORT_LAUNCHED server mock4 127.0.0.1 5554\r\n");
|
|
|
|
tt_str_op(smartlist_get(controlevent_msgs, 4), ==,
|
|
|
|
"650 TRANSPORT_LAUNCHED server mock5 127.0.0.1 5555\r\n");
|
|
|
|
|
2013-08-05 19:54:54 +02:00
|
|
|
{ /* check that the transport info were saved properly in the tor state */
|
|
|
|
config_line_t *transport_in_state = NULL;
|
|
|
|
smartlist_t *transport_info_sl = smartlist_new();
|
|
|
|
char *name_of_transport = NULL;
|
|
|
|
char *bindaddr = NULL;
|
|
|
|
|
|
|
|
/* Get the bindaddr for "mock1" and check it against the bindaddr
|
|
|
|
that the mocked tor_get_lines_from_handle() generated. */
|
|
|
|
transport_in_state = get_transport_in_state_by_name("mock1");
|
|
|
|
test_assert(transport_in_state);
|
|
|
|
smartlist_split_string(transport_info_sl, transport_in_state->value,
|
|
|
|
NULL, 0, 0);
|
|
|
|
name_of_transport = smartlist_get(transport_info_sl, 0);
|
|
|
|
bindaddr = smartlist_get(transport_info_sl, 1);
|
|
|
|
tt_str_op(name_of_transport, ==, "mock1");
|
|
|
|
tt_str_op(bindaddr, ==, "127.0.0.1:5551");
|
|
|
|
|
|
|
|
SMARTLIST_FOREACH(transport_info_sl, char *, cp, tor_free(cp));
|
|
|
|
smartlist_free(transport_info_sl);
|
|
|
|
}
|
|
|
|
|
2013-07-29 15:59:59 +02:00
|
|
|
done:
|
2014-04-26 17:28:39 +02:00
|
|
|
or_state_free(dummy_state);
|
2013-07-29 15:59:59 +02:00
|
|
|
UNMOCK(tor_get_lines_from_handle);
|
|
|
|
UNMOCK(tor_process_handle_destroy);
|
2013-08-25 17:29:03 +02:00
|
|
|
UNMOCK(get_or_state);
|
|
|
|
UNMOCK(send_control_event_string);
|
|
|
|
if (controlevent_msgs) {
|
|
|
|
SMARTLIST_FOREACH(controlevent_msgs, char *, cp, tor_free(cp));
|
|
|
|
smartlist_free(controlevent_msgs);
|
|
|
|
controlevent_msgs = NULL;
|
|
|
|
}
|
2014-04-26 17:28:39 +02:00
|
|
|
if (mp->transports) {
|
|
|
|
SMARTLIST_FOREACH(mp->transports, transport_t *, t, transport_free(t));
|
|
|
|
smartlist_free(mp->transports);
|
|
|
|
}
|
|
|
|
smartlist_free(mp->transports_to_launch);
|
|
|
|
tor_free(mp->process_handle);
|
|
|
|
tor_free(mp->argv[0]);
|
|
|
|
tor_free(mp->argv);
|
|
|
|
tor_free(mp);
|
2013-07-29 15:59:59 +02:00
|
|
|
}
|
2013-07-29 17:37:39 +02:00
|
|
|
|
2011-07-13 19:06:14 +02:00
|
|
|
#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),
|
2013-07-15 23:32:08 +02:00
|
|
|
{ "get_transport_options", test_pt_get_transport_options, TT_FORK,
|
|
|
|
NULL, NULL },
|
2013-07-16 17:53:36 +02:00
|
|
|
{ "get_extrainfo_string", test_pt_get_extrainfo_string, TT_FORK,
|
|
|
|
NULL, NULL },
|
2013-07-29 15:59:59 +02:00
|
|
|
{ "configure_proxy",test_pt_configure_proxy, TT_FORK,
|
|
|
|
NULL, NULL },
|
2011-07-13 19:06:14 +02:00
|
|
|
END_OF_TESTCASES
|
|
|
|
};
|
|
|
|
|