From ec0da9a6f150c3e96a5aa777dea38105350a2b53 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 24 Jul 2017 13:17:59 +0300 Subject: [PATCH] test: Unbreak test_upload_descriptors() To upload the descriptor we needed a state file to write the rev counters in, but that test did not have a state file initialized. Also fix the typo in its func name. Signed-off-by: David Goulet --- src/test/test_hs_service.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 664277b198..6d5ea7ed7d 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -16,6 +16,7 @@ #define HS_INTROPOINT_PRIVATE #define MAIN_PRIVATE #define NETWORKSTATUS_PRIVATE +#define STATEFILE_PRIVATE #define TOR_CHANNEL_INTERNAL_ #include "test.h" @@ -43,6 +44,7 @@ #include "hs_service.h" #include "main.h" #include "rendservice.h" +#include "statefile.h" /* Trunnel */ #include "hs/cell_establish_intro.h" @@ -56,6 +58,15 @@ mock_networkstatus_get_live_consensus(time_t now) return &mock_ns; } +static or_state_t *dummy_state = NULL; + +/* Mock function to get fake or state (used for rev counters) */ +static or_state_t * +get_or_state_replacement(void) +{ + return dummy_state; +} + /* Mock function because we are not trying to test the close circuit that does * an awful lot of checks on the circuit object. */ static void @@ -779,6 +790,10 @@ test_introduce2(void *arg) hs_init(); MOCK(circuit_mark_for_close_, mock_circuit_mark_for_close); + MOCK(get_or_state, + get_or_state_replacement); + + dummy_state = tor_malloc_zero(sizeof(or_state_t)); circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_S_INTRO, flags); @@ -830,6 +845,8 @@ test_introduce2(void *arg) tt_u64_op(ip->introduce2_count, OP_EQ, 0); done: + or_state_free(dummy_state); + dummy_state = NULL; circuit_free(TO_CIRCUIT(circ)); hs_free_all(); UNMOCK(circuit_mark_for_close_); @@ -1011,6 +1028,10 @@ test_build_update_descriptors(void *arg) hs_init(); MOCK(hs_overlap_mode_is_active, mock_hs_overlap_mode_is_active_true); + MOCK(get_or_state, + get_or_state_replacement); + + dummy_state = tor_malloc_zero(sizeof(or_state_t)); /* Create a service without a current descriptor to trigger a build. */ service = hs_service_new(get_options()); @@ -1133,7 +1154,7 @@ test_build_update_descriptors(void *arg) } static void -test_upload_desctriptors(void *arg) +test_upload_descriptors(void *arg) { int ret; time_t now = time(NULL); @@ -1144,6 +1165,10 @@ test_upload_desctriptors(void *arg) hs_init(); MOCK(hs_overlap_mode_is_active, mock_hs_overlap_mode_is_active_true); + MOCK(get_or_state, + get_or_state_replacement); + + dummy_state = tor_malloc_zero(sizeof(or_state_t)); /* Create a service with no descriptor. It's added to the global map. */ service = hs_service_new(get_options()); @@ -1278,7 +1303,7 @@ struct testcase_t hs_service_tests[] = { NULL, NULL }, { "build_update_descriptors", test_build_update_descriptors, TT_FORK, NULL, NULL }, - { "upload_desctriptors", test_upload_desctriptors, TT_FORK, + { "upload_descriptors", test_upload_descriptors, TT_FORK, NULL, NULL }, { "revision_counter_state", test_revision_counter_state, TT_FORK, NULL, NULL },