summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-09-13 09:45:55 -0400
committerNick Mathewson <nickm@torproject.org>2016-09-13 09:45:55 -0400
commit8fdf2f583c73f249791bd3a7627d27da4a6ef36f (patch)
tree62b891ef9b04d44b44c86ea54c56c63cc650b895 /src
parent08d2d7c404af9fd836f2fcc35936899a99f813ae (diff)
downloadtor-8fdf2f583c73f249791bd3a7627d27da4a6ef36f.tar.gz
tor-8fdf2f583c73f249791bd3a7627d27da4a6ef36f.zip
Unit tests for proposal 271 client-side implementation
Diffstat (limited to 'src')
-rw-r--r--src/or/routerparse.c2
-rw-r--r--src/or/routerparse.h8
-rw-r--r--src/test/test_dir.c44
3 files changed, 53 insertions, 1 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index d7fa17dd9d..b1d9a85e1d 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -2731,7 +2731,7 @@ routerstatus_parse_guardfraction(const char *guardfraction_str,
*
* Parse according to the syntax used by the consensus flavor <b>flav</b>.
**/
-static routerstatus_t *
+STATIC routerstatus_t *
routerstatus_parse_entry_from_string(memarea_t *area,
const char **s, smartlist_t *tokens,
networkstatus_t *vote,
diff --git a/src/or/routerparse.h b/src/or/routerparse.h
index 81ef724945..9a3fadca1f 100644
--- a/src/or/routerparse.h
+++ b/src/or/routerparse.h
@@ -112,6 +112,14 @@ MOCK_DECL(STATIC dumped_desc_t *, dump_desc_populate_one_file,
STATIC void dump_desc_populate_fifo_from_directory(const char *dirname);
STATIC void dump_desc(const char *desc, const char *type);
STATIC void dump_desc_fifo_cleanup(void);
+struct memarea_t;
+STATIC routerstatus_t *routerstatus_parse_entry_from_string(
+ struct memarea_t *area,
+ const char **s, smartlist_t *tokens,
+ networkstatus_t *vote,
+ vote_routerstatus_t *vote_rs,
+ int consensus_method,
+ consensus_flavor_t flav);
#endif
#define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1"
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 4a6c5a9b5a..1ea7fc9a38 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -5390,6 +5390,49 @@ test_dir_find_dl_schedule(void* data)
mock_options = NULL;
}
+static void
+test_dir_assumed_flags(void *arg)
+{
+ (void)arg;
+ smartlist_t *tokens = smartlist_new();
+ memarea_t *area = memarea_new();
+ routerstatus_t *rs = NULL;
+
+ /* First, we should always assume that the Running flag is set, even
+ * when it isn't listed, since the consensus method is always
+ * higher than 4. */
+ const char *str1 =
+ "r example hereiswhereyouridentitygoes 2015-08-30 12:00:00 "
+ "192.168.0.1 9001 0\n"
+ "m thisoneislongerbecauseitisa256bitmddigest33\n"
+ "s Fast Guard Stable\n";
+
+ const char *cp = str1;
+ rs = routerstatus_parse_entry_from_string(area, &cp, tokens, NULL, NULL,
+ 23, FLAV_MICRODESC);
+ tt_assert(rs);
+ tt_assert(rs->is_flagged_running);
+ tt_assert(! rs->is_valid);
+ tt_assert(! rs->is_exit);
+ tt_assert(rs->is_fast);
+ routerstatus_free(rs);
+
+ /* With method 24 or later, we can assume "valid" is set. */
+ cp = str1;
+ rs = routerstatus_parse_entry_from_string(area, &cp, tokens, NULL, NULL,
+ 24, FLAV_MICRODESC);
+ tt_assert(rs);
+ tt_assert(rs->is_flagged_running);
+ tt_assert(rs->is_valid);
+ tt_assert(! rs->is_exit);
+ tt_assert(rs->is_fast);
+
+ done:
+ smartlist_free(tokens);
+ memarea_drop_all(area);
+ routerstatus_free(rs);
+}
+
#define DIR_LEGACY(name) \
{ #name, test_dir_ ## name , TT_FORK, NULL, NULL }
@@ -5443,6 +5486,7 @@ struct testcase_t dir_tests[] = {
DIR_ARG(find_dl_schedule, TT_FORK, "ba"),
DIR_ARG(find_dl_schedule, TT_FORK, "cf"),
DIR_ARG(find_dl_schedule, TT_FORK, "ca"),
+ DIR(assumed_flags, 0),
END_OF_TESTCASES
};