1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497 |
- /* Copyright (c) 2001-2004, Roger Dingledine.
- * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2016, The Tor Project, Inc. */
- /* See LICENSE for licensing information */
- #define RENDCOMMON_PRIVATE
- #define GEOIP_PRIVATE
- #define CONNECTION_PRIVATE
- #define CONFIG_PRIVATE
- #define RENDCACHE_PRIVATE
- #include "or.h"
- #include "config.h"
- #include "connection.h"
- #include "directory.h"
- #include "test.h"
- #include "connection.h"
- #include "rendcommon.h"
- #include "rendcache.h"
- #include "router.h"
- #include "routerlist.h"
- #include "rend_test_helpers.h"
- #include "microdesc.h"
- #include "test_helpers.h"
- #include "nodelist.h"
- #include "entrynodes.h"
- #include "routerparse.h"
- #include "networkstatus.h"
- #include "geoip.h"
- #include "dirserv.h"
- #include "torgzip.h"
- #include "dirvote.h"
- #ifdef _WIN32
- /* For mkdir() */
- #include <direct.h>
- #else
- #include <dirent.h>
- #endif
- #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
- DISABLE_GCC_WARNING(overlength-strings)
- /* We allow huge string constants in the unit tests, but not in the code
- * at large. */
- #endif
- #include "vote_descriptors.inc"
- #ifdef HAVE_CFLAG_WOVERLENGTH_STRINGS
- ENABLE_GCC_WARNING(overlength-strings)
- #endif
- #define NS_MODULE dir_handle_get
- #define NOT_FOUND "HTTP/1.0 404 Not found\r\n\r\n"
- #define BAD_REQUEST "HTTP/1.0 400 Bad request\r\n\r\n"
- #define SERVER_BUSY "HTTP/1.0 503 Directory busy, try again later\r\n\r\n"
- #define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
- "Consensus not signed by sufficient number of requested authorities\r\n\r\n"
- static dir_connection_t *
- new_dir_conn(void)
- {
- dir_connection_t *conn = dir_connection_new(AF_INET);
- tor_addr_from_ipv4h(&conn->base_.addr, 0x7f000001);
- return conn;
- }
- static void
- test_dir_handle_get_bad_request(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(directory_handle_command_get(conn, "", NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(header, OP_EQ, BAD_REQUEST);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_v1_command_not_found(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- // no frontpage configured
- tt_ptr_op(get_dirportfrontpage(), OP_EQ, NULL);
- /* V1 path */
- tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
- OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static const char*
- mock_get_dirportfrontpage(void)
- {
- return "HELLO FROM FRONTPAGE";
- }
- static void
- test_dir_handle_get_v1_command(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0, body_len = 0;
- const char *exp_body = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- MOCK(get_dirportfrontpage, mock_get_dirportfrontpage);
- exp_body = get_dirportfrontpage();
- body_len = strlen(exp_body);
- conn = new_dir_conn();
- tt_int_op(directory_handle_command_get(conn, GET("/tor/"), NULL, 0),
- OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, body_len+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/html\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 20\r\n"));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, exp_body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- UNMOCK(get_dirportfrontpage);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- }
- static void
- test_dir_handle_get_not_found(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- /* Unrecognized path */
- tt_int_op(directory_handle_command_get(conn, GET("/anything"), NULL, 0),
- OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_robots_txt(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(directory_handle_command_get(conn, GET("/tor/robots.txt"),
- NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, 29, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 28\r\n"));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, "User-agent: *\r\nDisallow: /\r\n");
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- }
- #define RENDEZVOUS2_GET(descid) GET("/tor/rendezvous2/" descid)
- static void
- test_dir_handle_get_rendezvous2_not_found_if_not_encrypted(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- // connection is not encrypted
- tt_assert(!connection_dir_is_encrypted(conn))
- tt_int_op(directory_handle_command_get(conn, RENDEZVOUS2_GET(), NULL, 0),
- OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id(
- void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- // connection is encrypted
- TO_CONN(conn)->linked = 1;
- tt_assert(connection_dir_is_encrypted(conn));
- tt_int_op(directory_handle_command_get(conn,
- RENDEZVOUS2_GET("invalid-desc-id"), NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(header, OP_EQ, BAD_REQUEST);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_rendezvous2_on_encrypted_conn_not_well_formed(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- // connection is encrypted
- TO_CONN(conn)->linked = 1;
- tt_assert(connection_dir_is_encrypted(conn));
- //TODO: this cant be reached because rend_valid_descriptor_id() prevents this
- //case to happen. This test is the same as
- //test_dir_handle_get_rendezvous2_on_encrypted_conn_with_invalid_desc_id
- //We should refactor to remove the case from the switch.
- const char *req = RENDEZVOUS2_GET("1bababababababababababababababab");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(header, OP_EQ, BAD_REQUEST);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_rendezvous2_not_found(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- rend_cache_init();
- // connection is encrypted
- TO_CONN(conn)->linked = 1;
- tt_assert(connection_dir_is_encrypted(conn));
- const char *req = RENDEZVOUS2_GET("3xqunszqnaolrrfmtzgaki7mxelgvkje");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- rend_cache_free_all();
- }
- NS_DECL(const routerinfo_t *, router_get_my_routerinfo, (void));
- static routerinfo_t *mock_routerinfo;
- static const routerinfo_t *
- NS(router_get_my_routerinfo)(void)
- {
- if (!mock_routerinfo) {
- mock_routerinfo = tor_malloc_zero(sizeof(routerinfo_t));
- }
- return mock_routerinfo;
- }
- static void
- test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- char buff[30];
- char req[70];
- rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
- char *service_id = NULL;
- char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
- size_t body_len = 0;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- NS_MOCK(router_get_my_routerinfo);
- rend_cache_init();
- /* create a valid rend service descriptor */
- #define RECENT_TIME -10
- generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
- tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
- OP_EQ, 0);
- base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
- DIGEST_LEN);
- conn = new_dir_conn();
- // connection is encrypted
- TO_CONN(conn)->linked = 1;
- tt_assert(connection_dir_is_encrypted(conn));
- tor_snprintf(req, sizeof(req), RENDEZVOUS2_GET("%s"), desc_id_base32);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- body_len = strlen(desc_holder->desc_str);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, body_len+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Pragma: no-cache\r\n"));
- tor_snprintf(buff, sizeof(buff), "Content-Length: %ld\r\n", (long) body_len);
- tt_assert(strstr(header, buff));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, desc_holder->desc_str);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- NS_UNMOCK(router_get_my_routerinfo);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- rend_encoded_v2_service_descriptor_free(desc_holder);
- tor_free(service_id);
- rend_cache_free_all();
- }
- #define MICRODESC_GET(digest) GET("/tor/micro/d/" digest)
- static void
- test_dir_handle_get_micro_d_not_found(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- #define B64_256_1 "8/Pz8/u7vz8/Pz+7vz8/Pz+7u/Pz8/P7u/Pz8/P7u78"
- #define B64_256_2 "zMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMw"
- conn = new_dir_conn();
- const char *req = MICRODESC_GET(B64_256_1 "-" B64_256_2);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static or_options_t *mock_options = NULL;
- static void
- init_mock_options(void)
- {
- mock_options = tor_malloc(sizeof(or_options_t));
- memset(mock_options, 0, sizeof(or_options_t));
- mock_options->TestingTorNetwork = 1;
- }
- static const or_options_t *
- mock_get_options(void)
- {
- tor_assert(mock_options);
- return mock_options;
- }
- static const char microdesc[] =
- "onion-key\n"
- "-----BEGIN RSA PUBLIC KEY-----\n"
- "MIGJAoGBAMjlHH/daN43cSVRaHBwgUfnszzAhg98EvivJ9Qxfv51mvQUxPjQ07es\n"
- "gV/3n8fyh3Kqr/ehi9jxkdgSRfSnmF7giaHL1SLZ29kA7KtST+pBvmTpDtHa3ykX\n"
- "Xorc7hJvIyTZoc1HU+5XSynj3gsBE5IGK1ZRzrNS688LnuZMVp1tAgMBAAE=\n"
- "-----END RSA PUBLIC KEY-----\n";
- static void
- test_dir_handle_get_micro_d(void *data)
- {
- dir_connection_t *conn = NULL;
- microdesc_cache_t *mc = NULL ;
- smartlist_t *list = NULL;
- char digest[DIGEST256_LEN];
- char digest_base64[128];
- char path[80];
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- (void) data;
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* SETUP */
- init_mock_options();
- const char *fn = get_fname("dir_handle_datadir_test1");
- mock_options->DataDirectory = tor_strdup(fn);
- #ifdef _WIN32
- tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
- #else
- tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
- #endif
- /* Add microdesc to cache */
- crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
- base64_encode_nopad(digest_base64, sizeof(digest_base64),
- (uint8_t *) digest, DIGEST256_LEN);
- mc = get_microdesc_cache();
- list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
- time(NULL), NULL);
- tt_int_op(1, OP_EQ, smartlist_len(list));
- /* Make the request */
- conn = new_dir_conn();
- tor_snprintf(path, sizeof(path), MICRODESC_GET("%s"), digest_base64);
- tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(microdesc)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, microdesc);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- smartlist_free(list);
- microdesc_free_all();
- }
- static void
- test_dir_handle_get_micro_d_server_busy(void *data)
- {
- dir_connection_t *conn = NULL;
- microdesc_cache_t *mc = NULL ;
- smartlist_t *list = NULL;
- char digest[DIGEST256_LEN];
- char digest_base64[128];
- char path[80];
- char *header = NULL;
- (void) data;
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* SETUP */
- init_mock_options();
- const char *fn = get_fname("dir_handle_datadir_test2");
- mock_options->DataDirectory = tor_strdup(fn);
- #ifdef _WIN32
- tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory));
- #else
- tt_int_op(0, OP_EQ, mkdir(mock_options->DataDirectory, 0700));
- #endif
- /* Add microdesc to cache */
- crypto_digest256(digest, microdesc, strlen(microdesc), DIGEST_SHA256);
- base64_encode_nopad(digest_base64, sizeof(digest_base64),
- (uint8_t *) digest, DIGEST256_LEN);
- mc = get_microdesc_cache();
- list = microdescs_add_to_cache(mc, microdesc, NULL, SAVED_NOWHERE, 0,
- time(NULL), NULL);
- tt_int_op(1, OP_EQ, smartlist_len(list));
- //Make it busy
- mock_options->CountPrivateBandwidth = 1;
- /* Make the request */
- conn = new_dir_conn();
- tor_snprintf(path, sizeof(path), MICRODESC_GET("%s"), digest_base64);
- tt_int_op(directory_handle_command_get(conn, path, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- smartlist_free(list);
- microdesc_free_all();
- }
- #define BRIDGES_PATH "/tor/networkstatus-bridges"
- static void
- test_dir_handle_get_networkstatus_bridges_not_found_without_auth(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* SETUP */
- init_mock_options();
- mock_options->BridgeAuthoritativeDir = 1;
- mock_options->BridgePassword_AuthDigest_ = tor_strdup("digest");
- conn = new_dir_conn();
- TO_CONN(conn)->linked = 1;
- const char *req = GET(BRIDGES_PATH);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_networkstatus_bridges(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* SETUP */
- init_mock_options();
- mock_options->BridgeAuthoritativeDir = 1;
- mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
- crypto_digest256(mock_options->BridgePassword_AuthDigest_,
- "abcdefghijklm12345", 18, DIGEST_SHA256);
- conn = new_dir_conn();
- TO_CONN(conn)->linked = 1;
- const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
- "Authorization: Basic abcdefghijklm12345\r\n\r\n";
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 0\r\n"));
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_networkstatus_bridges_not_found_wrong_auth(void *data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* SETUP */
- init_mock_options();
- mock_options->BridgeAuthoritativeDir = 1;
- mock_options->BridgePassword_AuthDigest_ = tor_malloc(DIGEST256_LEN);
- crypto_digest256(mock_options->BridgePassword_AuthDigest_,
- "abcdefghijklm12345", 18, DIGEST_SHA256);
- conn = new_dir_conn();
- TO_CONN(conn)->linked = 1;
- const char *req = "GET " BRIDGES_PATH " HTTP/1.0\r\n"
- "Authorization: Basic NOTSAMEDIGEST\r\n\r\n";
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- #define SERVER_DESC_GET(id) GET("/tor/server/" id)
- static void
- test_dir_handle_get_server_descriptors_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = SERVER_DESC_GET("invalid");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_SERVER_BY_FP);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- or_options_free(mock_options); mock_options = NULL;
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_server_descriptors_all(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- (void) data;
- /* Setup fake routerlist. */
- helper_setup_fake_routerlist();
- //TODO: change to router_get_my_extrainfo when testing "extra" path
- NS_MOCK(router_get_my_routerinfo);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- // We are one of the routers
- routerlist_t *our_routerlist = router_get_routerlist();
- tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
- mock_routerinfo = smartlist_get(our_routerlist->routers, 0);
- set_server_identity_key(mock_routerinfo->identity_pkey);
- /* Treat "all" requests as if they were unencrypted */
- mock_routerinfo->cache_info.send_unencrypted = 1;
- conn = new_dir_conn();
- const char *req = SERVER_DESC_GET("all");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- //TODO: Is this a BUG?
- //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
- //which is smaller than that by annotation_len bytes
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used,
- mock_routerinfo->cache_info.signed_descriptor_len+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- //TODO: Is this a BUG?
- //This is what should be expected: tt_int_op(body_used, OP_EQ, strlen(body));
- tt_int_op(body_used, OP_EQ,
- mock_routerinfo->cache_info.signed_descriptor_len);
- tt_str_op(body, OP_EQ, mock_routerinfo->cache_info.signed_descriptor_body +
- mock_routerinfo->cache_info.annotations_len);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
- done:
- NS_UNMOCK(router_get_my_routerinfo);
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- routerlist_free_all();
- nodelist_free_all();
- entry_guards_free_all();
- }
- static char
- TEST_DESCRIPTOR[] =
- "@uploaded-at 2014-06-08 19:20:11\n"
- "@source \"127.0.0.1\"\n"
- "router test000a 127.0.0.1 5000 0 7000\n"
- "platform Tor 0.2.5.3-alpha-dev on Linux\n"
- "protocols Link 1 2 Circuit 1\n"
- "published 2014-06-08 19:20:11\n"
- "fingerprint C7E7 CCB8 179F 8CC3 7F5C 8A04 2B3A 180B 934B 14BA\n"
- "uptime 0\n"
- "bandwidth 1073741824 1073741824 0\n"
- "extra-info-digest 67A152A4C7686FB07664F872620635F194D76D95\n"
- "caches-extra-info\n"
- "onion-key\n"
- "-----BEGIN RSA PUBLIC KEY-----\n"
- "MIGJAoGBAOuBUIEBARMkkka/TGyaQNgUEDLP0KG7sy6KNQTNOlZHUresPr/vlVjo\n"
- "HPpLMfu9M2z18c51YX/muWwY9x4MyQooD56wI4+AqXQcJRwQfQlPn3Ay82uZViA9\n"
- "DpBajRieLlKKkl145KjArpD7F5BVsqccvjErgFYXvhhjSrx7BVLnAgMBAAE=\n"
- "-----END RSA PUBLIC KEY-----\n"
- "signing-key\n"
- "-----BEGIN RSA PUBLIC KEY-----\n"
- "MIGJAoGBAN6NLnSxWQnFXxqZi5D3b0BMgV6y9NJLGjYQVP+eWtPZWgqyv4zeYsqv\n"
- "O9y6c5lvxyUxmNHfoAbe/s8f2Vf3/YaC17asAVSln4ktrr3e9iY74a9RMWHv1Gzk\n"
- "3042nMcqj3PEhRN0PoLkcOZNjjmNbaqki6qy9bWWZDNTdo+uI44dAgMBAAE=\n"
- "-----END RSA PUBLIC KEY-----\n"
- "hidden-service-dir\n"
- "contact auth0@test.test\n"
- "ntor-onion-key pK4bs08ERYN591jj7ca17Rn9Q02TIEfhnjR6hSq+fhU=\n"
- "reject *:*\n"
- "router-signature\n"
- "-----BEGIN SIGNATURE-----\n"
- "rx88DuM3Y7tODlHNDDEVzKpwh3csaG1or+T4l2Xs1oq3iHHyPEtB6QTLYrC60trG\n"
- "aAPsj3DEowGfjga1b248g2dtic8Ab+0exfjMm1RHXfDam5TXXZU3A0wMyoHjqHuf\n"
- "eChGPgFNUvEc+5YtD27qEDcUjcinYztTs7/dzxBT4PE=\n"
- "-----END SIGNATURE-----\n";
- static void
- test_dir_handle_get_server_descriptors_authority(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- crypto_pk_t *identity_pkey = pk_generate(0);
- (void) data;
- NS_MOCK(router_get_my_routerinfo);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* init mock */
- router_get_my_routerinfo();
- crypto_pk_get_digest(identity_pkey,
- mock_routerinfo->cache_info.identity_digest);
- // the digest is mine (the channel is unnecrypted, so we must allow sending)
- set_server_identity_key(identity_pkey);
- mock_routerinfo->cache_info.send_unencrypted = 1;
- /* Setup descriptor */
- long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
- mock_routerinfo->cache_info.signed_descriptor_body =
- tor_strdup(TEST_DESCRIPTOR);
- mock_routerinfo->cache_info.signed_descriptor_len =
- strlen(TEST_DESCRIPTOR) - annotation_len;;
- mock_routerinfo->cache_info.annotations_len = annotation_len;
- conn = new_dir_conn();
- const char *req = SERVER_DESC_GET("authority");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- //TODO: Is this a BUG?
- //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
- //is smaller than that by annotation_len bytes
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
- done:
- NS_UNMOCK(router_get_my_routerinfo);
- UNMOCK(connection_write_to_buf_impl_);
- tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
- tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- crypto_pk_free(identity_pkey);
- }
- static void
- test_dir_handle_get_server_descriptors_fp(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- crypto_pk_t *identity_pkey = pk_generate(0);
- (void) data;
- NS_MOCK(router_get_my_routerinfo);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* init mock */
- router_get_my_routerinfo();
- crypto_pk_get_digest(identity_pkey,
- mock_routerinfo->cache_info.identity_digest);
- // the digest is mine (the channel is unnecrypted, so we must allow sending)
- set_server_identity_key(identity_pkey);
- mock_routerinfo->cache_info.send_unencrypted = 1;
- /* Setup descriptor */
- long annotation_len = strstr(TEST_DESCRIPTOR, "router ") - TEST_DESCRIPTOR;
- mock_routerinfo->cache_info.signed_descriptor_body =
- tor_strdup(TEST_DESCRIPTOR);
- mock_routerinfo->cache_info.signed_descriptor_len =
- strlen(TEST_DESCRIPTOR) - annotation_len;
- mock_routerinfo->cache_info.annotations_len = annotation_len;
- conn = new_dir_conn();
- #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
- #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
- const char *hex_digest = hex_str(mock_routerinfo->cache_info.identity_digest,
- DIGEST_LEN);
- char req[155];
- tor_snprintf(req, sizeof(req), SERVER_DESC_GET("fp/%s+" HEX1 "+" HEX2),
- hex_digest);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- //TODO: Is this a BUG?
- //It requires strlen(TEST_DESCRIPTOR)+1 as body_len but returns a body which
- //is smaller than that by annotation_len bytes
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_DESCRIPTOR)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_int_op(body_used, OP_EQ, strlen(body));
- tt_str_op(body, OP_EQ, TEST_DESCRIPTOR + annotation_len);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
- done:
- NS_UNMOCK(router_get_my_routerinfo);
- UNMOCK(connection_write_to_buf_impl_);
- tor_free(mock_routerinfo->cache_info.signed_descriptor_body);
- tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- crypto_pk_free(identity_pkey);
- }
- #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
- #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
- static void
- test_dir_handle_get_server_descriptors_d(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- crypto_pk_t *identity_pkey = pk_generate(0);
- (void) data;
- /* Setup fake routerlist. */
- helper_setup_fake_routerlist();
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* Get one router's signed_descriptor_digest */
- routerlist_t *our_routerlist = router_get_routerlist();
- tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
- routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
- const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
- DIGEST_LEN);
- conn = new_dir_conn();
- char req_header[155]; /* XXX Why 155? What kind of number is that?? */
- tor_snprintf(req_header, sizeof(req_header),
- SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
- tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
- //TODO: Is this a BUG?
- //It requires strlen(signed_descriptor_len)+1 as body_len but returns a body
- //which is smaller than that by annotation_len bytes
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used,
- router->cache_info.signed_descriptor_len+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- //TODO: Is this a BUG?
- //This is what should be expected:
- //tt_int_op(body_used, OP_EQ, strlen(body));
- tt_int_op(body_used, OP_EQ, router->cache_info.signed_descriptor_len);
- tt_str_op(body, OP_EQ, router->cache_info.signed_descriptor_body +
- router->cache_info.annotations_len);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- crypto_pk_free(identity_pkey);
- routerlist_free_all();
- nodelist_free_all();
- entry_guards_free_all();
- }
- static void
- test_dir_handle_get_server_descriptors_busy(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- crypto_pk_t *identity_pkey = pk_generate(0);
- (void) data;
- /* Setup fake routerlist. */
- helper_setup_fake_routerlist();
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- //Make it busy
- MOCK(get_options, mock_get_options);
- init_mock_options();
- mock_options->CountPrivateBandwidth = 1;
- /* Get one router's signed_descriptor_digest */
- routerlist_t *our_routerlist = router_get_routerlist();
- tt_int_op(smartlist_len(our_routerlist->routers), OP_GE, 1);
- routerinfo_t *router = smartlist_get(our_routerlist->routers, 0);
- const char *hex_digest = hex_str(router->cache_info.signed_descriptor_digest,
- DIGEST_LEN);
- conn = new_dir_conn();
- #define HEX1 "Fe0daff89127389bc67558691231234551193EEE"
- #define HEX2 "Deadbeef99999991111119999911111111f00ba4"
- char req_header[155]; /* XXX 155? Why 155? */
- tor_snprintf(req_header, sizeof(req_header),
- SERVER_DESC_GET("d/%s+" HEX1 "+" HEX2), hex_digest);
- tt_int_op(directory_handle_command_get(conn, req_header, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- tt_int_op(conn->dir_spool_src, OP_EQ, DIR_SPOOL_NONE);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- tor_free(mock_routerinfo);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- crypto_pk_free(identity_pkey);
- routerlist_free_all();
- nodelist_free_all();
- entry_guards_free_all();
- }
- static void
- test_dir_handle_get_server_keys_bad_req(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(BAD_REQUEST, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_server_keys_all_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/all");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- #define TEST_CERTIFICATE AUTHORITY_CERT_3
- #define TEST_SIGNING_KEY AUTHORITY_SIGNKEY_A_DIGEST
- static const char TEST_CERT_IDENT_KEY[] =
- "D867ACF56A9D229B35C25F0090BC9867E906BE69";
- static void
- test_dir_handle_get_server_keys_all(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- const char digest[DIGEST_LEN] = "";
- dir_server_t *ds = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- clear_dir_servers();
- routerlist_free_all();
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- dir_server_add(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/all");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 1883\r\n"));
- tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- clear_dir_servers();
- routerlist_free_all();
- }
- static void
- test_dir_handle_get_server_keys_authority_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/authority");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static authority_cert_t * mock_cert = NULL;
- static authority_cert_t *
- get_my_v3_authority_cert_m(void)
- {
- tor_assert(mock_cert);
- return mock_cert;
- }
- static void
- test_dir_handle_get_server_keys_authority(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- (void) data;
- mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
- MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/authority");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 1883\r\n"));
- tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
- done:
- UNMOCK(get_my_v3_authority_cert);
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- authority_cert_free(mock_cert); mock_cert = NULL;
- }
- static void
- test_dir_handle_get_server_keys_fp_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/fp/somehex");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_server_keys_fp(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- dir_server_t *ds = NULL;
- const char digest[DIGEST_LEN] = "";
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- clear_dir_servers();
- routerlist_free_all();
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- dir_server_add(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- conn = new_dir_conn();
- char req[71];
- tor_snprintf(req, sizeof(req),
- GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 1883\r\n"));
- tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- clear_dir_servers();
- routerlist_free_all();
- }
- static void
- test_dir_handle_get_server_keys_sk_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/sk/somehex");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_server_keys_sk(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- (void) data;
- mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
- MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- clear_dir_servers();
- routerlist_free_all();
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- conn = new_dir_conn();
- char req[71];
- tor_snprintf(req, sizeof(req),
- GET("/tor/keys/sk/%s"), TEST_SIGNING_KEY);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 1883\r\n"));
- tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
- done:
- UNMOCK(get_my_v3_authority_cert);
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- authority_cert_free(mock_cert); mock_cert = NULL;
- tor_free(header);
- tor_free(body);
- }
- static void
- test_dir_handle_get_server_keys_fpsk_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- const char *req = GET("/tor/keys/fp-sk/somehex");
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_server_keys_fpsk(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- dir_server_t *ds = NULL;
- const char digest[DIGEST_LEN] = "";
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- clear_dir_servers();
- routerlist_free_all();
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- dir_server_add(ds);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- conn = new_dir_conn();
- char req[115];
- tor_snprintf(req, sizeof(req),
- GET("/tor/keys/fp-sk/%s-%s"),
- TEST_CERT_IDENT_KEY, TEST_SIGNING_KEY);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(TEST_CERTIFICATE)+1, 0);
- tt_assert(header);
- tt_assert(body);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 1883\r\n"));
- tt_str_op(TEST_CERTIFICATE, OP_EQ, body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- clear_dir_servers();
- routerlist_free_all();
- }
- static void
- test_dir_handle_get_server_keys_busy(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- dir_server_t *ds = NULL;
- const char digest[DIGEST_LEN] = "";
- (void) data;
- clear_dir_servers();
- routerlist_free_all();
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- dir_server_add(ds);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* setup busy server */
- init_mock_options();
- mock_options->CountPrivateBandwidth = 1;
- conn = new_dir_conn();
- char req[71];
- tor_snprintf(req, sizeof(req), GET("/tor/keys/fp/%s"), TEST_CERT_IDENT_KEY);
- tt_int_op(directory_handle_command_get(conn, req, NULL, 0), OP_EQ, 0);
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- done:
- UNMOCK(get_options);
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- or_options_free(mock_options); mock_options = NULL;
- clear_dir_servers();
- routerlist_free_all();
- }
- static networkstatus_t *mock_ns_val = NULL;
- static networkstatus_t *
- mock_ns_get_by_flavor(consensus_flavor_t f)
- {
- (void)f;
- return mock_ns_val;
- }
- static void
- test_dir_handle_get_status_vote_current_consensus_ns_not_enough_sigs(void* d)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *stats = NULL;
- (void) d;
- /* init mock */
- mock_ns_val = tor_malloc_zero(sizeof(networkstatus_t));
- mock_ns_val->flavor = FLAV_NS;
- mock_ns_val->voters = smartlist_new();
- /* init mock */
- init_mock_options();
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- MOCK(networkstatus_get_latest_consensus_by_flavor, mock_ns_get_by_flavor);
- /* start gathering stats */
- mock_options->DirReqStatistics = 1;
- geoip_dirreq_stats_init(time(NULL));
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/consensus-ns/" HEX1 "+" HEX2), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_ENOUGH_CONSENSUS_SIGNATURES, OP_EQ, header);
- stats = geoip_format_dirreq_stats(time(NULL));
- tt_assert(stats);
- tt_assert(strstr(stats, "not-enough-sigs=8"));
- done:
- UNMOCK(networkstatus_get_latest_consensus_by_flavor);
- UNMOCK(connection_write_to_buf_impl_);
- UNMOCK(get_options);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(stats);
- smartlist_free(mock_ns_val->voters);
- tor_free(mock_ns_val);
- or_options_free(mock_options); mock_options = NULL;
- }
- static void
- test_dir_handle_get_status_vote_current_consensus_ns_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- char *stats = NULL;
- (void) data;
- init_mock_options();
- MOCK(get_options, mock_get_options);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- /* start gathering stats */
- mock_options->DirReqStatistics = 1;
- geoip_dirreq_stats_init(time(NULL));
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- stats = geoip_format_dirreq_stats(time(NULL));
- tt_assert(stats);
- tt_assert(strstr(stats, "not-found=8"));
- done:
- UNMOCK(connection_write_to_buf_impl_);
- UNMOCK(get_options);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(stats);
- or_options_free(mock_options); mock_options = NULL;
- }
- NS_DECL(int, geoip_get_country_by_addr, (const tor_addr_t *addr));
- int
- NS(geoip_get_country_by_addr)(const tor_addr_t *addr)
- {
- (void)addr;
- CALLED(geoip_get_country_by_addr)++;
- return 1;
- }
- static void
- status_vote_current_consensus_ns_test(char **header, char **body,
- size_t *body_len)
- {
- common_digests_t digests;
- dir_connection_t *conn = NULL;
- #define NETWORK_STATUS "some network status string"
- dirserv_set_cached_consensus_networkstatus(NETWORK_STATUS, "ns", &digests,
- time(NULL));
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- tt_assert(mock_options);
- mock_options->DirReqStatistics = 1;
- geoip_dirreq_stats_init(time(NULL));
- /* init geoip database */
- geoip_parse_entry("10,50,AB", AF_INET);
- tt_str_op("ab", OP_EQ, geoip_get_country_name(1));
- conn = new_dir_conn();
- TO_CONN(conn)->address = tor_strdup("127.0.0.1");
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/consensus-ns"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
- body, body_len, strlen(NETWORK_STATUS)+7, 0);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- }
- static void
- test_dir_handle_get_status_vote_current_consensus_ns(void* data)
- {
- char *header = NULL;
- char *body = NULL, *comp_body = NULL;
- size_t body_used = 0, comp_body_used = 0;
- char *stats = NULL, *hist = NULL;
- (void) data;
- dirserv_free_all();
- clear_geoip_db();
- NS_MOCK(geoip_get_country_by_addr);
- MOCK(get_options, mock_get_options);
- init_mock_options();
- status_vote_current_consensus_ns_test(&header, &comp_body, &comp_body_used);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Pragma: no-cache\r\n"));
- compress_method_t compression = detect_compression_method(comp_body,
- comp_body_used);
- tt_int_op(ZLIB_METHOD, OP_EQ, compression);
- tor_gzip_uncompress(&body, &body_used, comp_body, comp_body_used,
- compression, 0, LOG_PROTOCOL_WARN);
- tt_str_op(NETWORK_STATUS, OP_EQ, body);
- tt_int_op(strlen(NETWORK_STATUS), OP_EQ, body_used);
- stats = geoip_format_dirreq_stats(time(NULL));
- tt_assert(stats);
- tt_assert(strstr(stats, "ok=8"));
- tt_assert(strstr(stats, "dirreq-v3-ips ab=8"));
- tt_assert(strstr(stats, "dirreq-v3-reqs ab=8"));
- tt_assert(strstr(stats, "dirreq-v3-direct-dl"
- " complete=0,timeout=0,running=4"));
- hist = geoip_get_request_history();
- tt_assert(hist);
- tt_str_op("ab=8", OP_EQ, hist);
- done:
- NS_UNMOCK(geoip_get_country_by_addr);
- UNMOCK(get_options);
- tor_free(header);
- tor_free(comp_body);
- tor_free(body);
- tor_free(stats);
- tor_free(hist);
- or_options_free(mock_options); mock_options = NULL;
- dirserv_free_all();
- clear_geoip_db();
- }
- static void
- test_dir_handle_get_status_vote_current_consensus_ns_busy(void* data)
- {
- char *header = NULL;
- char *body = NULL;
- size_t body_used = 0;
- char *stats = NULL;
- (void) data;
- dirserv_free_all();
- clear_geoip_db();
- MOCK(get_options, mock_get_options);
- // Make it busy
- init_mock_options();
- mock_options->CountPrivateBandwidth = 1;
- status_vote_current_consensus_ns_test(&header, &body, &body_used);
- tt_assert(header);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- stats = geoip_format_dirreq_stats(time(NULL));
- tt_assert(stats);
- tt_assert(strstr(stats, "busy=8"));
- done:
- UNMOCK(get_options);
- tor_free(header);
- tor_free(body);
- or_options_free(mock_options); mock_options = NULL;
- tor_free(stats);
- dirserv_free_all();
- clear_geoip_db();
- }
- static void
- test_dir_handle_get_status_vote_current_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/" HEX1), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- #define VOTE_DIGEST "312A4890D4D832597ABBD3089C782DBBFB81E48D"
- static void
- status_vote_current_d_test(char **header, char **body, size_t *body_l)
- {
- dir_connection_t *conn = NULL;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/d/" VOTE_DIGEST), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
- body, body_l, strlen(VOTE_BODY_V3)+1, 0);
- tt_assert(header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- }
- static void
- status_vote_next_d_test(char **header, char **body, size_t *body_l)
- {
- dir_connection_t *conn = NULL;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/d/" VOTE_DIGEST), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
- body, body_l, strlen(VOTE_BODY_V3)+1, 0);
- tt_assert(header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- }
- static void
- test_dir_handle_get_status_vote_current_d_not_found(void* data)
- {
- char *header = NULL;
- (void) data;
- status_vote_current_d_test(&header, NULL, NULL);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- tor_free(header);
- }
- static void
- test_dir_handle_get_status_vote_next_d_not_found(void* data)
- {
- char *header = NULL;
- (void) data;
- status_vote_next_d_test(&header, NULL, NULL);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- tor_free(header);
- }
- static void
- test_dir_handle_get_status_vote_d(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used = 0;
- dir_server_t *ds = NULL;
- const char digest[DIGEST_LEN] = "";
- (void) data;
- clear_dir_servers();
- dirvote_free_all();
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- dir_server_add(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- init_mock_options();
- mock_options->AuthoritativeDir = 1;
- mock_options->V3AuthoritativeDir = 1;
- mock_options->TestingV3AuthVotingStartOffset = 0;
- mock_options->TestingV3AuthInitialVotingInterval = 1;
- mock_options->TestingV3AuthInitialVoteDelay = 1;
- mock_options->TestingV3AuthInitialDistDelay = 1;
- time_t now = 1441223455 -1;
- dirvote_recalculate_timing(mock_options, now);
- const char *msg_out = NULL;
- int status_out = 0;
- struct pending_vote_t *pv = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
- &status_out);
- tt_assert(pv);
- status_vote_current_d_test(&header, &body, &body_used);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 4135\r\n"));
- tt_str_op(VOTE_BODY_V3, OP_EQ, body);
- tor_free(header);
- tor_free(body);
- status_vote_next_d_test(&header, &body, &body_used);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 4135\r\n"));
- tt_str_op(VOTE_BODY_V3, OP_EQ, body);
- done:
- tor_free(header);
- tor_free(body);
- or_options_free(mock_options); mock_options = NULL;
- clear_dir_servers();
- dirvote_free_all();
- }
- static void
- test_dir_handle_get_status_vote_next_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/" HEX1), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- status_vote_next_consensus_test(char **header, char **body, size_t *body_used)
- {
- dir_connection_t *conn = NULL;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/consensus"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
- body, body_used, 18, 0);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- }
- static void
- test_dir_handle_get_status_vote_next_consensus_not_found(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used;
- (void) data;
- status_vote_next_consensus_test(&header, &body, &body_used);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- tor_free(header);
- tor_free(body);
- }
- static void
- test_dir_handle_get_status_vote_current_authority_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/authority"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- static void
- test_dir_handle_get_status_vote_next_authority_not_found(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL;
- (void) data;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/authority"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- NULL, NULL, 1, 0);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- }
- NS_DECL(const char*,
- dirvote_get_pending_consensus, (consensus_flavor_t flav));
- const char*
- NS(dirvote_get_pending_consensus)(consensus_flavor_t flav)
- {
- (void)flav;
- return "pending consensus";
- }
- static void
- test_dir_handle_get_status_vote_next_consensus(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used = 0;
- (void) data;
- NS_MOCK(dirvote_get_pending_consensus);
- status_vote_next_consensus_test(&header, &body, &body_used);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 17\r\n"));
- tt_str_op("pending consensus", OP_EQ, body);
- done:
- NS_UNMOCK(dirvote_get_pending_consensus);
- tor_free(header);
- tor_free(body);
- }
- static void
- test_dir_handle_get_status_vote_next_consensus_busy(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used = 0;
- (void) data;
- MOCK(get_options, mock_get_options);
- NS_MOCK(dirvote_get_pending_consensus);
- //Make it busy
- init_mock_options();
- mock_options->CountPrivateBandwidth = 1;
- status_vote_next_consensus_test(&header, &body, &body_used);
- tt_assert(header);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- done:
- NS_UNMOCK(dirvote_get_pending_consensus);
- UNMOCK(get_options);
- tor_free(header);
- tor_free(body);
- or_options_free(mock_options); mock_options = NULL;
- }
- static void
- status_vote_next_consensus_signatures_test(char **header, char **body,
- size_t *body_used)
- {
- dir_connection_t *conn = NULL;
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/consensus-signatures"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, header, MAX_HEADERS_SIZE,
- body, body_used, 22, 0);
- done:
- connection_free_(TO_CONN(conn));
- UNMOCK(connection_write_to_buf_impl_);
- }
- static void
- test_dir_handle_get_status_vote_next_consensus_signatures_not_found(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used;
- (void) data;
- status_vote_next_consensus_signatures_test(&header, &body, &body_used);
- tt_assert(header);
- tt_str_op(NOT_FOUND, OP_EQ, header);
- done:
- tor_free(header);
- tor_free(body);
- }
- NS_DECL(const char*,
- dirvote_get_pending_detached_signatures, (void));
- const char*
- NS(dirvote_get_pending_detached_signatures)(void)
- {
- return "pending detached sigs";
- }
- static void
- test_dir_handle_get_status_vote_next_consensus_signatures(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used = 0;
- (void) data;
- NS_MOCK(dirvote_get_pending_detached_signatures);
- status_vote_next_consensus_signatures_test(&header, &body, &body_used);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 21\r\n"));
- tt_str_op("pending detached sigs", OP_EQ, body);
- done:
- NS_UNMOCK(dirvote_get_pending_detached_signatures);
- tor_free(header);
- tor_free(body);
- }
- static void
- test_dir_handle_get_status_vote_next_consensus_signatures_busy(void* data)
- {
- char *header = NULL, *body = NULL;
- size_t body_used;
- (void) data;
- NS_MOCK(dirvote_get_pending_detached_signatures);
- MOCK(get_options, mock_get_options);
- //Make it busy
- init_mock_options();
- mock_options->CountPrivateBandwidth = 1;
- status_vote_next_consensus_signatures_test(&header, &body, &body_used);
- tt_assert(header);
- tt_str_op(SERVER_BUSY, OP_EQ, header);
- done:
- UNMOCK(get_options);
- NS_UNMOCK(dirvote_get_pending_detached_signatures);
- tor_free(header);
- tor_free(body);
- or_options_free(mock_options); mock_options = NULL;
- }
- static void
- test_dir_handle_get_status_vote_next_authority(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL, *body = NULL;
- const char *msg_out = NULL;
- int status_out = 0;
- size_t body_used = 0;
- dir_server_t *ds = NULL;
- const char digest[DIGEST_LEN] = "";
- (void) data;
- clear_dir_servers();
- routerlist_free_all();
- dirvote_free_all();
- mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- dir_server_add(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- init_mock_options();
- mock_options->AuthoritativeDir = 1;
- mock_options->V3AuthoritativeDir = 1;
- mock_options->TestingV3AuthVotingStartOffset = 0;
- mock_options->TestingV3AuthInitialVotingInterval = 1;
- mock_options->TestingV3AuthInitialVoteDelay = 1;
- mock_options->TestingV3AuthInitialDistDelay = 1;
- time_t now = 1441223455 -1;
- dirvote_recalculate_timing(mock_options, now);
- struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
- &status_out);
- tt_assert(vote);
- MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/next/authority"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 4135\r\n"));
- tt_str_op(VOTE_BODY_V3, OP_EQ, body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- UNMOCK(get_my_v3_authority_cert);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- authority_cert_free(mock_cert); mock_cert = NULL;
- or_options_free(mock_options); mock_options = NULL;
- clear_dir_servers();
- routerlist_free_all();
- dirvote_free_all();
- }
- static void
- test_dir_handle_get_status_vote_current_authority(void* data)
- {
- dir_connection_t *conn = NULL;
- char *header = NULL, *body = NULL;
- const char *msg_out = NULL;
- int status_out = 0;
- size_t body_used = 0;
- const char digest[DIGEST_LEN] = "";
- dir_server_t *ds = NULL;
- (void) data;
- clear_dir_servers();
- routerlist_free_all();
- dirvote_free_all();
- mock_cert = authority_cert_parse_from_string(TEST_CERTIFICATE, NULL);
- /* create a trusted ds */
- ds = trusted_dir_server_new("ds", "127.0.0.1", 9059, 9060, NULL, digest,
- NULL, V3_DIRINFO, 1.0);
- tt_assert(ds);
- dir_server_add(ds);
- /* ds v3_identity_digest is the certificate's identity_key */
- base16_decode(ds->v3_identity_digest, DIGEST_LEN,
- TEST_CERT_IDENT_KEY, HEX_DIGEST_LEN);
- tt_int_op(0, OP_EQ, trusted_dirs_load_certs_from_string(TEST_CERTIFICATE,
- TRUSTED_DIRS_CERTS_SRC_DL_BY_ID_DIGEST, 1, NULL));
- init_mock_options();
- mock_options->AuthoritativeDir = 1;
- mock_options->V3AuthoritativeDir = 1;
- mock_options->TestingV3AuthVotingStartOffset = 0;
- mock_options->TestingV3AuthInitialVotingInterval = 1;
- mock_options->TestingV3AuthInitialVoteDelay = 1;
- mock_options->TestingV3AuthInitialDistDelay = 1;
- time_t now = 1441223455;
- dirvote_recalculate_timing(mock_options, now-1);
- struct pending_vote_t *vote = dirvote_add_vote(VOTE_BODY_V3, &msg_out,
- &status_out);
- tt_assert(vote);
- // move the pending vote to previous vote
- dirvote_act(mock_options, now+1);
- MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
- MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock);
- conn = new_dir_conn();
- tt_int_op(0, OP_EQ, directory_handle_command_get(conn,
- GET("/tor/status-vote/current/authority"), NULL, 0));
- fetch_from_buf_http(TO_CONN(conn)->outbuf, &header, MAX_HEADERS_SIZE,
- &body, &body_used, strlen(VOTE_BODY_V3)+1, 0);
- tt_assert(header);
- tt_ptr_op(strstr(header, "HTTP/1.0 200 OK\r\n"), OP_EQ, header);
- tt_assert(strstr(header, "Content-Type: text/plain\r\n"));
- tt_assert(strstr(header, "Content-Encoding: identity\r\n"));
- tt_assert(strstr(header, "Content-Length: 4135\r\n"));
- tt_str_op(VOTE_BODY_V3, OP_EQ, body);
- done:
- UNMOCK(connection_write_to_buf_impl_);
- UNMOCK(get_my_v3_authority_cert);
- connection_free_(TO_CONN(conn));
- tor_free(header);
- tor_free(body);
- authority_cert_free(mock_cert); mock_cert = NULL;
- or_options_free(mock_options); mock_options = NULL;
- clear_dir_servers();
- routerlist_free_all();
- dirvote_free_all();
- }
- #define DIR_HANDLE_CMD(name,flags) \
- { #name, test_dir_handle_get_##name, (flags), NULL, NULL }
- struct testcase_t dir_handle_get_tests[] = {
- DIR_HANDLE_CMD(not_found, 0),
- DIR_HANDLE_CMD(bad_request, 0),
- DIR_HANDLE_CMD(v1_command_not_found, 0),
- DIR_HANDLE_CMD(v1_command, 0),
- DIR_HANDLE_CMD(robots_txt, 0),
- DIR_HANDLE_CMD(rendezvous2_not_found_if_not_encrypted, 0),
- DIR_HANDLE_CMD(rendezvous2_not_found, 0),
- DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_with_invalid_desc_id, 0),
- DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_not_well_formed, 0),
- DIR_HANDLE_CMD(rendezvous2_on_encrypted_conn_success, 0),
- DIR_HANDLE_CMD(micro_d_not_found, 0),
- DIR_HANDLE_CMD(micro_d_server_busy, 0),
- DIR_HANDLE_CMD(micro_d, 0),
- DIR_HANDLE_CMD(networkstatus_bridges_not_found_without_auth, 0),
- DIR_HANDLE_CMD(networkstatus_bridges_not_found_wrong_auth, 0),
- DIR_HANDLE_CMD(networkstatus_bridges, 0),
- DIR_HANDLE_CMD(server_descriptors_not_found, 0),
- DIR_HANDLE_CMD(server_descriptors_busy, TT_FORK),
- DIR_HANDLE_CMD(server_descriptors_all, TT_FORK),
- DIR_HANDLE_CMD(server_descriptors_authority, TT_FORK),
- DIR_HANDLE_CMD(server_descriptors_fp, TT_FORK),
- DIR_HANDLE_CMD(server_descriptors_d, TT_FORK),
- DIR_HANDLE_CMD(server_keys_bad_req, 0),
- DIR_HANDLE_CMD(server_keys_busy, 0),
- DIR_HANDLE_CMD(server_keys_all_not_found, 0),
- DIR_HANDLE_CMD(server_keys_all, 0),
- DIR_HANDLE_CMD(server_keys_authority_not_found, 0),
- DIR_HANDLE_CMD(server_keys_authority, 0),
- DIR_HANDLE_CMD(server_keys_fp_not_found, 0),
- DIR_HANDLE_CMD(server_keys_fp, 0),
- DIR_HANDLE_CMD(server_keys_sk_not_found, 0),
- DIR_HANDLE_CMD(server_keys_sk, 0),
- DIR_HANDLE_CMD(server_keys_fpsk_not_found, 0),
- DIR_HANDLE_CMD(server_keys_fpsk, 0),
- DIR_HANDLE_CMD(status_vote_current_not_found, 0),
- DIR_HANDLE_CMD(status_vote_next_not_found, 0),
- DIR_HANDLE_CMD(status_vote_current_authority_not_found, 0),
- DIR_HANDLE_CMD(status_vote_current_authority, 0),
- DIR_HANDLE_CMD(status_vote_next_authority_not_found, 0),
- DIR_HANDLE_CMD(status_vote_next_authority, 0),
- DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_enough_sigs, 0),
- DIR_HANDLE_CMD(status_vote_current_consensus_ns_not_found, 0),
- DIR_HANDLE_CMD(status_vote_current_consensus_ns_busy, 0),
- DIR_HANDLE_CMD(status_vote_current_consensus_ns, 0),
- DIR_HANDLE_CMD(status_vote_current_d_not_found, 0),
- DIR_HANDLE_CMD(status_vote_next_d_not_found, 0),
- DIR_HANDLE_CMD(status_vote_d, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus_not_found, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus_busy, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus_signatures_not_found, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus_signatures_busy, 0),
- DIR_HANDLE_CMD(status_vote_next_consensus_signatures, 0),
- END_OF_TESTCASES
- };
|