aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-03-29 19:50:59 +0000
committerNick Mathewson <nickm@torproject.org>2004-03-29 19:50:59 +0000
commit6a79b1cb57ac524c1085e23f32f410d79d5471d7 (patch)
tree218bd858b58fdfba0226b7af39b86a8bdf72432e
parent0e6084d751a66d45d5e6ac6d5d6de4771a24680f (diff)
downloadtor-6a79b1cb57ac524c1085e23f32f410d79d5471d7.tar
tor-6a79b1cb57ac524c1085e23f32f410d79d5471d7.tar.gz
Re-enable unit tests for directory generation.
svn:r1362
-rw-r--r--src/or/dirserv.c2
-rw-r--r--src/or/routerlist.c6
-rw-r--r--src/or/test.c43
3 files changed, 30 insertions, 21 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 8ed63566c..0e28c5802 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -26,7 +26,7 @@ typedef struct fingerprint_entry_t {
static fingerprint_entry_t fingerprint_list[MAX_ROUTERS_IN_DIR];
static int n_fingerprints = 0;
-static void
+void /* Should be static; exposed for testing */
add_fingerprint_to_dir(const char *nickname, const char *fp)
{
int i;
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 923f8b3c5..daabe5122 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -111,7 +111,7 @@ static int
router_get_list_from_string_impl(const char **s, routerlist_t **dest,
int n_good_nicknames,
const char **good_nickname_lst);
-static int
+int /* Exposed for unit tests */
router_get_routerlist_from_directory_impl(const char *s, routerlist_t **dest,
crypto_pk_env_t *pkey);
static int
@@ -119,8 +119,6 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok);
static int
router_resolve_routerlist(routerlist_t *dir);
-
-
static int router_get_hash_impl(const char *s, char *digest,
const char *start_str, const char *end_str);
static void token_free(directory_token_t *tok);
@@ -575,7 +573,7 @@ static int parse_time(const char *cp, time_t *t)
* resulting routerlist in *dest, freeing the old value if necessary.
* If pkey is provided, we check the directory signature with pkey.
*/
-static int
+int /* Should be static; exposed for unit tests */
router_get_routerlist_from_directory_impl(const char *str,
routerlist_t **dest,
crypto_pk_env_t *pkey)
diff --git a/src/or/test.c b/src/or/test.c
index 303400756..1e8f51833 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -17,6 +17,11 @@
int have_failed = 0;
+/* These functions are file-local, but are exposed so we can test. */
+int router_get_routerlist_from_directory_impl(
+ const char *s, routerlist_t **dest, crypto_pk_env_t *pkey);
+void add_fingerprint_to_dir(const char *nickname, const char *fp);
+
void
dump_hex(char *s, int len)
{
@@ -667,6 +672,7 @@ test_dir_format()
r2.link_pkey = pk2;
r2.bandwidthrate = r2.bandwidthburst = 3000;
r2.exit_policy = &ex1;
+ r2.nickname = "Fred";
test_assert(!crypto_pk_write_public_key_to_string(pk1, &pk1_str,
&pk1_str_len));
@@ -740,22 +746,27 @@ test_dir_format()
test_assert(rp2->exit_policy->next->next == NULL);
#endif
-#if 0
- /* XXX To re-enable this test, we need to separate directory generation
- * XXX from the directory backend again. Do this the next time we have
- * XXX directory trouble. */
/* Okay, now for the directories. */
- dir1 = (directory_t*) tor_malloc(sizeof(directory_t));
- dir1->n_routers = 2;
- dir1->routers = (routerinfo_t**) tor_malloc(sizeof(routerinfo_t*)*2);
- dir1->routers[0] = &r1;
- dir1->routers[1] = &r2;
- test_assert(! dump_signed_directory_to_string_impl(buf, 4096, dir1, pk1));
- /* puts(buf); */
-
- test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1));
- test_eq(2, dir2->n_routers);
-#endif
+ crypto_pk_get_fingerprint(pk2, buf);
+ add_fingerprint_to_dir("Magri", buf);
+ crypto_pk_get_fingerprint(pk1, buf);
+ add_fingerprint_to_dir("Fred", buf);
+ /* Make sure routers aren't too far in the past any more. */
+ r1.published_on = time(NULL);
+ r2.published_on = time(NULL)-3*60*60;
+ test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
+ cp = buf;
+ test_eq(dirserv_add_descriptor((const char**)&cp), 1);
+ test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
+ cp = buf;
+ test_eq(dirserv_add_descriptor((const char**)&cp), 1);
+ extern or_options_t options;
+ options.Nickname = "DirServer";
+ test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3));
+ cp = buf;
+ test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3));
+ test_eq(2, dir1->n_routers);
+ dirserv_free_fingerprint_list();
tor_free(pk1_str);
tor_free(pk2_str);
@@ -763,7 +774,7 @@ test_dir_format()
if (pk2) crypto_free_pk_env(pk2);
if (rp1) routerinfo_free(rp1);
if (rp2) routerinfo_free(rp2);
- tor_free(dir1); /* And more !*/
+ tor_free(dir1); /* XXXX And more !*/
tor_free(dir2); /* And more !*/
/* make sure is_recommended_version() works */