rip out hid_serv_acting_as_directory()
[tor.git] / src / test / test_dir_handle_get.c
blobc75b2b6632134273e1a8124f1d501d9d072c2cd4
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 #include "vote_descriptors.inc"
43 #define NS_MODULE dir_handle_get
45 static void
46 connection_write_to_buf_mock(const char *string, size_t len,
47 connection_t *conn, int zlib)
49 (void) zlib;
51 tor_assert(string);
52 tor_assert(conn);
54 write_to_buf(string, len, conn->outbuf);
57 #define GET(path) "GET " path " HTTP/1.0\r\n\r\n"
58 #define NOT_FOUND "HTTP/1.0 404 Not found\r\n\r\n"
59 #define BAD_REQUEST "HTTP/1.0 400 Bad request\r\n\r\n"
60 #define SERVER_BUSY "HTTP/1.0 503 Directory busy, try again later\r\n\r\n"
61 #define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
62 "Consensus not signed by sufficient number of requested authorities\r\n\r\n"
64 static tor_addr_t MOCK_TOR_ADDR;
66 static void
67 test_dir_handle_get_bad_request(void *data)
69 dir_connection_t *conn = NULL;
70 char *header = NULL;
71 (void) data;
73 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
75 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
76 tt_int_op(directory_handle_command_get(conn, "", NULL, 0), OP_EQ, 0);
78 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
79 NULL, NULL, 1, 0);
81 tt_str_op(header, OP_EQ, BAD_REQUEST);
83 done:
84 UNMOCK(connection_write_to_buf_impl_);
85 connection_free_(TO_CONN(conn));
86 tor_free(header);
89 static void
90 test_dir_handle_get_v1_command_not_found(void *data)
92 dir_connection_t *conn = NULL;
93 char *header = NULL;
94 (void) data;
96 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
98 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
100 // no frontpage configured
101 tt_ptr_op(get_dirportfrontpage(), OP_EQ, NULL);
103 /* V1 path */
104 tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
105 OP_EQ, 0);
107 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
108 NULL, NULL, 1, 0);
110 tt_str_op(NOT_FOUND, OP_EQ, header);
112 done:
113 UNMOCK(connection_write_to_buf_impl_);
114 connection_free_(TO_CONN(conn));
115 tor_free(header);
118 static const char*
119 mock_get_dirportfrontpage(void)
121 return "HELLO FROM FRONTPAGE";
124 static void
125 test_dir_handle_get_v1_command(void *data)
127 dir_connection_t *conn = NULL;
128 char *header = NULL;
129 char *body = NULL;
130 size_t body_used = 0, body_len = 0;
131 const char *exp_body = NULL;
132 (void) data;
134 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
135 MOCK(get_dirportfrontpage, mock_get_dirportfrontpage);
137 exp_body = get_dirportfrontpage();
138 body_len = strlen(exp_body);
140 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
141 tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
142 OP_EQ, 0);
144 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
145 &body, &body_used, body_len+1, 0);
147 tt_assert(header);
148 tt_assert(body);
150 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
151 tt_assert(strstr(header, "Content-Type: text/html\r\n"));
152 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
153 tt_assert(strstr(header, "Content-Length: 20\r\n"));
155 tt_int_op(body_used, OP_EQ, strlen(body));
156 tt_str_op(body, OP_EQ, exp_body);
158 done:
159 UNMOCK(connection_write_to_buf_impl_);
160 UNMOCK(get_dirportfrontpage);
161 connection_free_(TO_CONN(conn));
162 tor_free(header);
163 tor_free(body);
166 static void
167 test_dir_handle_get_not_found(void *data)
169 dir_connection_t *conn = NULL;
170 char *header = NULL;
171 (void) data;
173 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
175 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
177 /* Unrecognized path */
178 tt_int_op(directory_handle_command_get(conn, GET("/anything"), NULL, 0),
179 OP_EQ, 0);
180 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
181 NULL, NULL, 1, 0);
183 tt_str_op(NOT_FOUND, OP_EQ, header);
185 done:
186 UNMOCK(connection_write_to_buf_impl_);
187 connection_free_(TO_CONN(conn));
188 tor_free(header);
191 static void
192 test_dir_handle_get_robots_txt(void *data)
194 dir_connection_t *conn = NULL;
195 char *header = NULL;
196 char *body = NULL;
197 size_t body_used = 0;
198 (void) data;
200 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
202 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
204 tt_int_op(directory_handle_command_get(conn, GET("/tor/robots.txt"),
205 NULL, 0), OP_EQ, 0);
206 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
207 &body, &body_used, 29, 0);
209 tt_assert(header);
210 tt_assert(body);
212 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
213 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
214 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
215 tt_assert(strstr(header, "Content-Length: 28\r\n"));
217 tt_int_op(body_used, OP_EQ, strlen(body));
218 tt_str_op(body, OP_EQ, "User-agent: *\r\nDisallow: /\r\n");
220 done:
221 UNMOCK(connection_write_to_buf_impl_);
222 connection_free_(TO_CONN(conn));
223 tor_free(header);
224 tor_free(body);
227 static void
228 test_dir_handle_get_bytes_txt(void *data)
230 dir_connection_t *conn = NULL;
231 char *header = NULL;
232 char *body = NULL;
233 size_t body_used = 0, body_len = 0;
234 char buff[30];
235 char *exp_body = NULL;
236 (void) data;
238 exp_body = directory_dump_request_log();
239 body_len = strlen(exp_body);
241 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
243 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
245 tt_int_op(directory_handle_command_get(conn, GET("/tor/bytes.txt"), NULL, 0),
246 OP_EQ, 0);
247 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
248 &body, &body_used, body_len+1, 0);
250 tt_assert(header);
251 tt_assert(body);
253 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
254 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
255 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
256 tt_assert(strstr(header, "Pragma: no-cache\r\n"));
258 sprintf(buff, "Content-Length: %ld\r\n", (long) body_len);
259 tt_assert(strstr(header, buff));
261 tt_int_op(body_used, OP_EQ, strlen(body));
262 tt_str_op(body, OP_EQ, exp_body);
264 done:
265 UNMOCK(connection_write_to_buf_impl_);
266 connection_free_(TO_CONN(conn));
267 tor_free(header);
268 tor_free(body);
269 tor_free(exp_body);
272 #define RENDEZVOUS2_GET(descid) GET("/tor/rendezvous2/" descid)
273 static void
274 test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
276 dir_connection_t *conn = NULL;
277 char *header = NULL;
278 (void) data;
280 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
282 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
284 // connection is not encrypted
285 tt_assert(!connection_dir_is_encrypted(conn))
287 tt_int_op(directory_handle_command_get(conn, RENDEZVOUS2_GET(), NULL, 0),
288 OP_EQ, 0);
289 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
290 NULL, NULL, 1, 0);
292 tt_str_op(NOT_FOUND, OP_EQ, header);
294 done:
295 UNMOCK(connection_write_to_buf_impl_);
296 connection_free_(TO_CONN(conn));
297 tor_free(header);
300 static void
301 test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
302 void *data)
304 dir_connection_t *conn = NULL;
305 char *header = NULL;
306 (void) data;
308 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
309 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
311 // connection is encrypted
312 TO_CONN(conn)->linked = 1;
313 tt_assert(connection_dir_is_encrypted(conn));
315 tt_int_op(directory_handle_command_get(conn,
316 RENDEZVOUS2_GET("invalid-desc-id"), NULL, 0), OP_EQ, 0);
317 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
318 NULL, NULL, 1, 0);
320 tt_str_op(header, OP_EQ, BAD_REQUEST);
322 done:
323 UNMOCK(connection_write_to_buf_impl_);
324 connection_free_(TO_CONN(conn));
325 tor_free(header);
328 static void
329 test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
331 dir_connection_t *conn = NULL;
332 char *header = NULL;
333 (void) data;
335 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
336 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
338 // connection is encrypted
339 TO_CONN(conn)->linked = 1;
340 tt_assert(connection_dir_is_encrypted(conn));
342 //TODO: this cant be reached because rend_valid_descriptor_id() prevents this
343 //case to happen. This test is the same as
344 //test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id
345 //We should refactor to remove the case from the switch.
347 const char *req = RENDEZVOUS2_GET("1bababababababababababababababab");
348 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
350 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
351 NULL, NULL, 1, 0);
353 tt_str_op(header, OP_EQ, BAD_REQUEST);
355 done:
356 UNMOCK(connection_write_to_buf_impl_);
357 connection_free_(TO_CONN(conn));
358 tor_free(header);
361 static void
362 test_dir_handle_get_rendezvous2_not_found(void *data)
364 dir_connection_t *conn = NULL;
365 char *header = NULL;
366 (void) data;
368 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
369 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
371 rend_cache_init();
373 // connection is encrypted
374 TO_CONN(conn)->linked = 1;
375 tt_assert(connection_dir_is_encrypted(conn));
377 const char *req = RENDEZVOUS2_GET("3xqunszqnaolrrfmtzgaki7mxelgvkje");
378 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
379 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
380 NULL, NULL, 1, 0);
382 tt_str_op(NOT_FOUND, OP_EQ, header);
384 done:
385 UNMOCK(connection_write_to_buf_impl_);
386 connection_free_(TO_CONN(conn));
387 tor_free(header);
388 rend_cache_free_all();
391 NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
393 static routerinfo_t *mock_routerinfo;
395 static const routerinfo_t *
396 NS(router_get_my_routerinfo)(void)
398 if (!mock_routerinfo) {
399 mock_routerinfo = tor_malloc_zero(sizeof(routerinfo_t));
402 return mock_routerinfo;
405 static void
406 test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
408 dir_connection_t *conn = NULL;
409 char *header = NULL;
410 char *body = NULL;
411 size_t body_used = 0;
412 char buff[30];
413 char req[70];
414 rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
415 char *service_id = NULL;
416 char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
417 size_t body_len = 0;
418 (void) data;
420 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
421 NS_MOCK(router_get_my_routerinfo);
423 rend_cache_init();
425 /* create a valid rend service descriptor */
426 #define RECENT_TIME -10
427 generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
429 tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
430 OP_EQ, RCS_OKAY);
432 base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
433 DIGEST_LEN);
435 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
437 // connection is encrypted
438 TO_CONN(conn)->linked = 1;
439 tt_assert(connection_dir_is_encrypted(conn));
441 sprintf(req, RENDEZVOUS2_GET("%s"), desc_id_base32);
443 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
445 body_len = strlen(desc_holder->desc_str);
446 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
447 &body, &body_used, body_len+1, 0);
449 tt_assert(header);
450 tt_assert(body);
452 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
453 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
454 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
455 tt_assert(strstr(header, "Pragma: no-cache\r\n"));
456 sprintf(buff, "Content-Length: %ld\r\n", (long) body_len);
457 tt_assert(strstr(header, buff));
459 tt_int_op(body_used, OP_EQ, strlen(body));
460 tt_str_op(body, OP_EQ, desc_holder->desc_str);
462 done:
463 UNMOCK(connection_write_to_buf_impl_);
464 NS_UNMOCK(router_get_my_routerinfo);
466 connection_free_(TO_CONN(conn));
467 tor_free(header);
468 tor_free(body);
469 rend_encoded_v2_service_descriptor_free(desc_holder);
470 tor_free(service_id);
471 rend_cache_free_all();
474 #define MICRODESC_GET(digest) GET("/tor/micro/d/" digest)
475 static void
476 test_dir_handle_get_micro_d_not_found(void *data)
478 dir_connection_t *conn = NULL;
479 char *header = NULL;
480 (void) data;
482 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
484 #define B64_256_1 "8/Pz8/u7vz8/Pz+7vz8/Pz+7u/Pz8/P7u/Pz8/P7u78"
485 #define B64_256_2 "zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMw"
486 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
488 const char *req = MICRODESC_GET(B64_256_1 "-" B64_256_2);
489 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
491 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
492 NULL, NULL, 1, 0);
494 tt_str_op(NOT_FOUND, OP_EQ, header);
496 done:
497 UNMOCK(connection_write_to_buf_impl_);
499 connection_free_(TO_CONN(conn));
500 tor_free(header);
503 static or_options_t *mock_options = NULL;
504 static void
505 init_mock_options(void)
507 mock_options = malloc(sizeof(or_options_t));
508 memset(mock_options, 0, sizeof(or_options_t));
509 mock_options->TestingTorNetwork = 1;
512 static const or_options_t *
513 mock_get_options(void)
515 tor_assert(mock_options);
516 return mock_options;
519 static const char microdesc[] =
520 "onion-key\n"
521 "-----BEGIN RSA PUBLIC KEY-----\n"
522 "MIGJAoGBAMjlHH/daN43cSVRaHBwgUfnszzAhg98EvivJ9Qxfv51mvQUxPjQ07es\n"
523 "gV/3n8fyh3Kqr/ehi9jxkdgSRfSnmF7giaHL1SLZ29kA7KtST+pBvmTpDtHa3ykX\n"
524 "Xorc7hJvIyTZoc1HU+5XSynj3gsBE5IGK1ZRzrNS688LnuZMVp1tAgMBAAE=\n"
525 "-----END RSA PUBLIC KEY-----\n";
527 static void
528 test_dir_handle_get_micro_d(void *data)
530 dir_connection_t *conn = NULL;
531 microdesc_cache_t *mc = NULL ;
532 smartlist_t *list = NULL;
533 char digest[DIGEST256_LEN];
534 char digest_base64[128];
535 char path[80];
536 char *header = NULL;
537 char *body = NULL;
538 size_t body_used = 0;
539 (void) data;
541 MOCK(get_options, mock_get_options);
542 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
544 /* SETUP */
545 init_mock_options();
546 const char *fn = get_fname("dir_handle_datadir_test1");
547 mock_options->DataDirectory = tor_strdup(fn);
549 #ifdef _WIN32
550 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
551 #else
552 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
553 #endif
555 /* Add microdesc to cache */
556 crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
557 base64_encode_nopad(digest_base64, sizeof(digest_base64),
558 (uint8_t *) digest, DIGEST256_LEN);
560 mc = get_microdesc_cache();
561 list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
562 time(NULL), NULL);
563 tt_int_op(1, OP_EQ, smartlist_len(list));
565 /* Make the request */
566 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
568 sprintf(path, MICRODESC_GET("%s"), digest_base64);
569 tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
571 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
572 &body, &body_used, strlen(microdesc)+1, 0);
574 tt_assert(header);
575 tt_assert(body);
577 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
578 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
579 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
581 tt_int_op(body_used, OP_EQ, strlen(body));
582 tt_str_op(body, OP_EQ, microdesc);
584 done:
585 UNMOCK(get_options);
586 UNMOCK(connection_write_to_buf_impl_);
588 or_options_free(mock_options); mock_options = NULL;
589 connection_free_(TO_CONN(conn));
590 tor_free(header);
591 tor_free(body);
592 smartlist_free(list);
593 microdesc_free_all();
596 static void
597 test_dir_handle_get_micro_d_server_busy(void *data)
599 dir_connection_t *conn = NULL;
600 microdesc_cache_t *mc = NULL ;
601 smartlist_t *list = NULL;
602 char digest[DIGEST256_LEN];
603 char digest_base64[128];
604 char path[80];
605 char *header = NULL;
606 (void) data;
608 MOCK(get_options, mock_get_options);
609 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
611 /* SETUP */
612 init_mock_options();
613 const char *fn = get_fname("dir_handle_datadir_test2");
614 mock_options->DataDirectory = tor_strdup(fn);
616 #ifdef _WIN32
617 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
618 #else
619 tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
620 #endif
622 /* Add microdesc to cache */
623 crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
624 base64_encode_nopad(digest_base64, sizeof(digest_base64),
625 (uint8_t *) digest, DIGEST256_LEN);
627 mc = get_microdesc_cache();
628 list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
629 time(NULL), NULL);
630 tt_int_op(1, OP_EQ, smartlist_len(list));
632 //Make it busy
633 mock_options->CountPrivateBandwidth = 1;
635 /* Make the request */
636 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
638 sprintf(path, MICRODESC_GET("%s"), digest_base64);
639 tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
641 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
642 NULL, NULL, 1, 0);
644 tt_str_op(SERVER_BUSY, OP_EQ, header);
646 done:
647 UNMOCK(get_options);
648 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);
653 smartlist_free(list);
654 microdesc_free_all();
657 #define BRIDGES_PATH "/tor/networkstatus-bridges"
658 static void
659 test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data)
661 dir_connection_t *conn = NULL;
662 char *header = NULL;
663 (void) data;
665 MOCK(get_options, mock_get_options);
666 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
668 /* SETUP */
669 init_mock_options();
670 mock_options->BridgeAuthoritativeDir = 1;
671 mock_options->BridgePassword_AuthDigest_ = tor_strdup("digest");
673 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
674 TO_CONN(conn)->linked = 1;
676 const char *req = GET(BRIDGES_PATH);
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_str_op(NOT_FOUND, OP_EQ, header);
684 done:
685 UNMOCK(get_options);
686 UNMOCK(connection_write_to_buf_impl_);
687 or_options_free(mock_options); mock_options = NULL;
688 connection_free_(TO_CONN(conn));
689 tor_free(header);
692 static void
693 test_dir_handle_get_networkstatus_bridges(void *data)
695 dir_connection_t *conn = NULL;
696 char *header = NULL;
697 (void) data;
699 MOCK(get_options, mock_get_options);
700 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
702 /* SETUP */
703 init_mock_options();
704 mock_options->BridgeAuthoritativeDir = 1;
705 mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
706 crypto_digest256(mock_options->BridgePassword_AuthDigest_,
707 "abcdefghijklm12345", 18, DIGEST_SHA256);
709 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
710 TO_CONN(conn)->linked = 1;
712 const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
713 "Authorization: Basic abcdefghijklm12345\r\n\r\n";
714 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
716 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
717 NULL, NULL, 1, 0);
719 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
720 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
721 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
722 tt_assert(strstr(header, "Content-Length: 0\r\n"));
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 static void
733 test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data)
735 dir_connection_t *conn = NULL;
736 char *header = NULL;
737 (void) data;
739 MOCK(get_options, mock_get_options);
740 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
742 /* SETUP */
743 init_mock_options();
744 mock_options->BridgeAuthoritativeDir = 1;
745 mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
746 crypto_digest256(mock_options->BridgePassword_AuthDigest_,
747 "abcdefghijklm12345", 18, DIGEST_SHA256);
749 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
750 TO_CONN(conn)->linked = 1;
752 const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
753 "Authorization: Basic NOTSAMEDIGEST\r\n\r\n";
754 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
756 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
757 NULL, NULL, 1, 0);
759 tt_str_op(NOT_FOUND, OP_EQ, header);
761 done:
762 UNMOCK(get_options);
763 UNMOCK(connection_write_to_buf_impl_);
764 or_options_free(mock_options); mock_options = NULL;
765 connection_free_(TO_CONN(conn));
766 tor_free(header);
769 #define SERVER_DESC_GET(id) GET("/tor/server/" id)
770 static void
771 test_dir_handle_get_server_descriptors_not_found(void* data)
773 dir_connection_t *conn = NULL;
774 char *header = NULL;
775 (void) data;
777 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
779 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
781 const char *req = SERVER_DESC_GET("invalid");
782 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
784 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
785 NULL, NULL, 1, 0);
787 tt_str_op(NOT_FOUND, OP_EQ, header);
788 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_SERVER_BY_FP);
790 done:
791 UNMOCK(connection_write_to_buf_impl_);
792 or_options_free(mock_options); mock_options = NULL;
793 connection_free_(TO_CONN(conn));
794 tor_free(header);
797 static void
798 test_dir_handle_get_server_descriptors_all(void* data)
800 dir_connection_t *conn = NULL;
801 char *header = NULL;
802 char *body = NULL;
803 size_t body_used = 0;
804 (void) data;
806 /* Setup fake routerlist. */
807 helper_setup_fake_routerlist();
809 //TODO: change to router_get_my_extrainfo when testing "extra" path
810 NS_MOCK(router_get_my_routerinfo);
811 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
813 // We are one of the routers
814 routerlist_t *our_routerlist = router_get_routerlist();
815 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
816 mock_routerinfo = smartlist_get(our_routerlist->routers, 0);
817 set_server_identity_key(mock_routerinfo->identity_pkey);
819 /* Treat "all" requests as if they were unencrypted */
820 mock_routerinfo->cache_info.send_unencrypted = 1;
822 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
824 const char *req = SERVER_DESC_GET("all");
825 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
827 //TODO: Is this a BUG?
828 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
829 //which is smaller than that by annotation_len bytes
830 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
831 &body, &body_used,
832 mock_routerinfo->cache_info.signed_descriptor_len+1, 0);
834 tt_assert(header);
835 tt_assert(body);
837 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
838 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
839 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
841 //TODO: Is this a BUG?
842 //This is what should be expected: tt_int_op(body_used, OP_EQ, strlen(body));
843 tt_int_op(body_used, OP_EQ,
844 mock_routerinfo->cache_info.signed_descriptor_len);
846 tt_str_op(body, OP_EQ, mock_routerinfo->cache_info.signed_descriptor_body +
847 mock_routerinfo->cache_info.annotations_len);
848 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
850 done:
851 NS_UNMOCK(router_get_my_routerinfo);
852 UNMOCK(connection_write_to_buf_impl_);
853 connection_free_(TO_CONN(conn));
854 tor_free(header);
855 tor_free(body);
857 routerlist_free_all();
858 nodelist_free_all();
859 entry_guards_free_all();
862 static char
863 TEST_DESCRIPTOR[] =
864 "@uploaded-at 2014-06-08 19:20:11\n"
865 "@source \"127.0.0.1\"\n"
866 "router test000a 127.0.0.1 5000 0 7000\n"
867 "platform Tor 0.2.5.3-alpha-dev on Linux\n"
868 "protocols Link 1 2 Circuit 1\n"
869 "published 2014-06-08 19:20:11\n"
870 "fingerprint C7E7 CCB8 179F 8CC3 7F5C 8A04 2B3A 180B 934B 14BA\n"
871 "uptime 0\n"
872 "bandwidth 1073741824 1073741824 0\n"
873 "extra-info-digest 67A152A4C7686FB07664F872620635F194D76D95\n"
874 "caches-extra-info\n"
875 "onion-key\n"
876 "-----BEGIN RSA PUBLIC KEY-----\n"
877 "MIGJAoGBAOuBUIEBARMkkka/TGyaQNgUEDLP0KG7sy6KNQTNOlZHUresPr/vlVjo\n"
878 "HPpLMfu9M2z18c51YX/muWwY9x4MyQooD56wI4+AqXQcJRwQfQlPn3Ay82uZViA9\n"
879 "DpBajRieLlKKkl145KjArpD7F5BVsqccvjErgFYXvhhjSrx7BVLnAgMBAAE=\n"
880 "-----END RSA PUBLIC KEY-----\n"
881 "signing-key\n"
882 "-----BEGIN RSA PUBLIC KEY-----\n"
883 "MIGJAoGBAN6NLnSxWQnFXxqZi5D3b0BMgV6y9NJLGjYQVP+eWtPZWgqyv4zeYsqv\n"
884 "O9y6c5lvxyUxmNHfoAbe/s8f2Vf3/YaC17asAVSln4ktrr3e9iY74a9RMWHv1Gzk\n"
885 "3042nMcqj3PEhRN0PoLkcOZNjjmNbaqki6qy9bWWZDNTdo+uI44dAgMBAAE=\n"
886 "-----END RSA PUBLIC KEY-----\n"
887 "hidden-service-dir\n"
888 "contact auth0@test.test\n"
889 "ntor-onion-key pK4bs08ERYN591jj7ca17Rn9Q02TIEfhnjR6hSq+fhU=\n"
890 "reject *:*\n"
891 "router-signature\n"
892 "-----BEGIN SIGNATURE-----\n"
893 "rx88DuM3Y7tODlHNDDEVzKpwh3csaG1or+T4l2Xs1oq3iHHyPEtB6QTLYrC60trG\n"
894 "aAPsj3DEowGfjga1b248g2dtic8Ab+0exfjMm1RHXfDam5TXXZU3A0wMyoHjqHuf\n"
895 "eChGPgFNUvEc+5YtD27qEDcUjcinYztTs7/dzxBT4PE=\n"
896 "-----END SIGNATURE-----\n";
898 static void
899 test_dir_handle_get_server_descriptors_authority(void* data)
901 dir_connection_t *conn = NULL;
902 char *header = NULL;
903 char *body = NULL;
904 size_t body_used = 0;
905 crypto_pk_t *identity_pkey = pk_generate(0);
906 (void) data;
908 NS_MOCK(router_get_my_routerinfo);
909 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
911 /* init mock */
912 router_get_my_routerinfo();
913 crypto_pk_get_digest(identity_pkey,
914 mock_routerinfo->cache_info.identity_digest);
916 // the digest is mine (the channel is unnecrypted, so we must allow sending)
917 set_server_identity_key(identity_pkey);
918 mock_routerinfo->cache_info.send_unencrypted = 1;
920 /* Setup descriptor */
921 long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
922 mock_routerinfo->cache_info.signed_descriptor_body =
923 tor_strdup(TEST_DESCRIPTOR);
924 mock_routerinfo->cache_info.signed_descriptor_len =
925 strlen(TEST_DESCRIPTOR) - annotation_len;;
926 mock_routerinfo->cache_info.annotations_len = annotation_len;
928 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
930 const char *req = SERVER_DESC_GET("authority");
931 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
933 //TODO: Is this a BUG?
934 //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
935 //is smaller than that by annotation_len bytes
936 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
937 &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
939 tt_assert(header);
940 tt_assert(body);
942 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
943 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
944 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
946 tt_int_op(body_used, OP_EQ, strlen(body));
948 tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
949 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
951 done:
952 NS_UNMOCK(router_get_my_routerinfo);
953 UNMOCK(connection_write_to_buf_impl_);
954 tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
955 tor_free(mock_routerinfo);
956 connection_free_(TO_CONN(conn));
957 tor_free(header);
958 tor_free(body);
959 crypto_pk_free(identity_pkey);
962 static void
963 test_dir_handle_get_server_descriptors_fp(void* data)
965 dir_connection_t *conn = NULL;
966 char *header = NULL;
967 char *body = NULL;
968 size_t body_used = 0;
969 crypto_pk_t *identity_pkey = pk_generate(0);
970 (void) data;
972 NS_MOCK(router_get_my_routerinfo);
973 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
975 /* init mock */
976 router_get_my_routerinfo();
977 crypto_pk_get_digest(identity_pkey,
978 mock_routerinfo->cache_info.identity_digest);
980 // the digest is mine (the channel is unnecrypted, so we must allow sending)
981 set_server_identity_key(identity_pkey);
982 mock_routerinfo->cache_info.send_unencrypted = 1;
984 /* Setup descriptor */
985 long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
986 mock_routerinfo->cache_info.signed_descriptor_body =
987 tor_strdup(TEST_DESCRIPTOR);
988 mock_routerinfo->cache_info.signed_descriptor_len =
989 strlen(TEST_DESCRIPTOR) - annotation_len;
990 mock_routerinfo->cache_info.annotations_len = annotation_len;
992 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
994 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
995 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
996 const char *hex_digest = hex_str(mock_routerinfo->cache_info.identity_digest,
997 DIGEST_LEN);
999 char req[155];
1000 sprintf(req, SERVER_DESC_GET("fp/%s+" HEX1 "+" HEX2), hex_digest);
1001 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1003 //TODO: Is this a BUG?
1004 //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
1005 //is smaller than that by annotation_len bytes
1006 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1007 &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
1009 tt_assert(header);
1010 tt_assert(body);
1012 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1013 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1014 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1016 tt_int_op(body_used, OP_EQ, strlen(body));
1018 tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
1019 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
1021 done:
1022 NS_UNMOCK(router_get_my_routerinfo);
1023 UNMOCK(connection_write_to_buf_impl_);
1024 tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
1025 tor_free(mock_routerinfo);
1026 connection_free_(TO_CONN(conn));
1027 tor_free(header);
1028 tor_free(body);
1029 crypto_pk_free(identity_pkey);
1032 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
1033 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
1035 static void
1036 test_dir_handle_get_server_descriptors_d(void* data)
1038 dir_connection_t *conn = NULL;
1039 char *header = NULL;
1040 char *body = NULL;
1041 size_t body_used = 0;
1042 crypto_pk_t *identity_pkey = pk_generate(0);
1043 (void) data;
1045 /* Setup fake routerlist. */
1046 helper_setup_fake_routerlist();
1048 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1050 /* Get one router's signed_descriptor_digest */
1051 routerlist_t *our_routerlist = router_get_routerlist();
1052 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
1053 routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
1054 const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
1055 DIGEST_LEN);
1057 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1059 char req_header[155];
1060 sprintf(req_header, SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
1061 tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
1063 //TODO: Is this a BUG?
1064 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
1065 //which is smaller than that by annotation_len bytes
1066 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1067 &body, &body_used,
1068 router->cache_info.signed_descriptor_len+1, 0);
1070 tt_assert(header);
1071 tt_assert(body);
1073 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1074 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1075 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1077 //TODO: Is this a BUG?
1078 //This is what should be expected:
1079 //tt_int_op(body_used, OP_EQ, strlen(body));
1080 tt_int_op(body_used, OP_EQ, router->cache_info.signed_descriptor_len);
1082 tt_str_op(body, OP_EQ, router->cache_info.signed_descriptor_body +
1083 router->cache_info.annotations_len);
1084 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
1086 done:
1087 UNMOCK(connection_write_to_buf_impl_);
1088 tor_free(mock_routerinfo);
1089 connection_free_(TO_CONN(conn));
1090 tor_free(header);
1091 tor_free(body);
1092 crypto_pk_free(identity_pkey);
1094 routerlist_free_all();
1095 nodelist_free_all();
1096 entry_guards_free_all();
1099 static void
1100 test_dir_handle_get_server_descriptors_busy(void* data)
1102 dir_connection_t *conn = NULL;
1103 char *header = NULL;
1104 crypto_pk_t *identity_pkey = pk_generate(0);
1105 (void) data;
1107 /* Setup fake routerlist. */
1108 helper_setup_fake_routerlist();
1110 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1112 //Make it busy
1113 MOCK(get_options, mock_get_options);
1114 init_mock_options();
1115 mock_options->CountPrivateBandwidth = 1;
1117 /* Get one router's signed_descriptor_digest */
1118 routerlist_t *our_routerlist = router_get_routerlist();
1119 tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
1120 routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
1121 const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
1122 DIGEST_LEN);
1124 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1126 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
1127 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
1128 char req_header[155];
1129 sprintf(req_header, SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
1130 tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
1132 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1133 NULL, NULL, 1, 0);
1135 tt_assert(header);
1136 tt_str_op(SERVER_BUSY, OP_EQ, header);
1138 tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
1140 done:
1141 UNMOCK(get_options);
1142 UNMOCK(connection_write_to_buf_impl_);
1143 tor_free(mock_routerinfo);
1144 connection_free_(TO_CONN(conn));
1145 tor_free(header);
1146 crypto_pk_free(identity_pkey);
1148 routerlist_free_all();
1149 nodelist_free_all();
1150 entry_guards_free_all();
1153 static void
1154 test_dir_handle_get_server_keys_bad_req(void* data)
1156 dir_connection_t *conn = NULL;
1157 char *header = NULL;
1158 (void) data;
1160 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1162 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1164 const char *req = GET("/tor/keys/");
1165 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1167 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1168 NULL, NULL, 1, 0);
1170 tt_assert(header);
1171 tt_str_op(BAD_REQUEST, OP_EQ, header);
1173 done:
1174 UNMOCK(connection_write_to_buf_impl_);
1175 connection_free_(TO_CONN(conn));
1176 tor_free(header);
1179 static void
1180 test_dir_handle_get_server_keys_all_not_found(void* data)
1182 dir_connection_t *conn = NULL;
1183 char *header = NULL;
1184 (void) data;
1186 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1188 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1190 const char *req = GET("/tor/keys/all");
1191 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1193 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1194 NULL, NULL, 1, 0);
1196 tt_assert(header);
1197 tt_str_op(NOT_FOUND, OP_EQ, header);
1199 done:
1200 UNMOCK(connection_write_to_buf_impl_);
1201 connection_free_(TO_CONN(conn));
1202 tor_free(header);
1205 #define TEST_CERTIFICATE AUTHORITY_CERT_3
1206 #define TEST_SIGNING_KEY AUTHORITY_SIGNKEY_A_DIGEST
1207 extern const char AUTHORITY_CERT_3[];
1208 extern const char AUTHORITY_SIGNKEY_A_DIGEST[];
1210 static const char TEST_CERT_IDENT_KEY[] =
1211 "D867ACF56A9D229B35C25F0090BC9867E906BE69";
1213 static void
1214 test_dir_handle_get_server_keys_all(void* data)
1216 dir_connection_t *conn = NULL;
1217 char *header = NULL;
1218 char *body = NULL;
1219 size_t body_used = 0;
1220 const char digest[DIGEST_LEN] = "";
1222 dir_server_t *ds = NULL;
1223 (void) data;
1225 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1227 clear_dir_servers();
1228 routerlist_free_all();
1230 /* create a trusted ds */
1231 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1232 NULL, V3_DIRINFO, 1.0);
1233 tt_assert(ds);
1234 dir_server_add(ds);
1236 /* ds v3_identity_digest is the certificate's identity_key */
1237 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1238 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1239 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1240 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
1242 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1244 const char *req = GET("/tor/keys/all");
1245 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1247 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1248 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1250 tt_assert(header);
1251 tt_assert(body);
1253 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1254 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1255 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1256 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1258 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1260 done:
1261 UNMOCK(connection_write_to_buf_impl_);
1262 connection_free_(TO_CONN(conn));
1263 tor_free(header);
1264 tor_free(body);
1266 clear_dir_servers();
1267 routerlist_free_all();
1270 static void
1271 test_dir_handle_get_server_keys_authority_not_found(void* data)
1273 dir_connection_t *conn = NULL;
1274 char *header = NULL;
1275 (void) data;
1277 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1279 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1281 const char *req = GET("/tor/keys/authority");
1282 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1284 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1285 NULL, NULL, 1, 0);
1287 tt_assert(header);
1288 tt_str_op(NOT_FOUND, OP_EQ, header);
1290 done:
1291 UNMOCK(connection_write_to_buf_impl_);
1292 connection_free_(TO_CONN(conn));
1293 tor_free(header);
1296 static authority_cert_t * mock_cert = NULL;
1298 static authority_cert_t *
1299 get_my_v3_authority_cert_m(void)
1301 tor_assert(mock_cert);
1302 return mock_cert;
1305 static void
1306 test_dir_handle_get_server_keys_authority(void* data)
1308 dir_connection_t *conn = NULL;
1309 char *header = NULL;
1310 char *body = NULL;
1311 size_t body_used = 0;
1312 (void) data;
1314 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
1316 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
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/authority");
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 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1327 tt_assert(header);
1328 tt_assert(body);
1330 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1331 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1332 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1333 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1335 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1337 done:
1338 UNMOCK(get_my_v3_authority_cert);
1339 UNMOCK(connection_write_to_buf_impl_);
1340 connection_free_(TO_CONN(conn));
1341 tor_free(header);
1342 tor_free(body);
1343 authority_cert_free(mock_cert); mock_cert = NULL;
1346 static void
1347 test_dir_handle_get_server_keys_fp_not_found(void* data)
1349 dir_connection_t *conn = NULL;
1350 char *header = NULL;
1351 (void) data;
1353 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1355 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1357 const char *req = GET("/tor/keys/fp/somehex");
1358 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1360 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1361 NULL, NULL, 1, 0);
1363 tt_assert(header);
1364 tt_str_op(NOT_FOUND, OP_EQ, header);
1366 done:
1367 UNMOCK(connection_write_to_buf_impl_);
1368 connection_free_(TO_CONN(conn));
1369 tor_free(header);
1372 static void
1373 test_dir_handle_get_server_keys_fp(void* data)
1375 dir_connection_t *conn = NULL;
1376 char *header = NULL;
1377 char *body = NULL;
1378 size_t body_used = 0;
1379 dir_server_t *ds = NULL;
1380 const char digest[DIGEST_LEN] = "";
1381 (void) data;
1383 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1385 clear_dir_servers();
1386 routerlist_free_all();
1388 /* create a trusted ds */
1389 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1390 NULL, V3_DIRINFO, 1.0);
1391 tt_assert(ds);
1392 dir_server_add(ds);
1394 /* ds v3_identity_digest is the certificate's identity_key */
1395 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1396 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1398 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1399 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
1401 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1402 char req[71];
1403 sprintf(req, GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
1404 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1406 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1407 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1409 tt_assert(header);
1410 tt_assert(body);
1412 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1413 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1414 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1415 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1417 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1419 done:
1420 UNMOCK(connection_write_to_buf_impl_);
1421 connection_free_(TO_CONN(conn));
1422 tor_free(header);
1423 tor_free(body);
1424 clear_dir_servers();
1425 routerlist_free_all();
1428 static void
1429 test_dir_handle_get_server_keys_sk_not_found(void* data)
1431 dir_connection_t *conn = NULL;
1432 char *header = NULL;
1433 (void) data;
1435 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1437 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1439 const char *req = GET("/tor/keys/sk/somehex");
1440 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1442 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1443 NULL, NULL, 1, 0);
1445 tt_assert(header);
1446 tt_str_op(NOT_FOUND, OP_EQ, header);
1448 done:
1449 UNMOCK(connection_write_to_buf_impl_);
1450 connection_free_(TO_CONN(conn));
1451 tor_free(header);
1454 static void
1455 test_dir_handle_get_server_keys_sk(void* data)
1457 dir_connection_t *conn = NULL;
1458 char *header = NULL;
1459 char *body = NULL;
1460 size_t body_used = 0;
1461 (void) data;
1463 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
1464 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
1465 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1467 clear_dir_servers();
1468 routerlist_free_all();
1470 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1471 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
1473 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1474 char req[71];
1475 sprintf(req, GET("/tor/keys/sk/%s"), TEST_SIGNING_KEY);
1476 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1478 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1479 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1481 tt_assert(header);
1482 tt_assert(body);
1484 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1485 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1486 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1487 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1489 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1491 done:
1492 UNMOCK(get_my_v3_authority_cert);
1493 UNMOCK(connection_write_to_buf_impl_);
1494 connection_free_(TO_CONN(conn));
1495 authority_cert_free(mock_cert); mock_cert = NULL;
1496 tor_free(header);
1497 tor_free(body);
1500 static void
1501 test_dir_handle_get_server_keys_fpsk_not_found(void* data)
1503 dir_connection_t *conn = NULL;
1504 char *header = NULL;
1505 (void) data;
1507 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1509 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1511 const char *req = GET("/tor/keys/fp-sk/somehex");
1512 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1514 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1515 NULL, NULL, 1, 0);
1517 tt_assert(header);
1518 tt_str_op(NOT_FOUND, OP_EQ, header);
1520 done:
1521 UNMOCK(connection_write_to_buf_impl_);
1522 connection_free_(TO_CONN(conn));
1523 tor_free(header);
1526 static void
1527 test_dir_handle_get_server_keys_fpsk(void* data)
1529 dir_connection_t *conn = NULL;
1530 char *header = NULL;
1531 char *body = NULL;
1532 size_t body_used = 0;
1533 dir_server_t *ds = NULL;
1534 const char digest[DIGEST_LEN] = "";
1535 (void) data;
1537 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1539 clear_dir_servers();
1540 routerlist_free_all();
1542 /* create a trusted ds */
1543 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1544 NULL, V3_DIRINFO, 1.0);
1545 tt_assert(ds);
1547 /* ds v3_identity_digest is the certificate's identity_key */
1548 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1549 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1550 dir_server_add(ds);
1552 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1553 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
1555 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1557 char req[115];
1558 sprintf(req, GET("/tor/keys/fp-sk/%s-%s"),
1559 TEST_CERT_IDENT_KEY, TEST_SIGNING_KEY);
1561 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1563 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1564 &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
1566 tt_assert(header);
1567 tt_assert(body);
1569 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1570 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1571 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1572 tt_assert(strstr(header, "Content-Length: 1883\r\n"));
1574 tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
1576 done:
1577 UNMOCK(connection_write_to_buf_impl_);
1578 connection_free_(TO_CONN(conn));
1579 tor_free(header);
1580 tor_free(body);
1582 clear_dir_servers();
1583 routerlist_free_all();
1586 static void
1587 test_dir_handle_get_server_keys_busy(void* data)
1589 dir_connection_t *conn = NULL;
1590 char *header = NULL;
1591 dir_server_t *ds = NULL;
1592 const char digest[DIGEST_LEN] = "";
1593 (void) data;
1595 clear_dir_servers();
1596 routerlist_free_all();
1598 /* create a trusted ds */
1599 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1600 NULL, V3_DIRINFO, 1.0);
1601 tt_assert(ds);
1603 /* ds v3_identity_digest is the certificate's identity_key */
1604 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
1605 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
1606 dir_server_add(ds);
1608 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
1609 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
1611 MOCK(get_options, mock_get_options);
1612 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1614 /* setup busy server */
1615 init_mock_options();
1616 mock_options->CountPrivateBandwidth = 1;
1618 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1619 char req[71];
1620 sprintf(req, GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
1621 tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
1623 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1624 NULL, NULL, 1, 0);
1626 tt_assert(header);
1627 tt_str_op(SERVER_BUSY, OP_EQ, header);
1629 done:
1630 UNMOCK(get_options);
1631 UNMOCK(connection_write_to_buf_impl_);
1632 connection_free_(TO_CONN(conn));
1633 tor_free(header);
1634 or_options_free(mock_options); mock_options = NULL;
1636 clear_dir_servers();
1637 routerlist_free_all();
1640 static networkstatus_t *mock_ns_val = NULL;
1641 static networkstatus_t *
1642 mock_ns_get_by_flavor(consensus_flavor_t f)
1644 (void)f;
1645 return mock_ns_val;
1648 static void
1649 test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d)
1651 dir_connection_t *conn = NULL;
1652 char *header = NULL;
1653 char *stats = NULL;
1654 (void) d;
1656 /* init mock */
1657 mock_ns_val = tor_malloc_zero(sizeof(networkstatus_t));
1658 mock_ns_val->flavor = FLAV_NS;
1659 mock_ns_val->voters = smartlist_new();
1661 /* init mock */
1662 init_mock_options();
1664 MOCK(get_options, mock_get_options);
1665 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1666 MOCK(networkstatus_get_latest_consensus_by_flavor, mock_ns_get_by_flavor);
1668 /* start gathering stats */
1669 mock_options->DirReqStatistics = 1;
1670 geoip_dirreq_stats_init(time(NULL));
1672 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1674 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1675 GET("/tor/status-vote/current/consensus-ns/" HEX1 "+" HEX2), NULL, 0));
1677 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1678 NULL, NULL, 1, 0);
1680 tt_assert(header);
1681 tt_str_op(NOT_ENOUGH_CONSENSUS_SIGNATURES, OP_EQ, header);
1683 stats = geoip_format_dirreq_stats(time(NULL));
1684 tt_assert(stats);
1685 tt_assert(strstr(stats, "not-enough-sigs=8"));
1687 done:
1688 UNMOCK(networkstatus_get_latest_consensus_by_flavor);
1689 UNMOCK(connection_write_to_buf_impl_);
1690 UNMOCK(get_options);
1692 connection_free_(TO_CONN(conn));
1693 tor_free(header);
1694 tor_free(stats);
1695 smartlist_free(mock_ns_val->voters);
1696 tor_free(mock_ns_val);
1697 or_options_free(mock_options); mock_options = NULL;
1700 static void
1701 test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data)
1703 dir_connection_t *conn = NULL;
1704 char *header = NULL;
1705 char *stats = NULL;
1706 (void) data;
1708 init_mock_options();
1710 MOCK(get_options, mock_get_options);
1711 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1713 /* start gathering stats */
1714 mock_options->DirReqStatistics = 1;
1715 geoip_dirreq_stats_init(time(NULL));
1717 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1718 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1719 GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
1721 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1722 NULL, NULL, 1, 0);
1723 tt_assert(header);
1724 tt_str_op(NOT_FOUND, OP_EQ, header);
1726 stats = geoip_format_dirreq_stats(time(NULL));
1727 tt_assert(stats);
1728 tt_assert(strstr(stats, "not-found=8"));
1730 done:
1731 UNMOCK(connection_write_to_buf_impl_);
1732 UNMOCK(get_options);
1733 connection_free_(TO_CONN(conn));
1734 tor_free(header);
1735 tor_free(stats);
1736 or_options_free(mock_options); mock_options = NULL;
1739 NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
1742 NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
1744 (void)addr;
1745 CALLED(geoip_get_country_by_addr)++;
1746 return 1;
1749 static void
1750 status_vote_current_consensus_ns_test(char **header, char **body,
1751 size_t *body_len)
1753 common_digests_t digests;
1754 dir_connection_t *conn = NULL;
1756 #define NETWORK_STATUS "some network status string"
1757 dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS, "ns", &digests,
1758 time(NULL));
1760 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1762 tt_assert(mock_options);
1763 mock_options->DirReqStatistics = 1;
1764 geoip_dirreq_stats_init(time(NULL));
1766 /* init geoip database */
1767 geoip_parse_entry("10,50,AB", AF_INET);
1768 tt_str_op("ab", OP_EQ, geoip_get_country_name(1));
1770 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1771 TO_CONN(conn)->address = tor_strdup("127.0.0.1");
1773 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1774 GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
1776 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1777 body, body_len, strlen(NETWORK_STATUS)+7, 0);
1779 done:
1780 UNMOCK(connection_write_to_buf_impl_);
1781 connection_free_(TO_CONN(conn));
1784 static void
1785 test_dir_handle_get_status_vote_current_consensus_ns(void* data)
1787 char *header = NULL;
1788 char *body = NULL, *comp_body = NULL;
1789 size_t body_used = 0, comp_body_used = 0;
1790 char *stats = NULL, *hist = NULL;
1791 (void) data;
1793 dirserv_free_all();
1794 clear_geoip_db();
1796 NS_MOCK(geoip_get_country_by_addr);
1797 MOCK(get_options, mock_get_options);
1799 init_mock_options();
1801 status_vote_current_consensus_ns_test(&header, &comp_body, &comp_body_used);
1802 tt_assert(header);
1804 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
1805 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
1806 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
1807 tt_assert(strstr(header, "Pragma: no-cache\r\n"));
1809 compress_method_t compression = detect_compression_method(comp_body,
1810 comp_body_used);
1811 tt_int_op(ZLIB_METHOD, OP_EQ, compression);
1813 tor_gzip_uncompress(&body, &body_used, comp_body, comp_body_used,
1814 compression, 0, LOG_PROTOCOL_WARN);
1816 tt_str_op(NETWORK_STATUS, OP_EQ, body);
1817 tt_int_op(strlen(NETWORK_STATUS), OP_EQ, body_used);
1819 stats = geoip_format_dirreq_stats(time(NULL));
1820 tt_assert(stats);
1822 tt_assert(strstr(stats, "ok=8"));
1823 tt_assert(strstr(stats, "dirreq-v3-ips ab=8"));
1824 tt_assert(strstr(stats, "dirreq-v3-reqs ab=8"));
1825 tt_assert(strstr(stats, "dirreq-v3-direct-dl"
1826 " complete=0,timeout=0,running=4"));
1828 hist = geoip_get_request_history();
1829 tt_assert(hist);
1830 tt_str_op("ab=8", OP_EQ, hist);
1832 done:
1833 NS_UNMOCK(geoip_get_country_by_addr);
1834 UNMOCK(get_options);
1835 tor_free(header);
1836 tor_free(comp_body);
1837 tor_free(body);
1838 tor_free(stats);
1839 tor_free(hist);
1840 or_options_free(mock_options); mock_options = NULL;
1842 dirserv_free_all();
1843 clear_geoip_db();
1846 static void
1847 test_dir_handle_get_status_vote_current_consensus_ns_busy(void* data)
1849 char *header = NULL;
1850 char *body = NULL;
1851 size_t body_used = 0;
1852 char *stats = NULL;
1853 (void) data;
1855 dirserv_free_all();
1856 clear_geoip_db();
1858 MOCK(get_options, mock_get_options);
1860 // Make it busy
1861 init_mock_options();
1862 mock_options->CountPrivateBandwidth = 1;
1864 status_vote_current_consensus_ns_test(&header, &body, &body_used);
1865 tt_assert(header);
1867 tt_str_op(SERVER_BUSY, OP_EQ, header);
1869 stats = geoip_format_dirreq_stats(time(NULL));
1870 tt_assert(stats);
1871 tt_assert(strstr(stats, "busy=8"));
1873 done:
1874 UNMOCK(get_options);
1875 tor_free(header);
1876 tor_free(body);
1877 or_options_free(mock_options); mock_options = NULL;
1879 tor_free(stats);
1880 dirserv_free_all();
1881 clear_geoip_db();
1884 static void
1885 test_dir_handle_get_status_vote_current_not_found(void* data)
1887 dir_connection_t *conn = NULL;
1888 char *header = NULL;
1889 (void) data;
1891 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1893 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1894 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1895 GET("/tor/status-vote/current/" HEX1), NULL, 0));
1897 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
1898 NULL, NULL, 1, 0);
1899 tt_assert(header);
1900 tt_str_op(NOT_FOUND, OP_EQ, header);
1902 done:
1903 UNMOCK(connection_write_to_buf_impl_);
1904 connection_free_(TO_CONN(conn));
1905 tor_free(header);
1908 #define VOTE_DIGEST "312A4890D4D832597ABBD3089C782DBBFB81E48D"
1910 static void
1911 status_vote_current_d_test(char **header, char **body, size_t *body_l)
1913 dir_connection_t *conn = NULL;
1915 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1917 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1918 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1919 GET("/tor/status-vote/current/d/" VOTE_DIGEST), NULL, 0));
1921 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1922 body, body_l, strlen(VOTE_BODY_V3)+1, 0);
1923 tt_assert(header);
1925 done:
1926 UNMOCK(connection_write_to_buf_impl_);
1927 connection_free_(TO_CONN(conn));
1930 static void
1931 status_vote_next_d_test(char **header, char **body, size_t *body_l)
1933 dir_connection_t *conn = NULL;
1935 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
1937 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
1938 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
1939 GET("/tor/status-vote/next/d/" VOTE_DIGEST), NULL, 0));
1941 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
1942 body, body_l, strlen(VOTE_BODY_V3)+1, 0);
1943 tt_assert(header);
1945 done:
1946 UNMOCK(connection_write_to_buf_impl_);
1947 connection_free_(TO_CONN(conn));
1950 static void
1951 test_dir_handle_get_status_vote_current_d_not_found(void* data)
1953 char *header = NULL;
1954 (void) data;
1956 status_vote_current_d_test(&header, NULL, NULL);
1958 tt_assert(header);
1959 tt_str_op(NOT_FOUND, OP_EQ, header);
1961 done:
1962 tor_free(header);
1965 static void
1966 test_dir_handle_get_status_vote_next_d_not_found(void* data)
1968 char *header = NULL;
1969 (void) data;
1971 status_vote_next_d_test(&header, NULL, NULL);
1973 tt_assert(header);
1974 tt_str_op(NOT_FOUND, OP_EQ, header);
1976 done:
1977 UNMOCK(connection_write_to_buf_impl_);
1978 tor_free(header);
1981 static void
1982 test_dir_handle_get_status_vote_d(void* data)
1984 char *header = NULL, *body = NULL;
1985 size_t body_used = 0;
1986 dir_server_t *ds = NULL;
1987 const char digest[DIGEST_LEN] = "";
1988 (void) data;
1990 clear_dir_servers();
1991 dirvote_free_all();
1993 /* create a trusted ds */
1994 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
1995 NULL, V3_DIRINFO, 1.0);
1996 tt_assert(ds);
1997 dir_server_add(ds);
1999 /* ds v3_identity_digest is the certificate's identity_key */
2000 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
2001 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
2003 init_mock_options();
2004 mock_options->AuthoritativeDir = 1;
2005 mock_options->V3AuthoritativeDir = 1;
2006 mock_options->TestingV3AuthVotingStartOffset = 0;
2007 mock_options->TestingV3AuthInitialVotingInterval = 1;
2008 mock_options->TestingV3AuthInitialVoteDelay = 1;
2009 mock_options->TestingV3AuthInitialDistDelay = 1;
2011 time_t now = 1441223455 -1;
2012 dirvote_recalculate_timing(mock_options, now);
2014 const char *msg_out = NULL;
2015 int status_out = 0;
2016 struct pending_vote_t *pv = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
2017 &status_out);
2018 tt_assert(pv);
2020 status_vote_current_d_test(&header, &body, &body_used);
2022 tt_assert(header);
2023 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2024 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2025 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2026 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2028 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2030 tor_free(header);
2031 tor_free(body);
2033 status_vote_next_d_test(&header, &body, &body_used);
2035 tt_assert(header);
2036 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2037 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2038 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2039 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2041 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2043 done:
2044 tor_free(header);
2045 tor_free(body);
2046 or_options_free(mock_options); mock_options = NULL;
2048 clear_dir_servers();
2049 dirvote_free_all();
2052 static void
2053 test_dir_handle_get_status_vote_next_not_found(void* data)
2055 dir_connection_t *conn = NULL;
2056 char *header = NULL;
2057 (void) data;
2059 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2061 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2062 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2063 GET("/tor/status-vote/next/" HEX1), NULL, 0));
2065 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2066 NULL, NULL, 1, 0);
2067 tt_assert(header);
2068 tt_str_op(NOT_FOUND, OP_EQ, header);
2070 done:
2071 UNMOCK(connection_write_to_buf_impl_);
2072 connection_free_(TO_CONN(conn));
2073 tor_free(header);
2076 static void
2077 status_vote_next_consensus_test(char **header, char **body, size_t *body_used)
2079 dir_connection_t *conn = NULL;
2081 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2083 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2084 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2085 GET("/tor/status-vote/next/consensus"), NULL, 0));
2087 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
2088 body, body_used, 18, 0);
2089 done:
2090 UNMOCK(connection_write_to_buf_impl_);
2091 connection_free_(TO_CONN(conn));
2094 static void
2095 test_dir_handle_get_status_vote_next_consensus_not_found(void* data)
2097 char *header = NULL, *body = NULL;
2098 size_t body_used;
2099 (void) data;
2101 status_vote_next_consensus_test(&header, &body, &body_used);
2103 tt_assert(header);
2104 tt_str_op(NOT_FOUND, OP_EQ, header);
2106 done:
2107 tor_free(header);
2108 tor_free(body);
2111 static void
2112 test_dir_handle_get_status_vote_current_authority_not_found(void* data)
2114 dir_connection_t *conn = NULL;
2115 char *header = NULL;
2116 (void) data;
2118 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2120 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2121 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2122 GET("/tor/status-vote/current/authority"), NULL, 0));
2124 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2125 NULL, NULL, 1, 0);
2126 tt_assert(header);
2127 tt_str_op(NOT_FOUND, OP_EQ, header);
2129 done:
2130 UNMOCK(connection_write_to_buf_impl_);
2131 connection_free_(TO_CONN(conn));
2132 tor_free(header);
2135 static void
2136 test_dir_handle_get_status_vote_next_authority_not_found(void* data)
2138 dir_connection_t *conn = NULL;
2139 char *header = NULL;
2140 (void) data;
2142 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2144 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2145 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2146 GET("/tor/status-vote/next/authority"), NULL, 0));
2148 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2149 NULL, NULL, 1, 0);
2150 tt_assert(header);
2151 tt_str_op(NOT_FOUND, OP_EQ, header);
2153 done:
2154 UNMOCK(connection_write_to_buf_impl_);
2155 connection_free_(TO_CONN(conn));
2156 tor_free(header);
2159 NS_DECL(const char*,
2160 dirvote_get_pending_consensus, (consensus_flavor_t flav));
2162 const char*
2163 NS(dirvote_get_pending_consensus)(consensus_flavor_t flav)
2165 (void)flav;
2166 return "pending consensus";
2169 static void
2170 test_dir_handle_get_status_vote_next_consensus(void* data)
2172 char *header = NULL, *body = NULL;
2173 size_t body_used = 0;
2174 (void) data;
2176 NS_MOCK(dirvote_get_pending_consensus);
2178 status_vote_next_consensus_test(&header, &body, &body_used);
2179 tt_assert(header);
2181 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2182 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2183 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2184 tt_assert(strstr(header, "Content-Length: 17\r\n"));
2186 tt_str_op("pending consensus", OP_EQ, body);
2188 done:
2189 NS_UNMOCK(dirvote_get_pending_consensus);
2190 tor_free(header);
2191 tor_free(body);
2194 static void
2195 test_dir_handle_get_status_vote_next_consensus_busy(void* data)
2197 char *header = NULL, *body = NULL;
2198 size_t body_used = 0;
2199 (void) data;
2201 MOCK(get_options, mock_get_options);
2202 NS_MOCK(dirvote_get_pending_consensus);
2204 //Make it busy
2205 init_mock_options();
2206 mock_options->CountPrivateBandwidth = 1;
2208 status_vote_next_consensus_test(&header, &body, &body_used);
2210 tt_assert(header);
2211 tt_str_op(SERVER_BUSY, OP_EQ, header);
2213 done:
2214 NS_UNMOCK(dirvote_get_pending_consensus);
2215 UNMOCK(get_options);
2216 tor_free(header);
2217 tor_free(body);
2218 or_options_free(mock_options); mock_options = NULL;
2221 static void
2222 status_vote_next_consensus_signatures_test(char **header, char **body,
2223 size_t *body_used)
2225 dir_connection_t *conn = NULL;
2227 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2229 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2230 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2231 GET("/tor/status-vote/next/consensus-signatures"), NULL, 0));
2233 fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
2234 body, body_used, 22, 0);
2236 done:
2237 connection_free_(TO_CONN(conn));
2238 UNMOCK(connection_write_to_buf_impl_);
2241 static void
2242 test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data)
2244 char *header = NULL, *body = NULL;
2245 size_t body_used;
2246 (void) data;
2248 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2250 tt_assert(header);
2251 tt_str_op(NOT_FOUND, OP_EQ, header);
2253 done:
2254 tor_free(header);
2255 tor_free(body);
2258 NS_DECL(const char*,
2259 dirvote_get_pending_detached_signatures, (void));
2261 const char*
2262 NS(dirvote_get_pending_detached_signatures)(void)
2264 return "pending detached sigs";
2267 static void
2268 test_dir_handle_get_status_vote_next_consensus_signatures(void* data)
2270 char *header = NULL, *body = NULL;
2271 size_t body_used = 0;
2272 (void) data;
2274 NS_MOCK(dirvote_get_pending_detached_signatures);
2276 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2277 tt_assert(header);
2279 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2280 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2281 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2282 tt_assert(strstr(header, "Content-Length: 21\r\n"));
2284 tt_str_op("pending detached sigs", OP_EQ, body);
2286 done:
2287 NS_UNMOCK(dirvote_get_pending_detached_signatures);
2288 tor_free(header);
2289 tor_free(body);
2292 static void
2293 test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data)
2295 char *header = NULL, *body = NULL;
2296 size_t body_used;
2297 (void) data;
2299 NS_MOCK(dirvote_get_pending_detached_signatures);
2300 MOCK(get_options, mock_get_options);
2302 //Make it busy
2303 init_mock_options();
2304 mock_options->CountPrivateBandwidth = 1;
2306 status_vote_next_consensus_signatures_test(&header, &body, &body_used);
2308 tt_assert(header);
2309 tt_str_op(SERVER_BUSY, OP_EQ, header);
2311 done:
2312 UNMOCK(get_options);
2313 NS_UNMOCK(dirvote_get_pending_detached_signatures);
2314 tor_free(header);
2315 tor_free(body);
2316 or_options_free(mock_options); mock_options = NULL;
2319 static void
2320 test_dir_handle_get_status_vote_next_authority(void* data)
2322 dir_connection_t *conn = NULL;
2323 char *header = NULL, *body = NULL;
2324 const char *msg_out = NULL;
2325 int status_out = 0;
2326 size_t body_used = 0;
2327 dir_server_t *ds = NULL;
2328 const char digest[DIGEST_LEN] = "";
2329 (void) data;
2331 clear_dir_servers();
2332 routerlist_free_all();
2333 dirvote_free_all();
2335 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
2337 /* create a trusted ds */
2338 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
2339 NULL, V3_DIRINFO, 1.0);
2340 tt_assert(ds);
2341 dir_server_add(ds);
2343 /* ds v3_identity_digest is the certificate's identity_key */
2344 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
2345 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
2346 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
2347 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
2349 init_mock_options();
2350 mock_options->AuthoritativeDir = 1;
2351 mock_options->V3AuthoritativeDir = 1;
2352 mock_options->TestingV3AuthVotingStartOffset = 0;
2353 mock_options->TestingV3AuthInitialVotingInterval = 1;
2354 mock_options->TestingV3AuthInitialVoteDelay = 1;
2355 mock_options->TestingV3AuthInitialDistDelay = 1;
2357 time_t now = 1441223455 -1;
2358 dirvote_recalculate_timing(mock_options, now);
2360 struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
2361 &status_out);
2362 tt_assert(vote);
2364 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
2365 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2367 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2368 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2369 GET("/tor/status-vote/next/authority"), NULL, 0));
2371 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2372 &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
2374 tt_assert(header);
2375 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2376 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2377 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2378 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2380 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2382 done:
2383 UNMOCK(connection_write_to_buf_impl_);
2384 UNMOCK(get_my_v3_authority_cert);
2385 connection_free_(TO_CONN(conn));
2386 tor_free(header);
2387 tor_free(body);
2388 authority_cert_free(mock_cert); mock_cert = NULL;
2389 or_options_free(mock_options); mock_options = NULL;
2391 clear_dir_servers();
2392 routerlist_free_all();
2393 dirvote_free_all();
2396 static void
2397 test_dir_handle_get_status_vote_current_authority(void* data)
2399 dir_connection_t *conn = NULL;
2400 char *header = NULL, *body = NULL;
2401 const char *msg_out = NULL;
2402 int status_out = 0;
2403 size_t body_used = 0;
2404 const char digest[DIGEST_LEN] = "";
2406 dir_server_t *ds = NULL;
2407 (void) data;
2409 clear_dir_servers();
2410 routerlist_free_all();
2411 dirvote_free_all();
2413 mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
2415 /* create a trusted ds */
2416 ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
2417 NULL, V3_DIRINFO, 1.0);
2418 tt_assert(ds);
2419 dir_server_add(ds);
2421 /* ds v3_identity_digest is the certificate's identity_key */
2422 base16_decode(ds->v3_identity_digest, DIGEST_LEN,
2423 TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
2425 tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
2426 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1));
2428 init_mock_options();
2429 mock_options->AuthoritativeDir = 1;
2430 mock_options->V3AuthoritativeDir = 1;
2431 mock_options->TestingV3AuthVotingStartOffset = 0;
2432 mock_options->TestingV3AuthInitialVotingInterval = 1;
2433 mock_options->TestingV3AuthInitialVoteDelay = 1;
2434 mock_options->TestingV3AuthInitialDistDelay = 1;
2436 time_t now = 1441223455;
2437 dirvote_recalculate_timing(mock_options, now-1);
2439 struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
2440 &status_out);
2441 tt_assert(vote);
2443 // move the pending vote to previous vote
2444 dirvote_act(mock_options, now+1);
2446 MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
2447 MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
2449 conn = dir_connection_new(tor_addr_family(&MOCK_TOR_ADDR));
2450 tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
2451 GET("/tor/status-vote/current/authority"), NULL, 0));
2453 fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
2454 &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
2456 tt_assert(header);
2457 tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
2458 tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
2459 tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
2460 tt_assert(strstr(header, "Content-Length: 4135\r\n"));
2462 tt_str_op(VOTE_BODY_V3, OP_EQ, body);
2464 done:
2465 UNMOCK(connection_write_to_buf_impl_);
2466 UNMOCK(get_my_v3_authority_cert);
2467 connection_free_(TO_CONN(conn));
2468 tor_free(header);
2469 tor_free(body);
2470 authority_cert_free(mock_cert); mock_cert = NULL;
2471 or_options_free(mock_options); mock_options = NULL;
2473 clear_dir_servers();
2474 routerlist_free_all();
2475 dirvote_free_all();
2478 #define DIR_HANDLE_CMD(name,flags) \
2479 { #name, test_dir_handle_get_##name, (flags), NULL, NULL }
2481 struct testcase_t dir_handle_get_tests[] = {
2482 DIR_HANDLE_CMD(not_found, 0),
2483 DIR_HANDLE_CMD(bad_request, 0),
2484 DIR_HANDLE_CMD(v1_command_not_found, 0),
2485 DIR_HANDLE_CMD(v1_command, 0),
2486 DIR_HANDLE_CMD(robots_txt, 0),
2487 DIR_HANDLE_CMD(bytes_txt, 0),
2488 DIR_HANDLE_CMD(rendezvous2_not_found_if_not_encrypted, 0),
2489 DIR_HANDLE_CMD(rendezvous2_not_found, 0),
2490 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_with_invalid_desc_id, 0),
2491 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_not_well_formed, 0),
2492 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_success, 0),
2493 DIR_HANDLE_CMD(micro_d_not_found, 0),
2494 DIR_HANDLE_CMD(micro_d_server_busy, 0),
2495 DIR_HANDLE_CMD(micro_d, 0),
2496 DIR_HANDLE_CMD(networkstatus_bridges_not_found_without_auth, 0),
2497 DIR_HANDLE_CMD(networkstatus_bridges_not_found_wrong_auth, 0),
2498 DIR_HANDLE_CMD(networkstatus_bridges, 0),
2499 DIR_HANDLE_CMD(server_descriptors_not_found, 0),
2500 DIR_HANDLE_CMD(server_descriptors_busy, TT_FORK),
2501 DIR_HANDLE_CMD(server_descriptors_all, TT_FORK),
2502 DIR_HANDLE_CMD(server_descriptors_authority, TT_FORK),
2503 DIR_HANDLE_CMD(server_descriptors_fp, TT_FORK),
2504 DIR_HANDLE_CMD(server_descriptors_d, TT_FORK),
2505 DIR_HANDLE_CMD(server_keys_bad_req, 0),
2506 DIR_HANDLE_CMD(server_keys_busy, 0),
2507 DIR_HANDLE_CMD(server_keys_all_not_found, 0),
2508 DIR_HANDLE_CMD(server_keys_all, 0),
2509 DIR_HANDLE_CMD(server_keys_authority_not_found, 0),
2510 DIR_HANDLE_CMD(server_keys_authority, 0),
2511 DIR_HANDLE_CMD(server_keys_fp_not_found, 0),
2512 DIR_HANDLE_CMD(server_keys_fp, 0),
2513 DIR_HANDLE_CMD(server_keys_sk_not_found, 0),
2514 DIR_HANDLE_CMD(server_keys_sk, 0),
2515 DIR_HANDLE_CMD(server_keys_fpsk_not_found, 0),
2516 DIR_HANDLE_CMD(server_keys_fpsk, 0),
2517 DIR_HANDLE_CMD(status_vote_current_not_found, 0),
2518 DIR_HANDLE_CMD(status_vote_next_not_found, 0),
2519 DIR_HANDLE_CMD(status_vote_current_authority_not_found, 0),
2520 DIR_HANDLE_CMD(status_vote_current_authority, 0),
2521 DIR_HANDLE_CMD(status_vote_next_authority_not_found, 0),
2522 DIR_HANDLE_CMD(status_vote_next_authority, 0),
2523 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_enough_sigs, 0),
2524 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_found, 0),
2525 DIR_HANDLE_CMD(status_vote_current_consensus_ns_busy, 0),
2526 DIR_HANDLE_CMD(status_vote_current_consensus_ns, 0),
2527 DIR_HANDLE_CMD(status_vote_current_d_not_found, 0),
2528 DIR_HANDLE_CMD(status_vote_next_d_not_found, 0),
2529 DIR_HANDLE_CMD(status_vote_d, 0),
2530 DIR_HANDLE_CMD(status_vote_next_consensus_not_found, 0),
2531 DIR_HANDLE_CMD(status_vote_next_consensus_busy, 0),
2532 DIR_HANDLE_CMD(status_vote_next_consensus, 0),
2533 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_not_found, 0),
2534 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_busy, 0),
2535 DIR_HANDLE_CMD(status_vote_next_consensus_signatures, 0),
2536 END_OF_TESTCASES