aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_connection.c
diff options
context:
space:
mode:
authorSuphanat Chunhapanya <haxx.pop@gmail.com>2019-10-22 01:55:23 +0800
committerNick Mathewson <nickm@torproject.org>2020-01-06 13:39:10 -0500
commit4264717ca377464b5304df0e3a322afaef72d812 (patch)
treede7f32a1a44ccd0d442a0f78ad61120fb097218e /src/test/test_connection.c
parentde58a49a2db20638823a77a1fb4c7f913f4f2169 (diff)
downloadtor-4264717ca377464b5304df0e3a322afaef72d812.tar.gz
tor-4264717ca377464b5304df0e3a322afaef72d812.zip
test: HTTP CONNECT protocol
Diffstat (limited to 'src/test/test_connection.c')
-rw-r--r--src/test/test_connection.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/test/test_connection.c b/src/test/test_connection.c
index 36543b3af5..34ef3fdf18 100644
--- a/src/test/test_connection.c
+++ b/src/test/test_connection.c
@@ -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
@@ -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
@@ -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),
@@ -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