diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-08-01 17:29:10 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-15 12:03:37 -0400 |
commit | 28bb673584b3e7e839bebce64bd986c6c4ad1faa (patch) | |
tree | 102e828fd7f9be5ab565686fa3e0062acec3d58f /src/test/test_extorport.c | |
parent | 636aeb1f24fadd4c6c45dbfd1539f6312c91cc60 (diff) | |
download | tor-28bb673584b3e7e839bebce64bd986c6c4ad1faa.tar.gz tor-28bb673584b3e7e839bebce64bd986c6c4ad1faa.zip |
White-box tests for the succeeding case of ext_or_port handshake.
(Okay, white-box plus mocking enough other functions so they don't
crash.)
Diffstat (limited to 'src/test/test_extorport.c')
-rw-r--r-- | src/test/test_extorport.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c index 04524215ed..1d97557e41 100644 --- a/src/test/test_extorport.c +++ b/src/test/test_extorport.c @@ -7,6 +7,7 @@ #include "or.h" #include "buffers.h" #include "connection.h" +#include "connection_or.h" #include "config.h" #include "control.h" #include "ext_orport.h" @@ -344,6 +345,30 @@ ignore_bootstrap_problem(const char *warn, int reason) (void)reason; } +static int is_reading = 1; +static int handshake_start_called = 0; + +static void +note_read_stopped(connection_t *conn) +{ + (void)conn; + is_reading=0; +} +static void +note_read_started(connection_t *conn) +{ + (void)conn; + is_reading=1; +} +static int +handshake_start(or_connection_t *conn, int receiving) +{ + if (!conn || !receiving) + TT_FAIL(("Bad arguments to handshake_start")); + handshake_start_called = 1; + return 0; +} + static void test_ext_or_handshake(void *arg) { @@ -422,6 +447,10 @@ test_ext_or_handshake(void *arg) conn = NULL; UNMOCK(control_event_bootstrap_problem); + MOCK(connection_start_reading, note_read_started); + MOCK(connection_stop_reading, note_read_stopped); + MOCK(connection_tls_start_handshake, handshake_start); + /* Okay, this time let's succeed. */ conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET); tt_int_op(0, ==, connection_ext_or_start_auth(conn)); @@ -444,6 +473,39 @@ test_ext_or_handshake(void *arg) tt_assert(! TO_CONN(conn)->marked_for_close); tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN); + /* Now let's run through some messages. */ + /* First let's send some junk and make sure it's ignored. */ + WRITE("\xff\xf0\x00\x03""ABC", 7); + tt_int_op(0, ==, connection_ext_or_process_inbuf(conn)); + CONTAINS("", 0); + /* Now let's send a USERADDR command. */ + WRITE("\x00\x01\x00\x0c""1.2.3.4:5678", 16); + tt_int_op(0, ==, connection_ext_or_process_inbuf(conn)); + tt_int_op(TO_CONN(conn)->port, ==, 5678); + tt_int_op(tor_addr_to_ipv4h(&TO_CONN(conn)->addr), ==, 0x01020304); + /* Now let's send a TRANSPORT command. */ + WRITE("\x00\x02\x00\x07""rfc1149", 11); + tt_int_op(0, ==, connection_ext_or_process_inbuf(conn)); + tt_ptr_op(NULL, !=, conn->ext_or_transport); + tt_str_op("rfc1149", ==, conn->ext_or_transport); + tt_int_op(is_reading,==,1); + tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_OPEN); + /* DONE */ + WRITE("\x00\x00\x00\x00", 4); + tt_int_op(0, ==, connection_ext_or_process_inbuf(conn)); + tt_int_op(TO_CONN(conn)->state, ==, EXT_OR_CONN_STATE_FLUSHING); + tt_int_op(is_reading,==,0); + CONTAINS("\x10\x00\x00\x00", 4); + tt_int_op(handshake_start_called,==,0); + tt_int_op(0, ==, connection_ext_or_finished_flushing(conn)); + tt_int_op(is_reading,==,1); + tt_int_op(handshake_start_called,==,1); + tt_int_op(TO_CONN(conn)->type, ==, CONN_TYPE_OR); + /* XXXXX the state is now nonsensical! It should be set to something + * neutral (zero?) before we connection_or_change_state; right now + * it's EXT_OR_CONN_STATE_FLUSHING */ + /* tt_int_op(TO_CONN(conn)->state, ==, 0); XXXX */ + done: UNMOCK(connection_write_to_buf_impl_); UNMOCK(crypto_rand); |