[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Test get_guard_selection_by_name
commit a7bc73935b030100b0d7b9f39c5dec5ef6eb0a85
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Wed Nov 23 15:08:07 2016 -0500
Test get_guard_selection_by_name
---
src/or/entrynodes.c | 2 +-
src/or/entrynodes.h | 2 ++
src/test/test_entrynodes.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
index 860be9b..cf35b02 100644
--- a/src/or/entrynodes.c
+++ b/src/or/entrynodes.c
@@ -201,7 +201,7 @@ guard_selection_new(const char *name)
* <b>create_if_absent</b> is true, then create and return it. If there
* is none, and <b>create_if_absent</b> is false, then return NULL.
*/
-static guard_selection_t *
+STATIC guard_selection_t *
get_guard_selection_by_name(const char *name, int create_if_absent)
{
if (!guard_contexts) {
diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
index a514c13..285664d 100644
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@ -416,6 +416,8 @@ int num_bridges_usable(void);
// ---------- XXXX these functions and definitions are post-prop271.
HANDLE_DECL(entry_guard, entry_guard_t, STATIC)
STATIC guard_selection_t *guard_selection_new(const char *name);
+STATIC guard_selection_t *get_guard_selection_by_name(
+ const char *name, int create_if_absent);
STATIC void guard_selection_free(guard_selection_t *gs);
STATIC entry_guard_t *get_sampled_guard_with_id(guard_selection_t *gs,
const uint8_t *rsa_id);
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index cdf8672..785503b 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -1236,6 +1236,52 @@ test_entry_guard_parse_from_state_partial_failure(void *arg)
}
static void
+test_entry_guard_get_guard_selection_by_name(void *arg)
+{
+ (void)arg;
+ guard_selection_t *gs1, *gs2, *gs3;
+
+ gs1 = get_guard_selection_by_name("unlikely", 0);
+ tt_assert(gs1 == NULL);
+ gs1 = get_guard_selection_by_name("unlikely", 1);
+ tt_assert(gs1 != NULL);
+ gs2 = get_guard_selection_by_name("unlikely", 1);
+ tt_assert(gs2 == gs1);
+ gs2 = get_guard_selection_by_name("unlikely", 0);
+ tt_assert(gs2 == gs1);
+
+ gs2 = get_guard_selection_by_name("implausible", 0);
+ tt_assert(gs2 == NULL);
+ gs2 = get_guard_selection_by_name("implausible", 1);
+ tt_assert(gs2 != NULL);
+ tt_assert(gs2 != gs1);
+ gs3 = get_guard_selection_by_name("implausible", 0);
+ tt_assert(gs3 == gs2);
+
+ gs3 = get_guard_selection_by_name("default", 0);
+ tt_assert(gs3 == NULL);
+ gs3 = get_guard_selection_by_name("default", 1);
+ tt_assert(gs3 != NULL);
+ tt_assert(gs3 != gs2);
+ tt_assert(gs3 != gs1);
+ tt_assert(gs3 == get_guard_selection_info());
+
+#if 0
+ or_options_t *options = get_options_mutable();
+ options->UseDeprecatedGuardAlgorithm = 1;
+ gs4 = get_guard_selection_info();
+ tt_assert(gs4 != gs3);
+ tt_assert(gs4 == get_guard_selection_by_name("legacy", 1));
+
+ options->UseDeprecatedGuardAlgorithm = 0;
+ tt_assert(gs3 == get_guard_selection_info());
+#endif
+
+ done:
+ entry_guards_free_all();
+}
+
+static void
test_entry_guard_add_single_guard(void *arg)
{
(void)arg;
@@ -2245,6 +2291,8 @@ struct testcase_t entrynodes_tests[] = {
test_entry_guard_parse_from_state_failure, 0, NULL, NULL },
{ "parse_from_state_partial_failure",
test_entry_guard_parse_from_state_partial_failure, 0, NULL, NULL },
+ { "get_guard_selection_by_name",
+ test_entry_guard_get_guard_selection_by_name, TT_FORK, NULL, NULL },
BFN_TEST(add_single_guard),
BFN_TEST(node_filter),
BFN_TEST(expand_sample),
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits