From 90b5422e8ee9dd7c7d04507291668e5870f2e351 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 27 Jun 2019 14:06:42 -0400 Subject: test: Series of fixes for hs_dos.c unit tests Signed-off-by: David Goulet --- src/test/test_hs_dos.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/test/test_hs_dos.c') diff --git a/src/test/test_hs_dos.c b/src/test/test_hs_dos.c index 6b82610534..3dfa057a4a 100644 --- a/src/test/test_hs_dos.c +++ b/src/test/test_hs_dos.c @@ -7,16 +7,37 @@ */ #define CIRCUITLIST_PRIVATE +#define NETWORKSTATUS_PRIVATE #include "test/test.h" #include "test/test_helpers.h" #include "test/log_test_helpers.h" +#include "app/config/config.h" + #include "core/or/circuitlist.h" #include "core/or/circuituse.h" #include "core/or/or_circuit_st.h" #include "feature/hs/hs_dos.h" +#include "feature/nodelist/networkstatus.h" + +static void +setup_mock_consensus(void) +{ + current_ns_consensus = tor_malloc_zero(sizeof(networkstatus_t)); + current_ns_consensus->net_params = smartlist_new(); + smartlist_add(current_ns_consensus->net_params, + (void *) "HiddenServiceEnableIntroDoSDefense=1"); + hs_dos_consensus_has_changed(current_ns_consensus); +} + +static void +free_mock_consensus(void) +{ + smartlist_free(current_ns_consensus->net_params); + tor_free(current_ns_consensus); +} static void test_can_send_intro2(void *arg) @@ -26,8 +47,12 @@ test_can_send_intro2(void *arg) (void) arg; + hs_init(); hs_dos_init(); + get_options_mutable()->ORPort_set = 1; + setup_mock_consensus(); + or_circ = or_circuit_new(1, NULL); /* Make that circuit a service intro point. */ @@ -95,6 +120,9 @@ test_can_send_intro2(void *arg) done: circuit_free_(TO_CIRCUIT(or_circ)); + + hs_free_all(); + free_mock_consensus(); } struct testcase_t hs_dos_tests[] = { -- cgit v1.2.3-54-g00ecf