aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_hs_dos.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-06-27 14:06:42 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-08-06 07:58:14 -0400
commit90b5422e8ee9dd7c7d04507291668e5870f2e351 (patch)
treef36a15f5cad6ebb550a5d74adfe5fa496d12e963 /src/test/test_hs_dos.c
parente53796854811724fdd1db5127bb67943ba5d423c (diff)
downloadtor-90b5422e8ee9dd7c7d04507291668e5870f2e351.tar.gz
tor-90b5422e8ee9dd7c7d04507291668e5870f2e351.zip
test: Series of fixes for hs_dos.c unit tests
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs_dos.c')
-rw-r--r--src/test/test_hs_dos.c28
1 files changed, 28 insertions, 0 deletions
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[] = {