Skip to content
Snippets Groups Projects
Unverified Commit b69e85cc authored by JeremyRand's avatar JeremyRand
Browse files

Bug 19859: Add unit test for formatting

parent 56ee42e1
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,14 @@
#include "core/or/orconn_event.h"
#include "core/mainloop/connection.h"
#include "feature/control/control_events.h"
#include "feature/control/control_fmt.h"
#include "test/test.h"
#include "test/test_helpers.h"
#include "core/or/entry_connection_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/socks_request_st.h"
static void
add_testing_cell_stats_entry(circuit_t *circ, uint8_t command,
......@@ -537,6 +540,135 @@ test_cntev_orconn_state_proxy(void *arg)
UNMOCK(queue_control_event_string);
}
static void
test_cntev_format_stream(void *arg)
{
entry_connection_t *ec = NULL;
char *conndesc = NULL;
(void)arg;
ec = entry_connection_new(CONN_TYPE_AP, AF_INET);
char *username = tor_strdup("jeremy");
char *password = tor_strdup("letmein");
ec->socks_request->username = username; // steal reference
ec->socks_request->usernamelen = strlen(username);
ec->socks_request->password = password; // steal reference
ec->socks_request->passwordlen = strlen(password);
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "SOCKS_USERNAME=\"jeremy\""));
tt_assert(strstr(conndesc, "SOCKS_PASSWORD=\"letmein\""));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_LISTENER;
ec->socks_request->socks_version = 4;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=SOCKS4"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_LISTENER;
ec->socks_request->socks_version = 5;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=SOCKS5"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_LISTENER;
ec->socks_request->socks_version = 6;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=UNKNOWN"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_TRANS_LISTENER;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=TRANS"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_NATD_LISTENER;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=NATD"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_DNS_LISTENER;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=DNS"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_AP_HTTP_CONNECT_LISTENER;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=HTTPCONNECT"));
tor_free(conndesc);
ec->socks_request->listener_type = CONN_TYPE_OR;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "CLIENT_PROTOCOL=UNKNOWN"));
tor_free(conndesc);
ec->nym_epoch = 1337;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "NYM_EPOCH=1337"));
tor_free(conndesc);
ec->entry_cfg.session_group = 4321;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "SESSION_GROUP=4321"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_DESTPORT;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=DESTPORT"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=DESTPORT,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_DESTADDR;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=DESTADDR"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=DESTADDR,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_SOCKSAUTH;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=SOCKS_USERNAME,SOCKS_PASSWORD"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=SOCKS_USERNAME,SOCKS_PASSWORD,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_CLIENTPROTO;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=CLIENT_PROTOCOL"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=CLIENT_PROTOCOL,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_CLIENTADDR;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=CLIENTADDR"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=CLIENTADDR,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_SESSIONGRP;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=SESSION_GROUP"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=SESSION_GROUP,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_NYM_EPOCH;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc, "ISO_FIELDS=NYM_EPOCH"));
tt_assert(!strstr(conndesc, "ISO_FIELDS=NYM_EPOCH,"));
tor_free(conndesc);
ec->entry_cfg.isolation_flags = ISO_DESTPORT | ISO_SOCKSAUTH | ISO_NYM_EPOCH;
conndesc = entry_connection_describe_status_for_controller(ec);
tt_assert(strstr(conndesc,
"ISO_FIELDS=DESTPORT,SOCKS_USERNAME,SOCKS_PASSWORD,NYM_EPOCH"));
tt_assert(!strstr(conndesc,
"ISO_FIELDS=DESTPORT,SOCKS_USERNAME,SOCKS_PASSWORD,NYM_EPOCH,"));
done:
tor_free(username);
tor_free(password);
tor_free(conndesc);
connection_free_minimal(ENTRY_TO_CONN(ec));
}
#define TEST(name, flags) \
{ #name, test_cntev_ ## name, flags, 0, NULL }
......@@ -548,6 +680,7 @@ struct testcase_t controller_event_tests[] = {
TEST(append_cell_stats, TT_FORK),
TEST(format_cell_stats, TT_FORK),
TEST(event_mask, TT_FORK),
TEST(format_stream, TT_FORK),
T_PUBSUB(dirboot_defer_desc, TT_FORK),
T_PUBSUB(dirboot_defer_orconn, TT_FORK),
T_PUBSUB(orconn_state, TT_FORK),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment