test_dir.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2010, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #include "orconfig.h"
  6. #define DIRSERV_PRIVATE
  7. #define DIRVOTE_PRIVATE
  8. #define ROUTER_PRIVATE
  9. #include "or.h"
  10. #include "directory.h"
  11. #include "dirserv.h"
  12. #include "dirvote.h"
  13. #include "networkstatus.h"
  14. #include "router.h"
  15. #include "routerlist.h"
  16. #include "routerparse.h"
  17. #include "test.h"
  18. static void
  19. test_dir_nicknames(void)
  20. {
  21. test_assert( is_legal_nickname("a"));
  22. test_assert(!is_legal_nickname(""));
  23. test_assert(!is_legal_nickname("abcdefghijklmnopqrst")); /* 20 chars */
  24. test_assert(!is_legal_nickname("hyphen-")); /* bad char */
  25. test_assert( is_legal_nickname("abcdefghijklmnopqrs")); /* 19 chars */
  26. test_assert(!is_legal_nickname("$AAAAAAAA01234AAAAAAAAAAAAAAAAAAAAAAAAAAA"));
  27. /* valid */
  28. test_assert( is_legal_nickname_or_hexdigest(
  29. "$AAAAAAAA01234AAAAAAAAAAAAAAAAAAAAAAAAAAA"));
  30. test_assert( is_legal_nickname_or_hexdigest(
  31. "$AAAAAAAA01234AAAAAAAAAAAAAAAAAAAAAAAAAAA=fred"));
  32. test_assert( is_legal_nickname_or_hexdigest(
  33. "$AAAAAAAA01234AAAAAAAAAAAAAAAAAAAAAAAAAAA~fred"));
  34. /* too short */
  35. test_assert(!is_legal_nickname_or_hexdigest(
  36. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
  37. /* illegal char */
  38. test_assert(!is_legal_nickname_or_hexdigest(
  39. "$AAAAAAzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
  40. /* hex part too long */
  41. test_assert(!is_legal_nickname_or_hexdigest(
  42. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
  43. test_assert(!is_legal_nickname_or_hexdigest(
  44. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=fred"));
  45. /* Bad nickname */
  46. test_assert(!is_legal_nickname_or_hexdigest(
  47. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="));
  48. test_assert(!is_legal_nickname_or_hexdigest(
  49. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~"));
  50. test_assert(!is_legal_nickname_or_hexdigest(
  51. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~hyphen-"));
  52. test_assert(!is_legal_nickname_or_hexdigest(
  53. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA~"
  54. "abcdefghijklmnoppqrst"));
  55. /* Bad extra char. */
  56. test_assert(!is_legal_nickname_or_hexdigest(
  57. "$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"));
  58. test_assert(is_legal_nickname_or_hexdigest("xyzzy"));
  59. test_assert(is_legal_nickname_or_hexdigest("abcdefghijklmnopqrs"));
  60. test_assert(!is_legal_nickname_or_hexdigest("abcdefghijklmnopqrst"));
  61. done:
  62. ;
  63. }
  64. /** Run unit tests for router descriptor generation logic. */
  65. static void
  66. test_dir_formats(void)
  67. {
  68. char buf[8192], buf2[8192];
  69. char platform[256];
  70. char fingerprint[FINGERPRINT_LEN+1];
  71. char *pk1_str = NULL, *pk2_str = NULL, *pk3_str = NULL, *cp;
  72. size_t pk1_str_len, pk2_str_len, pk3_str_len;
  73. routerinfo_t *r1=NULL, *r2=NULL;
  74. crypto_pk_env_t *pk1 = NULL, *pk2 = NULL, *pk3 = NULL;
  75. routerinfo_t *rp1 = NULL;
  76. addr_policy_t *ex1, *ex2;
  77. routerlist_t *dir1 = NULL, *dir2 = NULL;
  78. pk1 = pk_generate(0);
  79. pk2 = pk_generate(1);
  80. pk3 = pk_generate(2);
  81. test_assert(pk1 && pk2 && pk3);
  82. get_platform_str(platform, sizeof(platform));
  83. r1 = tor_malloc_zero(sizeof(routerinfo_t));
  84. r1->address = tor_strdup("18.244.0.1");
  85. r1->addr = 0xc0a80001u; /* 192.168.0.1 */
  86. r1->cache_info.published_on = 0;
  87. r1->or_port = 9000;
  88. r1->dir_port = 9003;
  89. r1->onion_pkey = crypto_pk_dup_key(pk1);
  90. r1->identity_pkey = crypto_pk_dup_key(pk2);
  91. r1->bandwidthrate = 1000;
  92. r1->bandwidthburst = 5000;
  93. r1->bandwidthcapacity = 10000;
  94. r1->exit_policy = NULL;
  95. r1->nickname = tor_strdup("Magri");
  96. r1->platform = tor_strdup(platform);
  97. ex1 = tor_malloc_zero(sizeof(addr_policy_t));
  98. ex2 = tor_malloc_zero(sizeof(addr_policy_t));
  99. ex1->policy_type = ADDR_POLICY_ACCEPT;
  100. tor_addr_from_ipv4h(&ex1->addr, 0);
  101. ex1->maskbits = 0;
  102. ex1->prt_min = ex1->prt_max = 80;
  103. ex2->policy_type = ADDR_POLICY_REJECT;
  104. tor_addr_from_ipv4h(&ex2->addr, 18<<24);
  105. ex2->maskbits = 8;
  106. ex2->prt_min = ex2->prt_max = 24;
  107. r2 = tor_malloc_zero(sizeof(routerinfo_t));
  108. r2->address = tor_strdup("1.1.1.1");
  109. r2->addr = 0x0a030201u; /* 10.3.2.1 */
  110. r2->platform = tor_strdup(platform);
  111. r2->cache_info.published_on = 5;
  112. r2->or_port = 9005;
  113. r2->dir_port = 0;
  114. r2->onion_pkey = crypto_pk_dup_key(pk2);
  115. r2->identity_pkey = crypto_pk_dup_key(pk1);
  116. r2->bandwidthrate = r2->bandwidthburst = r2->bandwidthcapacity = 3000;
  117. r2->exit_policy = smartlist_create();
  118. smartlist_add(r2->exit_policy, ex2);
  119. smartlist_add(r2->exit_policy, ex1);
  120. r2->nickname = tor_strdup("Fred");
  121. test_assert(!crypto_pk_write_public_key_to_string(pk1, &pk1_str,
  122. &pk1_str_len));
  123. test_assert(!crypto_pk_write_public_key_to_string(pk2 , &pk2_str,
  124. &pk2_str_len));
  125. test_assert(!crypto_pk_write_public_key_to_string(pk3 , &pk3_str,
  126. &pk3_str_len));
  127. memset(buf, 0, 2048);
  128. test_assert(router_dump_router_to_string(buf, 2048, r1, pk2)>0);
  129. strlcpy(buf2, "router Magri 18.244.0.1 9000 0 9003\n"
  130. "platform Tor "VERSION" on ", sizeof(buf2));
  131. strlcat(buf2, get_uname(), sizeof(buf2));
  132. strlcat(buf2, "\n"
  133. "opt protocols Link 1 2 Circuit 1\n"
  134. "published 1970-01-01 00:00:00\n"
  135. "opt fingerprint ", sizeof(buf2));
  136. test_assert(!crypto_pk_get_fingerprint(pk2, fingerprint, 1));
  137. strlcat(buf2, fingerprint, sizeof(buf2));
  138. strlcat(buf2, "\nuptime 0\n"
  139. /* XXX the "0" above is hard-coded, but even if we made it reflect
  140. * uptime, that still wouldn't make it right, because the two
  141. * descriptors might be made on different seconds... hm. */
  142. "bandwidth 1000 5000 10000\n"
  143. "onion-key\n", sizeof(buf2));
  144. strlcat(buf2, pk1_str, sizeof(buf2));
  145. strlcat(buf2, "signing-key\n", sizeof(buf2));
  146. strlcat(buf2, pk2_str, sizeof(buf2));
  147. strlcat(buf2, "opt hidden-service-dir\n", sizeof(buf2));
  148. strlcat(buf2, "reject *:*\nrouter-signature\n", sizeof(buf2));
  149. buf[strlen(buf2)] = '\0'; /* Don't compare the sig; it's never the same
  150. * twice */
  151. test_streq(buf, buf2);
  152. test_assert(router_dump_router_to_string(buf, 2048, r1, pk2)>0);
  153. cp = buf;
  154. rp1 = router_parse_entry_from_string((const char*)cp,NULL,1,0,NULL);
  155. test_assert(rp1);
  156. test_streq(rp1->address, r1->address);
  157. test_eq(rp1->or_port, r1->or_port);
  158. //test_eq(rp1->dir_port, r1->dir_port);
  159. test_eq(rp1->bandwidthrate, r1->bandwidthrate);
  160. test_eq(rp1->bandwidthburst, r1->bandwidthburst);
  161. test_eq(rp1->bandwidthcapacity, r1->bandwidthcapacity);
  162. test_assert(crypto_pk_cmp_keys(rp1->onion_pkey, pk1) == 0);
  163. test_assert(crypto_pk_cmp_keys(rp1->identity_pkey, pk2) == 0);
  164. //test_assert(rp1->exit_policy == NULL);
  165. #if 0
  166. /* XXX Once we have exit policies, test this again. XXX */
  167. strlcpy(buf2, "router tor.tor.tor 9005 0 0 3000\n", sizeof(buf2));
  168. strlcat(buf2, pk2_str, sizeof(buf2));
  169. strlcat(buf2, "signing-key\n", sizeof(buf2));
  170. strlcat(buf2, pk1_str, sizeof(buf2));
  171. strlcat(buf2, "accept *:80\nreject 18.*:24\n\n", sizeof(buf2));
  172. test_assert(router_dump_router_to_string(buf, 2048, &r2, pk2)>0);
  173. test_streq(buf, buf2);
  174. cp = buf;
  175. rp2 = router_parse_entry_from_string(&cp,1);
  176. test_assert(rp2);
  177. test_streq(rp2->address, r2.address);
  178. test_eq(rp2->or_port, r2.or_port);
  179. test_eq(rp2->dir_port, r2.dir_port);
  180. test_eq(rp2->bandwidth, r2.bandwidth);
  181. test_assert(crypto_pk_cmp_keys(rp2->onion_pkey, pk2) == 0);
  182. test_assert(crypto_pk_cmp_keys(rp2->identity_pkey, pk1) == 0);
  183. test_eq(rp2->exit_policy->policy_type, EXIT_POLICY_ACCEPT);
  184. test_streq(rp2->exit_policy->string, "accept *:80");
  185. test_streq(rp2->exit_policy->address, "*");
  186. test_streq(rp2->exit_policy->port, "80");
  187. test_eq(rp2->exit_policy->next->policy_type, EXIT_POLICY_REJECT);
  188. test_streq(rp2->exit_policy->next->string, "reject 18.*:24");
  189. test_streq(rp2->exit_policy->next->address, "18.*");
  190. test_streq(rp2->exit_policy->next->port, "24");
  191. test_assert(rp2->exit_policy->next->next == NULL);
  192. /* Okay, now for the directories. */
  193. {
  194. fingerprint_list = smartlist_create();
  195. crypto_pk_get_fingerprint(pk2, buf, 1);
  196. add_fingerprint_to_dir("Magri", buf, fingerprint_list);
  197. crypto_pk_get_fingerprint(pk1, buf, 1);
  198. add_fingerprint_to_dir("Fred", buf, fingerprint_list);
  199. }
  200. {
  201. char d[DIGEST_LEN];
  202. const char *m;
  203. /* XXXX NM re-enable. */
  204. /* Make sure routers aren't too far in the past any more. */
  205. r1->cache_info.published_on = time(NULL);
  206. r2->cache_info.published_on = time(NULL)-3*60*60;
  207. test_assert(router_dump_router_to_string(buf, 2048, r1, pk2)>0);
  208. test_eq(dirserv_add_descriptor(buf,&m,""), ROUTER_ADDED_NOTIFY_GENERATOR);
  209. test_assert(router_dump_router_to_string(buf, 2048, r2, pk1)>0);
  210. test_eq(dirserv_add_descriptor(buf,&m,""), ROUTER_ADDED_NOTIFY_GENERATOR);
  211. get_options()->Nickname = tor_strdup("DirServer");
  212. test_assert(!dirserv_dump_directory_to_string(&cp,pk3, 0));
  213. crypto_pk_get_digest(pk3, d);
  214. test_assert(!router_parse_directory(cp));
  215. test_eq(2, smartlist_len(dir1->routers));
  216. tor_free(cp);
  217. }
  218. #endif
  219. dirserv_free_fingerprint_list();
  220. done:
  221. if (r1)
  222. routerinfo_free(r1);
  223. if (r2)
  224. routerinfo_free(r2);
  225. tor_free(pk1_str);
  226. tor_free(pk2_str);
  227. tor_free(pk3_str);
  228. if (pk1) crypto_free_pk_env(pk1);
  229. if (pk2) crypto_free_pk_env(pk2);
  230. if (pk3) crypto_free_pk_env(pk3);
  231. if (rp1) routerinfo_free(rp1);
  232. tor_free(dir1); /* XXXX And more !*/
  233. tor_free(dir2); /* And more !*/
  234. }
  235. static void
  236. test_dir_versions(void)
  237. {
  238. tor_version_t ver1;
  239. /* Try out version parsing functionality */
  240. test_eq(0, tor_version_parse("0.3.4pre2-cvs", &ver1));
  241. test_eq(0, ver1.major);
  242. test_eq(3, ver1.minor);
  243. test_eq(4, ver1.micro);
  244. test_eq(VER_PRE, ver1.status);
  245. test_eq(2, ver1.patchlevel);
  246. test_eq(0, tor_version_parse("0.3.4rc1", &ver1));
  247. test_eq(0, ver1.major);
  248. test_eq(3, ver1.minor);
  249. test_eq(4, ver1.micro);
  250. test_eq(VER_RC, ver1.status);
  251. test_eq(1, ver1.patchlevel);
  252. test_eq(0, tor_version_parse("1.3.4", &ver1));
  253. test_eq(1, ver1.major);
  254. test_eq(3, ver1.minor);
  255. test_eq(4, ver1.micro);
  256. test_eq(VER_RELEASE, ver1.status);
  257. test_eq(0, ver1.patchlevel);
  258. test_eq(0, tor_version_parse("1.3.4.999", &ver1));
  259. test_eq(1, ver1.major);
  260. test_eq(3, ver1.minor);
  261. test_eq(4, ver1.micro);
  262. test_eq(VER_RELEASE, ver1.status);
  263. test_eq(999, ver1.patchlevel);
  264. test_eq(0, tor_version_parse("0.1.2.4-alpha", &ver1));
  265. test_eq(0, ver1.major);
  266. test_eq(1, ver1.minor);
  267. test_eq(2, ver1.micro);
  268. test_eq(4, ver1.patchlevel);
  269. test_eq(VER_RELEASE, ver1.status);
  270. test_streq("alpha", ver1.status_tag);
  271. test_eq(0, tor_version_parse("0.1.2.4", &ver1));
  272. test_eq(0, ver1.major);
  273. test_eq(1, ver1.minor);
  274. test_eq(2, ver1.micro);
  275. test_eq(4, ver1.patchlevel);
  276. test_eq(VER_RELEASE, ver1.status);
  277. test_streq("", ver1.status_tag);
  278. #define tt_versionstatus_op(vs1, op, vs2) \
  279. tt_assert_test_type(vs1,vs2,#vs1" "#op" "#vs2,version_status_t, \
  280. (_val1 op _val2),"%d")
  281. #define test_v_i_o(val, ver, lst) \
  282. tt_versionstatus_op(val, ==, tor_version_is_obsolete(ver, lst))
  283. /* make sure tor_version_is_obsolete() works */
  284. test_v_i_o(VS_OLD, "0.0.1", "Tor 0.0.2");
  285. test_v_i_o(VS_OLD, "0.0.1", "0.0.2, Tor 0.0.3");
  286. test_v_i_o(VS_OLD, "0.0.1", "0.0.2,Tor 0.0.3");
  287. test_v_i_o(VS_OLD, "0.0.1","0.0.3,BetterTor 0.0.1");
  288. test_v_i_o(VS_RECOMMENDED, "0.0.2", "Tor 0.0.2,Tor 0.0.3");
  289. test_v_i_o(VS_NEW_IN_SERIES, "0.0.2", "Tor 0.0.2pre1,Tor 0.0.3");
  290. test_v_i_o(VS_OLD, "0.0.2", "Tor 0.0.2.1,Tor 0.0.3");
  291. test_v_i_o(VS_NEW, "0.1.0", "Tor 0.0.2,Tor 0.0.3");
  292. test_v_i_o(VS_RECOMMENDED, "0.0.7rc2", "0.0.7,Tor 0.0.7rc2,Tor 0.0.8");
  293. test_v_i_o(VS_OLD, "0.0.5.0", "0.0.5.1-cvs");
  294. test_v_i_o(VS_NEW_IN_SERIES, "0.0.5.1-cvs", "0.0.5, 0.0.6");
  295. /* Not on list, but newer than any in same series. */
  296. test_v_i_o(VS_NEW_IN_SERIES, "0.1.0.3",
  297. "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0");
  298. /* Series newer than any on list. */
  299. test_v_i_o(VS_NEW, "0.1.2.3", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0");
  300. /* Series older than any on list. */
  301. test_v_i_o(VS_OLD, "0.0.1.3", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0");
  302. /* Not on list, not newer than any on same series. */
  303. test_v_i_o(VS_UNRECOMMENDED, "0.1.0.1",
  304. "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0");
  305. /* On list, not newer than any on same series. */
  306. test_v_i_o(VS_UNRECOMMENDED,
  307. "0.1.0.1", "Tor 0.1.0.2,Tor 0.0.9.5,Tor 0.1.1.0");
  308. test_eq(0, tor_version_as_new_as("Tor 0.0.5", "0.0.9pre1-cvs"));
  309. test_eq(1, tor_version_as_new_as(
  310. "Tor 0.0.8 on Darwin 64-121-192-100.c3-0."
  311. "sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh",
  312. "0.0.8rc2"));
  313. test_eq(0, tor_version_as_new_as(
  314. "Tor 0.0.8 on Darwin 64-121-192-100.c3-0."
  315. "sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8.2"));
  316. /* Now try svn revisions. */
  317. test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
  318. "Tor 0.2.1.0-dev (r99)"));
  319. test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100) on Banana Jr",
  320. "Tor 0.2.1.0-dev (r99) on Hal 9000"));
  321. test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
  322. "Tor 0.2.1.0-dev on Colossus"));
  323. test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99)",
  324. "Tor 0.2.1.0-dev (r100)"));
  325. test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99) on MCP",
  326. "Tor 0.2.1.0-dev (r100) on AM"));
  327. test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev",
  328. "Tor 0.2.1.0-dev (r99)"));
  329. test_eq(1, tor_version_as_new_as("Tor 0.2.1.1",
  330. "Tor 0.2.1.0-dev (r99)"));
  331. /* Now try git revisions */
  332. test_eq(0, tor_version_parse("0.5.6.7 (git-ff00ff)", &ver1));
  333. test_eq(0, ver1.major);
  334. test_eq(5, ver1.minor);
  335. test_eq(6, ver1.micro);
  336. test_eq(7, ver1.patchlevel);
  337. test_eq(3, ver1.git_tag_len);
  338. test_memeq(ver1.git_tag, "\xff\x00\xff", 3);
  339. test_eq(-1, tor_version_parse("0.5.6.7 (git-ff00xx)", &ver1));
  340. test_eq(-1, tor_version_parse("0.5.6.7 (git-ff00fff)", &ver1));
  341. test_eq(0, tor_version_parse("0.5.6.7 (git ff00fff)", &ver1));
  342. done:
  343. ;
  344. }
  345. /** Run unit tests for directory fp_pair functions. */
  346. static void
  347. test_dir_fp_pairs(void)
  348. {
  349. smartlist_t *sl = smartlist_create();
  350. fp_pair_t *pair;
  351. dir_split_resource_into_fingerprint_pairs(
  352. /* Two pairs, out of order, with one duplicate. */
  353. "73656372657420646174612E0000000000FFFFFF-"
  354. "557365204145532d32353620696e73746561642e+"
  355. "73656372657420646174612E0000000000FFFFFF-"
  356. "557365204145532d32353620696e73746561642e+"
  357. "48657861646563696d616c2069736e277420736f-"
  358. "676f6f6420666f7220686964696e6720796f7572.z", sl);
  359. test_eq(smartlist_len(sl), 2);
  360. pair = smartlist_get(sl, 0);
  361. test_memeq(pair->first, "Hexadecimal isn't so", DIGEST_LEN);
  362. test_memeq(pair->second, "good for hiding your", DIGEST_LEN);
  363. pair = smartlist_get(sl, 1);
  364. test_memeq(pair->first, "secret data.\0\0\0\0\0\xff\xff\xff", DIGEST_LEN);
  365. test_memeq(pair->second, "Use AES-256 instead.", DIGEST_LEN);
  366. done:
  367. SMARTLIST_FOREACH(sl, fp_pair_t *, pair, tor_free(pair));
  368. smartlist_free(sl);
  369. }
  370. static void
  371. test_dir_split_fps(void *testdata)
  372. {
  373. smartlist_t *sl = smartlist_create();
  374. char *mem_op_hex_tmp = NULL;
  375. (void)testdata;
  376. /* Some example hex fingerprints and their base64 equivalents */
  377. #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
  378. #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
  379. #define HEX3 "b33ff00db33ff00db33ff00db33ff00db33ff00d"
  380. #define HEX256_1 \
  381. "f3f3f3f3fbbbbf3f3f3f3fbbbf3f3f3f3fbbbbf3f3f3f3fbbbf3f3f3f3fbbbbf"
  382. #define HEX256_2 \
  383. "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccCCc"
  384. #define HEX256_3 \
  385. "0123456789ABCdef0123456789ABCdef0123456789ABCdef0123456789ABCdef"
  386. #define B64_1 "/g2v+JEnOJvGdVhpEjEjRVEZPu4"
  387. #define B64_2 "3q2+75mZmZERERmZmRERERHwC6Q"
  388. #define B64_3 "sz/wDbM/8A2zP/ANsz/wDbM/8A0"
  389. #define B64_256_1 "8/Pz8/u7vz8/Pz+7vz8/Pz+7u/Pz8/P7u/Pz8/P7u78"
  390. #define B64_256_2 "zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMw"
  391. #define B64_256_3 "ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8"
  392. /* no flags set */
  393. dir_split_resource_into_fingerprints("A+C+B", sl, NULL, 0);
  394. tt_int_op(smartlist_len(sl), ==, 3);
  395. tt_str_op(smartlist_get(sl, 0), ==, "A");
  396. tt_str_op(smartlist_get(sl, 1), ==, "C");
  397. tt_str_op(smartlist_get(sl, 2), ==, "B");
  398. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  399. smartlist_clear(sl);
  400. /* uniq strings. */
  401. dir_split_resource_into_fingerprints("A+C+B+A+B+B", sl, NULL, DSR_SORT_UNIQ);
  402. tt_int_op(smartlist_len(sl), ==, 3);
  403. tt_str_op(smartlist_get(sl, 0), ==, "A");
  404. tt_str_op(smartlist_get(sl, 1), ==, "B");
  405. tt_str_op(smartlist_get(sl, 2), ==, "C");
  406. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  407. smartlist_clear(sl);
  408. /* Decode hex. */
  409. dir_split_resource_into_fingerprints(HEX1"+"HEX2, sl, NULL, DSR_HEX);
  410. tt_int_op(smartlist_len(sl), ==, 2);
  411. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX1);
  412. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX2);
  413. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  414. smartlist_clear(sl);
  415. /* decode hex and drop weirdness. */
  416. dir_split_resource_into_fingerprints(HEX1"+bogus+"HEX2"+"HEX256_1,
  417. sl, NULL, DSR_HEX);
  418. tt_int_op(smartlist_len(sl), ==, 2);
  419. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX1);
  420. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX2);
  421. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  422. smartlist_clear(sl);
  423. /* Decode long hex */
  424. dir_split_resource_into_fingerprints(HEX256_1"+"HEX256_2"+"HEX2"+"HEX256_3,
  425. sl, NULL, DSR_HEX|DSR_DIGEST256);
  426. tt_int_op(smartlist_len(sl), ==, 3);
  427. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX256_1);
  428. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX256_2);
  429. test_mem_op_hex(smartlist_get(sl, 2), ==, HEX256_3);
  430. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  431. smartlist_clear(sl);
  432. /* Decode hex and sort. */
  433. dir_split_resource_into_fingerprints(HEX1"+"HEX2"+"HEX3"+"HEX2,
  434. sl, NULL, DSR_HEX|DSR_SORT_UNIQ);
  435. tt_int_op(smartlist_len(sl), ==, 3);
  436. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX3);
  437. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX2);
  438. test_mem_op_hex(smartlist_get(sl, 2), ==, HEX1);
  439. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  440. smartlist_clear(sl);
  441. /* Decode long hex and sort */
  442. dir_split_resource_into_fingerprints(HEX256_1"+"HEX256_2"+"HEX256_3
  443. "+"HEX256_1,
  444. sl, NULL,
  445. DSR_HEX|DSR_DIGEST256|DSR_SORT_UNIQ);
  446. tt_int_op(smartlist_len(sl), ==, 3);
  447. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX256_3);
  448. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX256_2);
  449. test_mem_op_hex(smartlist_get(sl, 2), ==, HEX256_1);
  450. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  451. smartlist_clear(sl);
  452. /* Decode base64 */
  453. dir_split_resource_into_fingerprints(B64_1"-"B64_2, sl, NULL, DSR_BASE64);
  454. tt_int_op(smartlist_len(sl), ==, 2);
  455. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX1);
  456. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX2);
  457. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  458. smartlist_clear(sl);
  459. /* Decode long base64 */
  460. dir_split_resource_into_fingerprints(B64_256_1"-"B64_256_2,
  461. sl, NULL, DSR_BASE64|DSR_DIGEST256);
  462. tt_int_op(smartlist_len(sl), ==, 2);
  463. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX256_1);
  464. test_mem_op_hex(smartlist_get(sl, 1), ==, HEX256_2);
  465. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  466. smartlist_clear(sl);
  467. dir_split_resource_into_fingerprints(B64_256_1,
  468. sl, NULL, DSR_BASE64|DSR_DIGEST256);
  469. tt_int_op(smartlist_len(sl), ==, 1);
  470. test_mem_op_hex(smartlist_get(sl, 0), ==, HEX256_1);
  471. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  472. smartlist_clear(sl);
  473. done:
  474. SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
  475. smartlist_free(sl);
  476. tor_free(mem_op_hex_tmp);
  477. }
  478. static void
  479. test_dir_measured_bw(void)
  480. {
  481. measured_bw_line_t mbwl;
  482. int i;
  483. const char *lines_pass[] = {
  484. "node_id=$557365204145532d32353620696e73746561642e bw=1024\n",
  485. "node_id=$557365204145532d32353620696e73746561642e\t bw=1024 \n",
  486. " node_id=$557365204145532d32353620696e73746561642e bw=1024\n",
  487. "\tnoise\tnode_id=$557365204145532d32353620696e73746561642e "
  488. "bw=1024 junk=007\n",
  489. "misc=junk node_id=$557365204145532d32353620696e73746561642e "
  490. "bw=1024 junk=007\n",
  491. "end"
  492. };
  493. const char *lines_fail[] = {
  494. /* Test possible python stupidity on input */
  495. "node_id=None bw=1024\n",
  496. "node_id=$None bw=1024\n",
  497. "node_id=$557365204145532d32353620696e73746561642e bw=None\n",
  498. "node_id=$557365204145532d32353620696e73746561642e bw=1024.0\n",
  499. "node_id=$557365204145532d32353620696e73746561642e bw=.1024\n",
  500. "node_id=$557365204145532d32353620696e73746561642e bw=1.024\n",
  501. "node_id=$557365204145532d32353620696e73746561642e bw=1024 bw=0\n",
  502. "node_id=$557365204145532d32353620696e73746561642e bw=1024 bw=None\n",
  503. "node_id=$557365204145532d32353620696e73746561642e bw=-1024\n",
  504. /* Test incomplete writes due to race conditions, partial copies, etc */
  505. "node_i",
  506. "node_i\n",
  507. "node_id=",
  508. "node_id=\n",
  509. "node_id=$557365204145532d32353620696e73746561642e bw=",
  510. "node_id=$557365204145532d32353620696e73746561642e bw=1024",
  511. "node_id=$557365204145532d32353620696e73746561642e bw=\n",
  512. "node_id=$557365204145532d32353620696e7374",
  513. "node_id=$557365204145532d32353620696e7374\n",
  514. "",
  515. "\n",
  516. " \n ",
  517. " \n\n",
  518. /* Test assorted noise */
  519. " node_id= ",
  520. "node_id==$557365204145532d32353620696e73746561642e bw==1024\n",
  521. "node_id=$55736520414552d32353620696e73746561642e bw=1024\n",
  522. "node_id=557365204145532d32353620696e73746561642e bw=1024\n",
  523. "node_id= $557365204145532d32353620696e73746561642e bw=0.23\n",
  524. "end"
  525. };
  526. for (i = 0; strcmp(lines_fail[i], "end"); i++) {
  527. //fprintf(stderr, "Testing: %s\n", lines_fail[i]);
  528. test_assert(measured_bw_line_parse(&mbwl, lines_fail[i]) == -1);
  529. }
  530. for (i = 0; strcmp(lines_pass[i], "end"); i++) {
  531. //fprintf(stderr, "Testing: %s %d\n", lines_pass[i], TOR_ISSPACE('\n'));
  532. test_assert(measured_bw_line_parse(&mbwl, lines_pass[i]) == 0);
  533. test_assert(mbwl.bw == 1024);
  534. test_assert(strcmp(mbwl.node_hex,
  535. "557365204145532d32353620696e73746561642e") == 0);
  536. }
  537. done:
  538. return;
  539. }
  540. static void
  541. test_dir_param_voting(void)
  542. {
  543. networkstatus_t vote1, vote2, vote3, vote4;
  544. smartlist_t *votes = smartlist_create();
  545. char *res = NULL;
  546. /* dirvote_compute_params only looks at the net_params field of the votes,
  547. so that's all we need to set.
  548. */
  549. memset(&vote1, 0, sizeof(vote1));
  550. memset(&vote2, 0, sizeof(vote2));
  551. memset(&vote3, 0, sizeof(vote3));
  552. memset(&vote4, 0, sizeof(vote4));
  553. vote1.net_params = smartlist_create();
  554. vote2.net_params = smartlist_create();
  555. vote3.net_params = smartlist_create();
  556. vote4.net_params = smartlist_create();
  557. smartlist_split_string(vote1.net_params,
  558. "ab=90 abcd=20 cw=50 x-yz=-99", NULL, 0, 0);
  559. smartlist_split_string(vote2.net_params,
  560. "ab=27 cw=5 x-yz=88", NULL, 0, 0);
  561. smartlist_split_string(vote3.net_params,
  562. "abcd=20 c=60 cw=500 x-yz=-9 zzzzz=101", NULL, 0, 0);
  563. smartlist_split_string(vote4.net_params,
  564. "ab=900 abcd=200 c=1 cw=51 x-yz=100", NULL, 0, 0);
  565. test_eq(100, networkstatus_get_param(&vote4, "x-yz", 50));
  566. test_eq(222, networkstatus_get_param(&vote4, "foobar", 222));
  567. smartlist_add(votes, &vote1);
  568. smartlist_add(votes, &vote2);
  569. smartlist_add(votes, &vote3);
  570. smartlist_add(votes, &vote4);
  571. res = dirvote_compute_params(votes);
  572. test_streq(res,
  573. "ab=90 abcd=20 c=1 cw=50 x-yz=-9 zzzzz=101");
  574. done:
  575. tor_free(res);
  576. SMARTLIST_FOREACH(vote1.net_params, char *, cp, tor_free(cp));
  577. SMARTLIST_FOREACH(vote2.net_params, char *, cp, tor_free(cp));
  578. SMARTLIST_FOREACH(vote3.net_params, char *, cp, tor_free(cp));
  579. SMARTLIST_FOREACH(vote4.net_params, char *, cp, tor_free(cp));
  580. smartlist_free(vote1.net_params);
  581. smartlist_free(vote2.net_params);
  582. smartlist_free(vote3.net_params);
  583. smartlist_free(vote4.net_params);
  584. smartlist_free(votes);
  585. return;
  586. }
  587. extern const char AUTHORITY_CERT_1[];
  588. extern const char AUTHORITY_SIGNKEY_1[];
  589. extern const char AUTHORITY_CERT_2[];
  590. extern const char AUTHORITY_SIGNKEY_2[];
  591. extern const char AUTHORITY_CERT_3[];
  592. extern const char AUTHORITY_SIGNKEY_3[];
  593. /** Helper: Test that two networkstatus_voter_info_t do in fact represent the
  594. * same voting authority, and that they do in fact have all the same
  595. * information. */
  596. static void
  597. test_same_voter(networkstatus_voter_info_t *v1,
  598. networkstatus_voter_info_t *v2)
  599. {
  600. test_streq(v1->nickname, v2->nickname);
  601. test_memeq(v1->identity_digest, v2->identity_digest, DIGEST_LEN);
  602. test_streq(v1->address, v2->address);
  603. test_eq(v1->addr, v2->addr);
  604. test_eq(v1->dir_port, v2->dir_port);
  605. test_eq(v1->or_port, v2->or_port);
  606. test_streq(v1->contact, v2->contact);
  607. test_memeq(v1->vote_digest, v2->vote_digest, DIGEST_LEN);
  608. done:
  609. ;
  610. }
  611. /** Helper: Make a new routerinfo containing the right information for a
  612. * given vote_routerstatus_t. */
  613. static routerinfo_t *
  614. generate_ri_from_rs(const vote_routerstatus_t *vrs)
  615. {
  616. routerinfo_t *r;
  617. const routerstatus_t *rs = &vrs->status;
  618. static time_t published = 0;
  619. r = tor_malloc_zero(sizeof(routerinfo_t));
  620. memcpy(r->cache_info.identity_digest, rs->identity_digest, DIGEST_LEN);
  621. memcpy(r->cache_info.signed_descriptor_digest, rs->descriptor_digest,
  622. DIGEST_LEN);
  623. r->cache_info.do_not_cache = 1;
  624. r->cache_info.routerlist_index = -1;
  625. r->cache_info.signed_descriptor_body =
  626. tor_strdup("123456789012345678901234567890123");
  627. r->cache_info.signed_descriptor_len =
  628. strlen(r->cache_info.signed_descriptor_body);
  629. r->exit_policy = smartlist_create();
  630. r->cache_info.published_on = ++published + time(NULL);
  631. return r;
  632. }
  633. /** Helper: get a detached signatures document for one or two
  634. * consensuses. */
  635. static char *
  636. get_detached_sigs(networkstatus_t *ns, networkstatus_t *ns2)
  637. {
  638. char *r;
  639. smartlist_t *sl;
  640. tor_assert(ns && ns->flavor == FLAV_NS);
  641. sl = smartlist_create();
  642. smartlist_add(sl,ns);
  643. if (ns2)
  644. smartlist_add(sl,ns2);
  645. r = networkstatus_get_detached_signatures(sl);
  646. smartlist_free(sl);
  647. return r;
  648. }
  649. /** Run unit tests for generating and parsing V3 consensus networkstatus
  650. * documents. */
  651. static void
  652. test_dir_v3_networkstatus(void)
  653. {
  654. authority_cert_t *cert1=NULL, *cert2=NULL, *cert3=NULL;
  655. crypto_pk_env_t *sign_skey_1=NULL, *sign_skey_2=NULL, *sign_skey_3=NULL;
  656. crypto_pk_env_t *sign_skey_leg1=NULL;
  657. const char *msg=NULL;
  658. time_t now = time(NULL);
  659. networkstatus_voter_info_t *voter;
  660. document_signature_t *sig;
  661. networkstatus_t *vote=NULL, *v1=NULL, *v2=NULL, *v3=NULL, *con=NULL,
  662. *con_md=NULL;
  663. vote_routerstatus_t *vrs;
  664. routerstatus_t *rs;
  665. char *v1_text=NULL, *v2_text=NULL, *v3_text=NULL, *consensus_text=NULL, *cp;
  666. smartlist_t *votes = smartlist_create();
  667. /* For generating the two other consensuses. */
  668. char *detached_text1=NULL, *detached_text2=NULL;
  669. char *consensus_text2=NULL, *consensus_text3=NULL;
  670. char *consensus_text_md2=NULL, *consensus_text_md3=NULL;
  671. char *consensus_text_md=NULL;
  672. networkstatus_t *con2=NULL, *con_md2=NULL, *con3=NULL, *con_md3=NULL;
  673. ns_detached_signatures_t *dsig1=NULL, *dsig2=NULL;
  674. /* Parse certificates and keys. */
  675. cert1 = authority_cert_parse_from_string(AUTHORITY_CERT_1, NULL);
  676. test_assert(cert1);
  677. test_assert(cert1->is_cross_certified);
  678. cert2 = authority_cert_parse_from_string(AUTHORITY_CERT_2, NULL);
  679. test_assert(cert2);
  680. cert3 = authority_cert_parse_from_string(AUTHORITY_CERT_3, NULL);
  681. test_assert(cert3);
  682. sign_skey_1 = crypto_new_pk_env();
  683. sign_skey_2 = crypto_new_pk_env();
  684. sign_skey_3 = crypto_new_pk_env();
  685. sign_skey_leg1 = pk_generate(4);
  686. test_assert(!crypto_pk_read_private_key_from_string(sign_skey_1,
  687. AUTHORITY_SIGNKEY_1));
  688. test_assert(!crypto_pk_read_private_key_from_string(sign_skey_2,
  689. AUTHORITY_SIGNKEY_2));
  690. test_assert(!crypto_pk_read_private_key_from_string(sign_skey_3,
  691. AUTHORITY_SIGNKEY_3));
  692. test_assert(!crypto_pk_cmp_keys(sign_skey_1, cert1->signing_key));
  693. test_assert(!crypto_pk_cmp_keys(sign_skey_2, cert2->signing_key));
  694. /*
  695. * Set up a vote; generate it; try to parse it.
  696. */
  697. vote = tor_malloc_zero(sizeof(networkstatus_t));
  698. vote->type = NS_TYPE_VOTE;
  699. vote->published = now;
  700. vote->valid_after = now+1000;
  701. vote->fresh_until = now+2000;
  702. vote->valid_until = now+3000;
  703. vote->vote_seconds = 100;
  704. vote->dist_seconds = 200;
  705. vote->supported_methods = smartlist_create();
  706. smartlist_split_string(vote->supported_methods, "1 2 3", NULL, 0, -1);
  707. vote->client_versions = tor_strdup("0.1.2.14,0.1.2.15");
  708. vote->server_versions = tor_strdup("0.1.2.14,0.1.2.15,0.1.2.16");
  709. vote->known_flags = smartlist_create();
  710. smartlist_split_string(vote->known_flags,
  711. "Authority Exit Fast Guard Running Stable V2Dir Valid",
  712. 0, SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
  713. vote->voters = smartlist_create();
  714. voter = tor_malloc_zero(sizeof(networkstatus_voter_info_t));
  715. voter->nickname = tor_strdup("Voter1");
  716. voter->address = tor_strdup("1.2.3.4");
  717. voter->addr = 0x01020304;
  718. voter->dir_port = 80;
  719. voter->or_port = 9000;
  720. voter->contact = tor_strdup("voter@example.com");
  721. crypto_pk_get_digest(cert1->identity_key, voter->identity_digest);
  722. smartlist_add(vote->voters, voter);
  723. vote->cert = authority_cert_dup(cert1);
  724. vote->net_params = smartlist_create();
  725. smartlist_split_string(vote->net_params, "circuitwindow=101 foo=990",
  726. NULL, 0, 0);
  727. vote->routerstatus_list = smartlist_create();
  728. /* add the first routerstatus. */
  729. vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
  730. rs = &vrs->status;
  731. vrs->version = tor_strdup("0.1.2.14");
  732. rs->published_on = now-1500;
  733. strlcpy(rs->nickname, "router2", sizeof(rs->nickname));
  734. memset(rs->identity_digest, 3, DIGEST_LEN);
  735. memset(rs->descriptor_digest, 78, DIGEST_LEN);
  736. rs->addr = 0x99008801;
  737. rs->or_port = 443;
  738. rs->dir_port = 8000;
  739. /* all flags but running cleared */
  740. rs->is_running = 1;
  741. smartlist_add(vote->routerstatus_list, vrs);
  742. test_assert(router_add_to_routerlist(generate_ri_from_rs(vrs), &msg,0,0)>=0);
  743. /* add the second routerstatus. */
  744. vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
  745. rs = &vrs->status;
  746. vrs->version = tor_strdup("0.2.0.5");
  747. rs->published_on = now-1000;
  748. strlcpy(rs->nickname, "router1", sizeof(rs->nickname));
  749. memset(rs->identity_digest, 5, DIGEST_LEN);
  750. memset(rs->descriptor_digest, 77, DIGEST_LEN);
  751. rs->addr = 0x99009901;
  752. rs->or_port = 443;
  753. rs->dir_port = 0;
  754. rs->is_exit = rs->is_stable = rs->is_fast = rs->is_running =
  755. rs->is_valid = rs->is_v2_dir = rs->is_possible_guard = 1;
  756. smartlist_add(vote->routerstatus_list, vrs);
  757. test_assert(router_add_to_routerlist(generate_ri_from_rs(vrs), &msg,0,0)>=0);
  758. /* add the third routerstatus. */
  759. vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
  760. rs = &vrs->status;
  761. vrs->version = tor_strdup("0.1.0.3");
  762. rs->published_on = now-1000;
  763. strlcpy(rs->nickname, "router3", sizeof(rs->nickname));
  764. memset(rs->identity_digest, 33, DIGEST_LEN);
  765. memset(rs->descriptor_digest, 79, DIGEST_LEN);
  766. rs->addr = 0xAA009901;
  767. rs->or_port = 400;
  768. rs->dir_port = 9999;
  769. rs->is_authority = rs->is_exit = rs->is_stable = rs->is_fast =
  770. rs->is_running = rs->is_valid = rs->is_v2_dir = rs->is_possible_guard = 1;
  771. smartlist_add(vote->routerstatus_list, vrs);
  772. test_assert(router_add_to_routerlist(generate_ri_from_rs(vrs), &msg,0,0)>=0);
  773. /* add a fourth routerstatus that is not running. */
  774. vrs = tor_malloc_zero(sizeof(vote_routerstatus_t));
  775. rs = &vrs->status;
  776. vrs->version = tor_strdup("0.1.6.3");
  777. rs->published_on = now-1000;
  778. strlcpy(rs->nickname, "router4", sizeof(rs->nickname));
  779. memset(rs->identity_digest, 34, DIGEST_LEN);
  780. memset(rs->descriptor_digest, 47, DIGEST_LEN);
  781. rs->addr = 0xC0000203;
  782. rs->or_port = 500;
  783. rs->dir_port = 1999;
  784. /* Running flag (and others) cleared */
  785. smartlist_add(vote->routerstatus_list, vrs);
  786. test_assert(router_add_to_routerlist(generate_ri_from_rs(vrs), &msg,0,0)>=0);
  787. /* dump the vote and try to parse it. */
  788. v1_text = format_networkstatus_vote(sign_skey_1, vote);
  789. test_assert(v1_text);
  790. v1 = networkstatus_parse_vote_from_string(v1_text, NULL, NS_TYPE_VOTE);
  791. test_assert(v1);
  792. /* Make sure the parsed thing was right. */
  793. test_eq(v1->type, NS_TYPE_VOTE);
  794. test_eq(v1->published, vote->published);
  795. test_eq(v1->valid_after, vote->valid_after);
  796. test_eq(v1->fresh_until, vote->fresh_until);
  797. test_eq(v1->valid_until, vote->valid_until);
  798. test_eq(v1->vote_seconds, vote->vote_seconds);
  799. test_eq(v1->dist_seconds, vote->dist_seconds);
  800. test_streq(v1->client_versions, vote->client_versions);
  801. test_streq(v1->server_versions, vote->server_versions);
  802. test_assert(v1->voters && smartlist_len(v1->voters));
  803. voter = smartlist_get(v1->voters, 0);
  804. test_streq(voter->nickname, "Voter1");
  805. test_streq(voter->address, "1.2.3.4");
  806. test_eq(voter->addr, 0x01020304);
  807. test_eq(voter->dir_port, 80);
  808. test_eq(voter->or_port, 9000);
  809. test_streq(voter->contact, "voter@example.com");
  810. test_assert(v1->cert);
  811. test_assert(!crypto_pk_cmp_keys(sign_skey_1, v1->cert->signing_key));
  812. cp = smartlist_join_strings(v1->known_flags, ":", 0, NULL);
  813. test_streq(cp, "Authority:Exit:Fast:Guard:Running:Stable:V2Dir:Valid");
  814. tor_free(cp);
  815. test_eq(smartlist_len(v1->routerstatus_list), 4);
  816. /* Check the first routerstatus. */
  817. vrs = smartlist_get(v1->routerstatus_list, 0);
  818. rs = &vrs->status;
  819. test_streq(vrs->version, "0.1.2.14");
  820. test_eq(rs->published_on, now-1500);
  821. test_streq(rs->nickname, "router2");
  822. test_memeq(rs->identity_digest,
  823. "\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3",
  824. DIGEST_LEN);
  825. test_memeq(rs->descriptor_digest, "NNNNNNNNNNNNNNNNNNNN", DIGEST_LEN);
  826. test_eq(rs->addr, 0x99008801);
  827. test_eq(rs->or_port, 443);
  828. test_eq(rs->dir_port, 8000);
  829. test_eq(vrs->flags, U64_LITERAL(16)); // no flags except "running"
  830. /* Check the second routerstatus. */
  831. vrs = smartlist_get(v1->routerstatus_list, 1);
  832. rs = &vrs->status;
  833. test_streq(vrs->version, "0.2.0.5");
  834. test_eq(rs->published_on, now-1000);
  835. test_streq(rs->nickname, "router1");
  836. test_memeq(rs->identity_digest,
  837. "\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5",
  838. DIGEST_LEN);
  839. test_memeq(rs->descriptor_digest, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
  840. test_eq(rs->addr, 0x99009901);
  841. test_eq(rs->or_port, 443);
  842. test_eq(rs->dir_port, 0);
  843. test_eq(vrs->flags, U64_LITERAL(254)); // all flags except "authority."
  844. {
  845. measured_bw_line_t mbw;
  846. memset(mbw.node_id, 33, sizeof(mbw.node_id));
  847. mbw.bw = 1024;
  848. test_assert(measured_bw_line_apply(&mbw,
  849. v1->routerstatus_list) == 1);
  850. vrs = smartlist_get(v1->routerstatus_list, 2);
  851. test_assert(vrs->status.has_measured_bw &&
  852. vrs->status.measured_bw == 1024);
  853. }
  854. /* Generate second vote. It disagrees on some of the times,
  855. * and doesn't list versions, and knows some crazy flags */
  856. vote->published = now+1;
  857. vote->fresh_until = now+3005;
  858. vote->dist_seconds = 300;
  859. authority_cert_free(vote->cert);
  860. vote->cert = authority_cert_dup(cert2);
  861. vote->net_params = smartlist_create();
  862. smartlist_split_string(vote->net_params, "bar=2000000000 circuitwindow=20",
  863. NULL, 0, 0);
  864. tor_free(vote->client_versions);
  865. tor_free(vote->server_versions);
  866. voter = smartlist_get(vote->voters, 0);
  867. tor_free(voter->nickname);
  868. tor_free(voter->address);
  869. voter->nickname = tor_strdup("Voter2");
  870. voter->address = tor_strdup("2.3.4.5");
  871. voter->addr = 0x02030405;
  872. crypto_pk_get_digest(cert2->identity_key, voter->identity_digest);
  873. smartlist_add(vote->known_flags, tor_strdup("MadeOfCheese"));
  874. smartlist_add(vote->known_flags, tor_strdup("MadeOfTin"));
  875. smartlist_sort_strings(vote->known_flags);
  876. vrs = smartlist_get(vote->routerstatus_list, 2);
  877. smartlist_del_keeporder(vote->routerstatus_list, 2);
  878. tor_free(vrs->version);
  879. tor_free(vrs);
  880. vrs = smartlist_get(vote->routerstatus_list, 0);
  881. vrs->status.is_fast = 1;
  882. /* generate and parse. */
  883. v2_text = format_networkstatus_vote(sign_skey_2, vote);
  884. test_assert(v2_text);
  885. v2 = networkstatus_parse_vote_from_string(v2_text, NULL, NS_TYPE_VOTE);
  886. test_assert(v2);
  887. /* Check that flags come out right.*/
  888. cp = smartlist_join_strings(v2->known_flags, ":", 0, NULL);
  889. test_streq(cp, "Authority:Exit:Fast:Guard:MadeOfCheese:MadeOfTin:"
  890. "Running:Stable:V2Dir:Valid");
  891. tor_free(cp);
  892. vrs = smartlist_get(v2->routerstatus_list, 1);
  893. /* 1023 - authority(1) - madeofcheese(16) - madeoftin(32) */
  894. test_eq(vrs->flags, U64_LITERAL(974));
  895. /* Generate the third vote. */
  896. vote->published = now;
  897. vote->fresh_until = now+2003;
  898. vote->dist_seconds = 250;
  899. authority_cert_free(vote->cert);
  900. vote->cert = authority_cert_dup(cert3);
  901. vote->net_params = smartlist_create();
  902. smartlist_split_string(vote->net_params, "circuitwindow=80 foo=660",
  903. NULL, 0, 0);
  904. smartlist_add(vote->supported_methods, tor_strdup("4"));
  905. vote->client_versions = tor_strdup("0.1.2.14,0.1.2.17");
  906. vote->server_versions = tor_strdup("0.1.2.10,0.1.2.15,0.1.2.16");
  907. voter = smartlist_get(vote->voters, 0);
  908. tor_free(voter->nickname);
  909. tor_free(voter->address);
  910. voter->nickname = tor_strdup("Voter3");
  911. voter->address = tor_strdup("3.4.5.6");
  912. voter->addr = 0x03040506;
  913. crypto_pk_get_digest(cert3->identity_key, voter->identity_digest);
  914. /* This one has a legacy id. */
  915. memset(voter->legacy_id_digest, (int)'A', DIGEST_LEN);
  916. vrs = smartlist_get(vote->routerstatus_list, 0);
  917. smartlist_del_keeporder(vote->routerstatus_list, 0);
  918. tor_free(vrs->version);
  919. tor_free(vrs);
  920. vrs = smartlist_get(vote->routerstatus_list, 0);
  921. memset(vrs->status.descriptor_digest, (int)'Z', DIGEST_LEN);
  922. test_assert(router_add_to_routerlist(generate_ri_from_rs(vrs), &msg,0,0)>=0);
  923. v3_text = format_networkstatus_vote(sign_skey_3, vote);
  924. test_assert(v3_text);
  925. v3 = networkstatus_parse_vote_from_string(v3_text, NULL, NS_TYPE_VOTE);
  926. test_assert(v3);
  927. /* Compute a consensus as voter 3. */
  928. smartlist_add(votes, v3);
  929. smartlist_add(votes, v1);
  930. smartlist_add(votes, v2);
  931. consensus_text = networkstatus_compute_consensus(votes, 3,
  932. cert3->identity_key,
  933. sign_skey_3,
  934. "AAAAAAAAAAAAAAAAAAAA",
  935. sign_skey_leg1,
  936. FLAV_NS);
  937. test_assert(consensus_text);
  938. con = networkstatus_parse_vote_from_string(consensus_text, NULL,
  939. NS_TYPE_CONSENSUS);
  940. test_assert(con);
  941. //log_notice(LD_GENERAL, "<<%s>>\n<<%s>>\n<<%s>>\n",
  942. // v1_text, v2_text, v3_text);
  943. consensus_text_md = networkstatus_compute_consensus(votes, 3,
  944. cert3->identity_key,
  945. sign_skey_3,
  946. "AAAAAAAAAAAAAAAAAAAA",
  947. sign_skey_leg1,
  948. FLAV_MICRODESC);
  949. test_assert(consensus_text_md);
  950. con_md = networkstatus_parse_vote_from_string(consensus_text_md, NULL,
  951. NS_TYPE_CONSENSUS);
  952. test_assert(con_md);
  953. test_eq(con_md->flavor, FLAV_MICRODESC);
  954. /* Check consensus contents. */
  955. test_assert(con->type == NS_TYPE_CONSENSUS);
  956. test_eq(con->published, 0); /* this field only appears in votes. */
  957. test_eq(con->valid_after, now+1000);
  958. test_eq(con->fresh_until, now+2003); /* median */
  959. test_eq(con->valid_until, now+3000);
  960. test_eq(con->vote_seconds, 100);
  961. test_eq(con->dist_seconds, 250); /* median */
  962. test_streq(con->client_versions, "0.1.2.14");
  963. test_streq(con->server_versions, "0.1.2.15,0.1.2.16");
  964. cp = smartlist_join_strings(v2->known_flags, ":", 0, NULL);
  965. test_streq(cp, "Authority:Exit:Fast:Guard:MadeOfCheese:MadeOfTin:"
  966. "Running:Stable:V2Dir:Valid");
  967. tor_free(cp);
  968. cp = smartlist_join_strings(con->net_params, ":", 0, NULL);
  969. test_streq(cp, "bar=2000000000:circuitwindow=80:foo=660");
  970. tor_free(cp);
  971. test_eq(4, smartlist_len(con->voters)); /*3 voters, 1 legacy key.*/
  972. /* The voter id digests should be in this order. */
  973. test_assert(memcmp(cert2->cache_info.identity_digest,
  974. cert1->cache_info.identity_digest,DIGEST_LEN)<0);
  975. test_assert(memcmp(cert1->cache_info.identity_digest,
  976. cert3->cache_info.identity_digest,DIGEST_LEN)<0);
  977. test_same_voter(smartlist_get(con->voters, 1),
  978. smartlist_get(v2->voters, 0));
  979. test_same_voter(smartlist_get(con->voters, 2),
  980. smartlist_get(v1->voters, 0));
  981. test_same_voter(smartlist_get(con->voters, 3),
  982. smartlist_get(v3->voters, 0));
  983. test_assert(!con->cert);
  984. test_eq(2, smartlist_len(con->routerstatus_list));
  985. /* There should be two listed routers: one with identity 3, one with
  986. * identity 5. */
  987. /* This one showed up in 2 digests. */
  988. rs = smartlist_get(con->routerstatus_list, 0);
  989. test_memeq(rs->identity_digest,
  990. "\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3\x3",
  991. DIGEST_LEN);
  992. test_memeq(rs->descriptor_digest, "NNNNNNNNNNNNNNNNNNNN", DIGEST_LEN);
  993. test_assert(!rs->is_authority);
  994. test_assert(!rs->is_exit);
  995. test_assert(!rs->is_fast);
  996. test_assert(!rs->is_possible_guard);
  997. test_assert(!rs->is_stable);
  998. test_assert(rs->is_running); /* If it wasn't running it wouldn't be here */
  999. test_assert(!rs->is_v2_dir);
  1000. test_assert(!rs->is_valid);
  1001. test_assert(!rs->is_named);
  1002. /* XXXX check version */
  1003. rs = smartlist_get(con->routerstatus_list, 1);
  1004. /* This one showed up in 3 digests. Twice with ID 'M', once with 'Z'. */
  1005. test_memeq(rs->identity_digest,
  1006. "\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5\x5",
  1007. DIGEST_LEN);
  1008. test_streq(rs->nickname, "router1");
  1009. test_memeq(rs->descriptor_digest, "MMMMMMMMMMMMMMMMMMMM", DIGEST_LEN);
  1010. test_eq(rs->published_on, now-1000);
  1011. test_eq(rs->addr, 0x99009901);
  1012. test_eq(rs->or_port, 443);
  1013. test_eq(rs->dir_port, 0);
  1014. test_assert(!rs->is_authority);
  1015. test_assert(rs->is_exit);
  1016. test_assert(rs->is_fast);
  1017. test_assert(rs->is_possible_guard);
  1018. test_assert(rs->is_stable);
  1019. test_assert(rs->is_running);
  1020. test_assert(rs->is_v2_dir);
  1021. test_assert(rs->is_valid);
  1022. test_assert(!rs->is_named);
  1023. /* XXXX check version */
  1024. /* Check signatures. the first voter is a pseudo-entry with a legacy key.
  1025. * The second one hasn't signed. The fourth one has signed: validate it. */
  1026. voter = smartlist_get(con->voters, 1);
  1027. test_eq(smartlist_len(voter->sigs), 0);
  1028. voter = smartlist_get(con->voters, 3);
  1029. test_eq(smartlist_len(voter->sigs), 1);
  1030. sig = smartlist_get(voter->sigs, 0);
  1031. test_assert(sig->signature);
  1032. test_assert(!sig->good_signature);
  1033. test_assert(!sig->bad_signature);
  1034. test_assert(!networkstatus_check_document_signature(con, sig, cert3));
  1035. test_assert(sig->signature);
  1036. test_assert(sig->good_signature);
  1037. test_assert(!sig->bad_signature);
  1038. {
  1039. const char *msg=NULL;
  1040. /* Compute the other two signed consensuses. */
  1041. smartlist_shuffle(votes);
  1042. consensus_text2 = networkstatus_compute_consensus(votes, 3,
  1043. cert2->identity_key,
  1044. sign_skey_2, NULL,NULL,
  1045. FLAV_NS);
  1046. consensus_text_md2 = networkstatus_compute_consensus(votes, 3,
  1047. cert2->identity_key,
  1048. sign_skey_2, NULL,NULL,
  1049. FLAV_MICRODESC);
  1050. smartlist_shuffle(votes);
  1051. consensus_text3 = networkstatus_compute_consensus(votes, 3,
  1052. cert1->identity_key,
  1053. sign_skey_1, NULL,NULL,
  1054. FLAV_NS);
  1055. consensus_text_md3 = networkstatus_compute_consensus(votes, 3,
  1056. cert1->identity_key,
  1057. sign_skey_1, NULL,NULL,
  1058. FLAV_MICRODESC);
  1059. test_assert(consensus_text2);
  1060. test_assert(consensus_text3);
  1061. test_assert(consensus_text_md2);
  1062. test_assert(consensus_text_md3);
  1063. con2 = networkstatus_parse_vote_from_string(consensus_text2, NULL,
  1064. NS_TYPE_CONSENSUS);
  1065. con3 = networkstatus_parse_vote_from_string(consensus_text3, NULL,
  1066. NS_TYPE_CONSENSUS);
  1067. con_md2 = networkstatus_parse_vote_from_string(consensus_text_md2, NULL,
  1068. NS_TYPE_CONSENSUS);
  1069. con_md3 = networkstatus_parse_vote_from_string(consensus_text_md3, NULL,
  1070. NS_TYPE_CONSENSUS);
  1071. test_assert(con2);
  1072. test_assert(con3);
  1073. test_assert(con_md2);
  1074. test_assert(con_md3);
  1075. /* All three should have the same digest. */
  1076. test_memeq(&con->digests, &con2->digests, sizeof(digests_t));
  1077. test_memeq(&con->digests, &con3->digests, sizeof(digests_t));
  1078. test_memeq(&con_md->digests, &con_md2->digests, sizeof(digests_t));
  1079. test_memeq(&con_md->digests, &con_md3->digests, sizeof(digests_t));
  1080. /* Extract a detached signature from con3. */
  1081. detached_text1 = get_detached_sigs(con3, con_md3);
  1082. tor_assert(detached_text1);
  1083. /* Try to parse it. */
  1084. dsig1 = networkstatus_parse_detached_signatures(detached_text1, NULL);
  1085. tor_assert(dsig1);
  1086. /* Are parsed values as expected? */
  1087. test_eq(dsig1->valid_after, con3->valid_after);
  1088. test_eq(dsig1->fresh_until, con3->fresh_until);
  1089. test_eq(dsig1->valid_until, con3->valid_until);
  1090. {
  1091. digests_t *dsig_digests = strmap_get(dsig1->digests, "ns");
  1092. test_assert(dsig_digests);
  1093. test_memeq(dsig_digests->d[DIGEST_SHA1], con3->digests.d[DIGEST_SHA1],
  1094. DIGEST_LEN);
  1095. dsig_digests = strmap_get(dsig1->digests, "microdesc");
  1096. test_assert(dsig_digests);
  1097. test_memeq(dsig_digests->d[DIGEST_SHA256],
  1098. con_md3->digests.d[DIGEST_SHA256],
  1099. DIGEST256_LEN);
  1100. }
  1101. {
  1102. smartlist_t *dsig_signatures = strmap_get(dsig1->signatures, "ns");
  1103. test_assert(dsig_signatures);
  1104. test_eq(1, smartlist_len(dsig_signatures));
  1105. sig = smartlist_get(dsig_signatures, 0);
  1106. test_memeq(sig->identity_digest, cert1->cache_info.identity_digest,
  1107. DIGEST_LEN);
  1108. test_eq(sig->alg, DIGEST_SHA1);
  1109. dsig_signatures = strmap_get(dsig1->signatures, "microdesc");
  1110. test_assert(dsig_signatures);
  1111. test_eq(1, smartlist_len(dsig_signatures));
  1112. sig = smartlist_get(dsig_signatures, 0);
  1113. test_memeq(sig->identity_digest, cert1->cache_info.identity_digest,
  1114. DIGEST_LEN);
  1115. test_eq(sig->alg, DIGEST_SHA256);
  1116. }
  1117. /* Try adding it to con2. */
  1118. detached_text2 = get_detached_sigs(con2,con_md2);
  1119. test_eq(1, networkstatus_add_detached_signatures(con2, dsig1, &msg));
  1120. tor_free(detached_text2);
  1121. test_eq(1, networkstatus_add_detached_signatures(con_md2, dsig1, &msg));
  1122. tor_free(detached_text2);
  1123. detached_text2 = get_detached_sigs(con2,con_md2);
  1124. //printf("\n<%s>\n", detached_text2);
  1125. dsig2 = networkstatus_parse_detached_signatures(detached_text2, NULL);
  1126. test_assert(dsig2);
  1127. /*
  1128. printf("\n");
  1129. SMARTLIST_FOREACH(dsig2->signatures, networkstatus_voter_info_t *, vi, {
  1130. char hd[64];
  1131. base16_encode(hd, sizeof(hd), vi->identity_digest, DIGEST_LEN);
  1132. printf("%s\n", hd);
  1133. });
  1134. */
  1135. test_eq(2,
  1136. smartlist_len((smartlist_t*)strmap_get(dsig2->signatures, "ns")));
  1137. test_eq(2,
  1138. smartlist_len((smartlist_t*)strmap_get(dsig2->signatures,
  1139. "microdesc")));
  1140. /* Try adding to con2 twice; verify that nothing changes. */
  1141. test_eq(0, networkstatus_add_detached_signatures(con2, dsig1, &msg));
  1142. /* Add to con. */
  1143. test_eq(2, networkstatus_add_detached_signatures(con, dsig2, &msg));
  1144. /* Check signatures */
  1145. voter = smartlist_get(con->voters, 1);
  1146. sig = smartlist_get(voter->sigs, 0);
  1147. test_assert(sig);
  1148. test_assert(!networkstatus_check_document_signature(con, sig, cert2));
  1149. voter = smartlist_get(con->voters, 2);
  1150. sig = smartlist_get(voter->sigs, 0);
  1151. test_assert(sig);
  1152. test_assert(!networkstatus_check_document_signature(con, sig, cert1));
  1153. }
  1154. done:
  1155. smartlist_free(votes);
  1156. tor_free(v1_text);
  1157. tor_free(v2_text);
  1158. tor_free(v3_text);
  1159. tor_free(consensus_text);
  1160. tor_free(consensus_text_md);
  1161. if (vote)
  1162. networkstatus_vote_free(vote);
  1163. if (v1)
  1164. networkstatus_vote_free(v1);
  1165. if (v2)
  1166. networkstatus_vote_free(v2);
  1167. if (v3)
  1168. networkstatus_vote_free(v3);
  1169. if (con)
  1170. networkstatus_vote_free(con);
  1171. if (con_md)
  1172. networkstatus_vote_free(con_md);
  1173. if (sign_skey_1)
  1174. crypto_free_pk_env(sign_skey_1);
  1175. if (sign_skey_2)
  1176. crypto_free_pk_env(sign_skey_2);
  1177. if (sign_skey_3)
  1178. crypto_free_pk_env(sign_skey_3);
  1179. if (sign_skey_leg1)
  1180. crypto_free_pk_env(sign_skey_leg1);
  1181. if (cert1)
  1182. authority_cert_free(cert1);
  1183. if (cert2)
  1184. authority_cert_free(cert2);
  1185. if (cert3)
  1186. authority_cert_free(cert3);
  1187. tor_free(consensus_text2);
  1188. tor_free(consensus_text3);
  1189. tor_free(consensus_text_md2);
  1190. tor_free(consensus_text_md3);
  1191. tor_free(detached_text1);
  1192. tor_free(detached_text2);
  1193. if (con2)
  1194. networkstatus_vote_free(con2);
  1195. if (con3)
  1196. networkstatus_vote_free(con3);
  1197. if (con_md2)
  1198. networkstatus_vote_free(con_md2);
  1199. if (con_md3)
  1200. networkstatus_vote_free(con_md3);
  1201. if (dsig1)
  1202. ns_detached_signatures_free(dsig1);
  1203. if (dsig2)
  1204. ns_detached_signatures_free(dsig2);
  1205. }
  1206. #define DIR_LEGACY(name) \
  1207. { #name, legacy_test_helper, 0, &legacy_setup, test_dir_ ## name }
  1208. #define DIR(name) \
  1209. { #name, test_dir_##name, 0, NULL, NULL }
  1210. struct testcase_t dir_tests[] = {
  1211. DIR_LEGACY(nicknames),
  1212. DIR_LEGACY(formats),
  1213. DIR_LEGACY(versions),
  1214. DIR_LEGACY(fp_pairs),
  1215. DIR(split_fps),
  1216. DIR_LEGACY(measured_bw),
  1217. DIR_LEGACY(param_voting),
  1218. DIR_LEGACY(v3_networkstatus),
  1219. END_OF_TESTCASES
  1220. };