test_entrynodes.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /* Copyright (c) 2014, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #include "orconfig.h"
  4. #define STATEFILE_PRIVATE
  5. #define ENTRYNODES_PRIVATE
  6. #define ROUTERLIST_PRIVATE
  7. #include "or.h"
  8. #include "test.h"
  9. #include "entrynodes.h"
  10. #include "routerparse.h"
  11. #include "nodelist.h"
  12. #include "util.h"
  13. #include "routerlist.h"
  14. #include "routerset.h"
  15. #include "statefile.h"
  16. #include "config.h"
  17. #include "test_descriptors.inc"
  18. /* TODO:
  19. * choose_random_entry() test with state set.
  20. *
  21. * parse_state() tests with more than one guards.
  22. *
  23. * More tests for set_from_config(): Multiple nodes, use fingerprints,
  24. * use country codes.
  25. */
  26. /** Dummy Tor state used in unittests. */
  27. static or_state_t *dummy_state = NULL;
  28. static or_state_t *
  29. get_or_state_replacement(void)
  30. {
  31. return dummy_state;
  32. }
  33. /* NOP replacement for router_descriptor_is_older_than() */
  34. static int
  35. router_descriptor_is_older_than_replacement(const routerinfo_t *router,
  36. int seconds)
  37. {
  38. (void) router;
  39. (void) seconds;
  40. return 0;
  41. }
  42. /* Number of descriptors contained in test_descriptors.txt. */
  43. #define NUMBER_OF_DESCRIPTORS 8
  44. /** Parse a file containing router descriptors and load them to our
  45. routerlist. This function is used to setup an artificial network
  46. so that we can conduct entry guard tests. */
  47. static void
  48. setup_fake_routerlist(void)
  49. {
  50. int retval;
  51. routerlist_t *our_routerlist = NULL;
  52. smartlist_t *our_nodelist = NULL;
  53. /* Read the file that contains our test descriptors. */
  54. /* We need to mock this function otherwise the descriptors will not
  55. accepted as they are too old. */
  56. MOCK(router_descriptor_is_older_than,
  57. router_descriptor_is_older_than_replacement);
  58. /* Load all the test descriptors to the routerlist. */
  59. retval = router_load_routers_from_string(TEST_DESCRIPTORS,
  60. NULL, SAVED_IN_JOURNAL,
  61. NULL, 0, NULL);
  62. tt_int_op(retval, ==, NUMBER_OF_DESCRIPTORS);
  63. /* Sanity checking of routerlist and nodelist. */
  64. our_routerlist = router_get_routerlist();
  65. tt_int_op(smartlist_len(our_routerlist->routers), ==, NUMBER_OF_DESCRIPTORS);
  66. routerlist_assert_ok(our_routerlist);
  67. our_nodelist = nodelist_get_list();
  68. tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
  69. /* Mark all routers as non-guards but up and running! */
  70. SMARTLIST_FOREACH_BEGIN(our_nodelist, node_t *, node) {
  71. node->is_running = 1;
  72. node->is_valid = 1;
  73. node->is_possible_guard = 0;
  74. } SMARTLIST_FOREACH_END(node);
  75. done:
  76. UNMOCK(router_descriptor_is_older_than);
  77. }
  78. /* Unittest cleanup function: Cleanup the fake network. */
  79. static int
  80. fake_network_cleanup(const struct testcase_t *testcase, void *ptr)
  81. {
  82. (void) testcase;
  83. (void) ptr;
  84. routerlist_free_all();
  85. nodelist_free_all();
  86. entry_guards_free_all();
  87. or_state_free(dummy_state);
  88. return 1; /* NOP */
  89. }
  90. /* Unittest setup function: Setup a fake network. */
  91. static void *
  92. fake_network_setup(const struct testcase_t *testcase)
  93. {
  94. (void) testcase;
  95. /* Setup fake state */
  96. dummy_state = tor_malloc_zero(sizeof(or_state_t));
  97. MOCK(get_or_state,
  98. get_or_state_replacement);
  99. /* Setup fake routerlist. */
  100. setup_fake_routerlist();
  101. /* Return anything but NULL (it's interpreted as test fail) */
  102. return dummy_state;
  103. }
  104. /** Test choose_random_entry() with none of our routers being guard nodes. */
  105. static void
  106. test_choose_random_entry_no_guards(void *arg)
  107. {
  108. const node_t *chosen_entry = NULL;
  109. (void) arg;
  110. /* Try to pick an entry even though none of our routers are guards. */
  111. chosen_entry = choose_random_entry(NULL);
  112. /* Unintuitively, we actually pick a random node as our entry,
  113. because router_choose_random_node() relaxes its constraints if it
  114. can't find a proper entry guard. */
  115. test_assert(chosen_entry);
  116. done:
  117. ;
  118. }
  119. /** Test choose_random_entry() with only one of our routers being a
  120. guard node. */
  121. static void
  122. test_choose_random_entry_one_possible_guard(void *arg)
  123. {
  124. const node_t *chosen_entry = NULL;
  125. node_t *the_guard = NULL;
  126. smartlist_t *our_nodelist = NULL;
  127. (void) arg;
  128. /* Set one of the nodes to be a guard. */
  129. our_nodelist = nodelist_get_list();
  130. the_guard = smartlist_get(our_nodelist, 4); /* chosen by fair dice roll */
  131. the_guard->is_possible_guard = 1;
  132. /* Pick an entry. Make sure we pick the node we marked as guard. */
  133. chosen_entry = choose_random_entry(NULL);
  134. tt_ptr_op(chosen_entry, ==, the_guard);
  135. done:
  136. ;
  137. }
  138. /** Helper to conduct tests for populate_live_entry_guards().
  139. This test adds some entry guards to our list, and then tests
  140. populate_live_entry_guards() to mke sure it filters them correctly.
  141. <b>num_needed</b> is the number of guard nodes we support. It's
  142. configurable to make sure we function properly with 1 or 3 guard
  143. nodes configured.
  144. */
  145. static void
  146. populate_live_entry_guards_test_helper(int num_needed)
  147. {
  148. smartlist_t *our_nodelist = NULL;
  149. smartlist_t *live_entry_guards = smartlist_new();
  150. const smartlist_t *all_entry_guards = get_entry_guards();
  151. or_options_t *options = get_options_mutable();
  152. int retval;
  153. /* Set NumEntryGuards to the provided number. */
  154. options->NumEntryGuards = num_needed;
  155. tt_int_op(num_needed, ==, decide_num_guards(options, 0));
  156. /* The global entry guards smartlist should be empty now. */
  157. tt_int_op(smartlist_len(all_entry_guards), ==, 0);
  158. /* Walk the nodelist and add all nodes as entry guards. */
  159. our_nodelist = nodelist_get_list();
  160. tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
  161. SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
  162. const node_t *node_tmp;
  163. node_tmp = add_an_entry_guard(node, 0, 1, 0, 0);
  164. test_assert(node_tmp);
  165. } SMARTLIST_FOREACH_END(node);
  166. /* Make sure the nodes were added as entry guards. */
  167. tt_int_op(smartlist_len(all_entry_guards), ==, NUMBER_OF_DESCRIPTORS);
  168. /* Ensure that all the possible entry guards are enough to satisfy us. */
  169. tt_int_op(smartlist_len(all_entry_guards), >=, num_needed);
  170. /* Walk the entry guard list for some sanity checking */
  171. SMARTLIST_FOREACH_BEGIN(all_entry_guards, const entry_guard_t *, entry) {
  172. /* Since we called add_an_entry_guard() with 'for_discovery' being
  173. False, all guards should have made_contact enabled. */
  174. tt_int_op(entry->made_contact, ==, 1);
  175. /* Since we don't have a routerstatus, all of the entry guards are
  176. not directory servers. */
  177. tt_int_op(entry->is_dir_cache, ==, 0);
  178. } SMARTLIST_FOREACH_END(entry);
  179. /* First, try to get some fast guards. This should fail. */
  180. retval = populate_live_entry_guards(live_entry_guards,
  181. all_entry_guards,
  182. NULL,
  183. NO_DIRINFO, /* Don't care about DIRINFO*/
  184. 0, 0,
  185. 1); /* We want fast guard! */
  186. tt_int_op(retval, ==, 0);
  187. tt_int_op(smartlist_len(live_entry_guards), ==, 0);
  188. /* Now try to get some stable guards. This should fail too. */
  189. retval = populate_live_entry_guards(live_entry_guards,
  190. all_entry_guards,
  191. NULL,
  192. NO_DIRINFO,
  193. 0,
  194. 1, /* We want stable guard! */
  195. 0);
  196. tt_int_op(retval, ==, 0);
  197. tt_int_op(smartlist_len(live_entry_guards), ==, 0);
  198. /* Now try to get any guard we can find. This should succeed. */
  199. retval = populate_live_entry_guards(live_entry_guards,
  200. all_entry_guards,
  201. NULL,
  202. NO_DIRINFO,
  203. 0, 0, 0); /* No restrictions! */
  204. /* Since we had more than enough guards in 'all_entry_guards', we
  205. should have added 'num_needed' of them to live_entry_guards.
  206. 'retval' should be 1 since we now have enough live entry guards
  207. to pick one. */
  208. tt_int_op(retval, ==, 1);
  209. tt_int_op(smartlist_len(live_entry_guards), ==, num_needed);
  210. done:
  211. smartlist_free(live_entry_guards);
  212. }
  213. /* Test populate_live_entry_guards() for 1 guard node. */
  214. static void
  215. test_populate_live_entry_guards_1guard(void *arg)
  216. {
  217. (void) arg;
  218. populate_live_entry_guards_test_helper(1);
  219. }
  220. /* Test populate_live_entry_guards() for 3 guard nodes. */
  221. static void
  222. test_populate_live_entry_guards_3guards(void *arg)
  223. {
  224. (void) arg;
  225. populate_live_entry_guards_test_helper(3);
  226. }
  227. /** Append some EntryGuard lines to the Tor state at <b>state</b>.
  228. <b>entry_guard_lines</b> is a smartlist containing 2-tuple
  229. smartlists that carry the key and values of the statefile.
  230. As an example:
  231. entry_guard_lines =
  232. (("EntryGuard", "name 67E72FF33D7D41BF11C569646A0A7B4B188340DF DirCache"),
  233. ("EntryGuardDownSince", "2014-06-07 16:02:46 2014-06-07 16:02:46"))
  234. */
  235. static void
  236. state_insert_entry_guard_helper(or_state_t *state,
  237. smartlist_t *entry_guard_lines)
  238. {
  239. config_line_t **next, *line;
  240. next = &state->EntryGuards;
  241. *next = NULL;
  242. /* Loop over all the state lines in the smartlist */
  243. SMARTLIST_FOREACH_BEGIN(entry_guard_lines, const smartlist_t *,state_lines) {
  244. /* Get key and value for each line */
  245. const char *state_key = smartlist_get(state_lines, 0);
  246. const char *state_value = smartlist_get(state_lines, 1);
  247. *next = line = tor_malloc_zero(sizeof(config_line_t));
  248. line->key = tor_strdup(state_key);
  249. tor_asprintf(&line->value, "%s", state_value);
  250. next = &(line->next);
  251. } SMARTLIST_FOREACH_END(state_lines);
  252. }
  253. /** Free memory occupied by <b>entry_guard_lines</b>. */
  254. static void
  255. state_lines_free(smartlist_t *entry_guard_lines)
  256. {
  257. SMARTLIST_FOREACH_BEGIN(entry_guard_lines, smartlist_t *, state_lines) {
  258. char *state_key = smartlist_get(state_lines, 0);
  259. char *state_value = smartlist_get(state_lines, 1);
  260. tor_free(state_key);
  261. tor_free(state_value);
  262. smartlist_free(state_lines);
  263. } SMARTLIST_FOREACH_END(state_lines);
  264. smartlist_free(entry_guard_lines);
  265. }
  266. /* Tests entry_guards_parse_state(). It creates a fake Tor state with
  267. a saved entry guard and makes sure that Tor can parse it and
  268. creates the right entry node out of it.
  269. */
  270. static void
  271. test_entry_guards_parse_state_simple(void *arg)
  272. {
  273. or_state_t *state = or_state_new();
  274. const smartlist_t *all_entry_guards = get_entry_guards();
  275. smartlist_t *entry_state_lines = smartlist_new();
  276. char *msg = NULL;
  277. int retval;
  278. /* Details of our fake guard node */
  279. const char *nickname = "hagbard";
  280. const char *fpr = "B29D536DD1752D542E1FBB3C9CE4449D51298212";
  281. const char *tor_version = "0.2.5.3-alpha-dev";
  282. const char *added_at = "2014-05-22 02:40:47";
  283. const char *unlisted_since = "2014-06-08 16:16:50";
  284. (void) arg;
  285. /* The global entry guards smartlist should be empty now. */
  286. tt_int_op(smartlist_len(all_entry_guards), ==, 0);
  287. { /* Prepare the state entry */
  288. /* Prepare the smartlist to hold the key/value of each line */
  289. smartlist_t *state_line = smartlist_new();
  290. smartlist_add_asprintf(state_line, "EntryGuard");
  291. smartlist_add_asprintf(state_line, "%s %s %s", nickname, fpr, "DirCache");
  292. smartlist_add(entry_state_lines, state_line);
  293. state_line = smartlist_new();
  294. smartlist_add_asprintf(state_line, "EntryGuardAddedBy");
  295. smartlist_add_asprintf(state_line, "%s %s %s", fpr, tor_version, added_at);
  296. smartlist_add(entry_state_lines, state_line);
  297. state_line = smartlist_new();
  298. smartlist_add_asprintf(state_line, "EntryGuardUnlistedSince");
  299. smartlist_add_asprintf(state_line, "%s", unlisted_since);
  300. smartlist_add(entry_state_lines, state_line);
  301. }
  302. /* Inject our lines in the state */
  303. state_insert_entry_guard_helper(state, entry_state_lines);
  304. /* Parse state */
  305. retval = entry_guards_parse_state(state, 1, &msg);
  306. tt_int_op(retval, >=, 0);
  307. /* Test that the guard was registered.
  308. We need to re-get the entry guard list since its pointer was
  309. overwritten in entry_guards_parse_state(). */
  310. all_entry_guards = get_entry_guards();
  311. tt_int_op(smartlist_len(all_entry_guards), ==, 1);
  312. { /* Test the entry guard structure */
  313. char hex_digest[1024];
  314. char str_time[1024];
  315. const entry_guard_t *e = smartlist_get(all_entry_guards, 0);
  316. tt_str_op(e->nickname, ==, nickname); /* Verify nickname */
  317. base16_encode(hex_digest, sizeof(hex_digest),
  318. e->identity, DIGEST_LEN);
  319. tt_str_op(hex_digest, ==, fpr); /* Verify fingerprint */
  320. tt_assert(e->is_dir_cache); /* Verify dirness */
  321. tt_str_op(e->chosen_by_version, ==, tor_version); /* Verify tor version */
  322. tt_assert(e->made_contact); /* All saved guards have been contacted */
  323. tt_assert(e->bad_since); /* Verify bad_since timestamp */
  324. format_iso_time(str_time, e->bad_since);
  325. tt_str_op(str_time, ==, unlisted_since);
  326. /* The rest should be unset */
  327. tt_assert(!e->unreachable_since);
  328. tt_assert(!e->can_retry);
  329. tt_assert(!e->path_bias_noticed);
  330. tt_assert(!e->path_bias_warned);
  331. tt_assert(!e->path_bias_extreme);
  332. tt_assert(!e->path_bias_disabled);
  333. tt_assert(!e->path_bias_use_noticed);
  334. tt_assert(!e->path_bias_use_extreme);
  335. tt_assert(!e->last_attempted);
  336. }
  337. done:
  338. state_lines_free(entry_state_lines);
  339. or_state_free(state);
  340. }
  341. /** Similar to test_entry_guards_parse_state_simple() but aims to test
  342. the PathBias-related details of the entry guard. */
  343. static void
  344. test_entry_guards_parse_state_pathbias(void *arg)
  345. {
  346. or_state_t *state = or_state_new();
  347. const smartlist_t *all_entry_guards = get_entry_guards();
  348. char *msg = NULL;
  349. int retval;
  350. smartlist_t *entry_state_lines = smartlist_new();
  351. /* Path bias details of the fake guard */
  352. const double circ_attempts = 9;
  353. const double circ_successes = 8;
  354. const double successful_closed = 4;
  355. const double collapsed = 2;
  356. const double unusable = 0;
  357. const double timeouts = 1;
  358. (void) arg;
  359. /* The global entry guards smartlist should be empty now. */
  360. tt_int_op(smartlist_len(all_entry_guards), ==, 0);
  361. { /* Prepare the state entry */
  362. /* Prepare the smartlist to hold the key/value of each line */
  363. smartlist_t *state_line = smartlist_new();
  364. smartlist_add_asprintf(state_line, "EntryGuard");
  365. smartlist_add_asprintf(state_line,
  366. "givethanks B29D536DD1752D542E1FBB3C9CE4449D51298212 NoDirCache");
  367. smartlist_add(entry_state_lines, state_line);
  368. state_line = smartlist_new();
  369. smartlist_add_asprintf(state_line, "EntryGuardAddedBy");
  370. smartlist_add_asprintf(state_line,
  371. "B29D536DD1752D542E1FBB3C9CE4449D51298212 0.2.5.3-alpha-dev "
  372. "2014-05-22 02:40:47");
  373. smartlist_add(entry_state_lines, state_line);
  374. state_line = smartlist_new();
  375. smartlist_add_asprintf(state_line, "EntryGuardUnlistedSince");
  376. smartlist_add_asprintf(state_line, "2014-06-08 16:16:50");
  377. smartlist_add(entry_state_lines, state_line);
  378. state_line = smartlist_new();
  379. smartlist_add_asprintf(state_line, "EntryGuardPathBias");
  380. smartlist_add_asprintf(state_line, "%f %f %f %f %f %f",
  381. circ_attempts, circ_successes, successful_closed,
  382. collapsed, unusable, timeouts);
  383. smartlist_add(entry_state_lines, state_line);
  384. }
  385. /* Inject our lines in the state */
  386. state_insert_entry_guard_helper(state, entry_state_lines);
  387. /* Parse state */
  388. retval = entry_guards_parse_state(state, 1, &msg);
  389. tt_int_op(retval, >=, 0);
  390. /* Test that the guard was registered */
  391. all_entry_guards = get_entry_guards();
  392. tt_int_op(smartlist_len(all_entry_guards), ==, 1);
  393. { /* Test the path bias of this guard */
  394. const entry_guard_t *e = smartlist_get(all_entry_guards, 0);
  395. tt_assert(!e->is_dir_cache);
  396. tt_assert(!e->can_retry);
  397. /* XXX tt_double_op doesn't support equality. Cast to int for now. */
  398. tt_int_op((int)e->circ_attempts, ==, (int)circ_attempts);
  399. tt_int_op((int)e->circ_successes, ==, (int)circ_successes);
  400. tt_int_op((int)e->successful_circuits_closed, ==, (int)successful_closed);
  401. tt_int_op((int)e->timeouts, ==, (int)timeouts);
  402. tt_int_op((int)e->collapsed_circuits, ==, (int)collapsed);
  403. tt_int_op((int)e->unusable_circuits, ==, (int)unusable);
  404. }
  405. done:
  406. or_state_free(state);
  407. state_lines_free(entry_state_lines);
  408. }
  409. /* Simple test of entry_guards_set_from_config() by specifying a
  410. particular EntryNode and making sure it gets picked. */
  411. static void
  412. test_entry_guards_set_from_config(void *arg)
  413. {
  414. or_options_t *options = get_options_mutable();
  415. const smartlist_t *all_entry_guards = get_entry_guards();
  416. const char *entrynodes_str = "test003r";
  417. const node_t *chosen_entry = NULL;
  418. int retval;
  419. (void) arg;
  420. /* Prase EntryNodes as a routerset. */
  421. options->EntryNodes = routerset_new();
  422. retval = routerset_parse(options->EntryNodes,
  423. entrynodes_str,
  424. "test_entrynodes");
  425. tt_int_op(retval, >=, 0);
  426. /* Read nodes from EntryNodes */
  427. entry_guards_set_from_config(options);
  428. /* Test that only one guard was added. */
  429. tt_int_op(smartlist_len(all_entry_guards), ==, 1);
  430. /* Make sure it was the guard we specified. */
  431. chosen_entry = choose_random_entry(NULL);
  432. tt_str_op(chosen_entry->ri->nickname, ==, entrynodes_str);
  433. done:
  434. routerset_free(options->EntryNodes);
  435. }
  436. /** XXX Do some tests that entry_is_live() */
  437. static void
  438. test_entry_is_live(void *arg)
  439. {
  440. smartlist_t *our_nodelist = NULL;
  441. const smartlist_t *all_entry_guards = get_entry_guards();
  442. const node_t *test_node = NULL;
  443. const entry_guard_t *test_entry = NULL;
  444. const char *msg;
  445. int which_node;
  446. (void) arg;
  447. /* The global entry guards smartlist should be empty now. */
  448. tt_int_op(smartlist_len(all_entry_guards), ==, 0);
  449. /* Walk the nodelist and add all nodes as entry guards. */
  450. our_nodelist = nodelist_get_list();
  451. tt_int_op(smartlist_len(our_nodelist), ==, NUMBER_OF_DESCRIPTORS);
  452. SMARTLIST_FOREACH_BEGIN(our_nodelist, const node_t *, node) {
  453. const node_t *node_tmp;
  454. node_tmp = add_an_entry_guard(node, 0, 1, 0, 0);
  455. test_assert(node_tmp);
  456. tt_int_op(node->is_stable, ==, 0);
  457. tt_int_op(node->is_fast, ==, 0);
  458. } SMARTLIST_FOREACH_END(node);
  459. /* Make sure the nodes were added as entry guards. */
  460. tt_int_op(smartlist_len(all_entry_guards), ==, NUMBER_OF_DESCRIPTORS);
  461. /* Now get a random test entry that we will use for this unit test. */
  462. which_node = 3; /* (chosen by fair dice roll) */
  463. test_entry = smartlist_get(all_entry_guards, which_node);
  464. /* Let's do some entry_is_live() tests! */
  465. /* Require the node to be stable, but it's not. Should fail.
  466. Also enable 'assume_reachable' because why not. */
  467. test_node = entry_is_live(test_entry,
  468. ENTRY_NEED_UPTIME | ENTRY_ASSUME_REACHABLE,
  469. &msg);
  470. test_assert(!test_node);
  471. /* Require the node to be fast, but it's not. Should fail. */
  472. test_node = entry_is_live(test_entry,
  473. ENTRY_NEED_CAPACITY | ENTRY_ASSUME_REACHABLE,
  474. &msg);
  475. test_assert(!test_node);
  476. /* Don't impose any restrictions on the node. Should succeed. */
  477. test_node = entry_is_live(test_entry, 0, &msg);
  478. test_assert(test_node);
  479. tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
  480. /* Require descriptor for this node. It has one so it should succeed. */
  481. test_node = entry_is_live(test_entry, ENTRY_NEED_DESCRIPTOR, &msg);
  482. test_assert(test_node);
  483. tt_ptr_op(test_node, ==, node_get_by_id(test_entry->identity));
  484. done:
  485. ; /* XXX */
  486. }
  487. static const struct testcase_setup_t fake_network = {
  488. fake_network_setup, fake_network_cleanup
  489. };
  490. struct testcase_t entrynodes_tests[] = {
  491. { "choose_random_entry_no_guards", test_choose_random_entry_no_guards,
  492. TT_FORK, &fake_network, NULL },
  493. { "choose_random_entry_one_possibleguard",
  494. test_choose_random_entry_one_possible_guard,
  495. TT_FORK, &fake_network, NULL },
  496. { "populate_live_entry_guards_1guard",
  497. test_populate_live_entry_guards_1guard,
  498. TT_FORK, &fake_network, NULL },
  499. { "populate_live_entry_guards_3guards",
  500. test_populate_live_entry_guards_3guards,
  501. TT_FORK, &fake_network, NULL },
  502. { "entry_guards_parse_state_simple",
  503. test_entry_guards_parse_state_simple,
  504. TT_FORK, &fake_network, NULL },
  505. { "entry_guards_parse_state_pathbias",
  506. test_entry_guards_parse_state_pathbias,
  507. TT_FORK, &fake_network, NULL },
  508. { "entry_guards_set_from_config",
  509. test_entry_guards_set_from_config,
  510. TT_FORK, &fake_network, NULL },
  511. { "entry_is_live",
  512. test_entry_is_live,
  513. TT_FORK, &fake_network, NULL },
  514. END_OF_TESTCASES
  515. };