diff options
author | Nick Mathewson <nickm@torproject.org> | 2011-10-07 16:05:13 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-10-07 16:05:13 -0400 |
commit | ed39621a9d97dc07063b6e9052b52a91b99d82d6 (patch) | |
tree | 56c4e4aa1f00f4b53a0ef1ac2c8e06d1da4ff376 /src/test | |
parent | 98e5c63eb254cb4b744281b75093c4bd7f73b6c6 (diff) | |
parent | 1174bb95ce79767cfaee4f50ce70f42e7eb01b2e (diff) | |
download | tor-ed39621a9d97dc07063b6e9052b52a91b99d82d6.tar.gz tor-ed39621a9d97dc07063b6e9052b52a91b99d82d6.zip |
Merge remote-tracking branch 'asn2/bug3656'
Conflicts:
src/common/util.c
src/common/util.h
src/or/config.h
src/or/main.c
src/test/test_util.c
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/Makefile.am | 1 | ||||
-rw-r--r-- | src/test/test.c | 2 | ||||
-rw-r--r-- | src/test/test_pt.c | 147 | ||||
-rw-r--r-- | src/test/test_util.c | 8 |
4 files changed, 154 insertions, 4 deletions
diff --git a/src/test/Makefile.am b/src/test/Makefile.am index 852715079d..301452b4ec 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -19,6 +19,7 @@ test_SOURCES = \ test_data.c \ test_dir.c \ test_microdesc.c \ + test_pt.c \ test_util.c \ tinytest.c diff --git a/src/test/test.c b/src/test/test.c index 04e7e02863..aca7f10e60 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -1941,6 +1941,7 @@ extern struct testcase_t container_tests[]; extern struct testcase_t util_tests[]; extern struct testcase_t dir_tests[]; extern struct testcase_t microdesc_tests[]; +extern struct testcase_t pt_tests[]; static struct testgroup_t testgroups[] = { { "", test_array }, @@ -1951,6 +1952,7 @@ static struct testgroup_t testgroups[] = { { "util/", util_tests }, { "dir/", dir_tests }, { "dir/md/", microdesc_tests }, + { "pt/", pt_tests }, END_OF_GROUPS }; diff --git a/src/test/test_pt.c b/src/test/test_pt.c new file mode 100644 index 0000000000..f97b21fa0d --- /dev/null +++ b/src/test/test_pt.c @@ -0,0 +1,147 @@ +/* Copyright (c) 2001-2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2011, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#include "orconfig.h" +#define PT_PRIVATE +#include "or.h" +#include "transports.h" +#include "circuitbuild.h" +#include "test.h" + +static void +reset_mp(managed_proxy_t *mp) +{ + mp->conf_state = PT_PROTO_LAUNCHED; + SMARTLIST_FOREACH(mp->transports, transport_t *, t, transport_free(t)); + smartlist_clear(mp->transports); +} + +static void +test_pt_parsing(void) +{ + char line[200]; + + managed_proxy_t *mp = tor_malloc(sizeof(managed_proxy_t)); + mp->conf_state = PT_PROTO_INFANT; + mp->transports = smartlist_create(); + + /* incomplete cmethod */ + strcpy(line,"CMETHOD trebuchet"); + test_assert(parse_cmethod_line(line, mp) < 0); + + reset_mp(mp); + + /* wrong proxy type */ + strcpy(line,"CMETHOD trebuchet dog 127.0.0.1:1999"); + test_assert(parse_cmethod_line(line, mp) < 0); + + reset_mp(mp); + + /* wrong addrport */ + strcpy(line,"CMETHOD trebuchet socks4 abcd"); + test_assert(parse_cmethod_line(line, mp) < 0); + + reset_mp(mp); + + /* correct line */ + strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999"); + test_assert(parse_cmethod_line(line, mp) == 0); + test_assert(smartlist_len(mp->transports)); + + reset_mp(mp); + + /* incomplete smethod */ + strcpy(line,"SMETHOD trebuchet"); + test_assert(parse_smethod_line(line, mp) < 0); + + reset_mp(mp); + + /* wrong addr type */ + strcpy(line,"SMETHOD trebuchet abcd"); + test_assert(parse_smethod_line(line, mp) < 0); + + reset_mp(mp); + + /* cowwect */ + strcpy(line,"SMETHOD trebuchy 127.0.0.1:1999"); + test_assert(parse_smethod_line(line, mp) == 0); + + reset_mp(mp); + + /* unsupported version */ + strcpy(line,"VERSION 666"); + test_assert(parse_version(line, mp) < 0); + + /* incomplete VERSION */ + strcpy(line,"VERSION "); + test_assert(parse_version(line, mp) < 0); + + /* correct VERSION */ + strcpy(line,"VERSION 1"); + test_assert(parse_version(line, mp) == 0); + + done: + tor_free(mp); +} + +static void +test_pt_protocol(void) +{ + char line[200]; + + managed_proxy_t *mp = tor_malloc(sizeof(managed_proxy_t)); + mp->conf_state = PT_PROTO_LAUNCHED; + mp->transports = smartlist_create(); + + /* various wrong protocol runs: */ + + strcpy(line, "TEST TEST"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_BROKEN); + + reset_mp(mp); + + strcpy(line,"VERSION 1"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + + strcpy(line,"VERSION 1"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_BROKEN); + + reset_mp(mp); + + strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_BROKEN); + + reset_mp(mp); + + /* correct protocol run: */ + strcpy(line,"VERSION 1"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + + strcpy(line,"CMETHOD trebuchet socks5 127.0.0.1:1999"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_ACCEPTING_METHODS); + + strcpy(line,"CMETHODS DONE"); + handle_proxy_line(line, mp); + test_assert(mp->conf_state == PT_PROTO_CONFIGURED); + + done: + tor_free(mp); +} + +#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), + END_OF_TESTCASES +}; + diff --git a/src/test/test_util.c b/src/test/test_util.c index f9672c100b..6603ab00d3 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -1389,9 +1389,9 @@ run_util_spawn_background(const char *argv[], const char *expected_out, /* Start the program */ #ifdef MS_WINDOWS - tor_spawn_background(NULL, argv, &process_handle); + tor_spawn_background(NULL, argv, NULL, &process_handle); #else - tor_spawn_background(argv[0], argv, &process_handle); + tor_spawn_background(argv[0], argv, NULL, &process_handle); #endif tt_int_op(process_handle.status, ==, expected_status); @@ -1506,9 +1506,9 @@ test_util_spawn_background_partial_read(void *ptr) /* Start the program */ #ifdef MS_WINDOWS - tor_spawn_background(NULL, argv, &process_handle); + tor_spawn_background(NULL, argv, NULL, &process_handle); #else - tor_spawn_background(argv[0], argv, &process_handle); + tor_spawn_background(argv[0], argv, NULL, &process_handle); #endif tt_int_op(process_handle.status, ==, expected_status); |