1 /* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2018, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 #define RENDCOMMON_PRIVATE
8 #define CONNECTION_PRIVATE
10 #define RENDCACHE_PRIVATE
11 #define DIRCACHE_PRIVATE
13 #include "core/or/or.h"
14 #include "app/config/config.h"
15 #include "core/mainloop/connection.h"
16 #include "feature/dircache/consdiffmgr.h"
17 #include "feature/dircommon/directory.h"
18 #include "feature/dircache/dircache.h"
19 #include "test/test.h"
20 #include "lib/compress/compress.h"
21 #include "feature/rend/rendcommon.h"
22 #include "feature/rend/rendcache.h"
23 #include "feature/relay/router.h"
24 #include "feature/nodelist/authcert.h"
25 #include "feature/nodelist/dirlist.h"
26 #include "feature/nodelist/routerlist.h"
27 #include "test/rend_test_helpers.h"
28 #include "feature/nodelist/microdesc.h"
29 #include "test/test_helpers.h"
30 #include "feature/nodelist/nodelist.h"
31 #include "feature/client/entrynodes.h"
32 #include "feature/dirparse/authcert_parse.h"
33 #include "feature/dirparse/routerparse.h"
34 #include "feature/nodelist/networkstatus.h"
35 #include "core/proto/proto_http.h"
36 #include "lib/geoip/geoip.h"
37 #include "feature/stats/geoip_stats.h"
38 #include "feature/dircache/dirserv.h"
39 #include "feature/dirauth/dirvote.h"
40 #include "test/log_test_helpers.h"
41 #include "feature/dircommon/voting_schedule.h"
43 #include "feature/dircommon/dir_connection_st.h"
44 #include "feature/dirclient/dir_server_st.h"
45 #include "feature/nodelist/networkstatus_st.h"
46 #include "feature/rend/rend_encoded_v2_service_descriptor_st.h"
47 #include "feature/nodelist/routerinfo_st.h"
48 #include "feature/nodelist/routerlist_st.h"
55 #endif /* defined(_WIN32) */
57 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
58 DISABLE_GCC_WARNING(overlength
-strings
)
59 /* We allow huge string constants in the unit tests, but not in the code
62 #include "vote_descriptors.inc"
63 #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
64 ENABLE_GCC_WARNING(overlength
-strings
)
67 #define NS_MODULE dir_handle_get
69 #define NOT_FOUND "HTTP/1.0 404 Not found\r\n\r\n"
70 #define BAD_REQUEST "HTTP/1.0 400 Bad request\r\n\r\n"
71 #define SERVER_BUSY "HTTP/1.0 503 Directory busy, try again later\r\n\r\n"
72 #define TOO_OLD "HTTP/1.0 404 Consensus is too old\r\n\r\n"
73 #define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
74 "Consensus not signed by sufficient number of requested authorities\r\n\r\n"
76 static dir_connection_t
*
79 dir_connection_t
*conn
= dir_connection_new(AF_INET
);
80 tor_addr_from_ipv4h(&conn
->base_
.addr
, 0x7f000001);
81 TO_CONN(conn
)->address
= tor_strdup("127.0.0.1");
86 test_dir_handle_get_bad_request(void *data
)
88 dir_connection_t
*conn
= NULL
;
92 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
94 conn
= new_dir_conn();
95 tt_int_op(directory_handle_command_get(conn
, "", NULL
, 0), OP_EQ
, 0);
97 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
100 tt_str_op(header
, OP_EQ
, BAD_REQUEST
);
103 UNMOCK(connection_write_to_buf_impl_
);
104 connection_free_minimal(TO_CONN(conn
));
109 test_dir_handle_get_v1_command_not_found(void *data
)
111 dir_connection_t
*conn
= NULL
;
115 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
117 conn
= new_dir_conn();
119 // no frontpage configured
120 tt_ptr_op(get_dirportfrontpage(), OP_EQ
, NULL
);
123 tt_int_op(directory_handle_command_get(conn
, GET("/tor/"), NULL
, 0),
126 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
129 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
132 UNMOCK(connection_write_to_buf_impl_
);
133 connection_free_minimal(TO_CONN(conn
));
138 mock_get_dirportfrontpage(void)
140 return "HELLO FROM FRONTPAGE";
144 test_dir_handle_get_v1_command(void *data
)
146 dir_connection_t
*conn
= NULL
;
149 size_t body_used
= 0, body_len
= 0;
150 const char *exp_body
= NULL
;
153 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
154 MOCK(get_dirportfrontpage
, mock_get_dirportfrontpage
);
156 exp_body
= get_dirportfrontpage();
157 body_len
= strlen(exp_body
);
159 conn
= new_dir_conn();
160 tt_int_op(directory_handle_command_get(conn
, GET("/tor/"), NULL
, 0),
163 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
164 &body
, &body_used
, body_len
+1, 0);
169 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
170 tt_assert(strstr(header
, "Content-Type: text/html\r\n"));
171 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
172 tt_assert(strstr(header
, "Content-Length: 20\r\n"));
174 tt_int_op(body_used
, OP_EQ
, strlen(body
));
175 tt_str_op(body
, OP_EQ
, exp_body
);
178 UNMOCK(connection_write_to_buf_impl_
);
179 UNMOCK(get_dirportfrontpage
);
180 connection_free_minimal(TO_CONN(conn
));
186 test_dir_handle_get_not_found(void *data
)
188 dir_connection_t
*conn
= NULL
;
192 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
194 conn
= new_dir_conn();
196 /* Unrecognized path */
197 tt_int_op(directory_handle_command_get(conn
, GET("/anything"), NULL
, 0),
199 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
202 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
205 UNMOCK(connection_write_to_buf_impl_
);
206 connection_free_minimal(TO_CONN(conn
));
211 test_dir_handle_get_robots_txt(void *data
)
213 dir_connection_t
*conn
= NULL
;
216 size_t body_used
= 0;
219 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
221 conn
= new_dir_conn();
223 tt_int_op(directory_handle_command_get(conn
, GET("/tor/robots.txt"),
225 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
226 &body
, &body_used
, 29, 0);
231 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
232 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
233 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
234 tt_assert(strstr(header
, "Content-Length: 28\r\n"));
236 tt_int_op(body_used
, OP_EQ
, strlen(body
));
237 tt_str_op(body
, OP_EQ
, "User-agent: *\r\nDisallow: /\r\n");
240 UNMOCK(connection_write_to_buf_impl_
);
241 connection_free_minimal(TO_CONN(conn
));
246 #define RENDEZVOUS2_GET(descid) GET("/tor/rendezvous2/" descid)
248 test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data
)
250 dir_connection_t
*conn
= NULL
;
254 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
256 conn
= new_dir_conn();
258 // connection is not encrypted
259 tt_assert(!connection_dir_is_encrypted(conn
))
261 tt_int_op(directory_handle_command_get(conn
, RENDEZVOUS2_GET(), NULL
, 0),
263 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
266 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
269 UNMOCK(connection_write_to_buf_impl_
);
270 connection_free_minimal(TO_CONN(conn
));
275 test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
278 dir_connection_t
*conn
= NULL
;
282 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
283 conn
= new_dir_conn();
285 // connection is encrypted
286 TO_CONN(conn
)->linked
= 1;
287 tt_assert(connection_dir_is_encrypted(conn
));
289 tt_int_op(directory_handle_command_get(conn
,
290 RENDEZVOUS2_GET("invalid-desc-id"), NULL
, 0), OP_EQ
, 0);
291 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
294 tt_str_op(header
, OP_EQ
, BAD_REQUEST
);
297 UNMOCK(connection_write_to_buf_impl_
);
298 connection_free_minimal(TO_CONN(conn
));
303 test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data
)
305 dir_connection_t
*conn
= NULL
;
309 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
310 conn
= new_dir_conn();
312 // connection is encrypted
313 TO_CONN(conn
)->linked
= 1;
314 tt_assert(connection_dir_is_encrypted(conn
));
316 //TODO: this cant be reached because rend_valid_descriptor_id() prevents this
317 //case to happen. This test is the same as
318 //test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id
319 //We should refactor to remove the case from the switch.
321 const char *req
= RENDEZVOUS2_GET("1bababababababababababababababab");
322 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
324 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
327 tt_str_op(header
, OP_EQ
, BAD_REQUEST
);
330 UNMOCK(connection_write_to_buf_impl_
);
331 connection_free_minimal(TO_CONN(conn
));
336 test_dir_handle_get_rendezvous2_not_found(void *data
)
338 dir_connection_t
*conn
= NULL
;
342 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
343 conn
= new_dir_conn();
347 // connection is encrypted
348 TO_CONN(conn
)->linked
= 1;
349 tt_assert(connection_dir_is_encrypted(conn
));
351 const char *req
= RENDEZVOUS2_GET("3xqunszqnaolrrfmtzgaki7mxelgvkje");
352 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
353 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
356 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
359 UNMOCK(connection_write_to_buf_impl_
);
360 connection_free_minimal(TO_CONN(conn
));
362 rend_cache_free_all();
365 NS_DECL(const routerinfo_t
*, router_get_my_routerinfo
, (void));
367 static routerinfo_t
*mock_routerinfo
;
369 static const routerinfo_t
*
370 NS(router_get_my_routerinfo
)(void)
372 if (!mock_routerinfo
) {
373 mock_routerinfo
= tor_malloc_zero(sizeof(routerinfo_t
));
376 return mock_routerinfo
;
380 test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data
)
382 dir_connection_t
*conn
= NULL
;
385 size_t body_used
= 0;
388 rend_encoded_v2_service_descriptor_t
*desc_holder
= NULL
;
389 char *service_id
= NULL
;
390 char desc_id_base32
[REND_DESC_ID_V2_LEN_BASE32
+ 1];
394 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
395 NS_MOCK(router_get_my_routerinfo
);
399 /* create a valid rend service descriptor */
400 #define RECENT_TIME -10
401 generate_desc(RECENT_TIME
, &desc_holder
, &service_id
, 3);
403 tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder
->desc_str
),
406 base32_encode(desc_id_base32
, sizeof(desc_id_base32
), desc_holder
->desc_id
,
409 conn
= new_dir_conn();
411 // connection is encrypted
412 TO_CONN(conn
)->linked
= 1;
413 tt_assert(connection_dir_is_encrypted(conn
));
415 tor_snprintf(req
, sizeof(req
), RENDEZVOUS2_GET("%s"), desc_id_base32
);
417 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
419 body_len
= strlen(desc_holder
->desc_str
);
420 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
421 &body
, &body_used
, body_len
+1, 0);
426 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
427 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
428 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
429 tt_assert(strstr(header
, "Pragma: no-cache\r\n"));
430 tor_snprintf(buff
, sizeof(buff
), "Content-Length: %ld\r\n", (long) body_len
);
431 tt_assert(strstr(header
, buff
));
433 tt_int_op(body_used
, OP_EQ
, strlen(body
));
434 tt_str_op(body
, OP_EQ
, desc_holder
->desc_str
);
437 UNMOCK(connection_write_to_buf_impl_
);
438 NS_UNMOCK(router_get_my_routerinfo
);
440 connection_free_minimal(TO_CONN(conn
));
443 rend_encoded_v2_service_descriptor_free(desc_holder
);
444 tor_free(service_id
);
445 rend_cache_free_all();
448 #define MICRODESC_GET(digest) GET("/tor/micro/d/" digest)
450 test_dir_handle_get_micro_d_not_found(void *data
)
452 dir_connection_t
*conn
= NULL
;
456 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
458 #define B64_256_1 "8/Pz8/u7vz8/Pz+7vz8/Pz+7u/Pz8/P7u/Pz8/P7u78"
459 #define B64_256_2 "zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMw"
460 conn
= new_dir_conn();
462 const char *req
= MICRODESC_GET(B64_256_1
"-" B64_256_2
);
463 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
465 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
468 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
471 UNMOCK(connection_write_to_buf_impl_
);
473 connection_free_minimal(TO_CONN(conn
));
477 static or_options_t
*mock_options
= NULL
;
479 init_mock_options(void)
481 mock_options
= tor_malloc(sizeof(or_options_t
));
482 memset(mock_options
, 0, sizeof(or_options_t
));
483 mock_options
->TestingTorNetwork
= 1;
484 mock_options
->DataDirectory
= tor_strdup(get_fname_rnd("datadir_tmp"));
485 mock_options
->CacheDirectory
= tor_strdup(mock_options
->DataDirectory
);
486 check_private_dir(mock_options
->DataDirectory
, CPD_CREATE
, NULL
);
489 static const or_options_t
*
490 mock_get_options(void)
492 tor_assert(mock_options
);
496 static const char microdesc
[] =
498 "-----BEGIN RSA PUBLIC KEY-----\n"
499 "MIGJAoGBAMjlHH/daN43cSVRaHBwgUfnszzAhg98EvivJ9Qxfv51mvQUxPjQ07es\n"
500 "gV/3n8fyh3Kqr/ehi9jxkdgSRfSnmF7giaHL1SLZ29kA7KtST+pBvmTpDtHa3ykX\n"
501 "Xorc7hJvIyTZoc1HU+5XSynj3gsBE5IGK1ZRzrNS688LnuZMVp1tAgMBAAE=\n"
502 "-----END RSA PUBLIC KEY-----\n";
505 test_dir_handle_get_micro_d(void *data
)
507 dir_connection_t
*conn
= NULL
;
508 microdesc_cache_t
*mc
= NULL
;
509 smartlist_t
*list
= NULL
;
510 char digest
[DIGEST256_LEN
];
511 char digest_base64
[128];
515 size_t body_used
= 0;
518 MOCK(get_options
, mock_get_options
);
519 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
524 /* Add microdesc to cache */
525 crypto_digest256(digest
, microdesc
, strlen(microdesc
), DIGEST_SHA256
);
526 base64_encode_nopad(digest_base64
, sizeof(digest_base64
),
527 (uint8_t *) digest
, DIGEST256_LEN
);
529 mc
= get_microdesc_cache();
530 list
= microdescs_add_to_cache(mc
, microdesc
, NULL
, SAVED_NOWHERE
, 0,
532 tt_int_op(1, OP_EQ
, smartlist_len(list
));
534 /* Make the request */
535 conn
= new_dir_conn();
537 tor_snprintf(path
, sizeof(path
), MICRODESC_GET("%s"), digest_base64
);
538 tt_int_op(directory_handle_command_get(conn
, path
, NULL
, 0), OP_EQ
, 0);
540 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
541 &body
, &body_used
, strlen(microdesc
)+1, 0);
546 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
547 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
548 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
550 tt_int_op(body_used
, OP_EQ
, strlen(body
));
551 tt_str_op(body
, OP_EQ
, microdesc
);
555 UNMOCK(connection_write_to_buf_impl_
);
557 or_options_free(mock_options
); mock_options
= NULL
;
558 connection_free_minimal(TO_CONN(conn
));
561 smartlist_free(list
);
562 microdesc_free_all();
566 test_dir_handle_get_micro_d_server_busy(void *data
)
568 dir_connection_t
*conn
= NULL
;
569 microdesc_cache_t
*mc
= NULL
;
570 smartlist_t
*list
= NULL
;
571 char digest
[DIGEST256_LEN
];
572 char digest_base64
[128];
577 MOCK(get_options
, mock_get_options
);
578 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
583 /* Add microdesc to cache */
584 crypto_digest256(digest
, microdesc
, strlen(microdesc
), DIGEST_SHA256
);
585 base64_encode_nopad(digest_base64
, sizeof(digest_base64
),
586 (uint8_t *) digest
, DIGEST256_LEN
);
588 mc
= get_microdesc_cache();
589 list
= microdescs_add_to_cache(mc
, microdesc
, NULL
, SAVED_NOWHERE
, 0,
591 tt_int_op(1, OP_EQ
, smartlist_len(list
));
594 mock_options
->CountPrivateBandwidth
= 1;
596 /* Make the request */
597 conn
= new_dir_conn();
599 tor_snprintf(path
, sizeof(path
), MICRODESC_GET("%s"), digest_base64
);
600 tt_int_op(directory_handle_command_get(conn
, path
, NULL
, 0), OP_EQ
, 0);
602 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
605 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
609 UNMOCK(connection_write_to_buf_impl_
);
611 or_options_free(mock_options
); mock_options
= NULL
;
612 connection_free_minimal(TO_CONN(conn
));
614 smartlist_free(list
);
615 microdesc_free_all();
618 #define BRIDGES_PATH "/tor/networkstatus-bridges"
620 test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data
)
622 dir_connection_t
*conn
= NULL
;
626 MOCK(get_options
, mock_get_options
);
627 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
631 mock_options
->BridgeAuthoritativeDir
= 1;
632 mock_options
->BridgePassword_AuthDigest_
= tor_strdup("digest");
634 conn
= new_dir_conn();
635 TO_CONN(conn
)->linked
= 1;
637 const char *req
= GET(BRIDGES_PATH
);
638 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
640 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
643 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
647 UNMOCK(connection_write_to_buf_impl_
);
648 or_options_free(mock_options
); mock_options
= NULL
;
649 connection_free_minimal(TO_CONN(conn
));
654 test_dir_handle_get_networkstatus_bridges(void *data
)
656 dir_connection_t
*conn
= NULL
;
660 MOCK(get_options
, mock_get_options
);
661 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
665 mock_options
->BridgeAuthoritativeDir
= 1;
666 mock_options
->BridgePassword_AuthDigest_
= tor_malloc(DIGEST256_LEN
);
667 crypto_digest256(mock_options
->BridgePassword_AuthDigest_
,
668 "abcdefghijklm12345", 18, DIGEST_SHA256
);
670 conn
= new_dir_conn();
671 TO_CONN(conn
)->linked
= 1;
673 const char *req
= "GET " BRIDGES_PATH
" HTTP/1.0\r\n"
674 "Authorization: Basic abcdefghijklm12345\r\n\r\n";
675 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
677 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
680 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
681 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
682 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
683 tt_assert(strstr(header
, "Content-Length: 0\r\n"));
687 UNMOCK(connection_write_to_buf_impl_
);
688 or_options_free(mock_options
); mock_options
= NULL
;
689 connection_free_minimal(TO_CONN(conn
));
694 test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data
)
696 dir_connection_t
*conn
= NULL
;
700 MOCK(get_options
, mock_get_options
);
701 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
705 mock_options
->BridgeAuthoritativeDir
= 1;
706 mock_options
->BridgePassword_AuthDigest_
= tor_malloc(DIGEST256_LEN
);
707 crypto_digest256(mock_options
->BridgePassword_AuthDigest_
,
708 "abcdefghijklm12345", 18, DIGEST_SHA256
);
710 conn
= new_dir_conn();
711 TO_CONN(conn
)->linked
= 1;
713 const char *req
= "GET " BRIDGES_PATH
" HTTP/1.0\r\n"
714 "Authorization: Basic NOTSAMEDIGEST\r\n\r\n";
715 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
717 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
720 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
724 UNMOCK(connection_write_to_buf_impl_
);
725 or_options_free(mock_options
); mock_options
= NULL
;
726 connection_free_minimal(TO_CONN(conn
));
730 #define SERVER_DESC_GET(id) GET("/tor/server/" id)
732 test_dir_handle_get_server_descriptors_not_found(void* data
)
734 dir_connection_t
*conn
= NULL
;
738 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
740 conn
= new_dir_conn();
742 const char *req
= SERVER_DESC_GET("invalid");
743 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
745 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
748 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
749 tt_ptr_op(conn
->spool
, OP_EQ
, NULL
);
752 UNMOCK(connection_write_to_buf_impl_
);
753 or_options_free(mock_options
); mock_options
= NULL
;
754 connection_free_minimal(TO_CONN(conn
));
759 test_dir_handle_get_server_descriptors_all(void* data
)
761 dir_connection_t
*conn
= NULL
;
764 size_t body_used
= 0;
767 /* Setup fake routerlist. */
768 helper_setup_fake_routerlist();
770 //TODO: change to router_get_my_extrainfo when testing "extra" path
771 NS_MOCK(router_get_my_routerinfo
);
772 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
774 // We are one of the routers
775 routerlist_t
*our_routerlist
= router_get_routerlist();
776 tt_int_op(smartlist_len(our_routerlist
->routers
), OP_GE
, 1);
777 mock_routerinfo
= smartlist_get(our_routerlist
->routers
, 0);
778 set_server_identity_key(mock_routerinfo
->identity_pkey
);
779 mock_routerinfo
->cache_info
.published_on
= time(NULL
);
781 /* Treat "all" requests as if they were unencrypted */
782 mock_routerinfo
->cache_info
.send_unencrypted
= 1;
784 conn
= new_dir_conn();
786 const char *req
= SERVER_DESC_GET("all");
787 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
789 //TODO: Is this a BUG?
790 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
791 //which is smaller than that by annotation_len bytes
792 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
799 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
800 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
801 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
803 //TODO: Is this a BUG?
804 //This is what should be expected: tt_int_op(body_used, OP_EQ, strlen(body));
805 tt_int_op(body_used
, OP_EQ
,
806 mock_routerinfo
->cache_info
.signed_descriptor_len
);
808 tt_str_op(body
, OP_EQ
, mock_routerinfo
->cache_info
.signed_descriptor_body
+
809 mock_routerinfo
->cache_info
.annotations_len
);
810 tt_ptr_op(conn
->spool
, OP_EQ
, NULL
);
813 NS_UNMOCK(router_get_my_routerinfo
);
814 UNMOCK(connection_write_to_buf_impl_
);
815 connection_free_minimal(TO_CONN(conn
));
819 routerlist_free_all();
821 entry_guards_free_all();
826 "@uploaded-at 2014-06-08 19:20:11\n"
827 "@source \"127.0.0.1\"\n"
828 "router test000a 127.0.0.1 5000 0 7000\n"
829 "platform Tor 0.2.5.3-alpha-dev on Linux\n"
830 "protocols Link 1 2 Circuit 1\n"
831 "published 2014-06-08 19:20:11\n"
832 "fingerprint C7E7 CCB8 179F 8CC3 7F5C 8A04 2B3A 180B 934B 14BA\n"
834 "bandwidth 1073741824 1073741824 0\n"
835 "extra-info-digest 67A152A4C7686FB07664F872620635F194D76D95\n"
836 "caches-extra-info\n"
838 "-----BEGIN RSA PUBLIC KEY-----\n"
839 "MIGJAoGBAOuBUIEBARMkkka/TGyaQNgUEDLP0KG7sy6KNQTNOlZHUresPr/vlVjo\n"
840 "HPpLMfu9M2z18c51YX/muWwY9x4MyQooD56wI4+AqXQcJRwQfQlPn3Ay82uZViA9\n"
841 "DpBajRieLlKKkl145KjArpD7F5BVsqccvjErgFYXvhhjSrx7BVLnAgMBAAE=\n"
842 "-----END RSA PUBLIC KEY-----\n"
844 "-----BEGIN RSA PUBLIC KEY-----\n"
845 "MIGJAoGBAN6NLnSxWQnFXxqZi5D3b0BMgV6y9NJLGjYQVP+eWtPZWgqyv4zeYsqv\n"
846 "O9y6c5lvxyUxmNHfoAbe/s8f2Vf3/YaC17asAVSln4ktrr3e9iY74a9RMWHv1Gzk\n"
847 "3042nMcqj3PEhRN0PoLkcOZNjjmNbaqki6qy9bWWZDNTdo+uI44dAgMBAAE=\n"
848 "-----END RSA PUBLIC KEY-----\n"
849 "hidden-service-dir\n"
850 "contact auth0@test.test\n"
851 "ntor-onion-key pK4bs08ERYN591jj7ca17Rn9Q02TIEfhnjR6hSq+fhU=\n"
854 "-----BEGIN SIGNATURE-----\n"
855 "rx88DuM3Y7tODlHNDDEVzKpwh3csaG1or+T4l2Xs1oq3iHHyPEtB6QTLYrC60trG\n"
856 "aAPsj3DEowGfjga1b248g2dtic8Ab+0exfjMm1RHXfDam5TXXZU3A0wMyoHjqHuf\n"
857 "eChGPgFNUvEc+5YtD27qEDcUjcinYztTs7/dzxBT4PE=\n"
858 "-----END SIGNATURE-----\n";
861 test_dir_handle_get_server_descriptors_authority(void* data
)
863 dir_connection_t
*conn
= NULL
;
866 size_t body_used
= 0;
867 crypto_pk_t
*identity_pkey
= pk_generate(0);
870 NS_MOCK(router_get_my_routerinfo
);
871 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
874 router_get_my_routerinfo();
875 crypto_pk_get_digest(identity_pkey
,
876 mock_routerinfo
->cache_info
.identity_digest
);
878 // the digest is mine (the channel is unnecrypted, so we must allow sending)
879 set_server_identity_key(identity_pkey
);
880 mock_routerinfo
->cache_info
.send_unencrypted
= 1;
882 /* Setup descriptor */
883 long annotation_len
= strstr(TEST_DESCRIPTOR
, "router ") - TEST_DESCRIPTOR
;
884 mock_routerinfo
->cache_info
.signed_descriptor_body
=
885 tor_strdup(TEST_DESCRIPTOR
);
886 mock_routerinfo
->cache_info
.signed_descriptor_len
=
887 strlen(TEST_DESCRIPTOR
) - annotation_len
;
888 mock_routerinfo
->cache_info
.annotations_len
= annotation_len
;
889 mock_routerinfo
->cache_info
.published_on
= time(NULL
);
891 conn
= new_dir_conn();
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);
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_ptr_op(conn
->spool
, OP_EQ
, NULL
);
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_minimal(TO_CONN(conn
));
922 crypto_pk_free(identity_pkey
);
926 test_dir_handle_get_server_descriptors_fp(void* data
)
928 dir_connection_t
*conn
= NULL
;
931 size_t body_used
= 0;
932 crypto_pk_t
*identity_pkey
= pk_generate(0);
935 NS_MOCK(router_get_my_routerinfo
);
936 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_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
;
954 mock_routerinfo
->cache_info
.published_on
= time(NULL
);
956 conn
= new_dir_conn();
958 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
959 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
960 const char *hex_digest
= hex_str(mock_routerinfo
->cache_info
.identity_digest
,
964 tor_snprintf(req
, sizeof(req
), SERVER_DESC_GET("fp/%s+" HEX1
"+" HEX2
),
966 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
968 //TODO: Is this a BUG?
969 //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
970 //is smaller than that by annotation_len bytes
971 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
972 &body
, &body_used
, strlen(TEST_DESCRIPTOR
)+1, 0);
977 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
978 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
979 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
981 tt_int_op(body_used
, OP_EQ
, strlen(body
));
983 tt_str_op(body
, OP_EQ
, TEST_DESCRIPTOR
+ annotation_len
);
984 tt_ptr_op(conn
->spool
, OP_EQ
, NULL
);
987 NS_UNMOCK(router_get_my_routerinfo
);
988 UNMOCK(connection_write_to_buf_impl_
);
989 tor_free(mock_routerinfo
->cache_info
.signed_descriptor_body
);
990 tor_free(mock_routerinfo
);
991 connection_free_minimal(TO_CONN(conn
));
994 crypto_pk_free(identity_pkey
);
997 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
998 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
1001 test_dir_handle_get_server_descriptors_d(void* data
)
1003 dir_connection_t
*conn
= NULL
;
1004 char *header
= NULL
;
1006 size_t body_used
= 0;
1007 crypto_pk_t
*identity_pkey
= pk_generate(0);
1010 /* Setup fake routerlist. */
1011 helper_setup_fake_routerlist();
1013 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1015 /* Get one router's signed_descriptor_digest */
1016 routerlist_t
*our_routerlist
= router_get_routerlist();
1017 tt_int_op(smartlist_len(our_routerlist
->routers
), OP_GE
, 1);
1018 routerinfo_t
*router
= smartlist_get(our_routerlist
->routers
, 0);
1019 const char *hex_digest
= hex_str(router
->cache_info
.signed_descriptor_digest
,
1022 conn
= new_dir_conn();
1024 char req_header
[155]; /* XXX Why 155? What kind of number is that?? */
1025 tor_snprintf(req_header
, sizeof(req_header
),
1026 SERVER_DESC_GET("d/%s+" HEX1
"+" HEX2
), hex_digest
);
1027 tt_int_op(directory_handle_command_get(conn
, req_header
, NULL
, 0), OP_EQ
, 0);
1029 //TODO: Is this a BUG?
1030 //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
1031 //which is smaller than that by annotation_len bytes
1032 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1034 router
->cache_info
.signed_descriptor_len
+1, 0);
1039 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1040 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1041 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1043 //TODO: Is this a BUG?
1044 //This is what should be expected:
1045 //tt_int_op(body_used, OP_EQ, strlen(body));
1046 tt_int_op(body_used
, OP_EQ
, router
->cache_info
.signed_descriptor_len
);
1048 tt_str_op(body
, OP_EQ
, router
->cache_info
.signed_descriptor_body
+
1049 router
->cache_info
.annotations_len
);
1050 tt_ptr_op(conn
->spool
, OP_EQ
, NULL
);
1053 UNMOCK(connection_write_to_buf_impl_
);
1054 tor_free(mock_routerinfo
);
1055 connection_free_minimal(TO_CONN(conn
));
1058 crypto_pk_free(identity_pkey
);
1060 routerlist_free_all();
1061 nodelist_free_all();
1062 entry_guards_free_all();
1066 test_dir_handle_get_server_descriptors_busy(void* data
)
1068 dir_connection_t
*conn
= NULL
;
1069 char *header
= NULL
;
1070 crypto_pk_t
*identity_pkey
= pk_generate(0);
1073 /* Setup fake routerlist. */
1074 helper_setup_fake_routerlist();
1076 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1079 MOCK(get_options
, mock_get_options
);
1080 init_mock_options();
1081 mock_options
->CountPrivateBandwidth
= 1;
1083 /* Get one router's signed_descriptor_digest */
1084 routerlist_t
*our_routerlist
= router_get_routerlist();
1085 tt_int_op(smartlist_len(our_routerlist
->routers
), OP_GE
, 1);
1086 routerinfo_t
*router
= smartlist_get(our_routerlist
->routers
, 0);
1087 const char *hex_digest
= hex_str(router
->cache_info
.signed_descriptor_digest
,
1090 conn
= new_dir_conn();
1092 #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
1093 #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
1094 char req_header
[155]; /* XXX 155? Why 155? */
1095 tor_snprintf(req_header
, sizeof(req_header
),
1096 SERVER_DESC_GET("d/%s+" HEX1
"+" HEX2
), hex_digest
);
1097 tt_int_op(directory_handle_command_get(conn
, req_header
, NULL
, 0), OP_EQ
, 0);
1099 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1103 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
1105 tt_ptr_op(conn
->spool
, OP_EQ
, NULL
);
1108 UNMOCK(get_options
);
1109 UNMOCK(connection_write_to_buf_impl_
);
1110 tor_free(mock_routerinfo
);
1111 connection_free_minimal(TO_CONN(conn
));
1113 crypto_pk_free(identity_pkey
);
1115 routerlist_free_all();
1116 nodelist_free_all();
1117 entry_guards_free_all();
1121 test_dir_handle_get_server_keys_bad_req(void* data
)
1123 dir_connection_t
*conn
= NULL
;
1124 char *header
= NULL
;
1127 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1129 conn
= new_dir_conn();
1131 const char *req
= GET("/tor/keys/");
1132 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1134 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1138 tt_str_op(BAD_REQUEST
, OP_EQ
, header
);
1141 UNMOCK(connection_write_to_buf_impl_
);
1142 connection_free_minimal(TO_CONN(conn
));
1147 test_dir_handle_get_server_keys_all_not_found(void* data
)
1149 dir_connection_t
*conn
= NULL
;
1150 char *header
= NULL
;
1153 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1155 conn
= new_dir_conn();
1157 const char *req
= GET("/tor/keys/all");
1158 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1160 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1164 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1167 UNMOCK(connection_write_to_buf_impl_
);
1168 connection_free_minimal(TO_CONN(conn
));
1172 #define TEST_CERTIFICATE AUTHORITY_CERT_3
1173 #define TEST_SIGNING_KEY AUTHORITY_SIGNKEY_A_DIGEST
1175 static const char TEST_CERT_IDENT_KEY
[] =
1176 "D867ACF56A9D229B35C25F0090BC9867E906BE69";
1179 test_dir_handle_get_server_keys_all(void* data
)
1181 dir_connection_t
*conn
= NULL
;
1182 char *header
= NULL
;
1184 size_t body_used
= 0;
1185 const char digest
[DIGEST_LEN
] = "";
1187 dir_server_t
*ds
= NULL
;
1190 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1192 clear_dir_servers();
1193 routerlist_free_all();
1195 /* create a trusted ds */
1196 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
1197 NULL
, V3_DIRINFO
, 1.0);
1201 /* ds v3_identity_digest is the certificate's identity_key */
1202 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
1203 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
1204 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
1205 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
1207 conn
= new_dir_conn();
1209 const char *req
= GET("/tor/keys/all");
1210 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1212 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1213 &body
, &body_used
, strlen(TEST_CERTIFICATE
)+1, 0);
1218 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1219 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1220 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1221 tt_assert(strstr(header
, "Content-Length: 1883\r\n"));
1223 tt_str_op(TEST_CERTIFICATE
, OP_EQ
, body
);
1226 UNMOCK(connection_write_to_buf_impl_
);
1227 connection_free_minimal(TO_CONN(conn
));
1231 clear_dir_servers();
1232 routerlist_free_all();
1236 test_dir_handle_get_server_keys_authority_not_found(void* data
)
1238 dir_connection_t
*conn
= NULL
;
1239 char *header
= NULL
;
1242 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1244 conn
= new_dir_conn();
1246 const char *req
= GET("/tor/keys/authority");
1247 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1249 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1253 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1256 UNMOCK(connection_write_to_buf_impl_
);
1257 connection_free_minimal(TO_CONN(conn
));
1261 static authority_cert_t
* mock_cert
= NULL
;
1263 static authority_cert_t
*
1264 get_my_v3_authority_cert_m(void)
1266 tor_assert(mock_cert
);
1271 test_dir_handle_get_server_keys_authority(void* data
)
1273 dir_connection_t
*conn
= NULL
;
1274 char *header
= NULL
;
1276 size_t body_used
= 0;
1279 mock_cert
= authority_cert_parse_from_string(TEST_CERTIFICATE
, NULL
);
1281 MOCK(get_my_v3_authority_cert
, get_my_v3_authority_cert_m
);
1282 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1284 conn
= new_dir_conn();
1286 const char *req
= GET("/tor/keys/authority");
1287 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1289 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1290 &body
, &body_used
, strlen(TEST_CERTIFICATE
)+1, 0);
1295 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1296 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1297 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1298 tt_assert(strstr(header
, "Content-Length: 1883\r\n"));
1300 tt_str_op(TEST_CERTIFICATE
, OP_EQ
, body
);
1303 UNMOCK(get_my_v3_authority_cert
);
1304 UNMOCK(connection_write_to_buf_impl_
);
1305 connection_free_minimal(TO_CONN(conn
));
1308 authority_cert_free(mock_cert
); mock_cert
= NULL
;
1312 test_dir_handle_get_server_keys_fp_not_found(void* data
)
1314 dir_connection_t
*conn
= NULL
;
1315 char *header
= NULL
;
1318 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1320 conn
= new_dir_conn();
1322 const char *req
= GET("/tor/keys/fp/somehex");
1323 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1325 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1329 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1332 UNMOCK(connection_write_to_buf_impl_
);
1333 connection_free_minimal(TO_CONN(conn
));
1338 test_dir_handle_get_server_keys_fp(void* data
)
1340 dir_connection_t
*conn
= NULL
;
1341 char *header
= NULL
;
1343 size_t body_used
= 0;
1344 dir_server_t
*ds
= NULL
;
1345 const char digest
[DIGEST_LEN
] = "";
1348 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1350 clear_dir_servers();
1351 routerlist_free_all();
1353 /* create a trusted ds */
1354 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
1355 NULL
, V3_DIRINFO
, 1.0);
1359 /* ds v3_identity_digest is the certificate's identity_key */
1360 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
1361 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
1363 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
1364 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
1366 conn
= new_dir_conn();
1368 tor_snprintf(req
, sizeof(req
),
1369 GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY
);
1370 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1372 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1373 &body
, &body_used
, strlen(TEST_CERTIFICATE
)+1, 0);
1378 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1379 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1380 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1381 tt_assert(strstr(header
, "Content-Length: 1883\r\n"));
1383 tt_str_op(TEST_CERTIFICATE
, OP_EQ
, body
);
1386 UNMOCK(connection_write_to_buf_impl_
);
1387 connection_free_minimal(TO_CONN(conn
));
1390 clear_dir_servers();
1391 routerlist_free_all();
1395 test_dir_handle_get_server_keys_sk_not_found(void* data
)
1397 dir_connection_t
*conn
= NULL
;
1398 char *header
= NULL
;
1401 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1403 conn
= new_dir_conn();
1405 const char *req
= GET("/tor/keys/sk/somehex");
1406 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1408 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1412 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1415 UNMOCK(connection_write_to_buf_impl_
);
1416 connection_free_minimal(TO_CONN(conn
));
1421 test_dir_handle_get_server_keys_sk(void* data
)
1423 dir_connection_t
*conn
= NULL
;
1424 char *header
= NULL
;
1426 size_t body_used
= 0;
1429 mock_cert
= authority_cert_parse_from_string(TEST_CERTIFICATE
, NULL
);
1430 MOCK(get_my_v3_authority_cert
, get_my_v3_authority_cert_m
);
1431 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1433 clear_dir_servers();
1434 routerlist_free_all();
1436 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
1437 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
1439 conn
= new_dir_conn();
1441 tor_snprintf(req
, sizeof(req
),
1442 GET("/tor/keys/sk/%s"), TEST_SIGNING_KEY
);
1443 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1445 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1446 &body
, &body_used
, strlen(TEST_CERTIFICATE
)+1, 0);
1451 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1452 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1453 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1454 tt_assert(strstr(header
, "Content-Length: 1883\r\n"));
1456 tt_str_op(TEST_CERTIFICATE
, OP_EQ
, body
);
1459 UNMOCK(get_my_v3_authority_cert
);
1460 UNMOCK(connection_write_to_buf_impl_
);
1461 connection_free_minimal(TO_CONN(conn
));
1462 authority_cert_free(mock_cert
); mock_cert
= NULL
;
1468 test_dir_handle_get_server_keys_fpsk_not_found(void* data
)
1470 dir_connection_t
*conn
= NULL
;
1471 char *header
= NULL
;
1474 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1476 conn
= new_dir_conn();
1478 const char *req
= GET("/tor/keys/fp-sk/somehex");
1479 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1481 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1485 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1488 UNMOCK(connection_write_to_buf_impl_
);
1489 connection_free_minimal(TO_CONN(conn
));
1494 test_dir_handle_get_server_keys_fpsk(void* data
)
1496 dir_connection_t
*conn
= NULL
;
1497 char *header
= NULL
;
1499 size_t body_used
= 0;
1500 dir_server_t
*ds
= NULL
;
1501 const char digest
[DIGEST_LEN
] = "";
1504 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1506 clear_dir_servers();
1507 routerlist_free_all();
1509 /* create a trusted ds */
1510 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
1511 NULL
, V3_DIRINFO
, 1.0);
1514 /* ds v3_identity_digest is the certificate's identity_key */
1515 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
1516 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
1519 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
1520 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
1522 conn
= new_dir_conn();
1525 tor_snprintf(req
, sizeof(req
),
1526 GET("/tor/keys/fp-sk/%s-%s"),
1527 TEST_CERT_IDENT_KEY
, TEST_SIGNING_KEY
);
1529 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1531 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1532 &body
, &body_used
, strlen(TEST_CERTIFICATE
)+1, 0);
1537 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1538 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1539 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1540 tt_assert(strstr(header
, "Content-Length: 1883\r\n"));
1542 tt_str_op(TEST_CERTIFICATE
, OP_EQ
, body
);
1545 UNMOCK(connection_write_to_buf_impl_
);
1546 connection_free_minimal(TO_CONN(conn
));
1550 clear_dir_servers();
1551 routerlist_free_all();
1555 test_dir_handle_get_server_keys_busy(void* data
)
1557 dir_connection_t
*conn
= NULL
;
1558 char *header
= NULL
;
1559 dir_server_t
*ds
= NULL
;
1560 const char digest
[DIGEST_LEN
] = "";
1563 clear_dir_servers();
1564 routerlist_free_all();
1566 /* create a trusted ds */
1567 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
1568 NULL
, V3_DIRINFO
, 1.0);
1571 /* ds v3_identity_digest is the certificate's identity_key */
1572 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
1573 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
1576 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
1577 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
1579 MOCK(get_options
, mock_get_options
);
1580 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1582 /* setup busy server */
1583 init_mock_options();
1584 mock_options
->CountPrivateBandwidth
= 1;
1586 conn
= new_dir_conn();
1588 tor_snprintf(req
, sizeof(req
), GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY
);
1589 tt_int_op(directory_handle_command_get(conn
, req
, NULL
, 0), OP_EQ
, 0);
1591 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1595 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
1598 UNMOCK(get_options
);
1599 UNMOCK(connection_write_to_buf_impl_
);
1600 connection_free_minimal(TO_CONN(conn
));
1602 or_options_free(mock_options
); mock_options
= NULL
;
1604 clear_dir_servers();
1605 routerlist_free_all();
1608 static networkstatus_t
*mock_ns_val
= NULL
;
1609 static networkstatus_t
*
1610 mock_ns_get_by_flavor(consensus_flavor_t f
)
1617 test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d
)
1619 dir_connection_t
*conn
= NULL
;
1620 char *header
= NULL
;
1625 mock_ns_val
= tor_malloc_zero(sizeof(networkstatus_t
));
1626 mock_ns_val
->flavor
= FLAV_NS
;
1627 mock_ns_val
->type
= NS_TYPE_CONSENSUS
;
1628 mock_ns_val
->voters
= smartlist_new();
1629 mock_ns_val
->valid_after
= time(NULL
) - 1800;
1630 mock_ns_val
->valid_until
= time(NULL
) - 60;
1632 #define NETWORK_STATUS "some network status string"
1633 consdiffmgr_add_consensus(NETWORK_STATUS
, mock_ns_val
);
1636 init_mock_options();
1638 MOCK(get_options
, mock_get_options
);
1639 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1640 MOCK(networkstatus_get_latest_consensus_by_flavor
, mock_ns_get_by_flavor
);
1642 /* start gathering stats */
1643 mock_options
->DirReqStatistics
= 1;
1644 geoip_dirreq_stats_init(time(NULL
));
1646 conn
= new_dir_conn();
1648 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1649 GET("/tor/status-vote/current/consensus-ns/" HEX1
"+" HEX2
), NULL
, 0));
1651 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1655 tt_str_op(NOT_ENOUGH_CONSENSUS_SIGNATURES
, OP_EQ
, header
);
1657 stats
= geoip_format_dirreq_stats(time(NULL
));
1659 tt_assert(strstr(stats
, "not-enough-sigs=8"));
1662 UNMOCK(networkstatus_get_latest_consensus_by_flavor
);
1663 UNMOCK(connection_write_to_buf_impl_
);
1664 UNMOCK(get_options
);
1666 connection_free_minimal(TO_CONN(conn
));
1669 smartlist_free(mock_ns_val
->voters
);
1670 tor_free(mock_ns_val
);
1671 or_options_free(mock_options
); mock_options
= NULL
;
1675 test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data
)
1677 dir_connection_t
*conn
= NULL
;
1678 char *header
= NULL
;
1682 init_mock_options();
1684 MOCK(get_options
, mock_get_options
);
1685 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1687 /* start gathering stats */
1688 mock_options
->DirReqStatistics
= 1;
1689 geoip_dirreq_stats_init(time(NULL
));
1691 conn
= new_dir_conn();
1692 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1693 GET("/tor/status-vote/current/consensus-ns"), NULL
, 0));
1695 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1698 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1700 stats
= geoip_format_dirreq_stats(time(NULL
));
1702 tt_assert(strstr(stats
, "not-found=8"));
1705 UNMOCK(connection_write_to_buf_impl_
);
1706 UNMOCK(get_options
);
1707 connection_free_minimal(TO_CONN(conn
));
1710 or_options_free(mock_options
); mock_options
= NULL
;
1714 test_dir_handle_get_status_vote_current_consensus_too_old(void *data
)
1716 dir_connection_t
*conn
= NULL
;
1717 char *header
= NULL
;
1720 mock_ns_val
= tor_malloc_zero(sizeof(networkstatus_t
));
1721 mock_ns_val
->type
= NS_TYPE_CONSENSUS
;
1722 mock_ns_val
->flavor
= FLAV_MICRODESC
;
1723 mock_ns_val
->valid_after
= time(NULL
) - (24 * 60 * 60 + 1800);
1724 mock_ns_val
->fresh_until
= time(NULL
) - (24 * 60 * 60 + 900);
1725 mock_ns_val
->valid_until
= time(NULL
) - (24 * 60 * 60 + 20);
1727 #define NETWORK_STATUS "some network status string"
1728 consdiffmgr_add_consensus(NETWORK_STATUS
, mock_ns_val
);
1730 init_mock_options();
1732 MOCK(get_options
, mock_get_options
);
1733 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1734 MOCK(networkstatus_get_latest_consensus_by_flavor
, mock_ns_get_by_flavor
);
1736 conn
= new_dir_conn();
1738 setup_capture_of_logs(LOG_WARN
);
1740 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1741 GET("/tor/status-vote/current/consensus-microdesc"), NULL
, 0));
1743 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1746 tt_str_op(TOO_OLD
, OP_EQ
, header
);
1748 expect_log_msg_containing("too old");
1751 teardown_capture_of_logs();
1752 tor_free(mock_ns_val
);
1754 mock_ns_val
= tor_malloc_zero(sizeof(networkstatus_t
));
1755 mock_ns_val
->type
= NS_TYPE_CONSENSUS
;
1756 mock_ns_val
->flavor
= FLAV_NS
;
1757 mock_ns_val
->valid_after
= time(NULL
) - (24 * 60 * 60 + 1800);
1758 mock_ns_val
->fresh_until
= time(NULL
) - (24 * 60 * 60 + 900);
1759 mock_ns_val
->valid_until
= time(NULL
) - (24 * 60 * 60 + 20);
1761 #define NETWORK_STATUS "some network status string"
1762 consdiffmgr_add_consensus(NETWORK_STATUS
, mock_ns_val
);
1764 setup_capture_of_logs(LOG_WARN
);
1766 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1767 GET("/tor/status-vote/current/consensus"), NULL
, 0));
1769 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1772 tt_str_op(TOO_OLD
, OP_EQ
, header
);
1774 expect_no_log_entry();
1777 teardown_capture_of_logs();
1778 UNMOCK(networkstatus_get_latest_consensus_by_flavor
);
1779 UNMOCK(connection_write_to_buf_impl_
);
1780 UNMOCK(get_options
);
1781 connection_free_minimal(TO_CONN(conn
));
1783 tor_free(mock_ns_val
);
1784 or_options_free(mock_options
); mock_options
= NULL
;
1787 NS_DECL(int, geoip_get_country_by_addr
, (const tor_addr_t
*addr
));
1790 NS(geoip_get_country_by_addr
)(const tor_addr_t
*addr
)
1793 CALLED(geoip_get_country_by_addr
)++;
1798 status_vote_current_consensus_ns_test(char **header
, char **body
,
1801 dir_connection_t
*conn
= NULL
;
1803 #define NETWORK_STATUS "some network status string"
1805 common_digests_t digests
;
1806 uint8_t sha3
[DIGEST256_LEN
];
1807 memset(&digests
, 0x60, sizeof(digests
));
1808 memset(sha3
, 0x06, sizeof(sha3
));
1809 dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS
, "ns", &digests
,
1813 networkstatus_t
*ns
= tor_malloc_zero(sizeof(networkstatus_t
));
1814 ns
->type
= NS_TYPE_CONSENSUS
;
1815 ns
->flavor
= FLAV_NS
;
1816 ns
->valid_after
= time(NULL
) - 1800;
1817 ns
->fresh_until
= time(NULL
) - 900;
1818 ns
->valid_until
= time(NULL
) - 60;
1819 consdiffmgr_add_consensus(NETWORK_STATUS
, ns
);
1820 networkstatus_vote_free(ns
);
1822 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1824 tt_assert(mock_options
);
1825 mock_options
->DirReqStatistics
= 1;
1826 geoip_dirreq_stats_init(time(NULL
));
1828 /* init geoip database */
1829 geoip_parse_entry("10,50,AB", AF_INET
);
1830 tt_str_op("ab", OP_EQ
, geoip_get_country_name(1));
1832 conn
= new_dir_conn();
1834 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1835 GET("/tor/status-vote/current/consensus-ns"), NULL
, 0));
1837 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, header
, MAX_HEADERS_SIZE
,
1838 body
, body_len
, strlen(NETWORK_STATUS
)+7, 0);
1841 UNMOCK(connection_write_to_buf_impl_
);
1842 connection_free_minimal(TO_CONN(conn
));
1846 test_dir_handle_get_status_vote_current_consensus_ns(void* data
)
1848 char *header
= NULL
;
1849 char *body
= NULL
, *comp_body
= NULL
;
1850 size_t body_used
= 0, comp_body_used
= 0;
1851 char *stats
= NULL
, *hist
= NULL
;
1857 NS_MOCK(geoip_get_country_by_addr
);
1858 MOCK(get_options
, mock_get_options
);
1860 init_mock_options();
1862 status_vote_current_consensus_ns_test(&header
, &comp_body
, &comp_body_used
);
1865 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
1866 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
1867 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
1868 tt_assert(strstr(header
, "Pragma: no-cache\r\n"));
1870 compress_method_t compression
= detect_compression_method(comp_body
,
1872 tt_int_op(ZLIB_METHOD
, OP_EQ
, compression
);
1874 tor_uncompress(&body
, &body_used
, comp_body
, comp_body_used
,
1875 compression
, 0, LOG_PROTOCOL_WARN
);
1877 tt_str_op(NETWORK_STATUS
, OP_EQ
, body
);
1878 tt_int_op(strlen(NETWORK_STATUS
), OP_EQ
, body_used
);
1880 stats
= geoip_format_dirreq_stats(time(NULL
));
1883 tt_assert(strstr(stats
, "ok=8"));
1884 tt_assert(strstr(stats
, "dirreq-v3-ips ab=8"));
1885 tt_assert(strstr(stats
, "dirreq-v3-reqs ab=8"));
1886 tt_assert(strstr(stats
, "dirreq-v3-direct-dl"
1887 " complete=0,timeout=0,running=4"));
1889 hist
= geoip_get_request_history();
1891 tt_str_op("ab=8", OP_EQ
, hist
);
1894 NS_UNMOCK(geoip_get_country_by_addr
);
1895 UNMOCK(get_options
);
1897 tor_free(comp_body
);
1901 or_options_free(mock_options
); mock_options
= NULL
;
1908 test_dir_handle_get_status_vote_current_consensus_ns_busy(void* data
)
1910 char *header
= NULL
;
1912 size_t body_used
= 0;
1919 MOCK(get_options
, mock_get_options
);
1922 init_mock_options();
1923 mock_options
->CountPrivateBandwidth
= 1;
1925 status_vote_current_consensus_ns_test(&header
, &body
, &body_used
);
1928 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
1930 stats
= geoip_format_dirreq_stats(time(NULL
));
1932 tt_assert(strstr(stats
, "busy=8"));
1935 UNMOCK(get_options
);
1938 or_options_free(mock_options
); mock_options
= NULL
;
1946 test_dir_handle_get_status_vote_current_not_found(void* data
)
1948 dir_connection_t
*conn
= NULL
;
1949 char *header
= NULL
;
1952 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1954 conn
= new_dir_conn();
1955 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1956 GET("/tor/status-vote/current/" HEX1
), NULL
, 0));
1958 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
1961 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
1964 UNMOCK(connection_write_to_buf_impl_
);
1965 connection_free_minimal(TO_CONN(conn
));
1969 #define VOTE_DIGEST "312A4890D4D832597ABBD3089C782DBBFB81E48D"
1972 status_vote_current_d_test(char **header
, char **body
, size_t *body_l
)
1974 dir_connection_t
*conn
= NULL
;
1976 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1978 conn
= new_dir_conn();
1979 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
1980 GET("/tor/status-vote/current/d/" VOTE_DIGEST
), NULL
, 0));
1982 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, header
, MAX_HEADERS_SIZE
,
1983 body
, body_l
, strlen(VOTE_BODY_V3
)+1, 0);
1987 UNMOCK(connection_write_to_buf_impl_
);
1988 connection_free_minimal(TO_CONN(conn
));
1992 status_vote_next_d_test(char **header
, char **body
, size_t *body_l
)
1994 dir_connection_t
*conn
= NULL
;
1996 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
1998 conn
= new_dir_conn();
1999 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2000 GET("/tor/status-vote/next/d/" VOTE_DIGEST
), NULL
, 0));
2002 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, header
, MAX_HEADERS_SIZE
,
2003 body
, body_l
, strlen(VOTE_BODY_V3
)+1, 0);
2007 UNMOCK(connection_write_to_buf_impl_
);
2008 connection_free_minimal(TO_CONN(conn
));
2012 test_dir_handle_get_status_vote_current_d_not_found(void* data
)
2014 char *header
= NULL
;
2017 status_vote_current_d_test(&header
, NULL
, NULL
);
2020 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2027 test_dir_handle_get_status_vote_next_d_not_found(void* data
)
2029 char *header
= NULL
;
2032 status_vote_next_d_test(&header
, NULL
, NULL
);
2035 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2038 UNMOCK(connection_write_to_buf_impl_
);
2043 test_dir_handle_get_status_vote_d(void* data
)
2045 char *header
= NULL
, *body
= NULL
;
2046 size_t body_used
= 0;
2047 dir_server_t
*ds
= NULL
;
2048 const char digest
[DIGEST_LEN
] = "";
2051 clear_dir_servers();
2054 /* create a trusted ds */
2055 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
2056 NULL
, V3_DIRINFO
, 1.0);
2060 /* ds v3_identity_digest is the certificate's identity_key */
2061 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
2062 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
2064 init_mock_options();
2065 mock_options
->AuthoritativeDir
= 1;
2066 mock_options
->V3AuthoritativeDir
= 1;
2067 mock_options
->TestingV3AuthVotingStartOffset
= 0;
2068 mock_options
->TestingV3AuthInitialVotingInterval
= 1;
2069 mock_options
->TestingV3AuthInitialVoteDelay
= 1;
2070 mock_options
->TestingV3AuthInitialDistDelay
= 1;
2072 time_t now
= 1441223455 -1;
2073 voting_schedule_recalculate_timing(mock_options
, now
);
2075 const char *msg_out
= NULL
;
2077 struct pending_vote_t
*pv
= dirvote_add_vote(VOTE_BODY_V3
, &msg_out
,
2081 status_vote_current_d_test(&header
, &body
, &body_used
);
2084 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2085 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2086 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2087 tt_assert(strstr(header
, "Content-Length: 4135\r\n"));
2089 tt_str_op(VOTE_BODY_V3
, OP_EQ
, body
);
2094 status_vote_next_d_test(&header
, &body
, &body_used
);
2097 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2098 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2099 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2100 tt_assert(strstr(header
, "Content-Length: 4135\r\n"));
2102 tt_str_op(VOTE_BODY_V3
, OP_EQ
, body
);
2107 or_options_free(mock_options
); mock_options
= NULL
;
2109 clear_dir_servers();
2111 routerlist_free_all();
2115 test_dir_handle_get_status_vote_next_not_found(void* data
)
2117 dir_connection_t
*conn
= NULL
;
2118 char *header
= NULL
;
2121 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2123 conn
= new_dir_conn();
2124 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2125 GET("/tor/status-vote/next/" HEX1
), NULL
, 0));
2127 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
2130 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2133 UNMOCK(connection_write_to_buf_impl_
);
2134 connection_free_minimal(TO_CONN(conn
));
2139 status_vote_next_consensus_test(char **header
, char **body
, size_t *body_used
)
2141 dir_connection_t
*conn
= NULL
;
2143 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2145 conn
= new_dir_conn();
2146 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2147 GET("/tor/status-vote/next/consensus"), NULL
, 0));
2149 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, header
, MAX_HEADERS_SIZE
,
2150 body
, body_used
, 18, 0);
2152 UNMOCK(connection_write_to_buf_impl_
);
2153 connection_free_minimal(TO_CONN(conn
));
2157 test_dir_handle_get_status_vote_next_consensus_not_found(void* data
)
2159 char *header
= NULL
, *body
= NULL
;
2163 status_vote_next_consensus_test(&header
, &body
, &body_used
);
2166 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2174 test_dir_handle_get_status_vote_current_authority_not_found(void* data
)
2176 dir_connection_t
*conn
= NULL
;
2177 char *header
= NULL
;
2180 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2182 conn
= new_dir_conn();
2183 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2184 GET("/tor/status-vote/current/authority"), NULL
, 0));
2186 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
2189 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2192 UNMOCK(connection_write_to_buf_impl_
);
2193 connection_free_minimal(TO_CONN(conn
));
2198 test_dir_handle_get_status_vote_next_authority_not_found(void* data
)
2200 dir_connection_t
*conn
= NULL
;
2201 char *header
= NULL
;
2204 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2206 conn
= new_dir_conn();
2207 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2208 GET("/tor/status-vote/next/authority"), NULL
, 0));
2210 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
2213 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2216 UNMOCK(connection_write_to_buf_impl_
);
2217 connection_free_minimal(TO_CONN(conn
));
2221 NS_DECL(const char*,
2222 dirvote_get_pending_consensus
, (consensus_flavor_t flav
));
2225 NS(dirvote_get_pending_consensus
)(consensus_flavor_t flav
)
2228 return "pending consensus";
2232 test_dir_handle_get_status_vote_next_consensus(void* data
)
2234 char *header
= NULL
, *body
= NULL
;
2235 size_t body_used
= 0;
2238 NS_MOCK(dirvote_get_pending_consensus
);
2240 status_vote_next_consensus_test(&header
, &body
, &body_used
);
2243 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2244 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2245 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2246 tt_assert(strstr(header
, "Content-Length: 17\r\n"));
2248 tt_str_op("pending consensus", OP_EQ
, body
);
2251 NS_UNMOCK(dirvote_get_pending_consensus
);
2257 test_dir_handle_get_status_vote_next_consensus_busy(void* data
)
2259 char *header
= NULL
, *body
= NULL
;
2260 size_t body_used
= 0;
2263 MOCK(get_options
, mock_get_options
);
2264 NS_MOCK(dirvote_get_pending_consensus
);
2267 init_mock_options();
2268 mock_options
->CountPrivateBandwidth
= 1;
2270 status_vote_next_consensus_test(&header
, &body
, &body_used
);
2273 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
2276 NS_UNMOCK(dirvote_get_pending_consensus
);
2277 UNMOCK(get_options
);
2280 or_options_free(mock_options
); mock_options
= NULL
;
2284 status_vote_next_consensus_signatures_test(char **header
, char **body
,
2287 dir_connection_t
*conn
= NULL
;
2289 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2291 conn
= new_dir_conn();
2292 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2293 GET("/tor/status-vote/next/consensus-signatures"), NULL
, 0));
2295 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, header
, MAX_HEADERS_SIZE
,
2296 body
, body_used
, 22, 0);
2299 connection_free_minimal(TO_CONN(conn
));
2300 UNMOCK(connection_write_to_buf_impl_
);
2304 test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data
)
2306 char *header
= NULL
, *body
= NULL
;
2310 status_vote_next_consensus_signatures_test(&header
, &body
, &body_used
);
2313 tt_str_op(NOT_FOUND
, OP_EQ
, header
);
2320 NS_DECL(const char*,
2321 dirvote_get_pending_detached_signatures
, (void));
2324 NS(dirvote_get_pending_detached_signatures
)(void)
2326 return "pending detached sigs";
2330 test_dir_handle_get_status_vote_next_consensus_signatures(void* data
)
2332 char *header
= NULL
, *body
= NULL
;
2333 size_t body_used
= 0;
2336 NS_MOCK(dirvote_get_pending_detached_signatures
);
2338 status_vote_next_consensus_signatures_test(&header
, &body
, &body_used
);
2341 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2342 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2343 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2344 tt_assert(strstr(header
, "Content-Length: 21\r\n"));
2346 tt_str_op("pending detached sigs", OP_EQ
, body
);
2349 NS_UNMOCK(dirvote_get_pending_detached_signatures
);
2355 test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data
)
2357 char *header
= NULL
, *body
= NULL
;
2361 NS_MOCK(dirvote_get_pending_detached_signatures
);
2362 MOCK(get_options
, mock_get_options
);
2365 init_mock_options();
2366 mock_options
->CountPrivateBandwidth
= 1;
2368 status_vote_next_consensus_signatures_test(&header
, &body
, &body_used
);
2371 tt_str_op(SERVER_BUSY
, OP_EQ
, header
);
2374 UNMOCK(get_options
);
2375 NS_UNMOCK(dirvote_get_pending_detached_signatures
);
2378 or_options_free(mock_options
); mock_options
= NULL
;
2382 test_dir_handle_get_status_vote_next_authority(void* data
)
2384 dir_connection_t
*conn
= NULL
;
2385 char *header
= NULL
, *body
= NULL
;
2386 const char *msg_out
= NULL
;
2388 size_t body_used
= 0;
2389 dir_server_t
*ds
= NULL
;
2390 const char digest
[DIGEST_LEN
] = "";
2393 clear_dir_servers();
2394 routerlist_free_all();
2397 mock_cert
= authority_cert_parse_from_string(TEST_CERTIFICATE
, NULL
);
2399 /* create a trusted ds */
2400 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
2401 NULL
, V3_DIRINFO
, 1.0);
2405 /* ds v3_identity_digest is the certificate's identity_key */
2406 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
2407 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
2408 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
2409 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
2411 init_mock_options();
2412 mock_options
->AuthoritativeDir
= 1;
2413 mock_options
->V3AuthoritativeDir
= 1;
2414 mock_options
->TestingV3AuthVotingStartOffset
= 0;
2415 mock_options
->TestingV3AuthInitialVotingInterval
= 1;
2416 mock_options
->TestingV3AuthInitialVoteDelay
= 1;
2417 mock_options
->TestingV3AuthInitialDistDelay
= 1;
2419 time_t now
= 1441223455 -1;
2420 voting_schedule_recalculate_timing(mock_options
, now
);
2422 struct pending_vote_t
*vote
= dirvote_add_vote(VOTE_BODY_V3
, &msg_out
,
2426 MOCK(get_my_v3_authority_cert
, get_my_v3_authority_cert_m
);
2427 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2429 conn
= new_dir_conn();
2430 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2431 GET("/tor/status-vote/next/authority"), NULL
, 0));
2433 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
2434 &body
, &body_used
, strlen(VOTE_BODY_V3
)+1, 0);
2437 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2438 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2439 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2440 tt_assert(strstr(header
, "Content-Length: 4135\r\n"));
2442 tt_str_op(VOTE_BODY_V3
, OP_EQ
, body
);
2445 UNMOCK(connection_write_to_buf_impl_
);
2446 UNMOCK(get_my_v3_authority_cert
);
2447 connection_free_minimal(TO_CONN(conn
));
2450 authority_cert_free(mock_cert
); mock_cert
= NULL
;
2451 or_options_free(mock_options
); mock_options
= NULL
;
2453 clear_dir_servers();
2454 routerlist_free_all();
2459 test_dir_handle_get_status_vote_current_authority(void* data
)
2461 dir_connection_t
*conn
= NULL
;
2462 char *header
= NULL
, *body
= NULL
;
2463 const char *msg_out
= NULL
;
2465 size_t body_used
= 0;
2466 const char digest
[DIGEST_LEN
] = "";
2468 dir_server_t
*ds
= NULL
;
2471 clear_dir_servers();
2472 routerlist_free_all();
2475 mock_cert
= authority_cert_parse_from_string(TEST_CERTIFICATE
, NULL
);
2477 /* create a trusted ds */
2478 ds
= trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL
, digest
,
2479 NULL
, V3_DIRINFO
, 1.0);
2483 /* ds v3_identity_digest is the certificate's identity_key */
2484 base16_decode(ds
->v3_identity_digest
, DIGEST_LEN
,
2485 TEST_CERT_IDENT_KEY
, HEX_DIGEST_LEN
);
2487 tt_int_op(0, OP_EQ
, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE
,
2488 TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST
, 1, NULL
));
2490 init_mock_options();
2491 mock_options
->AuthoritativeDir
= 1;
2492 mock_options
->V3AuthoritativeDir
= 1;
2493 mock_options
->TestingV3AuthVotingStartOffset
= 0;
2494 mock_options
->TestingV3AuthInitialVotingInterval
= 1;
2495 mock_options
->TestingV3AuthInitialVoteDelay
= 1;
2496 mock_options
->TestingV3AuthInitialDistDelay
= 1;
2498 time_t now
= 1441223455;
2499 voting_schedule_recalculate_timing(mock_options
, now
-1);
2501 struct pending_vote_t
*vote
= dirvote_add_vote(VOTE_BODY_V3
, &msg_out
,
2505 // move the pending vote to previous vote
2506 dirvote_act(mock_options
, now
+1);
2508 MOCK(get_my_v3_authority_cert
, get_my_v3_authority_cert_m
);
2509 MOCK(connection_write_to_buf_impl_
, connection_write_to_buf_mock
);
2511 conn
= new_dir_conn();
2512 tt_int_op(0, OP_EQ
, directory_handle_command_get(conn
,
2513 GET("/tor/status-vote/current/authority"), NULL
, 0));
2515 fetch_from_buf_http(TO_CONN(conn
)->outbuf
, &header
, MAX_HEADERS_SIZE
,
2516 &body
, &body_used
, strlen(VOTE_BODY_V3
)+1, 0);
2519 tt_ptr_op(strstr(header
, "HTTP/1.0 200 OK\r\n"), OP_EQ
, header
);
2520 tt_assert(strstr(header
, "Content-Type: text/plain\r\n"));
2521 tt_assert(strstr(header
, "Content-Encoding: identity\r\n"));
2522 tt_assert(strstr(header
, "Content-Length: 4135\r\n"));
2524 tt_str_op(VOTE_BODY_V3
, OP_EQ
, body
);
2527 UNMOCK(connection_write_to_buf_impl_
);
2528 UNMOCK(get_my_v3_authority_cert
);
2529 connection_free_minimal(TO_CONN(conn
));
2532 authority_cert_free(mock_cert
); mock_cert
= NULL
;
2533 or_options_free(mock_options
); mock_options
= NULL
;
2535 clear_dir_servers();
2536 routerlist_free_all();
2541 test_dir_handle_get_parse_accept_encoding(void *arg
)
2544 const unsigned B_NONE
= 1u << NO_METHOD
;
2545 const unsigned B_ZLIB
= 1u << ZLIB_METHOD
;
2546 const unsigned B_GZIP
= 1u << GZIP_METHOD
;
2547 const unsigned B_LZMA
= 1u << LZMA_METHOD
;
2548 const unsigned B_ZSTD
= 1u << ZSTD_METHOD
;
2552 encodings
= parse_accept_encoding_header("");
2553 tt_uint_op(B_NONE
, OP_EQ
, encodings
);
2555 encodings
= parse_accept_encoding_header(" ");
2556 tt_uint_op(B_NONE
, OP_EQ
, encodings
);
2558 encodings
= parse_accept_encoding_header("dewey, cheatham, and howe ");
2559 tt_uint_op(B_NONE
, OP_EQ
, encodings
);
2561 encodings
= parse_accept_encoding_header("dewey, cheatham, and gzip");
2562 tt_uint_op(B_NONE
, OP_EQ
, encodings
);
2564 encodings
= parse_accept_encoding_header("dewey, cheatham, and, gzip");
2565 tt_uint_op(B_NONE
|B_GZIP
, OP_EQ
, encodings
);
2567 encodings
= parse_accept_encoding_header(" gzip");
2568 tt_uint_op(B_NONE
|B_GZIP
, OP_EQ
, encodings
);
2570 encodings
= parse_accept_encoding_header("gzip");
2571 tt_uint_op(B_NONE
|B_GZIP
, OP_EQ
, encodings
);
2573 encodings
= parse_accept_encoding_header("x-zstd, deflate, x-tor-lzma");
2574 tt_uint_op(B_NONE
|B_ZLIB
|B_ZSTD
|B_LZMA
, OP_EQ
, encodings
);
2576 encodings
= parse_accept_encoding_header(
2577 "x-zstd, deflate, x-tor-lzma, gzip");
2578 tt_uint_op(B_NONE
|B_ZLIB
|B_ZSTD
|B_LZMA
|B_GZIP
, OP_EQ
, encodings
);
2580 encodings
= parse_accept_encoding_header("x-zstd,deflate,x-tor-lzma,gzip");
2581 tt_uint_op(B_NONE
|B_ZLIB
|B_ZSTD
|B_LZMA
|B_GZIP
, OP_EQ
, encodings
);
2587 #define DIR_HANDLE_CMD(name,flags) \
2588 { #name, test_dir_handle_get_##name, (flags), NULL, NULL }
2590 struct testcase_t dir_handle_get_tests
[] = {
2591 DIR_HANDLE_CMD(not_found
, 0),
2592 DIR_HANDLE_CMD(bad_request
, 0),
2593 DIR_HANDLE_CMD(v1_command_not_found
, 0),
2594 DIR_HANDLE_CMD(v1_command
, 0),
2595 DIR_HANDLE_CMD(robots_txt
, 0),
2596 DIR_HANDLE_CMD(rendezvous2_not_found_if_not_encrypted
, 0),
2597 DIR_HANDLE_CMD(rendezvous2_not_found
, 0),
2598 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_with_invalid_desc_id
, 0),
2599 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_not_well_formed
, 0),
2600 DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_success
, 0),
2601 DIR_HANDLE_CMD(micro_d_not_found
, 0),
2602 DIR_HANDLE_CMD(micro_d_server_busy
, 0),
2603 DIR_HANDLE_CMD(micro_d
, 0),
2604 DIR_HANDLE_CMD(networkstatus_bridges_not_found_without_auth
, 0),
2605 DIR_HANDLE_CMD(networkstatus_bridges_not_found_wrong_auth
, 0),
2606 DIR_HANDLE_CMD(networkstatus_bridges
, 0),
2607 DIR_HANDLE_CMD(server_descriptors_not_found
, 0),
2608 DIR_HANDLE_CMD(server_descriptors_busy
, TT_FORK
),
2609 DIR_HANDLE_CMD(server_descriptors_all
, TT_FORK
),
2610 DIR_HANDLE_CMD(server_descriptors_authority
, TT_FORK
),
2611 DIR_HANDLE_CMD(server_descriptors_fp
, TT_FORK
),
2612 DIR_HANDLE_CMD(server_descriptors_d
, TT_FORK
),
2613 DIR_HANDLE_CMD(server_keys_bad_req
, 0),
2614 DIR_HANDLE_CMD(server_keys_busy
, 0),
2615 DIR_HANDLE_CMD(server_keys_all_not_found
, 0),
2616 DIR_HANDLE_CMD(server_keys_all
, 0),
2617 DIR_HANDLE_CMD(server_keys_authority_not_found
, 0),
2618 DIR_HANDLE_CMD(server_keys_authority
, 0),
2619 DIR_HANDLE_CMD(server_keys_fp_not_found
, 0),
2620 DIR_HANDLE_CMD(server_keys_fp
, 0),
2621 DIR_HANDLE_CMD(server_keys_sk_not_found
, 0),
2622 DIR_HANDLE_CMD(server_keys_sk
, 0),
2623 DIR_HANDLE_CMD(server_keys_fpsk_not_found
, 0),
2624 DIR_HANDLE_CMD(server_keys_fpsk
, 0),
2625 DIR_HANDLE_CMD(status_vote_current_not_found
, 0),
2626 DIR_HANDLE_CMD(status_vote_next_not_found
, 0),
2627 DIR_HANDLE_CMD(status_vote_current_authority_not_found
, 0),
2628 DIR_HANDLE_CMD(status_vote_current_authority
, 0),
2629 DIR_HANDLE_CMD(status_vote_next_authority_not_found
, 0),
2630 DIR_HANDLE_CMD(status_vote_next_authority
, 0),
2631 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_enough_sigs
, TT_FORK
),
2632 DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_found
, TT_FORK
),
2633 DIR_HANDLE_CMD(status_vote_current_consensus_too_old
, TT_FORK
),
2634 DIR_HANDLE_CMD(status_vote_current_consensus_ns_busy
, TT_FORK
),
2635 DIR_HANDLE_CMD(status_vote_current_consensus_ns
, TT_FORK
),
2636 DIR_HANDLE_CMD(status_vote_current_d_not_found
, 0),
2637 DIR_HANDLE_CMD(status_vote_next_d_not_found
, 0),
2638 DIR_HANDLE_CMD(status_vote_d
, 0),
2639 DIR_HANDLE_CMD(status_vote_next_consensus_not_found
, 0),
2640 DIR_HANDLE_CMD(status_vote_next_consensus_busy
, 0),
2641 DIR_HANDLE_CMD(status_vote_next_consensus
, 0),
2642 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_not_found
, 0),
2643 DIR_HANDLE_CMD(status_vote_next_consensus_signatures_busy
, 0),
2644 DIR_HANDLE_CMD(status_vote_next_consensus_signatures
, 0),
2645 DIR_HANDLE_CMD(parse_accept_encoding
, 0),