summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-11-07 09:58:53 -0500
committerNick Mathewson <nickm@torproject.org>2017-11-07 09:58:53 -0500
commitc6c4a421fd7d8a0d4baba8f34276acaa245548f1 (patch)
tree261e1193e7a18a8dc3c02950c35fa164b108ce27 /src/test
parent0227aab1b7084de271cfb7702cb3386bfb05a5bb (diff)
parent9d848ca58a4624df7abae298d8977ae82bcfb543 (diff)
downloadtor-c6c4a421fd7d8a0d4baba8f34276acaa245548f1.tar.gz
tor-c6c4a421fd7d8a0d4baba8f34276acaa245548f1.zip
Merge branch 'maint-0.3.2'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_dir.c1
-rw-r--r--src/test/test_hs_common.c21
-rw-r--r--src/test/test_hs_service.c4
-rw-r--r--src/test/test_shared_random.c149
4 files changed, 86 insertions, 89 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index b920655db5..87b86c38b8 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -2379,6 +2379,7 @@ test_a_networkstatus(
sign_skey_2 = crypto_pk_new();
sign_skey_3 = crypto_pk_new();
sign_skey_leg1 = pk_generate(4);
+ dirvote_recalculate_timing(get_options(), now);
sr_state_init(0, 0);
tt_assert(!crypto_pk_read_private_key_from_string(sign_skey_1,
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index 22fed12f1e..b435a93e33 100644
--- a/src/test/test_hs_common.c
+++ b/src/test/test_hs_common.c
@@ -23,6 +23,7 @@
#include "config.h"
#include "networkstatus.h"
#include "directory.h"
+#include "dirvote.h"
#include "nodelist.h"
#include "routerlist.h"
#include "statefile.h"
@@ -808,26 +809,41 @@ test_time_between_tp_and_srv(void *arg)
ret = parse_rfc1123_time("Sat, 26 Oct 1985 00:00:00 UTC", &ns.valid_after);
tt_int_op(ret, OP_EQ, 0);
+ ret = parse_rfc1123_time("Sat, 26 Oct 1985 01:00:00 UTC", &ns.fresh_until);
+ tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), ns.valid_after);
ret = hs_in_period_between_tp_and_srv(&ns, 0);
tt_int_op(ret, OP_EQ, 0);
ret = parse_rfc1123_time("Sat, 26 Oct 1985 11:00:00 UTC", &ns.valid_after);
tt_int_op(ret, OP_EQ, 0);
+ ret = parse_rfc1123_time("Sat, 26 Oct 1985 12:00:00 UTC", &ns.fresh_until);
+ tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), ns.valid_after);
ret = hs_in_period_between_tp_and_srv(&ns, 0);
tt_int_op(ret, OP_EQ, 0);
ret = parse_rfc1123_time("Sat, 26 Oct 1985 12:00:00 UTC", &ns.valid_after);
tt_int_op(ret, OP_EQ, 0);
+ ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", &ns.fresh_until);
+ tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), ns.valid_after);
ret = hs_in_period_between_tp_and_srv(&ns, 0);
tt_int_op(ret, OP_EQ, 1);
ret = parse_rfc1123_time("Sat, 26 Oct 1985 23:00:00 UTC", &ns.valid_after);
tt_int_op(ret, OP_EQ, 0);
+ ret = parse_rfc1123_time("Sat, 27 Oct 1985 00:00:00 UTC", &ns.fresh_until);
+ tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), ns.valid_after);
ret = hs_in_period_between_tp_and_srv(&ns, 0);
tt_int_op(ret, OP_EQ, 1);
- ret = parse_rfc1123_time("Sat, 26 Oct 1985 00:00:00 UTC", &ns.valid_after);
+ ret = parse_rfc1123_time("Sat, 27 Oct 1985 00:00:00 UTC", &ns.valid_after);
+ tt_int_op(ret, OP_EQ, 0);
+ ret = parse_rfc1123_time("Sat, 27 Oct 1985 01:00:00 UTC", &ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), ns.valid_after);
ret = hs_in_period_between_tp_and_srv(&ns, 0);
tt_int_op(ret, OP_EQ, 0);
@@ -1314,6 +1330,7 @@ run_reachability_scenario(const reachability_cfg_t *cfg, int num_scenario)
&mock_service_ns->valid_until);
set_consensus_times(cfg->service_valid_until,
&mock_service_ns->fresh_until);
+ dirvote_recalculate_timing(get_options(), mock_service_ns->valid_after);
/* Set client consensus time. */
set_consensus_times(cfg->client_valid_after,
&mock_client_ns->valid_after);
@@ -1321,6 +1338,7 @@ run_reachability_scenario(const reachability_cfg_t *cfg, int num_scenario)
&mock_client_ns->valid_until);
set_consensus_times(cfg->client_valid_until,
&mock_client_ns->fresh_until);
+ dirvote_recalculate_timing(get_options(), mock_client_ns->valid_after);
/* New time period checks for this scenario. */
tt_int_op(hs_in_period_between_tp_and_srv(mock_service_ns, 0), OP_EQ,
@@ -1544,6 +1562,7 @@ helper_set_consensus_and_system_time(networkstatus_t *ns, int position)
} else {
tt_assert(0);
}
+ dirvote_recalculate_timing(get_options(), ns->valid_after);
/* Set system time: pretend to be just 2 minutes before consensus expiry */
real_time = ns->valid_until - 120;
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 462c860a9a..3084c6b958 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -33,6 +33,7 @@
#include "circuitlist.h"
#include "circuituse.h"
#include "crypto.h"
+#include "dirvote.h"
#include "networkstatus.h"
#include "nodelist.h"
#include "relay.h"
@@ -967,6 +968,7 @@ test_rotate_descriptors(void *arg)
ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
&mock_ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
/* Create a service with a default descriptor and state. It's added to the
* global map. */
@@ -1004,6 +1006,7 @@ test_rotate_descriptors(void *arg)
ret = parse_rfc1123_time("Sat, 27 Oct 1985 02:00:00 UTC",
&mock_ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
/* Note down what to expect for the next rotation time which is 01:00 + 23h
* meaning 00:00:00. */
@@ -1065,6 +1068,7 @@ test_build_update_descriptors(void *arg)
ret = parse_rfc1123_time("Sat, 26 Oct 1985 04:00:00 UTC",
&mock_ns.fresh_until);
tt_int_op(ret, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), mock_ns.valid_after);
/* Create a service without a current descriptor to trigger a build. */
service = helper_create_service();
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 80494f64c0..b0278e8a1d 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -134,7 +134,15 @@ test_get_sr_protocol_phase(void *arg)
;
}
-static networkstatus_t *mock_consensus = NULL;
+static networkstatus_t mock_consensus;
+
+/* Mock function to immediately return our local 'mock_consensus'. */
+static networkstatus_t *
+mock_networkstatus_get_live_consensus(time_t now)
+{
+ (void) now;
+ return &mock_consensus;
+}
static void
test_get_state_valid_until_time(void *arg)
@@ -146,11 +154,23 @@ test_get_state_valid_until_time(void *arg)
(void) arg;
+ MOCK(networkstatus_get_live_consensus,
+ mock_networkstatus_get_live_consensus);
+
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 01:00:00 UTC",
+ &mock_consensus.fresh_until);
+ tt_int_op(retval, OP_EQ, 0);
+
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
+ &mock_consensus.valid_after);
+ tt_int_op(retval, OP_EQ, 0);
+
{
/* Get the valid until time if called at 00:00:01 */
retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
valid_until_time = get_state_valid_until_time(current_time);
/* Compare it with the correct result */
@@ -162,6 +182,7 @@ test_get_state_valid_until_time(void *arg)
retval = parse_rfc1123_time("Mon, 20 Apr 2015 19:22:00 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
valid_until_time = get_state_valid_until_time(current_time);
format_iso_time(tbuf, valid_until_time);
@@ -172,6 +193,7 @@ test_get_state_valid_until_time(void *arg)
retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:59:00 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
valid_until_time = get_state_valid_until_time(current_time);
format_iso_time(tbuf, valid_until_time);
@@ -182,6 +204,7 @@ test_get_state_valid_until_time(void *arg)
retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
valid_until_time = get_state_valid_until_time(current_time);
format_iso_time(tbuf, valid_until_time);
@@ -189,7 +212,7 @@ test_get_state_valid_until_time(void *arg)
}
done:
- ;
+ UNMOCK(networkstatus_get_live_consensus);
}
/** Test the function that calculates the start time of the current SRV
@@ -203,11 +226,23 @@ test_get_start_time_of_current_run(void *arg)
(void) arg;
+ MOCK(networkstatus_get_live_consensus,
+ mock_networkstatus_get_live_consensus);
+
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 01:00:00 UTC",
+ &mock_consensus.fresh_until);
+ tt_int_op(retval, OP_EQ, 0);
+
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
+ &mock_consensus.valid_after);
+ tt_int_op(retval, OP_EQ, 0);
+
{
/* Get start time if called at 00:00:01 */
retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
run_start_time =
sr_state_get_start_time_of_current_protocol_run(current_time);
@@ -220,6 +255,7 @@ test_get_start_time_of_current_run(void *arg)
retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:59:59 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
run_start_time =
sr_state_get_start_time_of_current_protocol_run(current_time);
@@ -232,6 +268,7 @@ test_get_start_time_of_current_run(void *arg)
retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
&current_time);
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
run_start_time =
sr_state_get_start_time_of_current_protocol_run(current_time);
@@ -240,6 +277,10 @@ test_get_start_time_of_current_run(void *arg)
tt_str_op("2015-04-20 00:00:00", OP_EQ, tbuf);
}
+ /* Next test is testing it without a consensus to use the testing voting
+ * interval . */
+ UNMOCK(networkstatus_get_live_consensus);
+
/* Now let's alter the voting schedule and check the correctness of the
* function. Voting interval of 10 seconds, means that an SRV protocol run
* takes 10 seconds * 24 rounds = 4 mins */
@@ -249,8 +290,8 @@ test_get_start_time_of_current_run(void *arg)
options->TestingV3AuthInitialVotingInterval = 10;
retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:15:32 UTC",
&current_time);
-
tt_int_op(retval, OP_EQ, 0);
+ dirvote_recalculate_timing(get_options(), current_time);
run_start_time =
sr_state_get_start_time_of_current_protocol_run(current_time);
@@ -269,22 +310,31 @@ static void
test_get_start_time_functions(void *arg)
{
(void) arg;
- time_t now = approx_time();
+ int retval;
+
+ MOCK(networkstatus_get_live_consensus,
+ mock_networkstatus_get_live_consensus);
+
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 01:00:00 UTC",
+ &mock_consensus.fresh_until);
+ tt_int_op(retval, OP_EQ, 0);
+ retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
+ &mock_consensus.valid_after);
+ tt_int_op(retval, OP_EQ, 0);
+ time_t now = mock_consensus.valid_after;
+
+ dirvote_recalculate_timing(get_options(), now);
time_t start_time_of_protocol_run =
sr_state_get_start_time_of_current_protocol_run(now);
tt_assert(start_time_of_protocol_run);
/* Check that the round start time of the beginning of the run, is itself */
- tt_int_op(get_start_time_of_current_round(start_time_of_protocol_run), OP_EQ,
+ tt_int_op(get_start_time_of_current_round(), OP_EQ,
start_time_of_protocol_run);
- /* Check that even if we increment the start time, we still get the start
- time of the run as the beginning of the round. */
- tt_int_op(get_start_time_of_current_round(start_time_of_protocol_run+1),
- OP_EQ, start_time_of_protocol_run);
-
- done: ;
+ done:
+ UNMOCK(networkstatus_get_live_consensus);
}
static void
@@ -306,81 +356,6 @@ test_get_sr_protocol_duration(void *arg)
done: ;
}
-/* Mock function to immediately return our local 'mock_consensus'. */
-static networkstatus_t *
-mock_networkstatus_get_live_consensus(time_t now)
-{
- (void) now;
- return mock_consensus;
-}
-
-/** Test the get_next_valid_after_time() function. */
-static void
-test_get_next_valid_after_time(void *arg)
-{
- time_t current_time;
- time_t valid_after_time;
- char tbuf[ISO_TIME_LEN + 1];
- int retval;
-
- (void) arg;
-
- {
- /* Setup a fake consensus just to get the times out of it, since
- get_next_valid_after_time() needs them. */
- mock_consensus = tor_malloc_zero(sizeof(networkstatus_t));
-
- retval = parse_rfc1123_time("Mon, 13 Jan 2016 16:00:00 UTC",
- &mock_consensus->fresh_until);
- tt_int_op(retval, OP_EQ, 0);
-
- retval = parse_rfc1123_time("Mon, 13 Jan 2016 15:00:00 UTC",
- &mock_consensus->valid_after);
- tt_int_op(retval, OP_EQ, 0);
-
- MOCK(networkstatus_get_live_consensus,
- mock_networkstatus_get_live_consensus);
- }
-
- {
- /* Get the valid after time if called at 00:00:00 */
- retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:00 UTC",
- &current_time);
- tt_int_op(retval, OP_EQ, 0);
- valid_after_time = get_next_valid_after_time(current_time);
-
- /* Compare it with the correct result */
- format_iso_time(tbuf, valid_after_time);
- tt_str_op("2015-04-20 01:00:00", OP_EQ, tbuf);
- }
-
- {
- /* Get the valid until time if called at 00:00:01 */
- retval = parse_rfc1123_time("Mon, 20 Apr 2015 00:00:01 UTC",
- &current_time);
- tt_int_op(retval, OP_EQ, 0);
- valid_after_time = get_next_valid_after_time(current_time);
-
- /* Compare it with the correct result */
- format_iso_time(tbuf, valid_after_time);
- tt_str_op("2015-04-20 01:00:00", OP_EQ, tbuf);
- }
-
- {
- retval = parse_rfc1123_time("Mon, 20 Apr 2015 23:30:01 UTC",
- &current_time);
- tt_int_op(retval, OP_EQ, 0);
- valid_after_time = get_next_valid_after_time(current_time);
-
- /* Compare it with the correct result */
- format_iso_time(tbuf, valid_after_time);
- tt_str_op("2015-04-21 00:00:00", OP_EQ, tbuf);
- }
-
- done:
- networkstatus_vote_free(mock_consensus);
-}
-
/* In this test we are going to generate a sr_commit_t object and validate
* it. We first generate our values, and then we parse them as if they were
* received from the network. After we parse both the commit and the reveal,
@@ -1389,8 +1364,6 @@ struct testcase_t sr_tests[] = {
NULL, NULL },
{ "encoding", test_encoding, TT_FORK,
NULL, NULL },
- { "get_next_valid_after_time", test_get_next_valid_after_time, TT_FORK,
- NULL, NULL },
{ "get_start_time_of_current_run", test_get_start_time_of_current_run,
TT_FORK, NULL, NULL },
{ "get_start_time_functions", test_get_start_time_functions,