test_entrynodes.c 21 KB

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