|
@@ -70,6 +70,14 @@ fake_network_setup(const struct testcase_t *testcase)
|
|
|
return dummy_state;
|
|
|
}
|
|
|
|
|
|
+static or_options_t mocked_options;
|
|
|
+
|
|
|
+static const or_options_t *
|
|
|
+mock_get_options(void)
|
|
|
+{
|
|
|
+ return &mocked_options;
|
|
|
+}
|
|
|
+
|
|
|
/** Test choose_random_entry() with none of our routers being guard nodes. */
|
|
|
static void
|
|
|
test_choose_random_entry_no_guards(void *arg)
|
|
@@ -78,6 +86,14 @@ test_choose_random_entry_no_guards(void *arg)
|
|
|
|
|
|
(void) arg;
|
|
|
|
|
|
+ MOCK(get_options, mock_get_options);
|
|
|
+
|
|
|
+ /* Check that we get a guard if it passes preferred
|
|
|
+ * address settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 1;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 0;
|
|
|
+
|
|
|
/* Try to pick an entry even though none of our routers are guards. */
|
|
|
chosen_entry = choose_random_entry(NULL);
|
|
|
|
|
@@ -86,8 +102,35 @@ test_choose_random_entry_no_guards(void *arg)
|
|
|
can't find a proper entry guard. */
|
|
|
tt_assert(chosen_entry);
|
|
|
|
|
|
+ /* And with the other IP version active */
|
|
|
+ mocked_options.ClientUseIPv6 = 1;
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+ tt_assert(chosen_entry);
|
|
|
+
|
|
|
+ /* Check that we don't get a guard if it doesn't pass mandatory address
|
|
|
+ * settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 0;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 0;
|
|
|
+
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+
|
|
|
+ /* If we don't allow IPv4 at all, we don't get a guard*/
|
|
|
+ tt_assert(!chosen_entry);
|
|
|
+
|
|
|
+ /* Check that we get a guard if it passes allowed but not preferred address
|
|
|
+ * settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 1;
|
|
|
+ mocked_options.ClientUseIPv6 = 1;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 1;
|
|
|
+
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+ tt_assert(chosen_entry);
|
|
|
+
|
|
|
done:
|
|
|
- ;
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ UNMOCK(get_options);
|
|
|
}
|
|
|
|
|
|
/** Test choose_random_entry() with only one of our routers being a
|
|
@@ -101,17 +144,55 @@ test_choose_random_entry_one_possible_guard(void *arg)
|
|
|
|
|
|
(void) arg;
|
|
|
|
|
|
+ MOCK(get_options, mock_get_options);
|
|
|
+
|
|
|
/* Set one of the nodes to be a guard. */
|
|
|
our_nodelist = nodelist_get_list();
|
|
|
the_guard = smartlist_get(our_nodelist, 4); /* chosen by fair dice roll */
|
|
|
the_guard->is_possible_guard = 1;
|
|
|
|
|
|
+ /* Check that we get the guard if it passes preferred
|
|
|
+ * address settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 1;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 0;
|
|
|
+
|
|
|
/* Pick an entry. Make sure we pick the node we marked as guard. */
|
|
|
chosen_entry = choose_random_entry(NULL);
|
|
|
tt_ptr_op(chosen_entry, OP_EQ, the_guard);
|
|
|
|
|
|
+ /* And with the other IP version active */
|
|
|
+ mocked_options.ClientUseIPv6 = 1;
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+ tt_ptr_op(chosen_entry, OP_EQ, the_guard);
|
|
|
+
|
|
|
+ /* Check that we don't get a guard if it doesn't pass mandatory address
|
|
|
+ * settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 0;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 0;
|
|
|
+
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+
|
|
|
+ /* If we don't allow IPv4 at all, we don't get a guard*/
|
|
|
+ tt_assert(!chosen_entry);
|
|
|
+
|
|
|
+ /* Check that we get a node if it passes allowed but not preferred
|
|
|
+ * address settings */
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ mocked_options.ClientUseIPv4 = 1;
|
|
|
+ mocked_options.ClientUseIPv6 = 1;
|
|
|
+ mocked_options.ClientPreferIPv6ORPort = 1;
|
|
|
+
|
|
|
+ chosen_entry = choose_random_entry(NULL);
|
|
|
+
|
|
|
+ /* We disable the guard check and the preferred address check at the same
|
|
|
+ * time, so we can't be sure we get the guard */
|
|
|
+ tt_assert(chosen_entry);
|
|
|
+
|
|
|
done:
|
|
|
- ;
|
|
|
+ memset(&mocked_options, 0, sizeof(mocked_options));
|
|
|
+ UNMOCK(get_options);
|
|
|
}
|
|
|
|
|
|
/** Helper to conduct tests for populate_live_entry_guards().
|
|
@@ -624,14 +705,6 @@ test_entry_is_live(void *arg)
|
|
|
; /* XXX */
|
|
|
}
|
|
|
|
|
|
-static or_options_t mocked_options;
|
|
|
-
|
|
|
-static const or_options_t *
|
|
|
-mock_get_options(void)
|
|
|
-{
|
|
|
- return &mocked_options;
|
|
|
-}
|
|
|
-
|
|
|
#define TEST_IPV4_ADDR "123.45.67.89"
|
|
|
#define TEST_IPV6_ADDR "[1234:5678:90ab:cdef::]"
|
|
|
|