Skip to content

Commit

Permalink
test: HTTP CONNECT protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ppopth authored and nmathewson committed Jan 6, 2020
1 parent de58a49 commit 4264717
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/test/test_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,7 @@ test_conn_download_status_teardown(const struct testcase_t *tc, void *arg)
static void *
test_conn_proxy_connect_setup(const struct testcase_t *tc)
{
tcp_proxy_protocol_t proxy_type = (tcp_proxy_protocol_t)tc->setup_data;
switch (proxy_type) {
case TCP_PROXY_PROTOCOL_HAPROXY:
return test_conn_get_proxy_or_connection(PROXY_HAPROXY);
default:
return NULL;
}
return test_conn_get_proxy_or_connection(*(unsigned int *)tc->setup_data);
}

static int
Expand Down Expand Up @@ -818,6 +812,25 @@ test_conn_download_status(void *arg)
/* the teardown function removes all the connections in the global list*/;
}

static void
test_conn_https_proxy_connect(void *arg)
{
size_t sz;
char *buf = NULL;
or_connection_t *conn = arg;

MOCK(connection_or_change_state, mock_connection_or_change_state);

tt_int_op(conn->base_.proxy_state, OP_EQ, PROXY_HTTPS_WANT_CONNECT_OK);

buf = buf_get_contents(conn->base_.outbuf, &sz);
tt_str_op(buf, OP_EQ, "CONNECT 127.0.0.1:12345 HTTP/1.0\r\n\r\n");

done:
UNMOCK(connection_or_change_state);
tor_free(buf);
}

static int handshake_start_called = 0;

static int
Expand Down Expand Up @@ -957,6 +970,9 @@ test_failed_orconn_tracker(void *arg)
#define CONNECTION_TESTCASE_ARG(name, fork, setup, arg) \
{ #name "_" #arg, test_conn_##name, fork, &setup, (void *)arg }

static const unsigned int PROXY_CONNECT_ARG = PROXY_CONNECT;
static const unsigned int PROXY_HAPROXY_ARG = PROXY_HAPROXY;

struct testcase_t connection_tests[] = {
CONNECTION_TESTCASE(get_basic, TT_FORK, test_conn_get_basic_st),
CONNECTION_TESTCASE(get_rend, TT_FORK, test_conn_get_rend_st),
Expand All @@ -966,9 +982,12 @@ struct testcase_t connection_tests[] = {
test_conn_download_status_st, FLAV_MICRODESC),
CONNECTION_TESTCASE_ARG(download_status, TT_FORK,
test_conn_download_status_st, FLAV_NS),

CONNECTION_TESTCASE_ARG(https_proxy_connect, TT_FORK,
test_conn_proxy_connect_st, &PROXY_CONNECT_ARG),
CONNECTION_TESTCASE_ARG(haproxy_proxy_connect, TT_FORK,
test_conn_proxy_connect_st,
TCP_PROXY_PROTOCOL_HAPROXY),
test_conn_proxy_connect_st, &PROXY_HAPROXY_ARG),

//CONNECTION_TESTCASE(func_suffix, TT_FORK, setup_func_pair),
{ "failed_orconn_tracker", test_failed_orconn_tracker, TT_FORK, NULL, NULL },
END_OF_TESTCASES
Expand Down

0 comments on commit 4264717

Please sign in to comment.