test_hs_cache.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /* Copyright (c) 2016-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file test_hs_cache.c
  5. * \brief Test hidden service caches.
  6. */
  7. #define CONNECTION_PRIVATE
  8. #define DIRCACHE_PRIVATE
  9. #define DIRCLIENT_PRIVATE
  10. #define HS_CACHE_PRIVATE
  11. #define TOR_CHANNEL_INTERNAL_
  12. #include "trunnel/ed25519_cert.h"
  13. #include "feature/hs/hs_cache.h"
  14. #include "feature/rend/rendcache.h"
  15. #include "feature/dircache/dircache.h"
  16. #include "feature/dirclient/dirclient.h"
  17. #include "feature/nodelist/networkstatus.h"
  18. #include "core/mainloop/connection.h"
  19. #include "core/proto/proto_http.h"
  20. #include "lib/crypt_ops/crypto_format.h"
  21. #include "core/or/circuitlist.h"
  22. #include "core/or/channel.h"
  23. #include "core/or/edge_connection_st.h"
  24. #include "core/or/or_circuit_st.h"
  25. #include "core/or/or_connection_st.h"
  26. #include "feature/dircommon/dir_connection_st.h"
  27. #include "feature/nodelist/networkstatus_st.h"
  28. #include "test/hs_test_helpers.h"
  29. #include "test/test_helpers.h"
  30. #include "test/test.h"
  31. /* Static variable used to encoded the HSDir query. */
  32. static char query_b64[256];
  33. /* Build an HSDir query using a ed25519 public key. */
  34. static const char *
  35. helper_get_hsdir_query(const hs_descriptor_t *desc)
  36. {
  37. ed25519_public_to_base64(query_b64, &desc->plaintext_data.blinded_pubkey);
  38. return query_b64;
  39. }
  40. static void
  41. init_test(void)
  42. {
  43. /* Always needed. Initialize the subsystem. */
  44. hs_cache_init();
  45. /* We need the v2 cache since our OOM and cache cleanup does poke at it. */
  46. rend_cache_init();
  47. }
  48. static void
  49. test_directory(void *arg)
  50. {
  51. int ret;
  52. size_t oom_size;
  53. char *desc1_str = NULL;
  54. const char *desc_out;
  55. ed25519_keypair_t signing_kp1;
  56. hs_descriptor_t *desc1 = NULL;
  57. (void) arg;
  58. init_test();
  59. /* Generate a valid descriptor with normal values. */
  60. ret = ed25519_keypair_generate(&signing_kp1, 0);
  61. tt_int_op(ret, OP_EQ, 0);
  62. desc1 = hs_helper_build_hs_desc_with_ip(&signing_kp1);
  63. tt_assert(desc1);
  64. ret = hs_desc_encode_descriptor(desc1, &signing_kp1, NULL, &desc1_str);
  65. tt_int_op(ret, OP_EQ, 0);
  66. /* Very first basic test, should be able to be stored, survive a
  67. * clean, found with a lookup and then cleaned by our OOM. */
  68. {
  69. ret = hs_cache_store_as_dir(desc1_str);
  70. tt_int_op(ret, OP_EQ, 0);
  71. /* Re-add, it should fail since we already have it. */
  72. ret = hs_cache_store_as_dir(desc1_str);
  73. tt_int_op(ret, OP_EQ, -1);
  74. /* Try to clean now which should be fine, there is at worst few seconds
  75. * between the store and this call. */
  76. hs_cache_clean_as_dir(time(NULL));
  77. /* We should find it in our cache. */
  78. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
  79. tt_int_op(ret, OP_EQ, 1);
  80. tt_str_op(desc_out, OP_EQ, desc1_str);
  81. /* Tell our OOM to run and to at least remove a byte which will result in
  82. * removing the descriptor from our cache. */
  83. oom_size = hs_cache_handle_oom(time(NULL), 1);
  84. tt_int_op(oom_size, OP_GE, 1);
  85. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), NULL);
  86. tt_int_op(ret, OP_EQ, 0);
  87. }
  88. /* Store two descriptors and remove the expiring one only. */
  89. {
  90. ed25519_keypair_t signing_kp_zero;
  91. ret = ed25519_keypair_generate(&signing_kp_zero, 0);
  92. tt_int_op(ret, OP_EQ, 0);
  93. hs_descriptor_t *desc_zero_lifetime;
  94. desc_zero_lifetime = hs_helper_build_hs_desc_with_ip(&signing_kp_zero);
  95. tt_assert(desc_zero_lifetime);
  96. desc_zero_lifetime->plaintext_data.revision_counter = 1;
  97. desc_zero_lifetime->plaintext_data.lifetime_sec = 0;
  98. char *desc_zero_lifetime_str;
  99. ret = hs_desc_encode_descriptor(desc_zero_lifetime, &signing_kp_zero,
  100. NULL, &desc_zero_lifetime_str);
  101. tt_int_op(ret, OP_EQ, 0);
  102. ret = hs_cache_store_as_dir(desc1_str);
  103. tt_int_op(ret, OP_EQ, 0);
  104. ret = hs_cache_store_as_dir(desc_zero_lifetime_str);
  105. tt_int_op(ret, OP_EQ, 0);
  106. /* This one should clear out our zero lifetime desc. */
  107. hs_cache_clean_as_dir(time(NULL));
  108. /* We should find desc1 in our cache. */
  109. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
  110. tt_int_op(ret, OP_EQ, 1);
  111. tt_str_op(desc_out, OP_EQ, desc1_str);
  112. /* We should NOT find our zero lifetime desc in our cache. */
  113. ret = hs_cache_lookup_as_dir(3,
  114. helper_get_hsdir_query(desc_zero_lifetime),
  115. NULL);
  116. tt_int_op(ret, OP_EQ, 0);
  117. /* Cleanup our entire cache. */
  118. oom_size = hs_cache_handle_oom(time(NULL), 1);
  119. tt_int_op(oom_size, OP_GE, 1);
  120. hs_descriptor_free(desc_zero_lifetime);
  121. tor_free(desc_zero_lifetime_str);
  122. }
  123. /* Throw junk at it. */
  124. {
  125. ret = hs_cache_store_as_dir("blah");
  126. tt_int_op(ret, OP_EQ, -1);
  127. /* Poor attempt at tricking the decoding. */
  128. ret = hs_cache_store_as_dir("hs-descriptor 3\nJUNK");
  129. tt_int_op(ret, OP_EQ, -1);
  130. /* Undecodable base64 query. */
  131. ret = hs_cache_lookup_as_dir(3, "blah", NULL);
  132. tt_int_op(ret, OP_EQ, -1);
  133. /* Decodable base64 query but wrong ed25519 size. */
  134. ret = hs_cache_lookup_as_dir(3, "dW5pY29ybg==", NULL);
  135. tt_int_op(ret, OP_EQ, -1);
  136. }
  137. /* Test descriptor replacement with revision counter. */
  138. {
  139. char *new_desc_str;
  140. /* Add a descriptor. */
  141. ret = hs_cache_store_as_dir(desc1_str);
  142. tt_int_op(ret, OP_EQ, 0);
  143. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
  144. tt_int_op(ret, OP_EQ, 1);
  145. /* Bump revision counter. */
  146. desc1->plaintext_data.revision_counter++;
  147. ret = hs_desc_encode_descriptor(desc1, &signing_kp1, NULL, &new_desc_str);
  148. tt_int_op(ret, OP_EQ, 0);
  149. ret = hs_cache_store_as_dir(new_desc_str);
  150. tt_int_op(ret, OP_EQ, 0);
  151. /* Look it up, it should have been replaced. */
  152. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), &desc_out);
  153. tt_int_op(ret, OP_EQ, 1);
  154. tt_str_op(desc_out, OP_EQ, new_desc_str);
  155. tor_free(new_desc_str);
  156. }
  157. done:
  158. hs_descriptor_free(desc1);
  159. tor_free(desc1_str);
  160. }
  161. static void
  162. test_clean_as_dir(void *arg)
  163. {
  164. size_t ret;
  165. char *desc1_str = NULL;
  166. time_t now = time(NULL);
  167. hs_descriptor_t *desc1 = NULL;
  168. ed25519_keypair_t signing_kp1;
  169. (void) arg;
  170. init_test();
  171. /* Generate a valid descriptor with values. */
  172. ret = ed25519_keypair_generate(&signing_kp1, 0);
  173. tt_int_op(ret, OP_EQ, 0);
  174. desc1 = hs_helper_build_hs_desc_with_ip(&signing_kp1);
  175. tt_assert(desc1);
  176. ret = hs_desc_encode_descriptor(desc1, &signing_kp1, NULL, &desc1_str);
  177. tt_int_op(ret, OP_EQ, 0);
  178. ret = hs_cache_store_as_dir(desc1_str);
  179. tt_int_op(ret, OP_EQ, 0);
  180. /* With the lifetime being 3 hours, a cleanup shouldn't remove it. */
  181. ret = cache_clean_v3_as_dir(now, 0);
  182. tt_int_op(ret, OP_EQ, 0);
  183. /* Should be present after clean up. */
  184. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), NULL);
  185. tt_int_op(ret, OP_EQ, 1);
  186. /* Set a cutoff 100 seconds in the past. It should not remove the entry
  187. * since the entry is still recent enough. */
  188. ret = cache_clean_v3_as_dir(now, now - 100);
  189. tt_int_op(ret, OP_EQ, 0);
  190. /* Should be present after clean up. */
  191. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), NULL);
  192. tt_int_op(ret, OP_EQ, 1);
  193. /* Set a cutoff of 100 seconds in the future. It should remove the entry
  194. * that we've just added since it's not too old for the cutoff. */
  195. ret = cache_clean_v3_as_dir(now, now + 100);
  196. tt_int_op(ret, OP_GT, 0);
  197. /* Shouldn't be present after clean up. */
  198. ret = hs_cache_lookup_as_dir(3, helper_get_hsdir_query(desc1), NULL);
  199. tt_int_op(ret, OP_EQ, 0);
  200. done:
  201. hs_descriptor_free(desc1);
  202. tor_free(desc1_str);
  203. }
  204. /* Test helper: Fetch an HS descriptor from an HSDir (for the hidden service
  205. with <b>blinded_key</b>. Return the received descriptor string. */
  206. static char *
  207. helper_fetch_desc_from_hsdir(const ed25519_public_key_t *blinded_key)
  208. {
  209. int retval;
  210. char *received_desc = NULL;
  211. char *hsdir_query_str = NULL;
  212. /* The dir conn we are going to simulate */
  213. dir_connection_t *conn = NULL;
  214. edge_connection_t *edge_conn = NULL;
  215. or_circuit_t *or_circ = NULL;
  216. /* First extract the blinded public key that we are going to use in our
  217. query, and then build the actual query string. */
  218. {
  219. char hsdir_cache_key[ED25519_BASE64_LEN+1];
  220. ed25519_public_to_base64(hsdir_cache_key, blinded_key);
  221. tor_asprintf(&hsdir_query_str, GET("/tor/hs/3/%s"), hsdir_cache_key);
  222. }
  223. /* Simulate an HTTP GET request to the HSDir */
  224. conn = dir_connection_new(AF_INET);
  225. tt_assert(conn);
  226. TO_CONN(conn)->linked = 1; /* Signal that it is encrypted. */
  227. tor_addr_from_ipv4h(&conn->base_.addr, 0x7f000001);
  228. /* Pretend this conn is anonymous. */
  229. edge_conn = edge_connection_new(CONN_TYPE_EXIT, AF_INET);
  230. TO_CONN(conn)->linked_conn = TO_CONN(edge_conn);
  231. or_circ = or_circuit_new(0, NULL);
  232. or_circ->p_chan = tor_malloc_zero(sizeof(channel_t));
  233. edge_conn->on_circuit = TO_CIRCUIT(or_circ);
  234. retval = directory_handle_command_get(conn, hsdir_query_str,
  235. NULL, 0);
  236. tt_int_op(retval, OP_EQ, 0);
  237. /* Read the descriptor that the HSDir just served us */
  238. {
  239. char *headers = NULL;
  240. size_t body_used = 0;
  241. fetch_from_buf_http(TO_CONN(conn)->outbuf, &headers, MAX_HEADERS_SIZE,
  242. &received_desc, &body_used, HS_DESC_MAX_LEN, 0);
  243. tor_free(headers);
  244. }
  245. done:
  246. tor_free(hsdir_query_str);
  247. if (conn) {
  248. tor_free(or_circ->p_chan);
  249. connection_free_minimal(TO_CONN(conn)->linked_conn);
  250. connection_free_minimal(TO_CONN(conn));
  251. }
  252. return received_desc;
  253. }
  254. /* Publish a descriptor to the HSDir, then fetch it. Check that the received
  255. descriptor matches the published one. */
  256. static void
  257. test_upload_and_download_hs_desc(void *arg)
  258. {
  259. int retval;
  260. hs_descriptor_t *published_desc = NULL;
  261. char *published_desc_str = NULL;
  262. char *received_desc_str = NULL;
  263. (void) arg;
  264. /* Initialize HSDir cache subsystem */
  265. init_test();
  266. /* Test a descriptor not found in the directory cache. */
  267. {
  268. ed25519_public_key_t blinded_key;
  269. memset(&blinded_key.pubkey, 'A', sizeof(blinded_key.pubkey));
  270. received_desc_str = helper_fetch_desc_from_hsdir(&blinded_key);
  271. tt_int_op(strlen(received_desc_str), OP_EQ, 0);
  272. tor_free(received_desc_str);
  273. }
  274. /* Generate a valid descriptor with normal values. */
  275. {
  276. ed25519_keypair_t signing_kp;
  277. retval = ed25519_keypair_generate(&signing_kp, 0);
  278. tt_int_op(retval, OP_EQ, 0);
  279. published_desc = hs_helper_build_hs_desc_with_ip(&signing_kp);
  280. tt_assert(published_desc);
  281. retval = hs_desc_encode_descriptor(published_desc, &signing_kp,
  282. NULL, &published_desc_str);
  283. tt_int_op(retval, OP_EQ, 0);
  284. }
  285. /* Publish descriptor to the HSDir */
  286. {
  287. retval = handle_post_hs_descriptor("/tor/hs/3/publish",published_desc_str);
  288. tt_int_op(retval, OP_EQ, 200);
  289. }
  290. /* Simulate a fetch of the previously published descriptor */
  291. {
  292. const ed25519_public_key_t *blinded_key;
  293. blinded_key = &published_desc->plaintext_data.blinded_pubkey;
  294. received_desc_str = helper_fetch_desc_from_hsdir(blinded_key);
  295. }
  296. /* Verify we received the exact same descriptor we published earlier */
  297. tt_str_op(received_desc_str, OP_EQ, published_desc_str);
  298. tor_free(received_desc_str);
  299. /* With a valid descriptor in the directory cache, try again an invalid. */
  300. {
  301. ed25519_public_key_t blinded_key;
  302. memset(&blinded_key.pubkey, 'A', sizeof(blinded_key.pubkey));
  303. received_desc_str = helper_fetch_desc_from_hsdir(&blinded_key);
  304. tt_int_op(strlen(received_desc_str), OP_EQ, 0);
  305. }
  306. done:
  307. tor_free(received_desc_str);
  308. tor_free(published_desc_str);
  309. hs_descriptor_free(published_desc);
  310. }
  311. /* Test that HSDirs reject outdated descriptors based on their revision
  312. * counter. Also test that HSDirs correctly replace old descriptors with newer
  313. * descriptors. */
  314. static void
  315. test_hsdir_revision_counter_check(void *arg)
  316. {
  317. int retval;
  318. ed25519_keypair_t signing_kp;
  319. hs_descriptor_t *published_desc = NULL;
  320. char *published_desc_str = NULL;
  321. uint8_t subcredential[DIGEST256_LEN];
  322. char *received_desc_str = NULL;
  323. hs_descriptor_t *received_desc = NULL;
  324. (void) arg;
  325. /* Initialize HSDir cache subsystem */
  326. init_test();
  327. /* Generate a valid descriptor with normal values. */
  328. {
  329. retval = ed25519_keypair_generate(&signing_kp, 0);
  330. tt_int_op(retval, OP_EQ, 0);
  331. published_desc = hs_helper_build_hs_desc_with_ip(&signing_kp);
  332. tt_assert(published_desc);
  333. retval = hs_desc_encode_descriptor(published_desc, &signing_kp,
  334. NULL, &published_desc_str);
  335. tt_int_op(retval, OP_EQ, 0);
  336. }
  337. /* Publish descriptor to the HSDir */
  338. {
  339. retval = handle_post_hs_descriptor("/tor/hs/3/publish",published_desc_str);
  340. tt_int_op(retval, OP_EQ, 200);
  341. }
  342. /* Try publishing again with the same revision counter: Should fail. */
  343. {
  344. retval = handle_post_hs_descriptor("/tor/hs/3/publish",published_desc_str);
  345. tt_int_op(retval, OP_EQ, 400);
  346. }
  347. /* Fetch the published descriptor and validate the revision counter. */
  348. {
  349. const ed25519_public_key_t *blinded_key;
  350. blinded_key = &published_desc->plaintext_data.blinded_pubkey;
  351. hs_get_subcredential(&signing_kp.pubkey, blinded_key, subcredential);
  352. received_desc_str = helper_fetch_desc_from_hsdir(blinded_key);
  353. retval = hs_desc_decode_descriptor(received_desc_str,
  354. subcredential, NULL, &received_desc);
  355. tt_int_op(retval, OP_EQ, 0);
  356. tt_assert(received_desc);
  357. /* Check that the revision counter is correct */
  358. tt_u64_op(received_desc->plaintext_data.revision_counter, OP_EQ, 42);
  359. hs_descriptor_free(received_desc);
  360. received_desc = NULL;
  361. tor_free(received_desc_str);
  362. }
  363. /* Increment the revision counter and try again. Should work. */
  364. {
  365. published_desc->plaintext_data.revision_counter = 1313;
  366. tor_free(published_desc_str);
  367. retval = hs_desc_encode_descriptor(published_desc, &signing_kp,
  368. NULL, &published_desc_str);
  369. tt_int_op(retval, OP_EQ, 0);
  370. retval = handle_post_hs_descriptor("/tor/hs/3/publish",published_desc_str);
  371. tt_int_op(retval, OP_EQ, 200);
  372. }
  373. /* Again, fetch the published descriptor and perform the revision counter
  374. validation. The revision counter must have changed. */
  375. {
  376. const ed25519_public_key_t *blinded_key;
  377. blinded_key = &published_desc->plaintext_data.blinded_pubkey;
  378. received_desc_str = helper_fetch_desc_from_hsdir(blinded_key);
  379. retval = hs_desc_decode_descriptor(received_desc_str,
  380. subcredential, NULL, &received_desc);
  381. tt_int_op(retval, OP_EQ, 0);
  382. tt_assert(received_desc);
  383. /* Check that the revision counter is the latest */
  384. tt_u64_op(received_desc->plaintext_data.revision_counter, OP_EQ, 1313);
  385. }
  386. done:
  387. hs_descriptor_free(published_desc);
  388. hs_descriptor_free(received_desc);
  389. tor_free(received_desc_str);
  390. tor_free(published_desc_str);
  391. }
  392. static networkstatus_t mock_ns;
  393. static networkstatus_t *
  394. mock_networkstatus_get_live_consensus(time_t now)
  395. {
  396. (void) now;
  397. return &mock_ns;
  398. }
  399. /** Test that we can store HS descriptors in the client HS cache. */
  400. static void
  401. test_client_cache(void *arg)
  402. {
  403. int retval;
  404. ed25519_keypair_t signing_kp;
  405. hs_descriptor_t *published_desc = NULL;
  406. char *published_desc_str = NULL;
  407. uint8_t wanted_subcredential[DIGEST256_LEN];
  408. response_handler_args_t *args = NULL;
  409. dir_connection_t *conn = NULL;
  410. (void) arg;
  411. /* Initialize HSDir cache subsystem */
  412. init_test();
  413. MOCK(networkstatus_get_live_consensus,
  414. mock_networkstatus_get_live_consensus);
  415. /* Set consensus time */
  416. parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
  417. &mock_ns.valid_after);
  418. parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
  419. &mock_ns.fresh_until);
  420. parse_rfc1123_time("Sat, 26 Oct 1985 16:00:00 UTC",
  421. &mock_ns.valid_until);
  422. /* Generate a valid descriptor with normal values. */
  423. {
  424. retval = ed25519_keypair_generate(&signing_kp, 0);
  425. tt_int_op(retval, OP_EQ, 0);
  426. published_desc = hs_helper_build_hs_desc_with_ip(&signing_kp);
  427. tt_assert(published_desc);
  428. retval = hs_desc_encode_descriptor(published_desc, &signing_kp,
  429. NULL, &published_desc_str);
  430. tt_int_op(retval, OP_EQ, 0);
  431. memcpy(wanted_subcredential, published_desc->subcredential, DIGEST256_LEN);
  432. tt_assert(!fast_mem_is_zero((char*)wanted_subcredential, DIGEST256_LEN));
  433. }
  434. /* Test handle_response_fetch_hsdesc_v3() */
  435. {
  436. args = tor_malloc_zero(sizeof(response_handler_args_t));
  437. args->status_code = 200;
  438. args->reason = NULL;
  439. args->body = published_desc_str;
  440. args->body_len = strlen(published_desc_str);
  441. conn = tor_malloc_zero(sizeof(dir_connection_t));
  442. conn->hs_ident = tor_malloc_zero(sizeof(hs_ident_dir_conn_t));
  443. ed25519_pubkey_copy(&conn->hs_ident->identity_pk, &signing_kp.pubkey);
  444. }
  445. /* store the descriptor! */
  446. retval = handle_response_fetch_hsdesc_v3(conn, args);
  447. tt_int_op(retval, == , 0);
  448. /* Progress time a bit and attempt to clean cache: our desc should not be
  449. * cleaned since we still in the same TP. */
  450. {
  451. parse_rfc1123_time("Sat, 27 Oct 1985 02:00:00 UTC",
  452. &mock_ns.valid_after);
  453. parse_rfc1123_time("Sat, 27 Oct 1985 03:00:00 UTC",
  454. &mock_ns.fresh_until);
  455. parse_rfc1123_time("Sat, 27 Oct 1985 05:00:00 UTC",
  456. &mock_ns.valid_until);
  457. /* fetch the descriptor and make sure it's there */
  458. const hs_descriptor_t *cached_desc = NULL;
  459. cached_desc = hs_cache_lookup_as_client(&signing_kp.pubkey);
  460. tt_assert(cached_desc);
  461. tt_mem_op(cached_desc->subcredential, OP_EQ, wanted_subcredential,
  462. DIGEST256_LEN);
  463. }
  464. /* Progress time to next TP and check that desc was cleaned */
  465. {
  466. parse_rfc1123_time("Sat, 27 Oct 1985 12:00:00 UTC",
  467. &mock_ns.valid_after);
  468. parse_rfc1123_time("Sat, 27 Oct 1985 13:00:00 UTC",
  469. &mock_ns.fresh_until);
  470. parse_rfc1123_time("Sat, 27 Oct 1985 15:00:00 UTC",
  471. &mock_ns.valid_until);
  472. const hs_descriptor_t *cached_desc = NULL;
  473. cached_desc = hs_cache_lookup_as_client(&signing_kp.pubkey);
  474. tt_assert(!cached_desc);
  475. }
  476. done:
  477. tor_free(args);
  478. hs_descriptor_free(published_desc);
  479. tor_free(published_desc_str);
  480. if (conn) {
  481. tor_free(conn->hs_ident);
  482. tor_free(conn);
  483. }
  484. }
  485. struct testcase_t hs_cache[] = {
  486. /* Encoding tests. */
  487. { "directory", test_directory, TT_FORK,
  488. NULL, NULL },
  489. { "clean_as_dir", test_clean_as_dir, TT_FORK,
  490. NULL, NULL },
  491. { "hsdir_revision_counter_check", test_hsdir_revision_counter_check, TT_FORK,
  492. NULL, NULL },
  493. { "upload_and_download_hs_desc", test_upload_and_download_hs_desc, TT_FORK,
  494. NULL, NULL },
  495. { "client_cache", test_client_cache, TT_FORK,
  496. NULL, NULL },
  497. END_OF_TESTCASES
  498. };