rip out hid_serv_acting_as_directory()
[tor.git] / src / test / test_rendcache.c
blob3ccfe5f9bc9c99effcb16b60e80b884d20d95ba2
1 /* Copyright (c) 2010-2016, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
4 #include "orconfig.h"
5 #include "or.h"
7 #include "test.h"
8 #define RENDCACHE_PRIVATE
9 #include "rendcache.h"
10 #include "router.h"
11 #include "routerlist.h"
12 #include "config.h"
13 #include <openssl/rsa.h>
14 #include "rend_test_helpers.h"
16 #define NS_MODULE rend_cache
18 static const int RECENT_TIME = -10;
19 static const int TIME_IN_THE_PAST = -(REND_CACHE_MAX_AGE + \
20 REND_CACHE_MAX_SKEW + 10);
21 static const int TIME_IN_THE_FUTURE = REND_CACHE_MAX_SKEW + 10;
23 extern strmap_t *rend_cache;
24 extern digestmap_t *rend_cache_v2_dir;
25 extern strmap_t *rend_cache_failure;
26 extern size_t rend_cache_total_allocation;
28 static rend_data_t *
29 mock_rend_data(const char *onion_address)
31 rend_data_t *rend_query = tor_malloc_zero(sizeof(rend_data_t));
33 strlcpy(rend_query->onion_address, onion_address,
34 sizeof(rend_query->onion_address));
35 rend_query->auth_type = REND_NO_AUTH;
36 rend_query->hsdirs_fp = smartlist_new();
37 smartlist_add(rend_query->hsdirs_fp, tor_memdup("aaaaaaaaaaaaaaaaaaaaaaaa",
38 DIGEST_LEN));
40 return rend_query;
43 static void
44 test_rend_cache_lookup_entry(void *data)
46 int ret;
47 rend_data_t *mock_rend_query = NULL;
48 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
49 rend_cache_entry_t *entry = NULL;
50 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
51 char *service_id = NULL;
52 (void)data;
54 rend_cache_init();
56 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
58 ret = rend_cache_lookup_entry("abababababababab", 0, NULL);
59 tt_int_op(ret, OP_EQ, -ENOENT);
61 ret = rend_cache_lookup_entry("invalid query", 2, NULL);
62 tt_int_op(ret, OP_EQ, -EINVAL);
64 ret = rend_cache_lookup_entry("abababababababab", 2, NULL);
65 tt_int_op(ret, OP_EQ, -ENOENT);
67 ret = rend_cache_lookup_entry("abababababababab", 4224, NULL);
68 tt_int_op(ret, OP_EQ, -ENOENT);
70 mock_rend_query = mock_rend_data(service_id);
71 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
72 DIGEST_LEN);
73 rend_cache_store_v2_desc_as_client(desc_holder->desc_str, desc_id_base32,
74 mock_rend_query, NULL);
76 ret = rend_cache_lookup_entry(service_id, 2, NULL);
77 tt_int_op(ret, OP_EQ, 0);
79 ret = rend_cache_lookup_entry(service_id, 2, &entry);
80 tt_assert(entry);
81 tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str));
82 tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
84 done:
85 rend_encoded_v2_service_descriptor_free(desc_holder);
86 tor_free(service_id);
87 rend_cache_free_all();
88 rend_data_free(mock_rend_query);
91 static void
92 test_rend_cache_store_v2_desc_as_client(void *data)
94 rend_cache_store_status_t ret;
95 rend_data_t *mock_rend_query;
96 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
97 rend_cache_entry_t *entry = NULL;
98 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
99 char *service_id = NULL;
100 char client_cookie[REND_DESC_COOKIE_LEN];
101 (void)data;
103 rend_cache_init();
105 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
107 // Test success
108 mock_rend_query = mock_rend_data(service_id);
109 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
110 DIGEST_LEN);
111 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
112 desc_id_base32, mock_rend_query,
113 &entry);
115 tt_int_op(ret, OP_EQ, RCS_OKAY);
116 tt_assert(entry);
117 tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str));
118 tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
120 // Test various failure modes
122 // TODO: a too long desc_id_base32 argument crashes the function
123 /* ret = rend_cache_store_v2_desc_as_client( */
124 /* desc_holder->desc_str, */
125 /* "3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG", */
126 /* &mock_rend_query, NULL); */
127 /* tt_int_op(ret, OP_EQ, RCS_BADDESC); */
129 // Test bad base32 failure
130 // This causes an assertion failure if we're running with assertions.
131 // But when building without asserts, we can test it.
132 #ifdef DISABLE_ASSERTS_IN_UNIT_TESTS
133 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
134 "!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
135 tt_int_op(ret, OP_EQ, RCS_BADDESC);
136 #endif
138 // Test invalid descriptor
139 ret = rend_cache_store_v2_desc_as_client("invalid descriptor",
140 "3xqunszqnaolrrfmtzgaki7mxelgvkje", mock_rend_query, NULL);
141 tt_int_op(ret, OP_EQ, RCS_BADDESC);
143 // TODO: it doesn't seem to be possible to test invalid service ID condition.
144 // that means it is likely not possible to have that condition without
145 // earlier conditions failing first (such as signature checking of the desc)
147 rend_cache_free_all();
149 // Test mismatch between service ID and onion address
150 rend_cache_init();
151 strncpy(mock_rend_query->onion_address, "abc", REND_SERVICE_ID_LEN_BASE32+1);
152 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
153 desc_id_base32,
154 mock_rend_query, NULL);
155 tt_int_op(ret, OP_EQ, RCS_BADDESC);
156 rend_cache_free_all();
157 rend_data_free(mock_rend_query);
159 // Test incorrect descriptor ID
160 rend_cache_init();
161 mock_rend_query = mock_rend_data(service_id);
162 desc_id_base32[0]++;
163 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
164 desc_id_base32, mock_rend_query,
165 NULL);
166 tt_int_op(ret, OP_EQ, RCS_BADDESC);
167 desc_id_base32[0]--;
168 rend_cache_free_all();
170 // Test too old descriptor
171 rend_cache_init();
172 rend_encoded_v2_service_descriptor_free(desc_holder);
173 tor_free(service_id);
174 rend_data_free(mock_rend_query);
176 generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
177 mock_rend_query = mock_rend_data(service_id);
178 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
179 DIGEST_LEN);
181 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
182 desc_id_base32,
183 mock_rend_query, NULL);
184 tt_int_op(ret, OP_EQ, RCS_BADDESC);
185 rend_cache_free_all();
187 // Test too new descriptor (in the future)
188 rend_cache_init();
189 rend_encoded_v2_service_descriptor_free(desc_holder);
190 tor_free(service_id);
191 rend_data_free(mock_rend_query);
193 generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
194 mock_rend_query = mock_rend_data(service_id);
195 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
196 DIGEST_LEN);
198 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
199 desc_id_base32, mock_rend_query,
200 NULL);
201 tt_int_op(ret, OP_EQ, RCS_BADDESC);
202 rend_cache_free_all();
204 // Test when a descriptor is already in the cache
205 rend_cache_init();
206 rend_encoded_v2_service_descriptor_free(desc_holder);
207 tor_free(service_id);
208 rend_data_free(mock_rend_query);
210 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
211 mock_rend_query = mock_rend_data(service_id);
212 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
213 DIGEST_LEN);
215 rend_cache_store_v2_desc_as_client(desc_holder->desc_str, desc_id_base32,
216 mock_rend_query, NULL);
217 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
218 desc_id_base32, mock_rend_query,
219 NULL);
220 tt_int_op(ret, OP_EQ, RCS_OKAY);
222 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
223 desc_id_base32, mock_rend_query,
224 &entry);
225 tt_int_op(ret, OP_EQ, RCS_OKAY);
226 tt_assert(entry);
227 rend_cache_free_all();
229 // Test unsuccessful decrypting of introduction points
230 rend_cache_init();
231 rend_encoded_v2_service_descriptor_free(desc_holder);
232 tor_free(service_id);
233 rend_data_free(mock_rend_query);
235 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
236 mock_rend_query = mock_rend_data(service_id);
237 mock_rend_query->auth_type = REND_BASIC_AUTH;
238 client_cookie[0] = 'A';
239 memcpy(mock_rend_query->descriptor_cookie, client_cookie,
240 REND_DESC_COOKIE_LEN);
241 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
242 DIGEST_LEN);
243 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
244 desc_id_base32, mock_rend_query,
245 NULL);
246 tt_int_op(ret, OP_EQ, RCS_OKAY);
247 rend_cache_free_all();
249 // Test successful run when we have REND_BASIC_AUTH but not cookie
250 rend_cache_init();
251 rend_encoded_v2_service_descriptor_free(desc_holder);
252 tor_free(service_id);
253 rend_data_free(mock_rend_query);
255 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
256 mock_rend_query = mock_rend_data(service_id);
257 mock_rend_query->auth_type = REND_BASIC_AUTH;
258 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
259 DIGEST_LEN);
260 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
261 desc_id_base32, mock_rend_query,
262 NULL);
263 tt_int_op(ret, OP_EQ, RCS_OKAY);
265 rend_cache_free_all();
267 // Test when we have no introduction points
268 rend_cache_init();
269 rend_encoded_v2_service_descriptor_free(desc_holder);
270 tor_free(service_id);
271 rend_data_free(mock_rend_query);
273 generate_desc(RECENT_TIME, &desc_holder, &service_id, 0);
274 mock_rend_query = mock_rend_data(service_id);
275 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
276 DIGEST_LEN);
277 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
278 desc_id_base32, mock_rend_query,
279 NULL);
280 tt_int_op(ret, OP_EQ, RCS_BADDESC);
281 rend_cache_free_all();
283 // Test when we have too many intro points
284 rend_cache_init();
285 rend_encoded_v2_service_descriptor_free(desc_holder);
286 tor_free(service_id);
287 rend_data_free(mock_rend_query);
289 generate_desc(RECENT_TIME, &desc_holder, &service_id, MAX_INTRO_POINTS+1);
290 mock_rend_query = mock_rend_data(service_id);
291 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
292 DIGEST_LEN);
293 ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
294 desc_id_base32, mock_rend_query,
295 NULL);
296 tt_int_op(ret, OP_EQ, RCS_BADDESC);
298 done:
299 rend_encoded_v2_service_descriptor_free(desc_holder);
300 tor_free(service_id);
301 rend_cache_free_all();
302 rend_data_free(mock_rend_query);
305 static void
306 test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
308 rend_cache_store_status_t ret;
309 rend_data_t *mock_rend_query;
310 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
311 rend_service_descriptor_t *generated = NULL;
312 smartlist_t *descs = smartlist_new();
313 time_t t;
314 char *service_id = NULL;
315 rend_encoded_v2_service_descriptor_t *desc_holder_newer;
316 rend_encoded_v2_service_descriptor_t *desc_holder_older;
318 t = time(NULL);
319 rend_cache_init();
321 create_descriptor(&generated, &service_id, 3);
323 generated->timestamp = t + RECENT_TIME;
324 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
325 REND_NO_AUTH, NULL, NULL);
326 desc_holder_newer = ((rend_encoded_v2_service_descriptor_t *)
327 smartlist_get(descs, 0));
328 smartlist_set(descs, 0, NULL);
330 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
331 rend_encoded_v2_service_descriptor_free(d));
332 smartlist_free(descs);
333 descs = smartlist_new();
335 generated->timestamp = (t + RECENT_TIME) - 20;
336 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
337 REND_NO_AUTH, NULL, NULL);
338 desc_holder_older = ((rend_encoded_v2_service_descriptor_t *)
339 smartlist_get(descs, 0));
340 smartlist_set(descs, 0, NULL);
341 (void)data;
343 // Test when a descriptor is already in the cache and it is newer than the
344 // one we submit
345 mock_rend_query = mock_rend_data(service_id);
346 base32_encode(desc_id_base32, sizeof(desc_id_base32),
347 desc_holder_newer->desc_id, DIGEST_LEN);
348 rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
349 desc_id_base32, mock_rend_query, NULL);
350 ret = rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
351 desc_id_base32, mock_rend_query,
352 NULL);
353 tt_int_op(ret, OP_EQ, RCS_OKAY);
355 rend_cache_free_all();
357 // Test when an old descriptor is in the cache and we submit a newer one
358 rend_cache_init();
359 rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
360 desc_id_base32, mock_rend_query, NULL);
361 ret = rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
362 desc_id_base32, mock_rend_query,
363 NULL);
364 tt_int_op(ret, OP_EQ, RCS_OKAY);
366 done:
367 rend_encoded_v2_service_descriptor_free(desc_holder_newer);
368 rend_encoded_v2_service_descriptor_free(desc_holder_older);
369 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
370 rend_encoded_v2_service_descriptor_free(d));
371 smartlist_free(descs);
372 rend_service_descriptor_free(generated);
373 tor_free(service_id);
374 rend_cache_free_all();
375 rend_data_free(mock_rend_query);
378 #define NS_SUBMODULE lookup_v2_desc_as_dir
379 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
381 static routerinfo_t *mock_routerinfo;
383 static const routerinfo_t *
384 NS(router_get_my_routerinfo)(void)
386 if (!mock_routerinfo) {
387 mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
390 return mock_routerinfo;
393 static void
394 test_rend_cache_lookup_v2_desc_as_dir(void *data)
396 int ret;
397 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
398 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
399 char *service_id = NULL;
400 const char *ret_desc = NULL;
402 (void)data;
404 NS_MOCK(router_get_my_routerinfo);
406 rend_cache_init();
408 // Test invalid base32
409 ret = rend_cache_lookup_v2_desc_as_dir("!bababababababab", NULL);
410 tt_int_op(ret, OP_EQ, -1);
412 // Test non-existent descriptor but well formed
413 ret = rend_cache_lookup_v2_desc_as_dir("3xqunszqnaolrrfmtzgaki7mxelgvkje",
414 NULL);
415 tt_int_op(ret, OP_EQ, 0);
417 // Test existing descriptor
418 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
419 rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
420 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
421 DIGEST_LEN);
422 ret = rend_cache_lookup_v2_desc_as_dir(desc_id_base32, &ret_desc);
423 tt_int_op(ret, OP_EQ, 1);
424 tt_assert(ret_desc);
426 done:
427 NS_UNMOCK(router_get_my_routerinfo);
428 tor_free(mock_routerinfo);
429 rend_cache_free_all();
430 rend_encoded_v2_service_descriptor_free(desc_holder);
431 tor_free(service_id);
434 #undef NS_SUBMODULE
436 #define NS_SUBMODULE store_v2_desc_as_dir
437 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
439 static const routerinfo_t *
440 NS(router_get_my_routerinfo)(void)
442 return mock_routerinfo;
445 static void
446 test_rend_cache_store_v2_desc_as_dir(void *data)
448 (void)data;
449 rend_cache_store_status_t ret;
450 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
451 char *service_id = NULL;
453 NS_MOCK(router_get_my_routerinfo);
455 rend_cache_init();
457 // Test when we can't parse the descriptor
458 mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
459 ret = rend_cache_store_v2_desc_as_dir("unparseable");
460 tt_int_op(ret, OP_EQ, RCS_BADDESC);
462 // Test when we have an old descriptor
463 generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
464 ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
465 tt_int_op(ret, OP_EQ, RCS_OKAY);
467 rend_encoded_v2_service_descriptor_free(desc_holder);
468 tor_free(service_id);
470 // Test when we have a descriptor in the future
471 generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
472 ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
473 tt_int_op(ret, OP_EQ, RCS_OKAY);
475 rend_encoded_v2_service_descriptor_free(desc_holder);
476 tor_free(service_id);
478 // Test when two descriptors
479 generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
480 ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
481 tt_int_op(ret, OP_EQ, RCS_OKAY);
483 rend_encoded_v2_service_descriptor_free(desc_holder);
484 tor_free(service_id);
486 // Test when asking for hidden service statistics HiddenServiceStatistics
487 rend_cache_purge();
488 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
489 get_options_mutable()->HiddenServiceStatistics = 1;
490 ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
491 tt_int_op(ret, OP_EQ, RCS_OKAY);
493 done:
494 NS_UNMOCK(router_get_my_routerinfo);
495 rend_encoded_v2_service_descriptor_free(desc_holder);
496 tor_free(service_id);
497 rend_cache_free_all();
498 tor_free(mock_routerinfo);
501 static void
502 test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
504 (void)data;
506 rend_cache_store_status_t ret;
507 rend_service_descriptor_t *generated = NULL;
508 smartlist_t *descs = smartlist_new();
509 time_t t;
510 char *service_id = NULL;
511 rend_encoded_v2_service_descriptor_t *desc_holder_newer;
512 rend_encoded_v2_service_descriptor_t *desc_holder_older;
514 NS_MOCK(router_get_my_routerinfo);
516 rend_cache_init();
518 t = time(NULL);
520 create_descriptor(&generated, &service_id, 3);
521 generated->timestamp = t + RECENT_TIME;
522 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
523 REND_NO_AUTH, NULL, NULL);
524 desc_holder_newer = ((rend_encoded_v2_service_descriptor_t *)
525 smartlist_get(descs, 0));
526 smartlist_set(descs, 0, NULL);
527 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
528 rend_encoded_v2_service_descriptor_free(d));
529 smartlist_free(descs);
530 descs = smartlist_new();
532 generated->timestamp = (t + RECENT_TIME) - 20;
533 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
534 REND_NO_AUTH, NULL, NULL);
535 desc_holder_older = ((rend_encoded_v2_service_descriptor_t *)
536 smartlist_get(descs, 0));
537 smartlist_set(descs, 0, NULL);
539 // Test when we have a newer descriptor stored
540 mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
541 rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
542 ret = rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
543 tt_int_op(ret, OP_EQ, RCS_OKAY);
545 // Test when we have an old descriptor stored
546 rend_cache_purge();
547 rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
548 ret = rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
549 tt_int_op(ret, OP_EQ, RCS_OKAY);
551 done:
552 NS_UNMOCK(router_get_my_routerinfo);
553 rend_cache_free_all();
554 rend_service_descriptor_free(generated);
555 tor_free(service_id);
556 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
557 rend_encoded_v2_service_descriptor_free(d));
558 smartlist_free(descs);
559 rend_encoded_v2_service_descriptor_free(desc_holder_newer);
560 rend_encoded_v2_service_descriptor_free(desc_holder_older);
561 tor_free(mock_routerinfo);
564 static void
565 test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
567 (void)data;
569 rend_cache_store_status_t ret;
570 rend_service_descriptor_t *generated = NULL;
571 smartlist_t *descs = smartlist_new();
572 time_t t;
573 char *service_id = NULL;
574 rend_encoded_v2_service_descriptor_t *desc_holder_one = NULL;
575 rend_encoded_v2_service_descriptor_t *desc_holder_two = NULL;
577 NS_MOCK(router_get_my_routerinfo);
579 rend_cache_init();
581 t = time(NULL);
583 create_descriptor(&generated, &service_id, 3);
584 generated->timestamp = t + RECENT_TIME;
585 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
586 REND_NO_AUTH, NULL, NULL);
587 desc_holder_one = ((rend_encoded_v2_service_descriptor_t *)
588 smartlist_get(descs, 0));
589 smartlist_set(descs, 0, NULL);
591 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
592 rend_encoded_v2_service_descriptor_free(d));
593 smartlist_free(descs);
594 descs = smartlist_new();
596 generated->timestamp = t + RECENT_TIME;
597 generated->protocols = 41;
598 rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
599 REND_NO_AUTH, NULL, NULL);
600 desc_holder_two = ((rend_encoded_v2_service_descriptor_t *)
601 smartlist_get(descs, 0));
602 smartlist_set(descs, 0, NULL);
604 // Test when we have another descriptor stored, with a different descriptor
605 mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
606 rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
607 ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
608 tt_int_op(ret, OP_EQ, RCS_OKAY);
610 done:
611 NS_UNMOCK(router_get_my_routerinfo);
612 rend_cache_free_all();
613 rend_service_descriptor_free(generated);
614 tor_free(service_id);
615 SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
616 rend_encoded_v2_service_descriptor_free(d));
617 smartlist_free(descs);
618 rend_encoded_v2_service_descriptor_free(desc_holder_one);
619 rend_encoded_v2_service_descriptor_free(desc_holder_two);
622 #undef NS_SUBMODULE
624 static void
625 test_rend_cache_init(void *data)
627 (void)data;
629 tt_assert_msg(!rend_cache, "rend_cache should be NULL when starting");
630 tt_assert_msg(!rend_cache_v2_dir, "rend_cache_v2_dir should be NULL "
631 "when starting");
632 tt_assert_msg(!rend_cache_failure, "rend_cache_failure should be NULL when "
633 "starting");
635 rend_cache_init();
637 tt_assert_msg(rend_cache, "rend_cache should not be NULL after initing");
638 tt_assert_msg(rend_cache_v2_dir, "rend_cache_v2_dir should not be NULL "
639 "after initing");
640 tt_assert_msg(rend_cache_failure, "rend_cache_failure should not be NULL "
641 "after initing");
643 tt_int_op(strmap_size(rend_cache), OP_EQ, 0);
644 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
645 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
647 done:
648 rend_cache_free_all();
651 static void
652 test_rend_cache_decrement_allocation(void *data)
654 (void)data;
656 // Test when the cache has enough allocations
657 rend_cache_total_allocation = 10;
658 rend_cache_decrement_allocation(3);
659 tt_int_op(rend_cache_total_allocation, OP_EQ, 7);
661 // Test when there are not enough allocations
662 rend_cache_total_allocation = 1;
663 rend_cache_decrement_allocation(2);
664 tt_int_op(rend_cache_total_allocation, OP_EQ, 0);
666 // And again
667 rend_cache_decrement_allocation(2);
668 tt_int_op(rend_cache_total_allocation, OP_EQ, 0);
670 done:
671 (void)0;
674 static void
675 test_rend_cache_increment_allocation(void *data)
677 (void)data;
679 // Test when the cache is not overflowing
680 rend_cache_total_allocation = 5;
681 rend_cache_increment_allocation(3);
682 tt_int_op(rend_cache_total_allocation, OP_EQ, 8);
684 // Test when there are too many allocations
685 rend_cache_total_allocation = SIZE_MAX-1;
686 rend_cache_increment_allocation(2);
687 tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
689 // And again
690 rend_cache_increment_allocation(2);
691 tt_u64_op(rend_cache_total_allocation, OP_EQ, SIZE_MAX);
693 done:
694 (void)0;
697 static void
698 test_rend_cache_failure_intro_entry_new(void *data)
700 time_t now;
701 rend_cache_failure_intro_t *entry;
702 rend_intro_point_failure_t failure;
704 (void)data;
706 failure = INTRO_POINT_FAILURE_TIMEOUT;
707 now = time(NULL);
708 entry = rend_cache_failure_intro_entry_new(failure);
710 tt_int_op(entry->failure_type, OP_EQ, INTRO_POINT_FAILURE_TIMEOUT);
711 tt_int_op(entry->created_ts, OP_GE, now-5);
712 tt_int_op(entry->created_ts, OP_LE, now+5);
714 done:
715 tor_free(entry);
718 static void
719 test_rend_cache_failure_intro_lookup(void *data)
721 (void)data;
722 int ret;
723 rend_cache_failure_t *failure;
724 rend_cache_failure_intro_t *ip;
725 rend_cache_failure_intro_t *entry;
726 const char key_ip_one[DIGEST_LEN] = "ip1";
727 const char key_ip_two[DIGEST_LEN] = "ip2";
728 const char key_foo[DIGEST_LEN] = "foo1";
730 rend_cache_init();
732 failure = rend_cache_failure_entry_new();
733 ip = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
734 digestmap_set(failure->intro_failures, key_ip_one, ip);
735 strmap_set_lc(rend_cache_failure, "foo1", failure);
737 // Test not found
738 ret = cache_failure_intro_lookup((const uint8_t *) key_foo, "foo2", NULL);
739 tt_int_op(ret, OP_EQ, 0);
741 // Test found with no intro failures in it
742 ret = cache_failure_intro_lookup((const uint8_t *) key_ip_two, "foo1", NULL);
743 tt_int_op(ret, OP_EQ, 0);
745 // Test found
746 ret = cache_failure_intro_lookup((const uint8_t *) key_ip_one, "foo1", NULL);
747 tt_int_op(ret, OP_EQ, 1);
749 // Test found and asking for entry
750 cache_failure_intro_lookup((const uint8_t *) key_ip_one, "foo1", &entry);
751 tt_assert(entry);
752 tt_assert(entry == ip);
754 done:
755 rend_cache_free_all();
758 static void
759 test_rend_cache_clean(void *data)
761 rend_cache_entry_t *one, *two;
762 rend_service_descriptor_t *desc_one, *desc_two;
763 strmap_iter_t *iter = NULL;
764 const char *key;
765 void *val;
767 (void)data;
769 rend_cache_init();
771 // Test with empty rendcache
772 rend_cache_clean(time(NULL), REND_CACHE_TYPE_CLIENT);
773 tt_int_op(strmap_size(rend_cache), OP_EQ, 0);
775 // Test with two old entries
776 one = tor_malloc_zero(sizeof(rend_cache_entry_t));
777 two = tor_malloc_zero(sizeof(rend_cache_entry_t));
778 desc_one = tor_malloc_zero(sizeof(rend_service_descriptor_t));
779 desc_two = tor_malloc_zero(sizeof(rend_service_descriptor_t));
780 one->parsed = desc_one;
781 two->parsed = desc_two;
783 desc_one->timestamp = time(NULL) + TIME_IN_THE_PAST;
784 desc_two->timestamp = (time(NULL) + TIME_IN_THE_PAST) - 10;
785 desc_one->pk = pk_generate(0);
786 desc_two->pk = pk_generate(1);
788 strmap_set_lc(rend_cache, "foo1", one);
789 strmap_set_lc(rend_cache, "foo2", two);
791 rend_cache_clean(time(NULL), REND_CACHE_TYPE_CLIENT);
792 tt_int_op(strmap_size(rend_cache), OP_EQ, 0);
794 // Test with one old entry and one newer entry
795 one = tor_malloc_zero(sizeof(rend_cache_entry_t));
796 two = tor_malloc_zero(sizeof(rend_cache_entry_t));
797 desc_one = tor_malloc_zero(sizeof(rend_service_descriptor_t));
798 desc_two = tor_malloc_zero(sizeof(rend_service_descriptor_t));
799 one->parsed = desc_one;
800 two->parsed = desc_two;
802 desc_one->timestamp = (time(NULL) + TIME_IN_THE_PAST) - 10;
803 desc_two->timestamp = time(NULL) - 100;
804 desc_one->pk = pk_generate(0);
805 desc_two->pk = pk_generate(1);
807 strmap_set_lc(rend_cache, "foo1", one);
808 strmap_set_lc(rend_cache, "foo2", two);
810 rend_cache_clean(time(NULL), REND_CACHE_TYPE_CLIENT);
811 tt_int_op(strmap_size(rend_cache), OP_EQ, 1);
813 iter = strmap_iter_init(rend_cache);
814 strmap_iter_get(iter, &key, &val);
815 tt_str_op(key, OP_EQ, "foo2");
817 done:
818 rend_cache_free_all();
821 static void
822 test_rend_cache_failure_entry_new(void *data)
824 rend_cache_failure_t *failure;
826 (void)data;
828 failure = rend_cache_failure_entry_new();
829 tt_assert(failure);
830 tt_int_op(digestmap_size(failure->intro_failures), OP_EQ, 0);
832 done:
833 rend_cache_failure_entry_free(failure);
836 static void
837 test_rend_cache_failure_entry_free(void *data)
839 (void)data;
841 // Test that it can deal with a NULL argument
842 rend_cache_failure_entry_free(NULL);
844 /* done: */
845 /* (void)0; */
848 static void
849 test_rend_cache_failure_clean(void *data)
851 rend_cache_failure_t *failure;
852 rend_cache_failure_intro_t *ip_one, *ip_two;
854 const char key_one[DIGEST_LEN] = "ip1";
855 const char key_two[DIGEST_LEN] = "ip2";
857 (void)data;
859 rend_cache_init();
861 // Test with empty failure cache
862 rend_cache_failure_clean(time(NULL));
863 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
865 // Test with one empty failure entry
866 failure = rend_cache_failure_entry_new();
867 strmap_set_lc(rend_cache_failure, "foo1", failure);
868 rend_cache_failure_clean(time(NULL));
869 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
871 // Test with one new intro point
872 failure = rend_cache_failure_entry_new();
873 ip_one = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
874 digestmap_set(failure->intro_failures, key_one, ip_one);
875 strmap_set_lc(rend_cache_failure, "foo1", failure);
876 rend_cache_failure_clean(time(NULL));
877 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 1);
879 // Test with one old intro point
880 rend_cache_failure_purge();
881 failure = rend_cache_failure_entry_new();
882 ip_one = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
883 ip_one->created_ts = time(NULL) - 7*60;
884 digestmap_set(failure->intro_failures, key_one, ip_one);
885 strmap_set_lc(rend_cache_failure, "foo1", failure);
886 rend_cache_failure_clean(time(NULL));
887 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
889 // Test with one old intro point and one new one
890 rend_cache_failure_purge();
891 failure = rend_cache_failure_entry_new();
892 ip_one = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
893 ip_one->created_ts = time(NULL) - 7*60;
894 digestmap_set(failure->intro_failures, key_one, ip_one);
895 ip_two = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
896 ip_two->created_ts = time(NULL) - 2*60;
897 digestmap_set(failure->intro_failures, key_two, ip_two);
898 strmap_set_lc(rend_cache_failure, "foo1", failure);
899 rend_cache_failure_clean(time(NULL));
900 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 1);
901 tt_int_op(digestmap_size(failure->intro_failures), OP_EQ, 1);
903 done:
904 rend_cache_free_all();
907 static void
908 test_rend_cache_failure_remove(void *data)
910 rend_service_descriptor_t *desc;
911 (void)data;
913 rend_cache_init();
915 // Test that it deals well with a NULL desc
916 rend_cache_failure_remove(NULL);
918 // Test a descriptor that isn't in the cache
919 desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
920 desc->pk = pk_generate(0);
921 rend_cache_failure_remove(desc);
923 // There seems to not exist any way of getting rend_cache_failure_remove()
924 // to fail because of a problem with rend_get_service_id from here
925 rend_cache_free_all();
927 rend_service_descriptor_free(desc);
928 /* done: */
929 /* (void)0; */
932 static void
933 test_rend_cache_free_all(void *data)
935 rend_cache_failure_t *failure;
936 rend_cache_entry_t *one;
937 rend_service_descriptor_t *desc_one;
939 (void)data;
941 rend_cache_init();
943 failure = rend_cache_failure_entry_new();
944 strmap_set_lc(rend_cache_failure, "foo1", failure);
946 one = tor_malloc_zero(sizeof(rend_cache_entry_t));
947 desc_one = tor_malloc_zero(sizeof(rend_service_descriptor_t));
948 one->parsed = desc_one;
949 desc_one->timestamp = time(NULL) + TIME_IN_THE_PAST;
950 desc_one->pk = pk_generate(0);
951 strmap_set_lc(rend_cache, "foo1", one);
953 rend_cache_free_all();
955 tt_assert(!rend_cache);
956 tt_assert(!rend_cache_v2_dir);
957 tt_assert(!rend_cache_failure);
958 tt_assert(!rend_cache_total_allocation);
960 done:
961 rend_cache_free_all();
964 static void
965 test_rend_cache_entry_free(void *data)
967 (void)data;
968 rend_cache_entry_t *e;
970 // Handles NULL correctly
971 rend_cache_entry_free(NULL);
973 // Handles NULL descriptor correctly
974 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
975 rend_cache_entry_free(e);
977 // Handles non-NULL descriptor correctly
978 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
979 e->desc = (char *)malloc(10);
980 rend_cache_entry_free(e);
982 /* done: */
983 /* (void)0; */
986 static void
987 test_rend_cache_purge(void *data)
989 (void)data;
991 // Deals with a NULL rend_cache
992 rend_cache_purge();
993 tt_assert(rend_cache);
994 tt_assert(strmap_size(rend_cache) == 0);
996 // Deals with existing rend_cache
997 rend_cache_free_all();
998 rend_cache_init();
999 tt_assert(rend_cache);
1000 tt_assert(strmap_size(rend_cache) == 0);
1002 rend_cache_purge();
1003 tt_assert(rend_cache);
1004 tt_assert(strmap_size(rend_cache) == 0);
1006 done:
1007 rend_cache_free_all();
1010 static void
1011 test_rend_cache_failure_intro_add(void *data)
1013 (void)data;
1014 rend_cache_failure_t *fail_entry;
1015 rend_cache_failure_intro_t *entry;
1016 const char identity[DIGEST_LEN] = "foo1";
1018 rend_cache_init();
1020 // Adds non-existing entry
1021 cache_failure_intro_add((const uint8_t *) identity, "foo2",
1022 INTRO_POINT_FAILURE_TIMEOUT);
1023 fail_entry = strmap_get_lc(rend_cache_failure, "foo2");
1024 tt_assert(fail_entry);
1025 tt_int_op(digestmap_size(fail_entry->intro_failures), OP_EQ, 1);
1026 entry = digestmap_get(fail_entry->intro_failures, identity);
1027 tt_assert(entry);
1029 // Adds existing entry
1030 cache_failure_intro_add((const uint8_t *) identity, "foo2",
1031 INTRO_POINT_FAILURE_TIMEOUT);
1032 fail_entry = strmap_get_lc(rend_cache_failure, "foo2");
1033 tt_assert(fail_entry);
1034 tt_int_op(digestmap_size(fail_entry->intro_failures), OP_EQ, 1);
1035 entry = digestmap_get(fail_entry->intro_failures, identity);
1036 tt_assert(entry);
1038 done:
1039 rend_cache_free_all();
1042 static void
1043 test_rend_cache_intro_failure_note(void *data)
1045 (void)data;
1046 rend_cache_failure_t *fail_entry;
1047 rend_cache_failure_intro_t *entry;
1048 const char key[DIGEST_LEN] = "foo1";
1050 rend_cache_init();
1052 // Test not found
1053 rend_cache_intro_failure_note(INTRO_POINT_FAILURE_TIMEOUT,
1054 (const uint8_t *) key, "foo2");
1055 fail_entry = strmap_get_lc(rend_cache_failure, "foo2");
1056 tt_assert(fail_entry);
1057 tt_int_op(digestmap_size(fail_entry->intro_failures), OP_EQ, 1);
1058 entry = digestmap_get(fail_entry->intro_failures, key);
1059 tt_assert(entry);
1060 tt_int_op(entry->failure_type, OP_EQ, INTRO_POINT_FAILURE_TIMEOUT);
1062 // Test found
1063 rend_cache_intro_failure_note(INTRO_POINT_FAILURE_UNREACHABLE,
1064 (const uint8_t *) key, "foo2");
1065 tt_int_op(entry->failure_type, OP_EQ, INTRO_POINT_FAILURE_UNREACHABLE);
1067 done:
1068 rend_cache_free_all();
1071 #define NS_SUBMODULE clean_v2_descs_as_dir
1073 static void
1074 test_rend_cache_clean_v2_descs_as_dir(void *data)
1076 rend_cache_entry_t *e;
1077 time_t now;
1078 rend_service_descriptor_t *desc;
1079 now = time(NULL);
1080 const char key[DIGEST_LEN] = "abcde";
1082 (void)data;
1084 rend_cache_init();
1086 // Test running with an empty cache
1087 rend_cache_clean_v2_descs_as_dir(now, 0);
1088 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
1090 // Test with only one new entry
1091 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
1092 e->last_served = now;
1093 desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
1094 desc->timestamp = now;
1095 desc->pk = pk_generate(0);
1096 e->parsed = desc;
1097 digestmap_set(rend_cache_v2_dir, key, e);
1099 rend_cache_clean_v2_descs_as_dir(now, 0);
1100 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
1102 // Test with one old entry
1103 desc->timestamp = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
1104 rend_cache_clean_v2_descs_as_dir(now, 0);
1105 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
1107 // Test with one entry that has an old last served
1108 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
1109 e->last_served = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
1110 desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
1111 desc->timestamp = now;
1112 desc->pk = pk_generate(0);
1113 e->parsed = desc;
1114 digestmap_set(rend_cache_v2_dir, key, e);
1116 rend_cache_clean_v2_descs_as_dir(now, 0);
1117 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
1119 // Test a run through asking for a large force_remove
1120 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
1121 e->last_served = now;
1122 desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
1123 desc->timestamp = now;
1124 desc->pk = pk_generate(0);
1125 e->parsed = desc;
1126 digestmap_set(rend_cache_v2_dir, key, e);
1128 rend_cache_clean_v2_descs_as_dir(now, 20000);
1129 tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
1131 done:
1132 rend_cache_free_all();
1135 #undef NS_SUBMODULE
1137 static void
1138 test_rend_cache_entry_allocation(void *data)
1140 (void)data;
1142 size_t ret;
1143 rend_cache_entry_t *e = NULL;
1145 // Handles a null argument
1146 ret = rend_cache_entry_allocation(NULL);
1147 tt_int_op(ret, OP_EQ, 0);
1149 // Handles a non-null argument
1150 e = tor_malloc_zero(sizeof(rend_cache_entry_t));
1151 ret = rend_cache_entry_allocation(e);
1152 tt_int_op(ret, OP_GT, sizeof(rend_cache_entry_t));
1154 done:
1155 tor_free(e);
1158 static void
1159 test_rend_cache_failure_intro_entry_free(void *data)
1161 (void)data;
1162 rend_cache_failure_intro_t *entry;
1164 // Handles a null argument
1165 rend_cache_failure_intro_entry_free(NULL);
1167 // Handles a non-null argument
1168 entry = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
1169 rend_cache_failure_intro_entry_free(entry);
1172 static void
1173 test_rend_cache_failure_purge(void *data)
1175 (void)data;
1177 // Handles a null failure cache
1178 strmap_free(rend_cache_failure, rend_cache_failure_entry_free_);
1179 rend_cache_failure = NULL;
1181 rend_cache_failure_purge();
1183 tt_ptr_op(rend_cache_failure, OP_NE, NULL);
1184 tt_int_op(strmap_size(rend_cache_failure), OP_EQ, 0);
1186 done:
1187 rend_cache_free_all();
1190 static void
1191 test_rend_cache_validate_intro_point_failure(void *data)
1193 (void)data;
1194 rend_service_descriptor_t *desc = NULL;
1195 char *service_id = NULL;
1196 rend_intro_point_t *intro = NULL;
1197 const char *identity = NULL;
1198 rend_cache_failure_t *failure;
1199 rend_cache_failure_intro_t *ip;
1201 rend_cache_init();
1203 create_descriptor(&desc, &service_id, 3);
1204 desc->timestamp = time(NULL) + RECENT_TIME;
1206 intro = (rend_intro_point_t *)smartlist_get(desc->intro_nodes, 0);
1207 identity = intro->extend_info->identity_digest;
1209 failure = rend_cache_failure_entry_new();
1210 ip = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT);
1211 digestmap_set(failure->intro_failures, identity, ip);
1212 strmap_set_lc(rend_cache_failure, service_id, failure);
1214 // Test when we have an intro point in our cache
1215 validate_intro_point_failure(desc, service_id);
1216 tt_int_op(smartlist_len(desc->intro_nodes), OP_EQ, 2);
1218 done:
1219 rend_cache_free_all();
1220 rend_service_descriptor_free(desc);
1221 tor_free(service_id);
1224 struct testcase_t rend_cache_tests[] = {
1225 { "init", test_rend_cache_init, 0, NULL, NULL },
1226 { "decrement_allocation", test_rend_cache_decrement_allocation, 0,
1227 NULL, NULL },
1228 { "increment_allocation", test_rend_cache_increment_allocation, 0,
1229 NULL, NULL },
1230 { "clean", test_rend_cache_clean, TT_FORK, NULL, NULL },
1231 { "clean_v2_descs_as_dir", test_rend_cache_clean_v2_descs_as_dir, 0,
1232 NULL, NULL },
1233 { "entry_allocation", test_rend_cache_entry_allocation, 0, NULL, NULL },
1234 { "entry_free", test_rend_cache_entry_free, 0, NULL, NULL },
1235 { "failure_intro_entry_free", test_rend_cache_failure_intro_entry_free, 0,
1236 NULL, NULL },
1237 { "free_all", test_rend_cache_free_all, 0, NULL, NULL },
1238 { "purge", test_rend_cache_purge, 0, NULL, NULL },
1239 { "failure_clean", test_rend_cache_failure_clean, 0, NULL, NULL },
1240 { "failure_entry_new", test_rend_cache_failure_entry_new, 0, NULL, NULL },
1241 { "failure_entry_free", test_rend_cache_failure_entry_free, 0, NULL, NULL },
1242 { "failure_intro_add", test_rend_cache_failure_intro_add, 0, NULL, NULL },
1243 { "failure_intro_entry_new", test_rend_cache_failure_intro_entry_new, 0,
1244 NULL, NULL },
1245 { "failure_intro_lookup", test_rend_cache_failure_intro_lookup, 0,
1246 NULL, NULL },
1247 { "failure_purge", test_rend_cache_failure_purge, 0, NULL, NULL },
1248 { "failure_remove", test_rend_cache_failure_remove, 0, NULL, NULL },
1249 { "intro_failure_note", test_rend_cache_intro_failure_note, 0, NULL, NULL },
1250 { "lookup", test_rend_cache_lookup_entry, 0, NULL, NULL },
1251 { "lookup_v2_desc_as_dir", test_rend_cache_lookup_v2_desc_as_dir, 0,
1252 NULL, NULL },
1253 { "store_v2_desc_as_client", test_rend_cache_store_v2_desc_as_client, 0,
1254 NULL, NULL },
1255 { "store_v2_desc_as_client_with_different_time",
1256 test_rend_cache_store_v2_desc_as_client_with_different_time, 0,
1257 NULL, NULL },
1258 { "store_v2_desc_as_dir", test_rend_cache_store_v2_desc_as_dir, 0,
1259 NULL, NULL },
1260 { "store_v2_desc_as_dir_with_different_time",
1261 test_rend_cache_store_v2_desc_as_dir_with_different_time, 0, NULL, NULL },
1262 { "store_v2_desc_as_dir_with_different_content",
1263 test_rend_cache_store_v2_desc_as_dir_with_different_content, 0,
1264 NULL, NULL },
1265 { "validate_intro_point_failure",
1266 test_rend_cache_validate_intro_point_failure, 0, NULL, NULL },
1267 END_OF_TESTCASES