Edit changelog a little for clarity and conciseness
[tor.git] / src / test / test_dir_handle_get.c
blob3282037243f2fb50538d4987b6e6cfddb380fc64
1 /* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2016, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #define RENDCOMMON_PRIVATE
7 #define GEOIP_PRIVATE
8 #define CONNECTION_PRIVATE
9 #define CONFIG_PRIVATE
10 #define RENDCACHE_PRIVATE
12 #include "or.h"
13 #include "config.h"
14 #include "connection.h"
15 #include "directory.h"
16 #include "test.h"
17 #include "connection.h"
18 #include "rendcommon.h"
19 #include "rendcache.h"
20 #include "router.h"
21 #include "routerlist.h"
22 #include "rend_test_helpers.h"
23 #include "microdesc.h"
24 #include "test_helpers.h"
25 #include "nodelist.h"
26 #include "entrynodes.h"
27 #include "routerparse.h"
28 #include "networkstatus.h"
29 #include "geoip.h"
30 #include "dirserv.h"
31 #include "torgzip.h"
32 #include "dirvote.h"
34 #ifdef _WIN32
35 /* For mkdir() */
36 #include <direct.h>
37 #else
38 #include <dirent.h>
39 #endif
41 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
42 DISABLE_GCC_WARNING(overlength-strings)
43 /* We allow huge string constants in the unit tests, but not in the code
44 * at large. */
45 #endif
46 #include "vote_descriptors.inc"
47 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
48 ENABLE_GCC_WARNING(overlength-strings)
49 #endif
51 #define NS_MODULE dir_handle_get
53 static void
54 connection_write_to_buf_mock(const char *string, size_t len,
55 connection_t *conn, int zlib)
57 (void) zlib;
59 tor_assert(string);
60 tor_assert(conn);
62 write_to_buf(string, len, conn->outbuf);
65 #define GET(path) "GET " path " HTTP/1.0\r\n\r\n"
66 #define NOT_FOUND "HTTP/1.0 404 Not found\r\n\r\n"
67 #define BAD_REQUEST "HTTP/1.0 400 Bad request\r\n\r\n"
68 #define SERVER_BUSY "HTTP/1.0 503 Directory busy, try again later\r\n\r\n"
69 #define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
70 "Consensus not signed by sufficient number of requested authorities\r\n\r\n"
72 static tor_addr_t MOCK_TOR_ADDR;
74 static void
75 test_dir_handle_get_bad_request(void *data)
77 dir_connection_t *conn = NULL;
78 char *header = NULL;
79 (void) data;
81 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
83 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
84 tt_int_op(directory_handle_command_get(conn, "", NULL, 0), OP_EQ, 0);
86 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
87 NULL, NULL, 1, 0);
89 tt_str_op(header, OP_EQ, BAD_REQUEST);
91 done:
92 UNMOCK(connection_write_to_buf_impl_);
93 connection_free_(TO_CONN(conn));
94 tor_free(header);
97 static void
98 test_dir_handle_get_v1_command_not_found(void *data)
100 dir_connection_t *conn = NULL;
101 char *header = NULL;
102 (void) data;
104 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
106 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
108 // no frontpage configured
109 tt_ptr_op(get_dirportfrontpage(), OP_EQ, NULL);
111 /* V1 path */
112 tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
113 OP_EQ, 0);
115 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
116 NULL, NULL, 1, 0);
118 tt_str_op(NOT_FOUND, OP_EQ, header);
120 done:
121 UNMOCK(connection_write_to_buf_impl_);
122 connection_free_(TO_CONN(conn));
123 tor_free(header);
126 static const char*
127 mock_get_dirportfrontpage(void)
129 return "HELLO FROM FRONTPAGE";
132 static void
133 test_dir_handle_get_v1_command(void *data)
135 dir_connection_t *conn = NULL;
136 char *header = NULL;
137 char *body = NULL;
138 size_t body_used = 0, body_len = 0;
139 const char *exp_body = NULL;
140 (void) data;
142 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
143 MOCK(get_dirportfrontpage, mock_get_dirportfrontpage);
145 exp_body = get_dirportfrontpage();
146 body_len = strlen(exp_body);
148 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
149 tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
150 OP_EQ, 0);
152 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
153 &body, &body_used, body_len+1, 0);
155 tt_assert(header);
156 tt_assert(body);
158 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
159 tt_assert(strstr(header, "Content-Type: text/html\r\n"));
160 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
161 tt_assert(strstr(header, "Content-Length: 20\r\n"));
163 tt_int_op(body_used, OP_EQ, strlen(body));
164 tt_str_op(body, OP_EQ, exp_body);
166 done:
167 UNMOCK(connection_write_to_buf_impl_);
168 UNMOCK(get_dirportfrontpage);
169 connection_free_(TO_CONN(conn));
170 tor_free(header);
171 tor_free(body);
174 static void
175 test_dir_handle_get_not_found(void *data)
177 dir_connection_t *conn = NULL;
178 char *header = NULL;
179 (void) data;
181 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
183 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
185 /* Unrecognized path */
186 tt_int_op(directory_handle_command_get(conn, GET("/anything"), NULL, 0),
187 OP_EQ, 0);
188 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
189 NULL, NULL, 1, 0);
191 tt_str_op(NOT_FOUND, OP_EQ, header);
193 done:
194 UNMOCK(connection_write_to_buf_impl_);
195 connection_free_(TO_CONN(conn));
196 tor_free(header);
199 static void
200 test_dir_handle_get_robots_txt(void *data)
202 dir_connection_t *conn = NULL;
203 char *header = NULL;
204 char *body = NULL;
205 size_t body_used = 0;
206 (void) data;
208 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
210 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
212 tt_int_op(directory_handle_command_get(conn, GET("/tor/robots.txt"),
213 NULL, 0), OP_EQ, 0);
214 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
215 &body, &body_used, 29, 0);
217 tt_assert(header);
218 tt_assert(body);
220 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
221 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
222 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
223 tt_assert(strstr(header, "Content-Length: 28\r\n"));
225 tt_int_op(body_used, OP_EQ, strlen(body));
226 tt_str_op(body, OP_EQ, "User-agent: *\r\nDisallow: /\r\n");
228 done:
229 UNMOCK(connection_write_to_buf_impl_);
230 connection_free_(TO_CONN(conn));
231 tor_free(header);
232 tor_free(body);
235 #define RENDEZVOUS2_GET(descid) GET("/tor/rendezvous2/" descid)
236 static void
237 test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
239 dir_connection_t *conn = NULL;
240 char *header = NULL;
241 (void) data;
243 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
245 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
247 // connection is not encrypted
248 tt_assert(!connection_dir_is_encrypted(conn))
250 tt_int_op(directory_handle_command_get(conn, RENDEZVOUS2_GET(), NULL, 0),
251 OP_EQ, 0);
252 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
253 NULL, NULL, 1, 0);
255 tt_str_op(NOT_FOUND, OP_EQ, header);
257 done:
258 UNMOCK(connection_write_to_buf_impl_);
259 connection_free_(TO_CONN(conn));
260 tor_free(header);
263 static void
264 test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
265 void *data)
267 dir_connection_t *conn = NULL;
268 char *header = NULL;
269 (void) data;
271 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
272 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
274 // connection is encrypted
275 TO_CONN(conn)->linked = 1;
276 tt_assert(connection_dir_is_encrypted(conn));
278 tt_int_op(directory_handle_command_get(conn,
279 RENDEZVOUS2_GET("invalid-desc-id"), NULL, 0), OP_EQ, 0);
280 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
281 NULL, NULL, 1, 0);
283 tt_str_op(header, OP_EQ, BAD_REQUEST);
285 done:
286 UNMOCK(connection_write_to_buf_impl_);
287 connection_free_(TO_CONN(conn));
288 tor_free(header);
291 static void
292 test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
294 dir_connection_t *conn = NULL;
295 char *header = NULL;
296 (void) data;
298 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
299 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
301 // connection is encrypted
302 TO_CONN(conn)->linked = 1;
303 tt_assert(connection_dir_is_encrypted(conn));
305 //TODO: this cant be reached because rend_valid_descriptor_id() prevents this
306 //case to happen. This test is the same as
307 //test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id
308 //We should refactor to remove the case from the switch.
310 const char *req = RENDEZVOUS2_GET("1bababababababababababababababab");
311 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
313 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
314 NULL, NULL, 1, 0);
316 tt_str_op(header, OP_EQ, BAD_REQUEST);
318 done:
319 UNMOCK(connection_write_to_buf_impl_);
320 connection_free_(TO_CONN(conn));
321 tor_free(header);
324 static void
325 test_dir_handle_get_rendezvous2_not_found(void *data)
327 dir_connection_t *conn = NULL;
328 char *header = NULL;
329 (void) data;
331 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
332 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
334 rend_cache_init();
336 // connection is encrypted
337 TO_CONN(conn)->linked = 1;
338 tt_assert(connection_dir_is_encrypted(conn));
340 const char *req = RENDEZVOUS2_GET("3xqunszqnaolrrfmtzgaki7mxelgvkje");
341 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
342 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
343 NULL, NULL, 1, 0);
345 tt_str_op(NOT_FOUND, OP_EQ, header);
347 done:
348 UNMOCK(connection_write_to_buf_impl_);
349 connection_free_(TO_CONN(conn));
350 tor_free(header);
351 rend_cache_free_all();
354 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
356 static routerinfo_t *mock_routerinfo;
358 static const routerinfo_t *
359 NS(router_get_my_routerinfo)(void)
361 if (!mock_routerinfo) {
362 mock_routerinfo = tor_malloc_zero(sizeof(routerinfo_t));
365 return mock_routerinfo;
368 static void
369 test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
371 dir_connection_t *conn = NULL;
372 char *header = NULL;
373 char *body = NULL;
374 size_t body_used = 0;
375 char buff[30];
376 char req[70];
377 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
378 char *service_id = NULL;
379 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
380 size_t body_len = 0;
381 (void) data;
383 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
384 NS_MOCK(router_get_my_routerinfo);
386 rend_cache_init();
388 /* create a valid rend service descriptor */
389 #define RECENT_TIME -10
390 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
392 tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
393 OP_EQ, 0);
395 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
396 DIGEST_LEN);
398 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
400 // connection is encrypted
401 TO_CONN(conn)->linked = 1;
402 tt_assert(connection_dir_is_encrypted(conn));
404 tor_snprintf(req, sizeof(req), RENDEZVOUS2_GET("%s"), desc_id_base32);
406 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
408 body_len = strlen(desc_holder->desc_str);
409 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
410 &body, &body_used, body_len+1, 0);
412 tt_assert(header);
413 tt_assert(body);
415 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
416 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
417 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
418 tt_assert(strstr(header, "Pragma: no-cache\r\n"));
419 tor_snprintf(buff, sizeof(buff), "Content-Length: %ld\r\n", (long) body_len);
420 tt_assert(strstr(header, buff));
422 tt_int_op(body_used, OP_EQ, strlen(body));
423 tt_str_op(body, OP_EQ, desc_holder->desc_str);
425 done:
426 UNMOCK(connection_write_to_buf_impl_);
427 NS_UNMOCK(router_get_my_routerinfo);
429 connection_free_(TO_CONN(conn));
430 tor_free(header);
431 tor_free(body);
432 rend_encoded_v2_service_descriptor_free(desc_holder);
433 tor_free(service_id);
434 rend_cache_free_all();
437 #define MICRODESC_GET(digest) GET("/tor/micro/d/" digest)
438 static void
439 test_dir_handle_get_micro_d_not_found(void *data)
441 dir_connection_t *conn = NULL;
442 char *header = NULL;
443 (void) data;
445 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
447 #define B64_256_1 "8/Pz8/u7vz8/Pz+7vz8/Pz+7u/Pz8/P7u/Pz8/P7u78"
448 #define B64_256_2 "zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMw"
449 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
451 const char *req = MICRODESC_GET(B64_256_1 "-" B64_256_2);
452 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
454 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
455 NULL, NULL, 1, 0);
457 tt_str_op(NOT_FOUND, OP_EQ, header);
459 done:
460 UNMOCK(connection_write_to_buf_impl_);
462 connection_free_(TO_CONN(conn));
463 tor_free(header);
466 static or_options_t *mock_options = NULL;
467 static void
468 init_mock_options(void)
470 mock_options = tor_malloc(sizeof(or_options_t));
471 memset(mock_options, 0, sizeof(or_options_t));
472 mock_options->TestingTorNetwork = 1;
475 static const or_options_t *
476 mock_get_options(void)
478 tor_assert(mock_options);
479 return mock_options;
482 static const char microdesc[] =
483 "onion-key\n"
484 "-----BEGIN RSA PUBLIC KEY-----\n"
485 "MIGJAoGBAMjlHH/daN43cSVRaHBwgUfnszzAhg98EvivJ9Qxfv51mvQUxPjQ07es\n"
486 "gV/3n8fyh3Kqr/ehi9jxkdgSRfSnmF7giaHL1SLZ29kA7KtST+pBvmTpDtHa3ykX\n"
487 "Xorc7hJvIyTZoc1HU+5XSynj3gsBE5IGK1ZRzrNS688LnuZMVp1tAgMBAAE=\n"
488 "-----END RSA PUBLIC KEY-----\n";
490 static void
491 test_dir_handle_get_micro_d(void *data)
493 dir_connection_t *conn = NULL;
494 microdesc_cache_t *mc = NULL ;
495 smartlist_t *list = NULL;
496 char digest[DIGEST256_LEN];
497 char digest_base64[128];
498 char path[80];
499 char *header = NULL;
500 char *body = NULL;
501 size_t body_used = 0;
502 (void) data;
504 MOCK(get_options, mock_get_options);
505 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
507 /* SETUP */
508 init_mock_options();
509 const char *fn = get_fname("dir_handle_datadir_test1");
510 mock_options->DataDirectory = tor_strdup(fn);
512 #ifdef _WIN32
513 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
514 #else
515 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
516 #endif
518 /* Add microdesc to cache */
519 crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
520 base64_encode_nopad(digest_base64, sizeof(digest_base64),
521 (uint8_t *) digest, DIGEST256_LEN);
523 mc = get_microdesc_cache();
524 list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
525 time(NULL), NULL);
526 tt_int_op(1, OP_EQ, smartlist_len(list));
528 /* Make the request */
529 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
531 tor_snprintf(path, sizeof(path), MICRODESC_GET("%s"), digest_base64);
532 tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
534 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
535 &body, &body_used, strlen(microdesc)+1, 0);
537 tt_assert(header);
538 tt_assert(body);
540 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
541 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
542 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
544 tt_int_op(body_used, OP_EQ, strlen(body));
545 tt_str_op(body, OP_EQ, microdesc);
547 done:
548 UNMOCK(get_options);
549 UNMOCK(connection_write_to_buf_impl_);
551 or_options_free(mock_options); mock_options = NULL;
552 connection_free_(TO_CONN(conn));
553 tor_free(header);
554 tor_free(body);
555 smartlist_free(list);
556 microdesc_free_all();
559 static void
560 test_dir_handle_get_micro_d_server_busy(void *data)
562 dir_connection_t *conn = NULL;
563 microdesc_cache_t *mc = NULL ;
564 smartlist_t *list = NULL;
565 char digest[DIGEST256_LEN];
566 char digest_base64[128];
567 char path[80];
568 char *header = NULL;
569 (void) data;
571 MOCK(get_options, mock_get_options);
572 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
574 /* SETUP */
575 init_mock_options();
576 const char *fn = get_fname("dir_handle_datadir_test2");
577 mock_options->DataDirectory = tor_strdup(fn);
579 #ifdef _WIN32
580 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
581 #else
582 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
583 #endif
585 /* Add microdesc to cache */
586 crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
587 base64_encode_nopad(digest_base64, sizeof(digest_base64),
588 (uint8_t *) digest, DIGEST256_LEN);
590 mc = get_microdesc_cache();
591 list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
592 time(NULL), NULL);
593 tt_int_op(1, OP_EQ, smartlist_len(list));
595 //Make it busy
596 mock_options->CountPrivateBandwidth = 1;
598 /* Make the request */
599 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
601 tor_snprintf(path, sizeof(path), MICRODESC_GET("%s"), digest_base64);
602 tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
604 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
605 NULL, NULL, 1, 0);
607 tt_str_op(SERVER_BUSY, OP_EQ, header);
609 done:
610 UNMOCK(get_options);
611 UNMOCK(connection_write_to_buf_impl_);
613 or_options_free(mock_options); mock_options = NULL;
614 connection_free_(TO_CONN(conn));
615 tor_free(header);
616 smartlist_free(list);
617 microdesc_free_all();
620 #define BRIDGES_PATH "/tor/networkstatus-bridges"
621 static void
622 test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data)
624 dir_connection_t *conn = NULL;
625 char *header = NULL;
626 (void) data;
628 MOCK(get_options, mock_get_options);
629 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
631 /* SETUP */
632 init_mock_options();
633 mock_options->BridgeAuthoritativeDir = 1;
634 mock_options->BridgePassword_AuthDigest_ = tor_strdup("digest");
636 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
637 TO_CONN(conn)->linked = 1;
639 const char *req = GET(BRIDGES_PATH);
640 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
642 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
643 NULL, NULL, 1, 0);
645 tt_str_op(NOT_FOUND, OP_EQ, header);
647 done:
648 UNMOCK(get_options);
649 UNMOCK(connection_write_to_buf_impl_);
650 or_options_free(mock_options); mock_options = NULL;
651 connection_free_(TO_CONN(conn));
652 tor_free(header);
655 static void
656 test_dir_handle_get_networkstatus_bridges(void *data)
658 dir_connection_t *conn = NULL;
659 char *header = NULL;
660 (void) data;
662 MOCK(get_options, mock_get_options);
663 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
665 /* SETUP */
666 init_mock_options();
667 mock_options->BridgeAuthoritativeDir = 1;
668 mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
669 crypto_digest256(mock_options->BridgePassword_AuthDigest_,
670 "abcdefghijklm12345", 18, DIGEST_SHA256);
672 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
673 TO_CONN(conn)->linked = 1;
675 const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
676 "Authorization: Basic abcdefghijklm12345\r\n\r\n";
677 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
679 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
680 NULL, NULL, 1, 0);
682 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
683 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
684 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
685 tt_assert(strstr(header, "Content-Length: 0\r\n"));
687 done:
688 UNMOCK(get_options);
689 UNMOCK(connection_write_to_buf_impl_);
690 or_options_free(mock_options); mock_options = NULL;
691 connection_free_(TO_CONN(conn));
692 tor_free(header);
695 static void
696 test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data)
698 dir_connection_t *conn = NULL;
699 char *header = NULL;
700 (void) data;
702 MOCK(get_options, mock_get_options);
703 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
705 /* SETUP */
706 init_mock_options();
707 mock_options->BridgeAuthoritativeDir = 1;
708 mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
709 crypto_digest256(mock_options->BridgePassword_AuthDigest_,
710 "abcdefghijklm12345", 18, DIGEST_SHA256);
712 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
713 TO_CONN(conn)->linked = 1;
715 const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
716 "Authorization: Basic NOTSAMEDIGEST\r\n\r\n";
717 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
719 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
720 NULL, NULL, 1, 0);
722 tt_str_op(NOT_FOUND, OP_EQ, header);
724 done:
725 UNMOCK(get_options);
726 UNMOCK(connection_write_to_buf_impl_);
727 or_options_free(mock_options); mock_options = NULL;
728 connection_free_(TO_CONN(conn));
729 tor_free(header);
732 #define SERVER_DESC_GET(id) GET("/tor/server/" id)
733 static void
734 test_dir_handle_get_server_descriptors_not_found(void* data)
736 dir_connection_t *conn = NULL;
737 char *header = NULL;
738 (void) data;
740 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
742 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
744 const char *req = SERVER_DESC_GET("invalid");
745 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
747 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
748 NULL, NULL, 1, 0);
750 tt_str_op(NOT_FOUND, OP_EQ, header);
751 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_SERVER_BY_FP);
753 done:
754 UNMOCK(connection_write_to_buf_impl_);
755 or_options_free(mock_options); mock_options = NULL;
756 connection_free_(TO_CONN(conn));
757 tor_free(header);
760 static void
761 test_dir_handle_get_server_descriptors_all(void* data)
763 dir_connection_t *conn = NULL;
764 char *header = NULL;
765 char *body = NULL;
766 size_t body_used = 0;
767 (void) data;
769 /* Setup fake routerlist. */
770 helper_setup_fake_routerlist();
772 //TODO: change to router_get_my_extrainfo when testing "extra" path
773 NS_MOCK(router_get_my_routerinfo);
774 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
776 // We are one of the routers
777 routerlist_t *our_routerlist = router_get_routerlist();
778 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
779 mock_routerinfo = smartlist_get(our_routerlist->routers, 0);
780 set_server_identity_key(mock_routerinfo->identity_pkey);
782 /* Treat "all" requests as if they were unencrypted */
783 mock_routerinfo->cache_info.send_unencrypted = 1;
785 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
787 const char *req = SERVER_DESC_GET("all");
788 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
790 //TODO: Is this a BUG?
791 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
792 //which is smaller than that by annotation_len bytes
793 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
794 &body, &body_used,
795 mock_routerinfo->cache_info.signed_descriptor_len+1, 0);
797 tt_assert(header);
798 tt_assert(body);
800 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
801 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
802 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
804 //TODO: Is this a BUG?
805 //This is what should be expected: tt_int_op(body_used, OP_EQ, strlen(body));
806 tt_int_op(body_used, OP_EQ,
807 mock_routerinfo->cache_info.signed_descriptor_len);
809 tt_str_op(body, OP_EQ, mock_routerinfo->cache_info.signed_descriptor_body +
810 mock_routerinfo->cache_info.annotations_len);
811 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
813 done:
814 NS_UNMOCK(router_get_my_routerinfo);
815 UNMOCK(connection_write_to_buf_impl_);
816 connection_free_(TO_CONN(conn));
817 tor_free(header);
818 tor_free(body);
820 routerlist_free_all();
821 nodelist_free_all();
822 entry_guards_free_all();
825 static char
826 TEST_DESCRIPTOR[] =
827 "@uploaded-at 2014-06-08 19:20:11\n"
828 "@source \"127.0.0.1\"\n"
829 "router test000a 127.0.0.1 5000 0 7000\n"
830 "platform Tor 0.2.5.3-alpha-dev on Linux\n"
831 "protocols Link 1 2 Circuit 1\n"
832 "published 2014-06-08 19:20:11\n"
833 "fingerprint C7E7 CCB8 179F 8CC3 7F5C 8A04 2B3A 180B 934B 14BA\n"
834 "uptime 0\n"
835 "bandwidth 1073741824 1073741824 0\n"
836 "extra-info-digest 67A152A4C7686FB07664F872620635F194D76D95\n"
837 "caches-extra-info\n"
838 "onion-key\n"
839 "-----BEGIN RSA PUBLIC KEY-----\n"
840 "MIGJAoGBAOuBUIEBARMkkka/TGyaQNgUEDLP0KG7sy6KNQTNOlZHUresPr/vlVjo\n"
841 "HPpLMfu9M2z18c51YX/muWwY9x4MyQooD56wI4+AqXQcJRwQfQlPn3Ay82uZViA9\n"
842 "DpBajRieLlKKkl145KjArpD7F5BVsqccvjErgFYXvhhjSrx7BVLnAgMBAAE=\n"
843 "-----END RSA PUBLIC KEY-----\n"
844 "signing-key\n"
845 "-----BEGIN RSA PUBLIC KEY-----\n"
846 "MIGJAoGBAN6NLnSxWQnFXxqZi5D3b0BMgV6y9NJLGjYQVP+eWtPZWgqyv4zeYsqv\n"
847 "O9y6c5lvxyUxmNHfoAbe/s8f2Vf3/YaC17asAVSln4ktrr3e9iY74a9RMWHv1Gzk\n"
848 "3042nMcqj3PEhRN0PoLkcOZNjjmNbaqki6qy9bWWZDNTdo+uI44dAgMBAAE=\n"
849 "-----END RSA PUBLIC KEY-----\n"
850 "hidden-service-dir\n"
851 "contact auth0@test.test\n"
852 "ntor-onion-key pK4bs08ERYN591jj7ca17Rn9Q02TIEfhnjR6hSq+fhU=\n"
853 "reject *:*\n"
854 "router-signature\n"
855 "-----BEGIN SIGNATURE-----\n"
856 "rx88DuM3Y7tODlHNDDEVzKpwh3csaG1or+T4l2Xs1oq3iHHyPEtB6QTLYrC60trG\n"
857 "aAPsj3DEowGfjga1b248g2dtic8Ab+0exfjMm1RHXfDam5TXXZU3A0wMyoHjqHuf\n"
858 "eChGPgFNUvEc+5YtD27qEDcUjcinYztTs7/dzxBT4PE=\n"
859 "-----END SIGNATURE-----\n";
861 static void
862 test_dir_handle_get_server_descriptors_authority(void* data)
864 dir_connection_t *conn = NULL;
865 char *header = NULL;
866 char *body = NULL;
867 size_t body_used = 0;
868 crypto_pk_t *identity_pkey = pk_generate(0);
869 (void) data;
871 NS_MOCK(router_get_my_routerinfo);
872 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
874 /* init mock */
875 router_get_my_routerinfo();
876 crypto_pk_get_digest(identity_pkey,
877 mock_routerinfo->cache_info.identity_digest);
879 // the digest is mine (the channel is unnecrypted, so we must allow sending)
880 set_server_identity_key(identity_pkey);
881 mock_routerinfo->cache_info.send_unencrypted = 1;
883 /* Setup descriptor */
884 long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
885 mock_routerinfo->cache_info.signed_descriptor_body =
886 tor_strdup(TEST_DESCRIPTOR);
887 mock_routerinfo->cache_info.signed_descriptor_len =
888 strlen(TEST_DESCRIPTOR) - annotation_len;;
889 mock_routerinfo->cache_info.annotations_len = annotation_len;
891 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
893 const char *req = SERVER_DESC_GET("authority");
894 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
896 //TODO: Is this a BUG?
897 //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
898 //is smaller than that by annotation_len bytes
899 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
900 &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
902 tt_assert(header);
903 tt_assert(body);
905 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
906 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
907 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
909 tt_int_op(body_used, OP_EQ, strlen(body));
911 tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
912 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
914 done:
915 NS_UNMOCK(router_get_my_routerinfo);
916 UNMOCK(connection_write_to_buf_impl_);
917 tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
918 tor_free(mock_routerinfo);
919 connection_free_(TO_CONN(conn));
920 tor_free(header);
921 tor_free(body);
922 crypto_pk_free(identity_pkey);
925 static void
926 test_dir_handle_get_server_descriptors_fp(void* data)
928 dir_connection_t *conn = NULL;
929 char *header = NULL;
930 char *body = NULL;
931 size_t body_used = 0;
932 crypto_pk_t *identity_pkey = pk_generate(0);
933 (void) data;
935 NS_MOCK(router_get_my_routerinfo);
936 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
938 /* init mock */
939 router_get_my_routerinfo();
940 crypto_pk_get_digest(identity_pkey,
941 mock_routerinfo->cache_info.identity_digest);
943 // the digest is mine (the channel is unnecrypted, so we must allow sending)
944 set_server_identity_key(identity_pkey);
945 mock_routerinfo->cache_info.send_unencrypted = 1;
947 /* Setup descriptor */
948 long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
949 mock_routerinfo->cache_info.signed_descriptor_body =
950 tor_strdup(TEST_DESCRIPTOR);
951 mock_routerinfo->cache_info.signed_descriptor_len =
952 strlen(TEST_DESCRIPTOR) - annotation_len;
953 mock_routerinfo->cache_info.annotations_len = annotation_len;
955 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
957 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
958 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
959 const char *hex_digest = hex_str(mock_routerinfo->cache_info.identity_digest,
960 DIGEST_LEN);
962 char req[155];
963 tor_snprintf(req, sizeof(req), SERVER_DESC_GET("fp/%s+" HEX1 "+" HEX2),
964 hex_digest);
965 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
967 //TODO: Is this a BUG?
968 //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
969 //is smaller than that by annotation_len bytes
970 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
971 &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
973 tt_assert(header);
974 tt_assert(body);
976 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
977 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
978 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
980 tt_int_op(body_used, OP_EQ, strlen(body));
982 tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
983 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
985 done:
986 NS_UNMOCK(router_get_my_routerinfo);
987 UNMOCK(connection_write_to_buf_impl_);
988 tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
989 tor_free(mock_routerinfo);
990 connection_free_(TO_CONN(conn));
991 tor_free(header);
992 tor_free(body);
993 crypto_pk_free(identity_pkey);
996 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
997 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
999 static void
1000 test_dir_handle_get_server_descriptors_d(void* data)
1002 dir_connection_t *conn = NULL;
1003 char *header = NULL;
1004 char *body = NULL;
1005 size_t body_used = 0;
1006 crypto_pk_t *identity_pkey = pk_generate(0);
1007 (void) data;
1009 /* Setup fake routerlist. */
1010 helper_setup_fake_routerlist();
1012 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1014 /* Get one router's signed_descriptor_digest */
1015 routerlist_t *our_routerlist = router_get_routerlist();
1016 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
1017 routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
1018 const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
1019 DIGEST_LEN);
1021 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1023 char req_header[155]; /* XXX Why 155? What kind of number is that?? */
1024 tor_snprintf(req_header, sizeof(req_header),
1025 SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
1026 tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
1028 //TODO: Is this a BUG?
1029 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
1030 //which is smaller than that by annotation_len bytes
1031 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1032 &body, &body_used,
1033 router->cache_info.signed_descriptor_len+1, 0);
1035 tt_assert(header);
1036 tt_assert(body);
1038 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1039 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1040 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1042 //TODO: Is this a BUG?
1043 //This is what should be expected:
1044 //tt_int_op(body_used, OP_EQ, strlen(body));
1045 tt_int_op(body_used, OP_EQ, router->cache_info.signed_descriptor_len);
1047 tt_str_op(body, OP_EQ, router->cache_info.signed_descriptor_body +
1048 router->cache_info.annotations_len);
1049 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
1051 done:
1052 UNMOCK(connection_write_to_buf_impl_);
1053 tor_free(mock_routerinfo);
1054 connection_free_(TO_CONN(conn));
1055 tor_free(header);
1056 tor_free(body);
1057 crypto_pk_free(identity_pkey);
1059 routerlist_free_all();
1060 nodelist_free_all();
1061 entry_guards_free_all();
1064 static void
1065 test_dir_handle_get_server_descriptors_busy(void* data)
1067 dir_connection_t *conn = NULL;
1068 char *header = NULL;
1069 crypto_pk_t *identity_pkey = pk_generate(0);
1070 (void) data;
1072 /* Setup fake routerlist. */
1073 helper_setup_fake_routerlist();
1075 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1077 //Make it busy
1078 MOCK(get_options, mock_get_options);
1079 init_mock_options();
1080 mock_options->CountPrivateBandwidth = 1;
1082 /* Get one router's signed_descriptor_digest */
1083 routerlist_t *our_routerlist = router_get_routerlist();
1084 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
1085 routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
1086 const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
1087 DIGEST_LEN);
1089 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1091 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
1092 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
1093 char req_header[155]; /* XXX 155? Why 155? */
1094 tor_snprintf(req_header, sizeof(req_header),
1095 SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
1096 tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
1098 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1099 NULL, NULL, 1, 0);
1101 tt_assert(header);
1102 tt_str_op(SERVER_BUSY, OP_EQ, header);
1104 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
1106 done:
1107 UNMOCK(get_options);
1108 UNMOCK(connection_write_to_buf_impl_);
1109 tor_free(mock_routerinfo);
1110 connection_free_(TO_CONN(conn));
1111 tor_free(header);
1112 crypto_pk_free(identity_pkey);
1114 routerlist_free_all();
1115 nodelist_free_all();
1116 entry_guards_free_all();
1119 static void
1120 test_dir_handle_get_server_keys_bad_req(void* data)
1122 dir_connection_t *conn = NULL;
1123 char *header = NULL;
1124 (void) data;
1126 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1128 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1130 const char *req = GET("/tor/keys/");
1131 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1133 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1134 NULL, NULL, 1, 0);
1136 tt_assert(header);
1137 tt_str_op(BAD_REQUEST, OP_EQ, header);
1139 done:
1140 UNMOCK(connection_write_to_buf_impl_);
1141 connection_free_(TO_CONN(conn));
1142 tor_free(header);
1145 static void
1146 test_dir_handle_get_server_keys_all_not_found(void* data)
1148 dir_connection_t *conn = NULL;
1149 char *header = NULL;
1150 (void) data;
1152 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1154 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1156 const char *req = GET("/tor/keys/all");
1157 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1159 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1160 NULL, NULL, 1, 0);
1162 tt_assert(header);
1163 tt_str_op(NOT_FOUND, OP_EQ, header);
1165 done:
1166 UNMOCK(connection_write_to_buf_impl_);
1167 connection_free_(TO_CONN(conn));
1168 tor_free(header);
1171 #define TEST_CERTIFICATE AUTHORITY_CERT_3
1172 #define TEST_SIGNING_KEY AUTHORITY_SIGNKEY_A_DIGEST
1174 static const char TEST_CERT_IDENT_KEY[] =
1175 "D867ACF56A9D229B35C25F0090BC9867E906BE69";
1177 static void
1178 test_dir_handle_get_server_keys_all(void* data)
1180 dir_connection_t *conn = NULL;
1181 char *header = NULL;
1182 char *body = NULL;
1183 size_t body_used = 0;
1184 const char digest[DIGEST_LEN] = "";
1186 dir_server_t *ds = NULL;
1187 (void) data;
1189 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1191 clear_dir_servers();
1192 routerlist_free_all();
1194 /* create a trusted ds */
1195 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1196 NULL, V3_DIRINFO, 1.0);
1197 tt_assert(ds);
1198 dir_server_add(ds);
1200 /* ds v3_identity_digest is the certificate's identity_key */
1201 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1202 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1203 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1204 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
1206 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1208 const char *req = GET("/tor/keys/all");
1209 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1211 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1212 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1214 tt_assert(header);
1215 tt_assert(body);
1217 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1218 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1219 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1220 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1222 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1224 done:
1225 UNMOCK(connection_write_to_buf_impl_);
1226 connection_free_(TO_CONN(conn));
1227 tor_free(header);
1228 tor_free(body);
1230 clear_dir_servers();
1231 routerlist_free_all();
1234 static void
1235 test_dir_handle_get_server_keys_authority_not_found(void* data)
1237 dir_connection_t *conn = NULL;
1238 char *header = NULL;
1239 (void) data;
1241 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1243 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1245 const char *req = GET("/tor/keys/authority");
1246 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1248 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1249 NULL, NULL, 1, 0);
1251 tt_assert(header);
1252 tt_str_op(NOT_FOUND, OP_EQ, header);
1254 done:
1255 UNMOCK(connection_write_to_buf_impl_);
1256 connection_free_(TO_CONN(conn));
1257 tor_free(header);
1260 static authority_cert_t * mock_cert = NULL;
1262 static authority_cert_t *
1263 get_my_v3_authority_cert_m(void)
1265 tor_assert(mock_cert);
1266 return mock_cert;
1269 static void
1270 test_dir_handle_get_server_keys_authority(void* data)
1272 dir_connection_t *conn = NULL;
1273 char *header = NULL;
1274 char *body = NULL;
1275 size_t body_used = 0;
1276 (void) data;
1278 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
1280 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
1281 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1283 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1285 const char *req = GET("/tor/keys/authority");
1286 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1288 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1289 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1291 tt_assert(header);
1292 tt_assert(body);
1294 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1295 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1296 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1297 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1299 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1301 done:
1302 UNMOCK(get_my_v3_authority_cert);
1303 UNMOCK(connection_write_to_buf_impl_);
1304 connection_free_(TO_CONN(conn));
1305 tor_free(header);
1306 tor_free(body);
1307 authority_cert_free(mock_cert); mock_cert = NULL;
1310 static void
1311 test_dir_handle_get_server_keys_fp_not_found(void* data)
1313 dir_connection_t *conn = NULL;
1314 char *header = NULL;
1315 (void) data;
1317 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1319 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1321 const char *req = GET("/tor/keys/fp/somehex");
1322 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1324 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1325 NULL, NULL, 1, 0);
1327 tt_assert(header);
1328 tt_str_op(NOT_FOUND, OP_EQ, header);
1330 done:
1331 UNMOCK(connection_write_to_buf_impl_);
1332 connection_free_(TO_CONN(conn));
1333 tor_free(header);
1336 static void
1337 test_dir_handle_get_server_keys_fp(void* data)
1339 dir_connection_t *conn = NULL;
1340 char *header = NULL;
1341 char *body = NULL;
1342 size_t body_used = 0;
1343 dir_server_t *ds = NULL;
1344 const char digest[DIGEST_LEN] = "";
1345 (void) data;
1347 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1349 clear_dir_servers();
1350 routerlist_free_all();
1352 /* create a trusted ds */
1353 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1354 NULL, V3_DIRINFO, 1.0);
1355 tt_assert(ds);
1356 dir_server_add(ds);
1358 /* ds v3_identity_digest is the certificate's identity_key */
1359 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1360 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1362 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1363 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
1365 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1366 char req[71];
1367 tor_snprintf(req, sizeof(req),
1368 GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
1369 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1371 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1372 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1374 tt_assert(header);
1375 tt_assert(body);
1377 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1378 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1379 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1380 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1382 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1384 done:
1385 UNMOCK(connection_write_to_buf_impl_);
1386 connection_free_(TO_CONN(conn));
1387 tor_free(header);
1388 tor_free(body);
1389 clear_dir_servers();
1390 routerlist_free_all();
1393 static void
1394 test_dir_handle_get_server_keys_sk_not_found(void* data)
1396 dir_connection_t *conn = NULL;
1397 char *header = NULL;
1398 (void) data;
1400 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1402 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1404 const char *req = GET("/tor/keys/sk/somehex");
1405 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1407 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1408 NULL, NULL, 1, 0);
1410 tt_assert(header);
1411 tt_str_op(NOT_FOUND, OP_EQ, header);
1413 done:
1414 UNMOCK(connection_write_to_buf_impl_);
1415 connection_free_(TO_CONN(conn));
1416 tor_free(header);
1419 static void
1420 test_dir_handle_get_server_keys_sk(void* data)
1422 dir_connection_t *conn = NULL;
1423 char *header = NULL;
1424 char *body = NULL;
1425 size_t body_used = 0;
1426 (void) data;
1428 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
1429 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
1430 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1432 clear_dir_servers();
1433 routerlist_free_all();
1435 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1436 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
1438 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1439 char req[71];
1440 tor_snprintf(req, sizeof(req),
1441 GET("/tor/keys/sk/%s"), TEST_SIGNING_KEY);
1442 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1444 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1445 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1447 tt_assert(header);
1448 tt_assert(body);
1450 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1451 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1452 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1453 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1455 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1457 done:
1458 UNMOCK(get_my_v3_authority_cert);
1459 UNMOCK(connection_write_to_buf_impl_);
1460 connection_free_(TO_CONN(conn));
1461 authority_cert_free(mock_cert); mock_cert = NULL;
1462 tor_free(header);
1463 tor_free(body);
1466 static void
1467 test_dir_handle_get_server_keys_fpsk_not_found(void* data)
1469 dir_connection_t *conn = NULL;
1470 char *header = NULL;
1471 (void) data;
1473 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1475 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1477 const char *req = GET("/tor/keys/fp-sk/somehex");
1478 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1480 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1481 NULL, NULL, 1, 0);
1483 tt_assert(header);
1484 tt_str_op(NOT_FOUND, OP_EQ, header);
1486 done:
1487 UNMOCK(connection_write_to_buf_impl_);
1488 connection_free_(TO_CONN(conn));
1489 tor_free(header);
1492 static void
1493 test_dir_handle_get_server_keys_fpsk(void* data)
1495 dir_connection_t *conn = NULL;
1496 char *header = NULL;
1497 char *body = NULL;
1498 size_t body_used = 0;
1499 dir_server_t *ds = NULL;
1500 const char digest[DIGEST_LEN] = "";
1501 (void) data;
1503 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1505 clear_dir_servers();
1506 routerlist_free_all();
1508 /* create a trusted ds */
1509 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1510 NULL, V3_DIRINFO, 1.0);
1511 tt_assert(ds);
1513 /* ds v3_identity_digest is the certificate's identity_key */
1514 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1515 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1516 dir_server_add(ds);
1518 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1519 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
1521 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1523 char req[115];
1524 tor_snprintf(req, sizeof(req),
1525 GET("/tor/keys/fp-sk/%s-%s"),
1526 TEST_CERT_IDENT_KEY, TEST_SIGNING_KEY);
1528 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1530 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1531 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1533 tt_assert(header);
1534 tt_assert(body);
1536 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1537 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1538 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1539 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1541 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1543 done:
1544 UNMOCK(connection_write_to_buf_impl_);
1545 connection_free_(TO_CONN(conn));
1546 tor_free(header);
1547 tor_free(body);
1549 clear_dir_servers();
1550 routerlist_free_all();
1553 static void
1554 test_dir_handle_get_server_keys_busy(void* data)
1556 dir_connection_t *conn = NULL;
1557 char *header = NULL;
1558 dir_server_t *ds = NULL;
1559 const char digest[DIGEST_LEN] = "";
1560 (void) data;
1562 clear_dir_servers();
1563 routerlist_free_all();
1565 /* create a trusted ds */
1566 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1567 NULL, V3_DIRINFO, 1.0);
1568 tt_assert(ds);
1570 /* ds v3_identity_digest is the certificate's identity_key */
1571 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1572 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1573 dir_server_add(ds);
1575 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1576 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
1578 MOCK(get_options, mock_get_options);
1579 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1581 /* setup busy server */
1582 init_mock_options();
1583 mock_options->CountPrivateBandwidth = 1;
1585 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1586 char req[71];
1587 tor_snprintf(req, sizeof(req), GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
1588 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1590 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1591 NULL, NULL, 1, 0);
1593 tt_assert(header);
1594 tt_str_op(SERVER_BUSY, OP_EQ, header);
1596 done:
1597 UNMOCK(get_options);
1598 UNMOCK(connection_write_to_buf_impl_);
1599 connection_free_(TO_CONN(conn));
1600 tor_free(header);
1601 or_options_free(mock_options); mock_options = NULL;
1603 clear_dir_servers();
1604 routerlist_free_all();
1607 static networkstatus_t *mock_ns_val = NULL;
1608 static networkstatus_t *
1609 mock_ns_get_by_flavor(consensus_flavor_t f)
1611 (void)f;
1612 return mock_ns_val;
1615 static void
1616 test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d)
1618 dir_connection_t *conn = NULL;
1619 char *header = NULL;
1620 char *stats = NULL;
1621 (void) d;
1623 /* init mock */
1624 mock_ns_val = tor_malloc_zero(sizeof(networkstatus_t));
1625 mock_ns_val->flavor = FLAV_NS;
1626 mock_ns_val->voters = smartlist_new();
1628 /* init mock */
1629 init_mock_options();
1631 MOCK(get_options, mock_get_options);
1632 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1633 MOCK(networkstatus_get_latest_consensus_by_flavor, mock_ns_get_by_flavor);
1635 /* start gathering stats */
1636 mock_options->DirReqStatistics = 1;
1637 geoip_dirreq_stats_init(time(NULL));
1639 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1641 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1642 GET("/tor/status-vote/current/consensus-ns/" HEX1 "+" HEX2), NULL, 0));
1644 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1645 NULL, NULL, 1, 0);
1647 tt_assert(header);
1648 tt_str_op(NOT_ENOUGH_CONSENSUS_SIGNATURES, OP_EQ, header);
1650 stats = geoip_format_dirreq_stats(time(NULL));
1651 tt_assert(stats);
1652 tt_assert(strstr(stats, "not-enough-sigs=8"));
1654 done:
1655 UNMOCK(networkstatus_get_latest_consensus_by_flavor);
1656 UNMOCK(connection_write_to_buf_impl_);
1657 UNMOCK(get_options);
1659 connection_free_(TO_CONN(conn));
1660 tor_free(header);
1661 tor_free(stats);
1662 smartlist_free(mock_ns_val->voters);
1663 tor_free(mock_ns_val);
1664 or_options_free(mock_options); mock_options = NULL;
1667 static void
1668 test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data)
1670 dir_connection_t *conn = NULL;
1671 char *header = NULL;
1672 char *stats = NULL;
1673 (void) data;
1675 init_mock_options();
1677 MOCK(get_options, mock_get_options);
1678 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1680 /* start gathering stats */
1681 mock_options->DirReqStatistics = 1;
1682 geoip_dirreq_stats_init(time(NULL));
1684 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1685 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1686 GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
1688 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1689 NULL, NULL, 1, 0);
1690 tt_assert(header);
1691 tt_str_op(NOT_FOUND, OP_EQ, header);
1693 stats = geoip_format_dirreq_stats(time(NULL));
1694 tt_assert(stats);
1695 tt_assert(strstr(stats, "not-found=8"));
1697 done:
1698 UNMOCK(connection_write_to_buf_impl_);
1699 UNMOCK(get_options);
1700 connection_free_(TO_CONN(conn));
1701 tor_free(header);
1702 tor_free(stats);
1703 or_options_free(mock_options); mock_options = NULL;
1706 NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
1709 NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
1711 (void)addr;
1712 CALLED(geoip_get_country_by_addr)++;
1713 return 1;
1716 static void
1717 status_vote_current_consensus_ns_test(char **header, char **body,
1718 size_t *body_len)
1720 common_digests_t digests;
1721 dir_connection_t *conn = NULL;
1723 #define NETWORK_STATUS "some network status string"
1724 dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS, "ns", &digests,
1725 time(NULL));
1727 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1729 tt_assert(mock_options);
1730 mock_options->DirReqStatistics = 1;
1731 geoip_dirreq_stats_init(time(NULL));
1733 /* init geoip database */
1734 geoip_parse_entry("10,50,AB", AF_INET);
1735 tt_str_op("ab", OP_EQ, geoip_get_country_name(1));
1737 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1738 TO_CONN(conn)->address = tor_strdup("127.0.0.1");
1740 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1741 GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
1743 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1744 body, body_len, strlen(NETWORK_STATUS)+7, 0);
1746 done:
1747 UNMOCK(connection_write_to_buf_impl_);
1748 connection_free_(TO_CONN(conn));
1751 static void
1752 test_dir_handle_get_status_vote_current_consensus_ns(void* data)
1754 char *header = NULL;
1755 char *body = NULL, *comp_body = NULL;
1756 size_t body_used = 0, comp_body_used = 0;
1757 char *stats = NULL, *hist = NULL;
1758 (void) data;
1760 dirserv_free_all();
1761 clear_geoip_db();
1763 NS_MOCK(geoip_get_country_by_addr);
1764 MOCK(get_options, mock_get_options);
1766 init_mock_options();
1768 status_vote_current_consensus_ns_test(&header, &comp_body, &comp_body_used);
1769 tt_assert(header);
1771 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1772 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1773 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1774 tt_assert(strstr(header, "Pragma: no-cache\r\n"));
1776 compress_method_t compression = detect_compression_method(comp_body,
1777 comp_body_used);
1778 tt_int_op(ZLIB_METHOD, OP_EQ, compression);
1780 tor_gzip_uncompress(&body, &body_used, comp_body, comp_body_used,
1781 compression, 0, LOG_PROTOCOL_WARN);
1783 tt_str_op(NETWORK_STATUS, OP_EQ, body);
1784 tt_int_op(strlen(NETWORK_STATUS), OP_EQ, body_used);
1786 stats = geoip_format_dirreq_stats(time(NULL));
1787 tt_assert(stats);
1789 tt_assert(strstr(stats, "ok=8"));
1790 tt_assert(strstr(stats, "dirreq-v3-ips ab=8"));
1791 tt_assert(strstr(stats, "dirreq-v3-reqs ab=8"));
1792 tt_assert(strstr(stats, "dirreq-v3-direct-dl"
1793 " complete=0,timeout=0,running=4"));
1795 hist = geoip_get_request_history();
1796 tt_assert(hist);
1797 tt_str_op("ab=8", OP_EQ, hist);
1799 done:
1800 NS_UNMOCK(geoip_get_country_by_addr);
1801 UNMOCK(get_options);
1802 tor_free(header);
1803 tor_free(comp_body);
1804 tor_free(body);
1805 tor_free(stats);
1806 tor_free(hist);
1807 or_options_free(mock_options); mock_options = NULL;
1809 dirserv_free_all();
1810 clear_geoip_db();
1813 static void
1814 test_dir_handle_get_status_vote_current_consensus_ns_busy(void* data)
1816 char *header = NULL;
1817 char *body = NULL;
1818 size_t body_used = 0;
1819 char *stats = NULL;
1820 (void) data;
1822 dirserv_free_all();
1823 clear_geoip_db();
1825 MOCK(get_options, mock_get_options);
1827 // Make it busy
1828 init_mock_options();
1829 mock_options->CountPrivateBandwidth = 1;
1831 status_vote_current_consensus_ns_test(&header, &body, &body_used);
1832 tt_assert(header);
1834 tt_str_op(SERVER_BUSY, OP_EQ, header);
1836 stats = geoip_format_dirreq_stats(time(NULL));
1837 tt_assert(stats);
1838 tt_assert(strstr(stats, "busy=8"));
1840 done:
1841 UNMOCK(get_options);
1842 tor_free(header);
1843 tor_free(body);
1844 or_options_free(mock_options); mock_options = NULL;
1846 tor_free(stats);
1847 dirserv_free_all();
1848 clear_geoip_db();
1851 static void
1852 test_dir_handle_get_status_vote_current_not_found(void* data)
1854 dir_connection_t *conn = NULL;
1855 char *header = NULL;
1856 (void) data;
1858 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1860 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1861 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1862 GET("/tor/status-vote/current/" HEX1), NULL, 0));
1864 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1865 NULL, NULL, 1, 0);
1866 tt_assert(header);
1867 tt_str_op(NOT_FOUND, OP_EQ, header);
1869 done:
1870 UNMOCK(connection_write_to_buf_impl_);
1871 connection_free_(TO_CONN(conn));
1872 tor_free(header);
1875 #define VOTE_DIGEST "312A4890D4D832597ABBD3089C782DBBFB81E48D"
1877 static void
1878 status_vote_current_d_test(char **header, char **body, size_t *body_l)
1880 dir_connection_t *conn = NULL;
1882 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1884 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1885 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1886 GET("/tor/status-vote/current/d/" VOTE_DIGEST), NULL, 0));
1888 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1889 body, body_l, strlen(VOTE_BODY_V3)+1, 0);
1890 tt_assert(header);
1892 done:
1893 UNMOCK(connection_write_to_buf_impl_);
1894 connection_free_(TO_CONN(conn));
1897 static void
1898 status_vote_next_d_test(char **header, char **body, size_t *body_l)
1900 dir_connection_t *conn = NULL;
1902 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1904 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1905 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1906 GET("/tor/status-vote/next/d/" VOTE_DIGEST), NULL, 0));
1908 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1909 body, body_l, strlen(VOTE_BODY_V3)+1, 0);
1910 tt_assert(header);
1912 done:
1913 UNMOCK(connection_write_to_buf_impl_);
1914 connection_free_(TO_CONN(conn));
1917 static void
1918 test_dir_handle_get_status_vote_current_d_not_found(void* data)
1920 char *header = NULL;
1921 (void) data;
1923 status_vote_current_d_test(&header, NULL, NULL);
1925 tt_assert(header);
1926 tt_str_op(NOT_FOUND, OP_EQ, header);
1928 done:
1929 tor_free(header);
1932 static void
1933 test_dir_handle_get_status_vote_next_d_not_found(void* data)
1935 char *header = NULL;
1936 (void) data;
1938 status_vote_next_d_test(&header, NULL, NULL);
1940 tt_assert(header);
1941 tt_str_op(NOT_FOUND, OP_EQ, header);
1943 done:
1944 UNMOCK(connection_write_to_buf_impl_);
1945 tor_free(header);
1948 static void
1949 test_dir_handle_get_status_vote_d(void* data)
1951 char *header = NULL, *body = NULL;
1952 size_t body_used = 0;
1953 dir_server_t *ds = NULL;
1954 const char digest[DIGEST_LEN] = "";
1955 (void) data;
1957 clear_dir_servers();
1958 dirvote_free_all();
1960 /* create a trusted ds */
1961 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1962 NULL, V3_DIRINFO, 1.0);
1963 tt_assert(ds);
1964 dir_server_add(ds);
1966 /* ds v3_identity_digest is the certificate's identity_key */
1967 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1968 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1970 init_mock_options();
1971 mock_options->AuthoritativeDir = 1;
1972 mock_options->V3AuthoritativeDir = 1;
1973 mock_options->TestingV3AuthVotingStartOffset = 0;
1974 mock_options->TestingV3AuthInitialVotingInterval = 1;
1975 mock_options->TestingV3AuthInitialVoteDelay = 1;
1976 mock_options->TestingV3AuthInitialDistDelay = 1;
1978 time_t now = 1441223455 -1;
1979 dirvote_recalculate_timing(mock_options, now);
1981 const char *msg_out = NULL;
1982 int status_out = 0;
1983 struct pending_vote_t *pv = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
1984 &status_out);
1985 tt_assert(pv);
1987 status_vote_current_d_test(&header, &body, &body_used);
1989 tt_assert(header);
1990 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1991 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1992 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1993 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
1995 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
1997 tor_free(header);
1998 tor_free(body);
2000 status_vote_next_d_test(&header, &body, &body_used);
2002 tt_assert(header);
2003 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2004 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2005 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2006 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2008 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2010 done:
2011 tor_free(header);
2012 tor_free(body);
2013 or_options_free(mock_options); mock_options = NULL;
2015 clear_dir_servers();
2016 dirvote_free_all();
2019 static void
2020 test_dir_handle_get_status_vote_next_not_found(void* data)
2022 dir_connection_t *conn = NULL;
2023 char *header = NULL;
2024 (void) data;
2026 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2028 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2029 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2030 GET("/tor/status-vote/next/" HEX1), NULL, 0));
2032 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2033 NULL, NULL, 1, 0);
2034 tt_assert(header);
2035 tt_str_op(NOT_FOUND, OP_EQ, header);
2037 done:
2038 UNMOCK(connection_write_to_buf_impl_);
2039 connection_free_(TO_CONN(conn));
2040 tor_free(header);
2043 static void
2044 status_vote_next_consensus_test(char **header, char **body, size_t *body_used)
2046 dir_connection_t *conn = NULL;
2048 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2050 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2051 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2052 GET("/tor/status-vote/next/consensus"), NULL, 0));
2054 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
2055 body, body_used, 18, 0);
2056 done:
2057 UNMOCK(connection_write_to_buf_impl_);
2058 connection_free_(TO_CONN(conn));
2061 static void
2062 test_dir_handle_get_status_vote_next_consensus_not_found(void* data)
2064 char *header = NULL, *body = NULL;
2065 size_t body_used;
2066 (void) data;
2068 status_vote_next_consensus_test(&header, &body, &body_used);
2070 tt_assert(header);
2071 tt_str_op(NOT_FOUND, OP_EQ, header);
2073 done:
2074 tor_free(header);
2075 tor_free(body);
2078 static void
2079 test_dir_handle_get_status_vote_current_authority_not_found(void* data)
2081 dir_connection_t *conn = NULL;
2082 char *header = NULL;
2083 (void) data;
2085 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2087 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2088 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2089 GET("/tor/status-vote/current/authority"), NULL, 0));
2091 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2092 NULL, NULL, 1, 0);
2093 tt_assert(header);
2094 tt_str_op(NOT_FOUND, OP_EQ, header);
2096 done:
2097 UNMOCK(connection_write_to_buf_impl_);
2098 connection_free_(TO_CONN(conn));
2099 tor_free(header);
2102 static void
2103 test_dir_handle_get_status_vote_next_authority_not_found(void* data)
2105 dir_connection_t *conn = NULL;
2106 char *header = NULL;
2107 (void) data;
2109 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2111 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2112 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2113 GET("/tor/status-vote/next/authority"), NULL, 0));
2115 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2116 NULL, NULL, 1, 0);
2117 tt_assert(header);
2118 tt_str_op(NOT_FOUND, OP_EQ, header);
2120 done:
2121 UNMOCK(connection_write_to_buf_impl_);
2122 connection_free_(TO_CONN(conn));
2123 tor_free(header);
2126 NS_DECL(const char*,
2127 dirvote_get_pending_consensus, (consensus_flavor_t flav));
2129 const char*
2130 NS(dirvote_get_pending_consensus)(consensus_flavor_t flav)
2132 (void)flav;
2133 return "pending consensus";
2136 static void
2137 test_dir_handle_get_status_vote_next_consensus(void* data)
2139 char *header = NULL, *body = NULL;
2140 size_t body_used = 0;
2141 (void) data;
2143 NS_MOCK(dirvote_get_pending_consensus);
2145 status_vote_next_consensus_test(&header, &body, &body_used);
2146 tt_assert(header);
2148 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2149 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2150 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2151 tt_assert(strstr(header, "Content-Length: 17\r\n"));
2153 tt_str_op("pending consensus", OP_EQ, body);
2155 done:
2156 NS_UNMOCK(dirvote_get_pending_consensus);
2157 tor_free(header);
2158 tor_free(body);
2161 static void
2162 test_dir_handle_get_status_vote_next_consensus_busy(void* data)
2164 char *header = NULL, *body = NULL;
2165 size_t body_used = 0;
2166 (void) data;
2168 MOCK(get_options, mock_get_options);
2169 NS_MOCK(dirvote_get_pending_consensus);
2171 //Make it busy
2172 init_mock_options();
2173 mock_options->CountPrivateBandwidth = 1;
2175 status_vote_next_consensus_test(&header, &body, &body_used);
2177 tt_assert(header);
2178 tt_str_op(SERVER_BUSY, OP_EQ, header);
2180 done:
2181 NS_UNMOCK(dirvote_get_pending_consensus);
2182 UNMOCK(get_options);
2183 tor_free(header);
2184 tor_free(body);
2185 or_options_free(mock_options); mock_options = NULL;
2188 static void
2189 status_vote_next_consensus_signatures_test(char **header, char **body,
2190 size_t *body_used)
2192 dir_connection_t *conn = NULL;
2194 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2196 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2197 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2198 GET("/tor/status-vote/next/consensus-signatures"), NULL, 0));
2200 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
2201 body, body_used, 22, 0);
2203 done:
2204 connection_free_(TO_CONN(conn));
2205 UNMOCK(connection_write_to_buf_impl_);
2208 static void
2209 test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data)
2211 char *header = NULL, *body = NULL;
2212 size_t body_used;
2213 (void) data;
2215 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2217 tt_assert(header);
2218 tt_str_op(NOT_FOUND, OP_EQ, header);
2220 done:
2221 tor_free(header);
2222 tor_free(body);
2225 NS_DECL(const char*,
2226 dirvote_get_pending_detached_signatures, (void));
2228 const char*
2229 NS(dirvote_get_pending_detached_signatures)(void)
2231 return "pending detached sigs";
2234 static void
2235 test_dir_handle_get_status_vote_next_consensus_signatures(void* data)
2237 char *header = NULL, *body = NULL;
2238 size_t body_used = 0;
2239 (void) data;
2241 NS_MOCK(dirvote_get_pending_detached_signatures);
2243 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2244 tt_assert(header);
2246 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2247 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2248 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2249 tt_assert(strstr(header, "Content-Length: 21\r\n"));
2251 tt_str_op("pending detached sigs", OP_EQ, body);
2253 done:
2254 NS_UNMOCK(dirvote_get_pending_detached_signatures);
2255 tor_free(header);
2256 tor_free(body);
2259 static void
2260 test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data)
2262 char *header = NULL, *body = NULL;
2263 size_t body_used;
2264 (void) data;
2266 NS_MOCK(dirvote_get_pending_detached_signatures);
2267 MOCK(get_options, mock_get_options);
2269 //Make it busy
2270 init_mock_options();
2271 mock_options->CountPrivateBandwidth = 1;
2273 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2275 tt_assert(header);
2276 tt_str_op(SERVER_BUSY, OP_EQ, header);
2278 done:
2279 UNMOCK(get_options);
2280 NS_UNMOCK(dirvote_get_pending_detached_signatures);
2281 tor_free(header);
2282 tor_free(body);
2283 or_options_free(mock_options); mock_options = NULL;
2286 static void
2287 test_dir_handle_get_status_vote_next_authority(void* data)
2289 dir_connection_t *conn = NULL;
2290 char *header = NULL, *body = NULL;
2291 const char *msg_out = NULL;
2292 int status_out = 0;
2293 size_t body_used = 0;
2294 dir_server_t *ds = NULL;
2295 const char digest[DIGEST_LEN] = "";
2296 (void) data;
2298 clear_dir_servers();
2299 routerlist_free_all();
2300 dirvote_free_all();
2302 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
2304 /* create a trusted ds */
2305 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
2306 NULL, V3_DIRINFO, 1.0);
2307 tt_assert(ds);
2308 dir_server_add(ds);
2310 /* ds v3_identity_digest is the certificate's identity_key */
2311 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
2312 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
2313 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
2314 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
2316 init_mock_options();
2317 mock_options->AuthoritativeDir = 1;
2318 mock_options->V3AuthoritativeDir = 1;
2319 mock_options->TestingV3AuthVotingStartOffset = 0;
2320 mock_options->TestingV3AuthInitialVotingInterval = 1;
2321 mock_options->TestingV3AuthInitialVoteDelay = 1;
2322 mock_options->TestingV3AuthInitialDistDelay = 1;
2324 time_t now = 1441223455 -1;
2325 dirvote_recalculate_timing(mock_options, now);
2327 struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
2328 &status_out);
2329 tt_assert(vote);
2331 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
2332 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2334 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2335 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2336 GET("/tor/status-vote/next/authority"), NULL, 0));
2338 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2339 &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
2341 tt_assert(header);
2342 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2343 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2344 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2345 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2347 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2349 done:
2350 UNMOCK(connection_write_to_buf_impl_);
2351 UNMOCK(get_my_v3_authority_cert);
2352 connection_free_(TO_CONN(conn));
2353 tor_free(header);
2354 tor_free(body);
2355 authority_cert_free(mock_cert); mock_cert = NULL;
2356 or_options_free(mock_options); mock_options = NULL;
2358 clear_dir_servers();
2359 routerlist_free_all();
2360 dirvote_free_all();
2363 static void
2364 test_dir_handle_get_status_vote_current_authority(void* data)
2366 dir_connection_t *conn = NULL;
2367 char *header = NULL, *body = NULL;
2368 const char *msg_out = NULL;
2369 int status_out = 0;
2370 size_t body_used = 0;
2371 const char digest[DIGEST_LEN] = "";
2373 dir_server_t *ds = NULL;
2374 (void) data;
2376 clear_dir_servers();
2377 routerlist_free_all();
2378 dirvote_free_all();
2380 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
2382 /* create a trusted ds */
2383 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
2384 NULL, V3_DIRINFO, 1.0);
2385 tt_assert(ds);
2386 dir_server_add(ds);
2388 /* ds v3_identity_digest is the certificate's identity_key */
2389 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
2390 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
2392 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
2393 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
2395 init_mock_options();
2396 mock_options->AuthoritativeDir = 1;
2397 mock_options->V3AuthoritativeDir = 1;
2398 mock_options->TestingV3AuthVotingStartOffset = 0;
2399 mock_options->TestingV3AuthInitialVotingInterval = 1;
2400 mock_options->TestingV3AuthInitialVoteDelay = 1;
2401 mock_options->TestingV3AuthInitialDistDelay = 1;
2403 time_t now = 1441223455;
2404 dirvote_recalculate_timing(mock_options, now-1);
2406 struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
2407 &status_out);
2408 tt_assert(vote);
2410 // move the pending vote to previous vote
2411 dirvote_act(mock_options, now+1);
2413 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
2414 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2416 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2417 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2418 GET("/tor/status-vote/current/authority"), NULL, 0));
2420 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2421 &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
2423 tt_assert(header);
2424 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2425 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2426 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2427 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2429 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2431 done:
2432 UNMOCK(connection_write_to_buf_impl_);
2433 UNMOCK(get_my_v3_authority_cert);
2434 connection_free_(TO_CONN(conn));
2435 tor_free(header);
2436 tor_free(body);
2437 authority_cert_free(mock_cert); mock_cert = NULL;
2438 or_options_free(mock_options); mock_options = NULL;
2440 clear_dir_servers();
2441 routerlist_free_all();
2442 dirvote_free_all();
2445 #define DIR_HANDLE_CMD(name,flags) \
2446 { #name, test_dir_handle_get_##name, (flags), NULL, NULL }
2448 struct testcase_t dir_handle_get_tests[] = {
2449 DIR_HANDLE_CMD(not_found, 0),
2450 DIR_HANDLE_CMD(bad_request, 0),
2451 DIR_HANDLE_CMD(v1_command_not_found, 0),
2452 DIR_HANDLE_CMD(v1_command, 0),
2453 DIR_HANDLE_CMD(robots_txt, 0),
2454 DIR_HANDLE_CMD(rendezvous2_not_found_if_not_encrypted, 0),
2455 DIR_HANDLE_CMD(rendezvous2_not_found, 0),
2456 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_with_invalid_desc_id, 0),
2457 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_not_well_formed, 0),
2458 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_success, 0),
2459 DIR_HANDLE_CMD(micro_d_not_found, 0),
2460 DIR_HANDLE_CMD(micro_d_server_busy, 0),
2461 DIR_HANDLE_CMD(micro_d, 0),
2462 DIR_HANDLE_CMD(networkstatus_bridges_not_found_without_auth, 0),
2463 DIR_HANDLE_CMD(networkstatus_bridges_not_found_wrong_auth, 0),
2464 DIR_HANDLE_CMD(networkstatus_bridges, 0),
2465 DIR_HANDLE_CMD(server_descriptors_not_found, 0),
2466 DIR_HANDLE_CMD(server_descriptors_busy, TT_FORK),
2467 DIR_HANDLE_CMD(server_descriptors_all, TT_FORK),
2468 DIR_HANDLE_CMD(server_descriptors_authority, TT_FORK),
2469 DIR_HANDLE_CMD(server_descriptors_fp, TT_FORK),
2470 DIR_HANDLE_CMD(server_descriptors_d, TT_FORK),
2471 DIR_HANDLE_CMD(server_keys_bad_req, 0),
2472 DIR_HANDLE_CMD(server_keys_busy, 0),
2473 DIR_HANDLE_CMD(server_keys_all_not_found, 0),
2474 DIR_HANDLE_CMD(server_keys_all, 0),
2475 DIR_HANDLE_CMD(server_keys_authority_not_found, 0),
2476 DIR_HANDLE_CMD(server_keys_authority, 0),
2477 DIR_HANDLE_CMD(server_keys_fp_not_found, 0),
2478 DIR_HANDLE_CMD(server_keys_fp, 0),
2479 DIR_HANDLE_CMD(server_keys_sk_not_found, 0),
2480 DIR_HANDLE_CMD(server_keys_sk, 0),
2481 DIR_HANDLE_CMD(server_keys_fpsk_not_found, 0),
2482 DIR_HANDLE_CMD(server_keys_fpsk, 0),
2483 DIR_HANDLE_CMD(status_vote_current_not_found, 0),
2484 DIR_HANDLE_CMD(status_vote_next_not_found, 0),
2485 DIR_HANDLE_CMD(status_vote_current_authority_not_found, 0),
2486 DIR_HANDLE_CMD(status_vote_current_authority, 0),
2487 DIR_HANDLE_CMD(status_vote_next_authority_not_found, 0),
2488 DIR_HANDLE_CMD(status_vote_next_authority, 0),
2489 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_enough_sigs, 0),
2490 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_found, 0),
2491 DIR_HANDLE_CMD(status_vote_current_consensus_ns_busy, 0),
2492 DIR_HANDLE_CMD(status_vote_current_consensus_ns, 0),
2493 DIR_HANDLE_CMD(status_vote_current_d_not_found, 0),
2494 DIR_HANDLE_CMD(status_vote_next_d_not_found, 0),
2495 DIR_HANDLE_CMD(status_vote_d, 0),
2496 DIR_HANDLE_CMD(status_vote_next_consensus_not_found, 0),
2497 DIR_HANDLE_CMD(status_vote_next_consensus_busy, 0),
2498 DIR_HANDLE_CMD(status_vote_next_consensus, 0),
2499 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_not_found, 0),
2500 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_busy, 0),
2501 DIR_HANDLE_CMD(status_vote_next_consensus_signatures, 0),
2502 END_OF_TESTCASES