summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-06-13 18:29:16 +0000
committerNick Mathewson <nickm@torproject.org>2007-06-13 18:29:16 +0000
commit05cf945a1c540806fd7e3be14a52d6c4c01215ea (patch)
treefb3c2bdf093d355eb7898b5e6511edc6a6ed0123 /src
parent0cf38ddef6af877a056a9c181fe2fd76d5c81ec5 (diff)
downloadtor-05cf945a1c540806fd7e3be14a52d6c4c01215ea.tar.gz
tor-05cf945a1c540806fd7e3be14a52d6c4c01215ea.zip
r13393@catbus: nickm | 2007-06-13 14:29:14 -0400
More vote unit tests: check that we are parsing routerstatuses correctly. svn:r10588
Diffstat (limited to 'src')
-rw-r--r--src/or/dirserv.c4
-rw-r--r--src/or/test.c36
2 files changed, 33 insertions, 7 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index b4fe5d49d2..01b6db731b 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1649,8 +1649,8 @@ routerstatus_format_entry(char *buf, size_t buf_len,
rs->is_named?" Named":"",
rs->is_stable?" Stable":"",
rs->is_running?" Running":"",
- rs->is_valid?" Valid":"",
- rs->is_v2_dir?" V2Dir":"");
+ rs->is_v2_dir?" V2Dir":"",
+ rs->is_valid?" Valid":"");
if (r<0) {
log_warn(LD_BUG, "Not enough space in buffer.");
return -1;
diff --git a/src/or/test.c b/src/or/test.c
index 26f42f976b..30870e32d6 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -2210,7 +2210,7 @@ test_v3_networkstatus(void)
rs->published_on = now-1500;
strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
memset(rs->identity_digest, 3, DIGEST_LEN);
- memset(rs->descriptor_digest, 11, DIGEST_LEN);
+ memset(rs->descriptor_digest, 78, DIGEST_LEN);
rs->addr = 0x99008801;
rs->or_port = 443;
rs->dir_port = 8000;
@@ -2223,13 +2223,12 @@ test_v3_networkstatus(void)
rs->published_on = now-1000;
strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
memset(rs->identity_digest, 5, DIGEST_LEN);
- memset(rs->descriptor_digest, 2, DIGEST_LEN);
+ memset(rs->descriptor_digest, 77, DIGEST_LEN);
rs->addr = 0x99009901;
rs->or_port = 443;
rs->dir_port = 0;
rs->is_exit = rs->is_stable = rs->is_fast = rs->is_running =
- rs->is_v2_dir = rs->is_possible_guard = 1;
- // rs->named = rs->is_bad_exit = rs->is_bad_directory = 1;
+ rs->is_valid = rs->is_v2_dir = rs->is_possible_guard = 1;
smartlist_add(vote->routerstatus_list, vrs);
/* dump the vote and try to parse it. */
@@ -2263,7 +2262,34 @@ test_v3_networkstatus(void)
test_streq(cp, "Authority:Exit:Fast:Guard:Running:Stable:V2Dir:Valid");
tor_free(cp);
test_eq(smartlist_len(v1->routerstatus_list), 2);
- /*XXXX020 test contents of v1->routerstatus_list. */
+ /* Check the first routerstatus. */
+ vrs = smartlist_get(v1->routerstatus_list, 0);
+ rs = &vrs->status;
+ test_streq(vrs->version, "0.1.2.14");
+ test_eq(rs->published_on, now-1500);
+ test_streq(rs->nickname, "router2");
+ test_memeq(rs->identity_digest,
+ "\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3",
+ DIGEST_LEN);
+ test_memeq(rs->descriptor_digest, "NNNNNNNNNNNNNNNNNNNN", DIGEST_LEN);
+ test_eq(rs->addr, 0x099008801);
+ test_eq(rs->or_port, 443);
+ test_eq(rs->dir_port, 8000);
+ test_eq(vrs->flags, U64_LITERAL(0));
+ /* Check the second routerstatus. */
+ vrs = smartlist_get(v1->routerstatus_list, 1);
+ rs = &vrs->status;
+ test_streq(vrs->version, "0.2.0.5");
+ test_eq(rs->published_on, now-1000);
+ test_streq(rs->nickname, "router1");
+ test_memeq(rs->identity_digest,
+ "\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5",
+ DIGEST_LEN);
+ test_memeq(rs->descriptor_digest, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
+ test_eq(rs->addr, 0x099009901);
+ test_eq(rs->or_port, 443);
+ test_eq(rs->dir_port, 0);
+ test_eq(vrs->flags, U64_LITERAL(254)); // all flags except "authority."
/* XXXXX020 Generate 2 more votes */