summaryrefslogtreecommitdiff
path: root/src/test/test_routerlist.c
diff options
context:
space:
mode:
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-05-18 22:05:35 -0400
committerNick Mathewson <nickm@torproject.org>2016-05-19 07:58:41 -0400
commitf698b509d8efdc055cfc05c6feaf0aecee41b9d0 (patch)
tree7d74711f1ee69f74def145f3517ecee2d69a202a /src/test/test_routerlist.c
parentd5c70d71027644efb31d16d17b46d43484b46b18 (diff)
downloadtor-f698b509d8efdc055cfc05c6feaf0aecee41b9d0.tar.gz
tor-f698b509d8efdc055cfc05c6feaf0aecee41b9d0.zip
Add unit tests for networkstatus_consensus_is_bootstrapping
Diffstat (limited to 'src/test/test_routerlist.c')
-rw-r--r--src/test/test_routerlist.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c
index 497606920d..2cffa6e801 100644
--- a/src/test/test_routerlist.c
+++ b/src/test/test_routerlist.c
@@ -15,6 +15,7 @@
#include "container.h"
#include "directory.h"
#include "dirvote.h"
+#include "microdesc.h"
#include "networkstatus.h"
#include "nodelist.h"
#include "policies.h"
@@ -190,6 +191,14 @@ construct_consensus(char **consensus_text_md)
crypto_pk_free(sign_skey_leg);
}
+static int mock_usable_consensus_flavor_value = FLAV_NS;
+
+static int
+mock_usable_consensus_flavor(void)
+{
+ return mock_usable_consensus_flavor_value;
+}
+
static void
test_router_pick_directory_server_impl(void *arg)
{
@@ -209,6 +218,22 @@ test_router_pick_directory_server_impl(void *arg)
(void)arg;
+ MOCK(usable_consensus_flavor, mock_usable_consensus_flavor);
+
+ /* With no consensus, we must be bootstrapping, regardless of time or flavor
+ */
+ mock_usable_consensus_flavor_value = FLAV_NS;
+ tt_assert(networkstatus_consensus_is_bootstrapping(now));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60));
+
+ mock_usable_consensus_flavor_value = FLAV_MICRODESC;
+ tt_assert(networkstatus_consensus_is_bootstrapping(now));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60));
+
/* No consensus available, fail early */
rs = router_pick_directory_server_impl(V3_DIRINFO, (const int) 0, NULL);
tt_assert(rs == NULL);
@@ -223,6 +248,28 @@ test_router_pick_directory_server_impl(void *arg)
tt_int_op(smartlist_len(con_md->routerstatus_list), ==, 3);
tt_assert(!networkstatus_set_current_consensus_from_ns(con_md,
"microdesc"));
+
+ /* If the consensus time or flavor doesn't match, we are still
+ * bootstrapping */
+ mock_usable_consensus_flavor_value = FLAV_NS;
+ tt_assert(networkstatus_consensus_is_bootstrapping(now));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2000));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60));
+
+ /* With a valid consensus for the current time and flavor, we stop
+ * bootstrapping, even if we have no certificates */
+ mock_usable_consensus_flavor_value = FLAV_MICRODESC;
+ tt_assert(!networkstatus_consensus_is_bootstrapping(now + 2000));
+ tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_after));
+ tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_until));
+ tt_assert(!networkstatus_consensus_is_bootstrapping(con_md->valid_until
+ + 24*60*60));
+ /* These times are outside the test validity period */
+ tt_assert(networkstatus_consensus_is_bootstrapping(now));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now + 2*24*60*60));
+ tt_assert(networkstatus_consensus_is_bootstrapping(now - 2*24*60*60));
+
nodelist_set_consensus(con_md);
nodelist_assert_ok();
@@ -362,6 +409,7 @@ test_router_pick_directory_server_impl(void *arg)
node_router1->rs->last_dir_503_at = 0;
done:
+ UNMOCK(usable_consensus_flavor);
if (router1_id)
tor_free(router1_id);
if (router2_id)