test_protover.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define PROTOVER_PRIVATE
  4. #include "orconfig.h"
  5. #include "test.h"
  6. #include "protover.h"
  7. #include "or.h"
  8. #include "connection_or.h"
  9. static void
  10. test_protover_parse(void *arg)
  11. {
  12. (void) arg;
  13. #ifdef HAVE_RUST
  14. /** This test is disabled on rust builds, because it only exists to test
  15. * internal C functions. */
  16. tt_skip();
  17. done:
  18. ;
  19. #else
  20. char *re_encoded = NULL;
  21. const char *orig = "Foo=1,3 Bar=3 Baz= Quux=9-12,14,15-16,900";
  22. smartlist_t *elts = parse_protocol_list(orig);
  23. tt_assert(elts);
  24. tt_int_op(smartlist_len(elts), OP_EQ, 4);
  25. const proto_entry_t *e;
  26. const proto_range_t *r;
  27. e = smartlist_get(elts, 0);
  28. tt_str_op(e->name, OP_EQ, "Foo");
  29. tt_int_op(smartlist_len(e->ranges), OP_EQ, 2);
  30. {
  31. r = smartlist_get(e->ranges, 0);
  32. tt_int_op(r->low, OP_EQ, 1);
  33. tt_int_op(r->high, OP_EQ, 1);
  34. r = smartlist_get(e->ranges, 1);
  35. tt_int_op(r->low, OP_EQ, 3);
  36. tt_int_op(r->high, OP_EQ, 3);
  37. }
  38. e = smartlist_get(elts, 1);
  39. tt_str_op(e->name, OP_EQ, "Bar");
  40. tt_int_op(smartlist_len(e->ranges), OP_EQ, 1);
  41. {
  42. r = smartlist_get(e->ranges, 0);
  43. tt_int_op(r->low, OP_EQ, 3);
  44. tt_int_op(r->high, OP_EQ, 3);
  45. }
  46. e = smartlist_get(elts, 2);
  47. tt_str_op(e->name, OP_EQ, "Baz");
  48. tt_int_op(smartlist_len(e->ranges), OP_EQ, 0);
  49. e = smartlist_get(elts, 3);
  50. tt_str_op(e->name, OP_EQ, "Quux");
  51. tt_int_op(smartlist_len(e->ranges), OP_EQ, 4);
  52. {
  53. r = smartlist_get(e->ranges, 0);
  54. tt_int_op(r->low, OP_EQ, 9);
  55. tt_int_op(r->high, OP_EQ, 12);
  56. r = smartlist_get(e->ranges, 1);
  57. tt_int_op(r->low, OP_EQ, 14);
  58. tt_int_op(r->high, OP_EQ, 14);
  59. r = smartlist_get(e->ranges, 2);
  60. tt_int_op(r->low, OP_EQ, 15);
  61. tt_int_op(r->high, OP_EQ, 16);
  62. r = smartlist_get(e->ranges, 3);
  63. tt_int_op(r->low, OP_EQ, 900);
  64. tt_int_op(r->high, OP_EQ, 900);
  65. }
  66. re_encoded = encode_protocol_list(elts);
  67. tt_assert(re_encoded);
  68. tt_str_op(re_encoded, OP_EQ, orig);
  69. done:
  70. if (elts)
  71. SMARTLIST_FOREACH(elts, proto_entry_t *, ent, proto_entry_free(ent));
  72. smartlist_free(elts);
  73. tor_free(re_encoded);
  74. #endif
  75. }
  76. static void
  77. test_protover_parse_fail(void *arg)
  78. {
  79. (void)arg;
  80. #ifdef HAVE_RUST
  81. /** This test is disabled on rust builds, because it only exists to test
  82. * internal C functions. */
  83. tt_skip();
  84. #else
  85. smartlist_t *elts;
  86. /* random junk */
  87. elts = parse_protocol_list("!!3@*");
  88. tt_ptr_op(elts, OP_EQ, NULL);
  89. /* Missing equals sign in an entry */
  90. elts = parse_protocol_list("Link=4 Haprauxymatyve Desc=9");
  91. tt_ptr_op(elts, OP_EQ, NULL);
  92. /* Missing word. */
  93. elts = parse_protocol_list("Link=4 =3 Desc=9");
  94. tt_ptr_op(elts, OP_EQ, NULL);
  95. /* Broken numbers */
  96. elts = parse_protocol_list("Link=fred");
  97. tt_ptr_op(elts, OP_EQ, NULL);
  98. elts = parse_protocol_list("Link=1,fred");
  99. tt_ptr_op(elts, OP_EQ, NULL);
  100. elts = parse_protocol_list("Link=1,fred,3");
  101. tt_ptr_op(elts, OP_EQ, NULL);
  102. /* Broken range */
  103. elts = parse_protocol_list("Link=1,9-8,3");
  104. tt_ptr_op(elts, OP_EQ, NULL);
  105. #endif
  106. done:
  107. ;
  108. }
  109. static void
  110. test_protover_vote(void *arg)
  111. {
  112. (void) arg;
  113. smartlist_t *lst = smartlist_new();
  114. char *result = protover_compute_vote(lst, 1);
  115. tt_str_op(result, OP_EQ, "");
  116. tor_free(result);
  117. smartlist_add(lst, (void*) "Foo=1-10,500 Bar=1,3-7,8");
  118. result = protover_compute_vote(lst, 1);
  119. tt_str_op(result, OP_EQ, "Bar=1,3-8 Foo=1-10,500");
  120. tor_free(result);
  121. smartlist_add(lst, (void*) "Quux=123-456,78 Bar=2-6,8 Foo=9");
  122. result = protover_compute_vote(lst, 1);
  123. tt_str_op(result, OP_EQ, "Bar=1-8 Foo=1-10,500 Quux=78,123-456");
  124. tor_free(result);
  125. result = protover_compute_vote(lst, 2);
  126. tt_str_op(result, OP_EQ, "Bar=3-6,8 Foo=9");
  127. tor_free(result);
  128. /* High threshold */
  129. result = protover_compute_vote(lst, 3);
  130. tt_str_op(result, OP_EQ, "");
  131. tor_free(result);
  132. /* Bad votes: the result must be empty */
  133. smartlist_clear(lst);
  134. smartlist_add(lst, (void*) "Faux=10-5");
  135. result = protover_compute_vote(lst, 1);
  136. tt_str_op(result, OP_EQ, "");
  137. tor_free(result);
  138. /* This fails, since "-0" is not valid. */
  139. smartlist_clear(lst);
  140. smartlist_add(lst, (void*) "Faux=-0");
  141. result = protover_compute_vote(lst, 1);
  142. tt_str_op(result, OP_EQ, "");
  143. tor_free(result);
  144. /* Vote large protover lists that are just below the threshold */
  145. /* Just below the threshold: Rust */
  146. smartlist_clear(lst);
  147. smartlist_add(lst, (void*) "Sleen=1-500");
  148. result = protover_compute_vote(lst, 1);
  149. tt_str_op(result, OP_EQ, "Sleen=1-500");
  150. tor_free(result);
  151. /* Just below the threshold: C */
  152. smartlist_clear(lst);
  153. smartlist_add(lst, (void*) "Sleen=1-65536");
  154. result = protover_compute_vote(lst, 1);
  155. tt_str_op(result, OP_EQ, "Sleen=1-65536");
  156. tor_free(result);
  157. /* Large protover lists that exceed the threshold */
  158. /* By adding two votes, C allows us to exceed the limit */
  159. smartlist_add(lst, (void*) "Sleen=1-65536");
  160. smartlist_add(lst, (void*) "Sleen=100000");
  161. result = protover_compute_vote(lst, 1);
  162. tt_str_op(result, OP_EQ, "Sleen=1-65536,100000");
  163. tor_free(result);
  164. /* Large integers */
  165. smartlist_clear(lst);
  166. smartlist_add(lst, (void*) "Sleen=4294967294");
  167. result = protover_compute_vote(lst, 1);
  168. tt_str_op(result, OP_EQ, "Sleen=4294967294");
  169. tor_free(result);
  170. /* This parses, but fails at the vote stage */
  171. smartlist_clear(lst);
  172. smartlist_add(lst, (void*) "Sleen=4294967295");
  173. result = protover_compute_vote(lst, 1);
  174. tt_str_op(result, OP_EQ, "");
  175. tor_free(result);
  176. smartlist_clear(lst);
  177. smartlist_add(lst, (void*) "Sleen=4294967296");
  178. result = protover_compute_vote(lst, 1);
  179. tt_str_op(result, OP_EQ, "");
  180. tor_free(result);
  181. done:
  182. tor_free(result);
  183. smartlist_free(lst);
  184. }
  185. static void
  186. test_protover_all_supported(void *arg)
  187. {
  188. (void)arg;
  189. char *msg = NULL;
  190. tt_assert(protover_all_supported(NULL, &msg));
  191. tt_ptr_op(msg, OP_EQ, NULL);
  192. tt_assert(protover_all_supported("", &msg));
  193. tt_ptr_op(msg, OP_EQ, NULL);
  194. // Some things that we do support
  195. tt_assert(protover_all_supported("Link=3-4", &msg));
  196. tt_ptr_op(msg, OP_EQ, NULL);
  197. tt_assert(protover_all_supported("Link=3-4 Desc=2", &msg));
  198. tt_ptr_op(msg, OP_EQ, NULL);
  199. // Some things we don't support
  200. tt_assert(! protover_all_supported("Wombat=9", &msg));
  201. tt_str_op(msg, OP_EQ, "Wombat=9");
  202. tor_free(msg);
  203. tt_assert(! protover_all_supported("Link=999", &msg));
  204. tt_str_op(msg, OP_EQ, "Link=999");
  205. tor_free(msg);
  206. // Mix of things we support and things we don't
  207. tt_assert(! protover_all_supported("Link=3-4 Wombat=9", &msg));
  208. tt_str_op(msg, OP_EQ, "Wombat=9");
  209. tor_free(msg);
  210. tt_assert(! protover_all_supported("Link=3-999", &msg));
  211. tt_str_op(msg, OP_EQ, "Link=3-999");
  212. tor_free(msg);
  213. /* CPU/RAM DoS loop: Rust only */
  214. tt_assert(! protover_all_supported("Sleen=0-2147483648", &msg));
  215. tt_str_op(msg, OP_EQ, "Sleen=0-2147483648");
  216. tor_free(msg);
  217. /* This case is allowed. */
  218. tt_assert(! protover_all_supported("Sleen=0-4294967294", &msg));
  219. tt_str_op(msg, OP_EQ, "Sleen=0-4294967294");
  220. tor_free(msg);
  221. /* If we get an unparseable list, we say "yes, that's supported." */
  222. #ifndef HAVE_RUST
  223. // XXXX let's make this section unconditional: rust should behave the
  224. // XXXX same as C here!
  225. tor_capture_bugs_(1);
  226. tt_assert(protover_all_supported("Fribble", &msg));
  227. tt_ptr_op(msg, OP_EQ, NULL);
  228. tor_end_capture_bugs_();
  229. /* This case is forbidden. Since it came from a protover_all_supported,
  230. * it can trigger a bug message. */
  231. tor_capture_bugs_(1);
  232. tt_assert(protover_all_supported("Sleen=0-4294967295", &msg));
  233. tt_ptr_op(msg, OP_EQ, NULL);
  234. tor_free(msg);
  235. tor_end_capture_bugs_();
  236. #endif
  237. done:
  238. tor_end_capture_bugs_();
  239. tor_free(msg);
  240. }
  241. static void
  242. test_protover_list_supports_protocol_returns_true(void *arg)
  243. {
  244. (void)arg;
  245. const char *protocols = "Link=1";
  246. int is_supported = protocol_list_supports_protocol(protocols, PRT_LINK, 1);
  247. tt_int_op(is_supported, OP_EQ, 1);
  248. done:
  249. ;
  250. }
  251. static void
  252. test_protover_list_supports_protocol_for_unsupported_returns_false(void *arg)
  253. {
  254. (void)arg;
  255. const char *protocols = "Link=1";
  256. int is_supported = protocol_list_supports_protocol(protocols, PRT_LINK, 10);
  257. tt_int_op(is_supported, OP_EQ, 0);
  258. done:
  259. ;
  260. }
  261. static void
  262. test_protover_supports_version(void *arg)
  263. {
  264. (void)arg;
  265. tt_assert(protocol_list_supports_protocol("Link=3-6", PRT_LINK, 3));
  266. tt_assert(protocol_list_supports_protocol("Link=3-6", PRT_LINK, 6));
  267. tt_assert(!protocol_list_supports_protocol("Link=3-6", PRT_LINK, 7));
  268. tt_assert(!protocol_list_supports_protocol("Link=3-6", PRT_LINKAUTH, 3));
  269. tt_assert(!protocol_list_supports_protocol("Link=4-6 LinkAuth=3",
  270. PRT_LINKAUTH, 2));
  271. tt_assert(protocol_list_supports_protocol("Link=4-6 LinkAuth=3",
  272. PRT_LINKAUTH, 3));
  273. tt_assert(!protocol_list_supports_protocol("Link=4-6 LinkAuth=3",
  274. PRT_LINKAUTH, 4));
  275. tt_assert(!protocol_list_supports_protocol_or_later("Link=4-6 LinkAuth=3",
  276. PRT_LINKAUTH, 4));
  277. tt_assert(protocol_list_supports_protocol_or_later("Link=4-6 LinkAuth=3",
  278. PRT_LINKAUTH, 3));
  279. tt_assert(protocol_list_supports_protocol_or_later("Link=4-6 LinkAuth=3",
  280. PRT_LINKAUTH, 2));
  281. tt_assert(!protocol_list_supports_protocol_or_later("Link=4-6 LinkAuth=3",
  282. PRT_DESC, 2));
  283. done:
  284. ;
  285. }
  286. /* This could be MAX_PROTOCOLS_TO_EXPAND, but that's not exposed by protover */
  287. #define MAX_PROTOCOLS_TO_TEST 1024
  288. /* LinkAuth and Relay protocol versions.
  289. * Hard-coded here, because they are not in the code, or not exposed in the
  290. * headers. */
  291. #define PROTOVER_LINKAUTH_V1 1
  292. #define PROTOVER_LINKAUTH_V3 3
  293. #define PROTOVER_RELAY_V1 1
  294. #define PROTOVER_RELAY_V2 2
  295. /* Highest supported HSv2 introduce protocol version.
  296. * Hard-coded here, because it does not appear anywhere in the code.
  297. * It's not clear if we actually support version 2, see #25068. */
  298. #define PROTOVER_HSINTRO_V2 3
  299. /* HSv2 Rend and HSDir protocol versions.
  300. * Hard-coded here, because they do not appear anywhere in the code. */
  301. #define PROTOVER_HS_RENDEZVOUS_POINT_V2 1
  302. #define PROTOVER_HSDIR_V2 1
  303. /* DirCache, Desc, Microdesc, and Cons protocol versions.
  304. * Hard-coded here, because they do not appear anywhere in the code. */
  305. #define PROTOVER_DIRCACHE_V1 1
  306. #define PROTOVER_DIRCACHE_V2 2
  307. #define PROTOVER_DESC_V1 1
  308. #define PROTOVER_DESC_V2 2
  309. #define PROTOVER_MICRODESC_V1 1
  310. #define PROTOVER_MICRODESC_V2 2
  311. #define PROTOVER_CONS_V1 1
  312. #define PROTOVER_CONS_V2 2
  313. /* Make sure we haven't forgotten any supported protocols */
  314. static void
  315. test_protover_supported_protocols(void *arg)
  316. {
  317. (void)arg;
  318. const char *supported_protocols = protover_get_supported_protocols();
  319. /* Test for new Link in the code, that hasn't been added to supported
  320. * protocols */
  321. tt_assert(protocol_list_supports_protocol(supported_protocols,
  322. PRT_LINK,
  323. MAX_LINK_PROTO));
  324. for (uint16_t i = 0; i < MAX_PROTOCOLS_TO_TEST; i++) {
  325. if (is_or_protocol_version_known(i)) {
  326. tt_assert(protocol_list_supports_protocol(supported_protocols,
  327. PRT_LINK,
  328. i));
  329. }
  330. }
  331. /* Legacy LinkAuth does not appear anywhere in the code. */
  332. tt_assert(protocol_list_supports_protocol(supported_protocols,
  333. PRT_LINKAUTH,
  334. PROTOVER_LINKAUTH_V1));
  335. /* Latest LinkAuth is not exposed in the headers. */
  336. tt_assert(protocol_list_supports_protocol(supported_protocols,
  337. PRT_LINKAUTH,
  338. PROTOVER_LINKAUTH_V3));
  339. /* Is there any way to test for new LinkAuth? */
  340. /* Relay protovers do not appear anywhere in the code. */
  341. tt_assert(protocol_list_supports_protocol(supported_protocols,
  342. PRT_RELAY,
  343. PROTOVER_RELAY_V1));
  344. tt_assert(protocol_list_supports_protocol(supported_protocols,
  345. PRT_RELAY,
  346. PROTOVER_RELAY_V2));
  347. /* Is there any way to test for new Relay? */
  348. /* We could test legacy HSIntro by calling rend_service_update_descriptor(),
  349. * and checking the protocols field. But that's unlikely to change, so
  350. * we just use a hard-coded value. */
  351. tt_assert(protocol_list_supports_protocol(supported_protocols,
  352. PRT_HSINTRO,
  353. PROTOVER_HSINTRO_V2));
  354. /* Test for HSv3 HSIntro */
  355. tt_assert(protocol_list_supports_protocol(supported_protocols,
  356. PRT_HSINTRO,
  357. PROTOVER_HS_INTRO_V3));
  358. /* Is there any way to test for new HSIntro? */
  359. /* Legacy HSRend does not appear anywhere in the code. */
  360. tt_assert(protocol_list_supports_protocol(supported_protocols,
  361. PRT_HSREND,
  362. PROTOVER_HS_RENDEZVOUS_POINT_V2));
  363. /* Test for HSv3 HSRend */
  364. tt_assert(protocol_list_supports_protocol(supported_protocols,
  365. PRT_HSREND,
  366. PROTOVER_HS_RENDEZVOUS_POINT_V3));
  367. /* Is there any way to test for new HSRend? */
  368. /* Legacy HSDir does not appear anywhere in the code. */
  369. tt_assert(protocol_list_supports_protocol(supported_protocols,
  370. PRT_HSDIR,
  371. PROTOVER_HSDIR_V2));
  372. /* Test for HSv3 HSDir */
  373. tt_assert(protocol_list_supports_protocol(supported_protocols,
  374. PRT_HSDIR,
  375. PROTOVER_HSDIR_V3));
  376. /* Is there any way to test for new HSDir? */
  377. /* No DirCache versions appear anywhere in the code. */
  378. tt_assert(protocol_list_supports_protocol(supported_protocols,
  379. PRT_DIRCACHE,
  380. PROTOVER_DIRCACHE_V1));
  381. tt_assert(protocol_list_supports_protocol(supported_protocols,
  382. PRT_DIRCACHE,
  383. PROTOVER_DIRCACHE_V2));
  384. /* Is there any way to test for new DirCache? */
  385. /* No Desc versions appear anywhere in the code. */
  386. tt_assert(protocol_list_supports_protocol(supported_protocols,
  387. PRT_DESC,
  388. PROTOVER_DESC_V1));
  389. tt_assert(protocol_list_supports_protocol(supported_protocols,
  390. PRT_DESC,
  391. PROTOVER_DESC_V2));
  392. /* Is there any way to test for new Desc? */
  393. /* No Microdesc versions appear anywhere in the code. */
  394. tt_assert(protocol_list_supports_protocol(supported_protocols,
  395. PRT_MICRODESC,
  396. PROTOVER_MICRODESC_V1));
  397. tt_assert(protocol_list_supports_protocol(supported_protocols,
  398. PRT_MICRODESC,
  399. PROTOVER_MICRODESC_V2));
  400. /* Is there any way to test for new Microdesc? */
  401. /* No Cons versions appear anywhere in the code. */
  402. tt_assert(protocol_list_supports_protocol(supported_protocols,
  403. PRT_CONS,
  404. PROTOVER_CONS_V1));
  405. tt_assert(protocol_list_supports_protocol(supported_protocols,
  406. PRT_CONS,
  407. PROTOVER_CONS_V2));
  408. /* Is there any way to test for new Cons? */
  409. done:
  410. ;
  411. }
  412. static void
  413. test_protover_vote_roundtrip(void *args)
  414. {
  415. (void) args;
  416. static const struct {
  417. const char *input;
  418. const char *expected_output;
  419. } examples[] = {
  420. { "Fkrkljdsf", NULL },
  421. { "Zn=4294967295", NULL },
  422. { "Zn=4294967295-1", NULL },
  423. { "Zn=4294967293-4294967295", NULL },
  424. /* Will fail because of 4294967295. */
  425. { "Foo=1,3 Bar=3 Baz= Quux=9-12,14,15-16,900 Zn=0,4294967295",
  426. NULL },
  427. { "Foo=1,3 Bar=3 Baz= Quux=9-12,14,15-16,900 Zn=0,4294967294",
  428. "Bar=3 Foo=1,3 Quux=9-12,14-16,900 Zn=0,4294967294" },
  429. { "Zu16=0,65536", "Zu16=0,65536" },
  430. { "N-1=1,2", "N-1=1-2" },
  431. { "-1=4294967295", NULL },
  432. { "-1=3", "-1=3" },
  433. /* junk. */
  434. { "!!3@*", NULL },
  435. /* Missing equals sign */
  436. { "Link=4 Haprauxymatyve Desc=9", NULL },
  437. { "Link=4 Haprauxymatyve=7 Desc=9",
  438. "Desc=9 Haprauxymatyve=7 Link=4" },
  439. { "=10-11", NULL },
  440. { "X=10-11", "X=10-11" },
  441. { "Link=4 =3 Desc=9", NULL },
  442. { "Link=4 Z=3 Desc=9", "Desc=9 Link=4 Z=3" },
  443. { "Link=fred", NULL },
  444. { "Link=1,fred", NULL },
  445. { "Link=1,fred,3", NULL },
  446. { "Link=1,9-8,3", NULL },
  447. { "Faux=-0", NULL },
  448. { "Faux=0--0", NULL },
  449. // "These fail at the splitting stage in Rust, but the number parsing
  450. // stage in C."
  451. { "Faux=-1", NULL },
  452. { "Faux=-1-3", NULL },
  453. { "Faux=1--1", NULL },
  454. /* Large integers */
  455. { "Link=4294967296", NULL },
  456. /* Large range */
  457. { "Sleen=1-501", "Sleen=1-501" },
  458. { "Sleen=1-65537", NULL },
  459. /* CPU/RAM DoS Loop: Rust only. */
  460. { "Sleen=0-2147483648", NULL },
  461. /* Rust seems to experience an internal error here. */
  462. { "Sleen=0-4294967295", NULL },
  463. };
  464. unsigned u;
  465. smartlist_t *votes = smartlist_new();
  466. char *result = NULL;
  467. for (u = 0; u < ARRAY_LENGTH(examples); ++u) {
  468. const char *input = examples[u].input;
  469. const char *expected_output = examples[u].expected_output;
  470. smartlist_add(votes, (void*)input);
  471. result = protover_compute_vote(votes, 1);
  472. if (expected_output != NULL) {
  473. tt_str_op(result, OP_EQ, expected_output);
  474. } else {
  475. tt_str_op(result, OP_EQ, "");
  476. }
  477. smartlist_clear(votes);
  478. tor_free(result);
  479. }
  480. done:
  481. smartlist_free(votes);
  482. tor_free(result);
  483. }
  484. #define PV_TEST(name, flags) \
  485. { #name, test_protover_ ##name, (flags), NULL, NULL }
  486. struct testcase_t protover_tests[] = {
  487. PV_TEST(parse, 0),
  488. PV_TEST(parse_fail, 0),
  489. PV_TEST(vote, 0),
  490. PV_TEST(all_supported, 0),
  491. PV_TEST(list_supports_protocol_for_unsupported_returns_false, 0),
  492. PV_TEST(list_supports_protocol_returns_true, 0),
  493. PV_TEST(supports_version, 0),
  494. PV_TEST(supported_protocols, 0),
  495. PV_TEST(vote_roundtrip, 0),
  496. END_OF_TESTCASES
  497. };