diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-06-13 20:17:27 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-06-13 20:17:27 +0000 |
commit | 64626836699c4d1644ebf5f1df72e7f84c35be44 (patch) | |
tree | 965b29ebdf864d3f32f56cf64bdbd93483f94b70 | |
parent | 4b162fd1f41c53e52746628b8dec41450e72b38a (diff) | |
download | tor-64626836699c4d1644ebf5f1df72e7f84c35be44.tar.gz tor-64626836699c4d1644ebf5f1df72e7f84c35be44.zip |
r13403@catbus: nickm | 2007-06-13 16:15:44 -0400
Test all of consensus contents, except for routerstatus_list contents. And signatures.
svn:r10593
-rw-r--r-- | src/or/dirvote.c | 3 | ||||
-rw-r--r-- | src/or/or.h | 2 | ||||
-rw-r--r-- | src/or/test.c | 66 | ||||
-rw-r--r-- | src/or/test_data.c | 1 |
4 files changed, 63 insertions, 9 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 4bd7cae2dd..d2950551f0 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -347,6 +347,9 @@ networkstatus_compute_consensus(smartlist_t *votes, smartlist_free(lst); } + /* XXXX020 we list any flag that _any_ dirserver lists. possible + * problem. + */ smartlist_sort_strings(flags); smartlist_uniq_strings(flags); diff --git a/src/or/or.h b/src/or/or.h index 64689d8c74..f2fe563b5b 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1315,7 +1315,7 @@ typedef struct networkstatus_voter_info_t { uint16_t dir_port; uint16_t or_port; char *contact; - char vote_digest[DIGEST_LEN]; /* consensus only. */ + char vote_digest[DIGEST_LEN]; char signing_key_digest[DIGEST_LEN]; /* This part is _not_ signed. */ char *pending_signature; diff --git a/src/or/test.c b/src/or/test.c index a604cc1e3f..8aeb91070c 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -2135,6 +2135,20 @@ extern const char AUTHORITY_CERT_3[]; extern const char AUTHORITY_SIGNKEY_3[]; static void +test_same_voter(networkstatus_voter_info_t *v1, + networkstatus_voter_info_t *v2) +{ + test_streq(v1->nickname, v2->nickname); + test_memeq(v1->identity_digest, v2->identity_digest, DIGEST_LEN); + test_streq(v1->address, v2->address); + test_eq(v1->addr, v2->addr); + test_eq(v1->dir_port, v2->dir_port); + test_eq(v1->or_port, v2->or_port); + test_streq(v1->contact, v2->contact); + test_memeq(v1->vote_digest, v2->vote_digest, DIGEST_LEN); +} + +static void test_v3_networkstatus(void) { authority_cert_t *cert1, *cert2, *cert3; @@ -2142,7 +2156,7 @@ test_v3_networkstatus(void) time_t now = time(NULL); networkstatus_voter_info_t *voter; - networkstatus_vote_t *vote, *v1, *v2, *v3, *consensus; + networkstatus_vote_t *vote, *v1, *v2, *v3, *con; vote_routerstatus_t *vrs; routerstatus_t *rs; char *v1_text, *v2_text, *v3_text, *consensus_text, *cp; @@ -2195,7 +2209,7 @@ test_v3_networkstatus(void) voter->addr = 0x01020304; voter->dir_port = 80; voter->or_port = 9000; - voter->contact = tor_strdup("voter1@example.com"); + voter->contact = tor_strdup("voter@example.com"); crypto_pk_get_digest(cert1->identity_key, voter->identity_digest); smartlist_add(vote->voters, voter); vote->cert = authority_cert_dup(cert1); @@ -2265,7 +2279,7 @@ test_v3_networkstatus(void) test_eq(voter->addr, 0x01020304); test_eq(voter->dir_port, 80); test_eq(voter->or_port, 9000); - test_streq(voter->contact, "voter1@example.com"); + test_streq(voter->contact, "voter@example.com"); test_assert(v1->cert); test_assert(!crypto_pk_cmp_keys(sign_skey_1, v1->cert->signing_key)); cp = smartlist_join_strings(v1->known_flags, ":", 0, NULL); @@ -2339,7 +2353,7 @@ test_v3_networkstatus(void) /* 1023 - authority(1) - madeofcheese(16) - madeoftin(32) */ test_eq(vrs->flags, U64_LITERAL(974)); - /* XXXX Generate third vote. */ + /* Generate the third vote. */ vote->published = now; vote->fresh_until = now+203; vote->dist_seconds = 250; @@ -2372,19 +2386,55 @@ test_v3_networkstatus(void) cert3->identity_key, sign_skey_3); test_assert(consensus_text); - consensus = networkstatus_parse_vote_from_string(consensus_text, 0); - test_assert(consensus); + con = networkstatus_parse_vote_from_string(consensus_text, 0); + test_assert(con); // log_notice(LD_GENERAL, "<<%s>>", consensus_text); - /* XXXX020 check consensus contents. */ - + /* Check consensus contents. */ + test_assert(!con->is_vote); + test_eq(con->published, 0); /* this field only appears in votes. */ + test_eq(con->valid_after, now+100); + test_eq(con->fresh_until, now+203); /* median */ + test_eq(con->valid_until, now+300); + test_eq(con->vote_seconds, 100); + test_eq(con->dist_seconds, 250); /* median */ + test_streq(con->client_versions, "0.1.2.14"); + test_streq(con->server_versions, "0.1.2.15,0.1.2.16"); + cp = smartlist_join_strings(v2->known_flags, ":", 0, NULL); + test_streq(cp, "Authority:Exit:Fast:Guard:MadeOfCheese:MadeOfTin:" + "Running:Stable:V2Dir:Valid"); + tor_free(cp); + test_eq(3, smartlist_len(con->voters)); + /* The voter id digests should be in this order. */ + test_assert(memcmp(cert2->cache_info.identity_digest, + cert3->cache_info.identity_digest,DIGEST_LEN)<0); + test_assert(memcmp(cert3->cache_info.identity_digest, + cert1->cache_info.identity_digest,DIGEST_LEN)<0); + test_same_voter(smartlist_get(con->voters, 0), + smartlist_get(v2->voters, 0)); + test_same_voter(smartlist_get(con->voters, 1), + smartlist_get(v3->voters, 0)); + test_same_voter(smartlist_get(con->voters, 2), + smartlist_get(v1->voters, 0)); + + test_assert(!con->cert); + test_eq(2, smartlist_len(con->routerstatus_list)); + /* XXXX020 test routerstatus_list contents */ + + /* XXXX020 Check signatures */ + + /* XXXX020 frob with detached signatures */ + + smartlist_free(votes); tor_free(v1_text); tor_free(v2_text); tor_free(v3_text); + tor_free(consensus_text); networkstatus_vote_free(vote); networkstatus_vote_free(v1); networkstatus_vote_free(v2); networkstatus_vote_free(v3); + networkstatus_vote_free(con); crypto_free_pk_env(sign_skey_1); crypto_free_pk_env(sign_skey_2); crypto_free_pk_env(sign_skey_3); diff --git a/src/or/test_data.c b/src/or/test_data.c index c0de0952c7..174600a12b 100644 --- a/src/or/test_data.c +++ b/src/or/test_data.c @@ -160,3 +160,4 @@ const char AUTHORITY_SIGNKEY_3[] = "VmMfzoFDHTkwYgj/F4PpAkEA+RaaSRP7BmbvFNqvlm8J/m0RVdAH4+p/Q5Z5u6Yo\n" "N7xC/gFi0qFPGKsDvD2CncAYmt+KNsd8S0JGDN4eieKn+Q==\n" "-----END RSA PRIVATE KEY-----\n"; + |