test_options.c 168 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2016, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #define CONFIG_PRIVATE
  6. #include "or.h"
  7. #include "confparse.h"
  8. #include "config.h"
  9. #include "test.h"
  10. #include "geoip.h"
  11. #define ROUTERSET_PRIVATE
  12. #include "routerset.h"
  13. #include "main.h"
  14. #include "log_test_helpers.h"
  15. #include "sandbox.h"
  16. #include "memarea.h"
  17. #include "policies.h"
  18. #define NS_MODULE test_options
  19. typedef struct {
  20. int severity;
  21. uint32_t domain;
  22. char *msg;
  23. } logmsg_t;
  24. static smartlist_t *messages = NULL;
  25. static void
  26. log_cback(int severity, uint32_t domain, const char *msg)
  27. {
  28. logmsg_t *x = tor_malloc(sizeof(*x));
  29. x->severity = severity;
  30. x->domain = domain;
  31. x->msg = tor_strdup(msg);
  32. if (!messages)
  33. messages = smartlist_new();
  34. smartlist_add(messages, x);
  35. }
  36. static void
  37. setup_log_callback(void)
  38. {
  39. log_severity_list_t lst;
  40. memset(&lst, 0, sizeof(lst));
  41. lst.masks[LOG_ERR - LOG_ERR] = ~0;
  42. lst.masks[LOG_WARN - LOG_ERR] = ~0;
  43. lst.masks[LOG_NOTICE - LOG_ERR] = ~0;
  44. add_callback_log(&lst, log_cback);
  45. mark_logs_temp();
  46. }
  47. static char *
  48. dump_logs(void)
  49. {
  50. smartlist_t *msgs;
  51. char *out;
  52. if (! messages)
  53. return tor_strdup("");
  54. msgs = smartlist_new();
  55. SMARTLIST_FOREACH_BEGIN(messages, logmsg_t *, x) {
  56. smartlist_add_asprintf(msgs, "[%s] %s",
  57. log_level_to_string(x->severity), x->msg);
  58. } SMARTLIST_FOREACH_END(x);
  59. out = smartlist_join_strings(msgs, "", 0, NULL);
  60. SMARTLIST_FOREACH(msgs, char *, cp, tor_free(cp));
  61. smartlist_free(msgs);
  62. return out;
  63. }
  64. static void
  65. clear_log_messages(void)
  66. {
  67. if (!messages)
  68. return;
  69. SMARTLIST_FOREACH(messages, logmsg_t *, m,
  70. { tor_free(m->msg); tor_free(m); });
  71. smartlist_free(messages);
  72. messages = NULL;
  73. }
  74. #define setup_options(opt,dflt) \
  75. do { \
  76. opt = options_new(); \
  77. opt->command = CMD_RUN_TOR; \
  78. options_init(opt); \
  79. \
  80. dflt = config_dup(&options_format, opt); \
  81. clear_log_messages(); \
  82. } while (0)
  83. #define VALID_DIR_AUTH "DirAuthority dizum orport=443 v3ident=E8A9C45" \
  84. "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
  85. " 083C 538F 4403 8BBF A077 587D D755\n"
  86. #define VALID_ALT_BRIDGE_AUTH \
  87. "AlternateBridgeAuthority dizum orport=443 v3ident=E8A9C45" \
  88. "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
  89. " 083C 538F 4403 8BBF A077 587D D755\n"
  90. #define VALID_ALT_DIR_AUTH \
  91. "AlternateDirAuthority dizum orport=443 v3ident=E8A9C45" \
  92. "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
  93. " 083C 538F 4403 8BBF A077 587D D755\n"
  94. static void
  95. test_options_validate_impl(const char *configuration,
  96. const char *expect_errmsg,
  97. int expect_log_severity,
  98. const char *expect_log)
  99. {
  100. or_options_t *opt=NULL;
  101. or_options_t *dflt;
  102. config_line_t *cl=NULL;
  103. char *msg=NULL;
  104. int r;
  105. setup_options(opt, dflt);
  106. r = config_get_lines(configuration, &cl, 1);
  107. tt_int_op(r, OP_EQ, 0);
  108. r = config_assign(&options_format, opt, cl, 0, &msg);
  109. tt_int_op(r, OP_EQ, 0);
  110. r = options_validate(NULL, opt, dflt, 0, &msg);
  111. if (expect_errmsg && !msg) {
  112. TT_DIE(("Expected error message <%s> from <%s>, but got none.",
  113. expect_errmsg, configuration));
  114. } else if (expect_errmsg && !strstr(msg, expect_errmsg)) {
  115. TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
  116. expect_errmsg, configuration, msg));
  117. } else if (!expect_errmsg && msg) {
  118. TT_DIE(("Expected no error message from <%s> but got <%s>.",
  119. configuration, msg));
  120. }
  121. tt_int_op((r == 0), OP_EQ, (msg == NULL));
  122. if (expect_log) {
  123. int found = 0;
  124. if (messages) {
  125. SMARTLIST_FOREACH_BEGIN(messages, logmsg_t *, m) {
  126. if (m->severity == expect_log_severity &&
  127. strstr(m->msg, expect_log)) {
  128. found = 1;
  129. break;
  130. }
  131. } SMARTLIST_FOREACH_END(m);
  132. }
  133. if (!found) {
  134. tor_free(msg);
  135. msg = dump_logs();
  136. TT_DIE(("Expected log message [%s] %s from <%s>, but got <%s>.",
  137. log_level_to_string(expect_log_severity), expect_log,
  138. configuration, msg));
  139. }
  140. }
  141. done:
  142. escaped(NULL);
  143. policies_free_all();
  144. config_free_lines(cl);
  145. or_options_free(opt);
  146. or_options_free(dflt);
  147. tor_free(msg);
  148. clear_log_messages();
  149. }
  150. #define WANT_ERR(config, msg) \
  151. test_options_validate_impl((config), (msg), 0, NULL)
  152. #define WANT_LOG(config, severity, msg) \
  153. test_options_validate_impl((config), NULL, (severity), (msg))
  154. #define WANT_ERR_LOG(config, msg, severity, logmsg) \
  155. test_options_validate_impl((config), (msg), (severity), (logmsg))
  156. #define OK(config) \
  157. test_options_validate_impl((config), NULL, 0, NULL)
  158. static void
  159. test_options_validate(void *arg)
  160. {
  161. (void)arg;
  162. setup_log_callback();
  163. sandbox_disable_getaddrinfo_cache();
  164. WANT_ERR("ExtORPort 500000", "Invalid ExtORPort");
  165. WANT_ERR_LOG("ServerTransportOptions trebuchet",
  166. "ServerTransportOptions did not parse",
  167. LOG_WARN, "Too few arguments");
  168. OK("ServerTransportOptions trebuchet sling=snappy");
  169. OK("ServerTransportOptions trebuchet sling=");
  170. WANT_ERR_LOG("ServerTransportOptions trebuchet slingsnappy",
  171. "ServerTransportOptions did not parse",
  172. LOG_WARN, "\"slingsnappy\" is not a k=v");
  173. WANT_ERR("DirPort 8080\nDirCache 0",
  174. "DirPort configured but DirCache disabled.");
  175. WANT_ERR("BridgeRelay 1\nDirCache 0",
  176. "We're a bridge but DirCache is disabled.");
  177. close_temp_logs();
  178. clear_log_messages();
  179. return;
  180. }
  181. #define MEGABYTEIFY(mb) (U64_LITERAL(mb) << 20)
  182. static void
  183. test_have_enough_mem_for_dircache(void *arg)
  184. {
  185. (void)arg;
  186. or_options_t *opt=NULL;
  187. or_options_t *dflt=NULL;
  188. config_line_t *cl=NULL;
  189. char *msg=NULL;;
  190. int r;
  191. const char *configuration = "ORPort 8080\nDirCache 1", *expect_errmsg;
  192. setup_options(opt, dflt);
  193. setup_log_callback();
  194. (void)dflt;
  195. r = config_get_lines(configuration, &cl, 1);
  196. tt_int_op(r, OP_EQ, 0);
  197. r = config_assign(&options_format, opt, cl, 0, &msg);
  198. tt_int_op(r, OP_EQ, 0);
  199. /* 300 MB RAM available, DirCache enabled */
  200. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
  201. tt_int_op(r, OP_EQ, 0);
  202. tt_assert(!msg);
  203. /* 200 MB RAM available, DirCache enabled */
  204. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
  205. tt_int_op(r, OP_EQ, -1);
  206. expect_errmsg = "Being a directory cache (default) with less than ";
  207. if (!strstr(msg, expect_errmsg)) {
  208. TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
  209. expect_errmsg, configuration, msg));
  210. }
  211. tor_free(msg);
  212. config_free_lines(cl); cl = NULL;
  213. configuration = "ORPort 8080\nDirCache 1\nBridgeRelay 1";
  214. r = config_get_lines(configuration, &cl, 1);
  215. tt_int_op(r, OP_EQ, 0);
  216. r = config_assign(&options_format, opt, cl, 0, &msg);
  217. tt_int_op(r, OP_EQ, 0);
  218. /* 300 MB RAM available, DirCache enabled, Bridge */
  219. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
  220. tt_int_op(r, OP_EQ, 0);
  221. tt_assert(!msg);
  222. /* 200 MB RAM available, DirCache enabled, Bridge */
  223. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
  224. tt_int_op(r, OP_EQ, -1);
  225. expect_errmsg = "Running a Bridge with less than ";
  226. if (!strstr(msg, expect_errmsg)) {
  227. TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
  228. expect_errmsg, configuration, msg));
  229. }
  230. tor_free(msg);
  231. config_free_lines(cl); cl = NULL;
  232. configuration = "ORPort 8080\nDirCache 0";
  233. r = config_get_lines(configuration, &cl, 1);
  234. tt_int_op(r, OP_EQ, 0);
  235. r = config_assign(&options_format, opt, cl, 0, &msg);
  236. tt_int_op(r, OP_EQ, 0);
  237. /* 200 MB RAM available, DirCache disabled */
  238. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
  239. tt_int_op(r, OP_EQ, 0);
  240. tt_assert(!msg);
  241. /* 300 MB RAM available, DirCache disabled */
  242. r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
  243. tt_int_op(r, OP_EQ, -1);
  244. expect_errmsg = "DirCache is disabled and we are configured as a ";
  245. if (!strstr(msg, expect_errmsg)) {
  246. TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
  247. expect_errmsg, configuration, msg));
  248. }
  249. tor_free(msg);
  250. clear_log_messages();
  251. done:
  252. if (msg)
  253. tor_free(msg);
  254. or_options_free(dflt);
  255. or_options_free(opt);
  256. config_free_lines(cl);
  257. return;
  258. }
  259. static const char *fixed_get_uname_result = NULL;
  260. static const char *
  261. fixed_get_uname(void)
  262. {
  263. return fixed_get_uname_result;
  264. }
  265. #define TEST_OPTIONS_OLD_VALUES "TestingV3AuthInitialVotingInterval 1800\n" \
  266. "ClientBootstrapConsensusMaxDownloadTries 7\n" \
  267. "ClientBootstrapConsensusAuthorityOnlyMaxDownloadTries 4\n" \
  268. "ClientBootstrapConsensusMaxInProgressTries 3\n" \
  269. "TestingV3AuthInitialVoteDelay 300\n" \
  270. "TestingV3AuthInitialDistDelay 300\n" \
  271. "TestingClientMaxIntervalWithoutRequest 600\n" \
  272. "TestingDirConnectionMaxStall 600\n" \
  273. "TestingConsensusMaxDownloadTries 8\n" \
  274. "TestingDescriptorMaxDownloadTries 8\n" \
  275. "TestingMicrodescMaxDownloadTries 8\n" \
  276. "TestingCertMaxDownloadTries 8\n"
  277. #define TEST_OPTIONS_DEFAULT_VALUES TEST_OPTIONS_OLD_VALUES \
  278. "MaxClientCircuitsPending 1\n" \
  279. "RendPostPeriod 1000\n" \
  280. "KeepAlivePeriod 1\n" \
  281. "ConnLimit 1\n" \
  282. "V3AuthVotingInterval 300\n" \
  283. "V3AuthVoteDelay 20\n" \
  284. "V3AuthDistDelay 20\n" \
  285. "V3AuthNIntervalsValid 3\n" \
  286. "ClientUseIPv4 1\n" \
  287. "VirtualAddrNetworkIPv4 127.192.0.0/10\n" \
  288. "VirtualAddrNetworkIPv6 [FE80::]/10\n" \
  289. "SchedulerHighWaterMark__ 42\n" \
  290. "SchedulerLowWaterMark__ 10\n"
  291. typedef struct {
  292. or_options_t *old_opt;
  293. or_options_t *opt;
  294. or_options_t *def_opt;
  295. } options_test_data_t;
  296. static void free_options_test_data(options_test_data_t *td);
  297. static options_test_data_t *
  298. get_options_test_data(const char *conf)
  299. {
  300. int rv = -1;
  301. char *msg = NULL;
  302. config_line_t *cl=NULL;
  303. options_test_data_t *result = tor_malloc(sizeof(options_test_data_t));
  304. result->opt = options_new();
  305. result->old_opt = options_new();
  306. result->def_opt = options_new();
  307. rv = config_get_lines(conf, &cl, 1);
  308. tt_assert(rv == 0);
  309. rv = config_assign(&options_format, result->opt, cl, 0, &msg);
  310. if (msg) {
  311. /* Display the parse error message by comparing it with an empty string */
  312. tt_str_op(msg, OP_EQ, "");
  313. }
  314. tt_assert(rv == 0);
  315. config_free_lines(cl);
  316. result->opt->LogTimeGranularity = 1;
  317. result->opt->TokenBucketRefillInterval = 1;
  318. rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
  319. tt_assert(rv == 0);
  320. rv = config_assign(&options_format, result->def_opt, cl, 0, &msg);
  321. if (msg) {
  322. /* Display the parse error message by comparing it with an empty string */
  323. tt_str_op(msg, OP_EQ, "");
  324. }
  325. tt_assert(rv == 0);
  326. done:
  327. config_free_lines(cl);
  328. if (rv != 0) {
  329. free_options_test_data(result);
  330. result = NULL;
  331. /* Callers expect a non-NULL result, so just die if we can't provide one.
  332. */
  333. tor_assert(0);
  334. }
  335. return result;
  336. }
  337. static void
  338. free_options_test_data(options_test_data_t *td)
  339. {
  340. if (!td) return;
  341. or_options_free(td->old_opt);
  342. or_options_free(td->opt);
  343. or_options_free(td->def_opt);
  344. tor_free(td);
  345. }
  346. static void
  347. test_options_validate__uname_for_server(void *ignored)
  348. {
  349. (void)ignored;
  350. char *msg;
  351. options_test_data_t *tdata = get_options_test_data(
  352. "ORListenAddress 127.0.0.1:5555");
  353. setup_capture_of_logs(LOG_WARN);
  354. MOCK(get_uname, fixed_get_uname);
  355. fixed_get_uname_result = "Windows 95";
  356. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  357. expect_log_msg("Tor is running as a server, but you"
  358. " are running Windows 95; this probably won't work. See https://www"
  359. ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
  360. tor_free(msg);
  361. fixed_get_uname_result = "Windows 98";
  362. mock_clean_saved_logs();
  363. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  364. expect_log_msg("Tor is running as a server, but you"
  365. " are running Windows 98; this probably won't work. See https://www"
  366. ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
  367. tor_free(msg);
  368. fixed_get_uname_result = "Windows Me";
  369. mock_clean_saved_logs();
  370. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  371. expect_log_msg("Tor is running as a server, but you"
  372. " are running Windows Me; this probably won't work. See https://www"
  373. ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
  374. tor_free(msg);
  375. fixed_get_uname_result = "Windows 2000";
  376. mock_clean_saved_logs();
  377. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  378. expect_log_entry();
  379. tor_free(msg);
  380. done:
  381. UNMOCK(get_uname);
  382. free_options_test_data(tdata);
  383. tor_free(msg);
  384. teardown_capture_of_logs();
  385. }
  386. static void
  387. test_options_validate__outbound_addresses(void *ignored)
  388. {
  389. (void)ignored;
  390. int ret;
  391. char *msg;
  392. options_test_data_t *tdata = get_options_test_data(
  393. "OutboundBindAddress xxyy!!!sdfaf");
  394. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  395. tt_int_op(ret, OP_EQ, -1);
  396. done:
  397. free_options_test_data(tdata);
  398. tor_free(msg);
  399. }
  400. static void
  401. test_options_validate__data_directory(void *ignored)
  402. {
  403. (void)ignored;
  404. int ret;
  405. char *msg;
  406. options_test_data_t *tdata = get_options_test_data(
  407. "DataDirectory longreallyl"
  408. "ongLONGLONGlongreallylong"
  409. "LONGLONGlongreallylongLON"
  410. "GLONGlongreallylongLONGLO"
  411. "NGlongreallylongLONGLONGl"
  412. "ongreallylongLONGLONGlong"
  413. "reallylongLONGLONGlongrea"
  414. "llylongLONGLONGlongreally"
  415. "longLONGLONGlongreallylon"
  416. "gLONGLONGlongreallylongLO"
  417. "NGLONGlongreallylongLONGL"
  418. "ONGlongreallylongLONGLONG"
  419. "longreallylongLONGLONGlon"
  420. "greallylongLONGLONGlongre"
  421. "allylongLONGLONGlongreall"
  422. "ylongLONGLONGlongreallylo"
  423. "ngLONGLONGlongreallylongL"
  424. "ONGLONGlongreallylongLONG"
  425. "LONG"); // 440 characters
  426. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  427. tt_int_op(ret, OP_EQ, -1);
  428. tt_str_op(msg, OP_EQ, "Invalid DataDirectory");
  429. done:
  430. free_options_test_data(tdata);
  431. tor_free(msg);
  432. }
  433. static void
  434. test_options_validate__nickname(void *ignored)
  435. {
  436. (void)ignored;
  437. int ret;
  438. char *msg;
  439. options_test_data_t *tdata = get_options_test_data(
  440. "Nickname ThisNickNameIsABitTooLong");
  441. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  442. tt_int_op(ret, OP_EQ, -1);
  443. tt_str_op(msg, OP_EQ,
  444. "Nickname 'ThisNickNameIsABitTooLong', nicknames must be between "
  445. "1 and 19 characters inclusive, and must contain only the "
  446. "characters [a-zA-Z0-9].");
  447. tor_free(msg);
  448. free_options_test_data(tdata);
  449. tdata = get_options_test_data("Nickname AMoreValidNick");
  450. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  451. tt_int_op(ret, OP_EQ, -1);
  452. tt_assert(!msg);
  453. free_options_test_data(tdata);
  454. tdata = get_options_test_data("DataDirectory /tmp/somewhere");
  455. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  456. tt_int_op(ret, OP_EQ, -1);
  457. tt_assert(!msg);
  458. done:
  459. free_options_test_data(tdata);
  460. tor_free(msg);
  461. }
  462. static void
  463. test_options_validate__contactinfo(void *ignored)
  464. {
  465. (void)ignored;
  466. int ret;
  467. char *msg;
  468. options_test_data_t *tdata = get_options_test_data(
  469. "ORListenAddress 127.0.0.1:5555\nORPort 955");
  470. setup_capture_of_logs(LOG_DEBUG);
  471. tdata->opt->ContactInfo = NULL;
  472. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  473. tt_int_op(ret, OP_EQ, -1);
  474. expect_log_msg(
  475. "Your ContactInfo config option is not"
  476. " set. Please consider setting it, so we can contact you if your"
  477. " server is misconfigured or something else goes wrong.\n");
  478. tor_free(msg);
  479. free_options_test_data(tdata);
  480. tdata = get_options_test_data("ORListenAddress 127.0.0.1:5555\nORPort 955\n"
  481. "ContactInfo hella@example.org");
  482. mock_clean_saved_logs();
  483. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  484. tt_int_op(ret, OP_EQ, -1);
  485. expect_no_log_msg(
  486. "Your ContactInfo config option is not"
  487. " set. Please consider setting it, so we can contact you if your"
  488. " server is misconfigured or something else goes wrong.\n");
  489. tor_free(msg);
  490. done:
  491. teardown_capture_of_logs();
  492. free_options_test_data(tdata);
  493. tor_free(msg);
  494. }
  495. static void
  496. test_options_validate__logs(void *ignored)
  497. {
  498. (void)ignored;
  499. int ret;
  500. (void)ret;
  501. char *msg;
  502. int orig_quiet_level = quiet_level;
  503. options_test_data_t *tdata = get_options_test_data("");
  504. tdata->opt->Logs = NULL;
  505. tdata->opt->RunAsDaemon = 0;
  506. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  507. tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log");
  508. tt_str_op(tdata->opt->Logs->value, OP_EQ, "notice stdout");
  509. tor_free(msg);
  510. free_options_test_data(tdata);
  511. tdata = get_options_test_data("");
  512. tdata->opt->Logs = NULL;
  513. tdata->opt->RunAsDaemon = 0;
  514. quiet_level = 1;
  515. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  516. tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log");
  517. tt_str_op(tdata->opt->Logs->value, OP_EQ, "warn stdout");
  518. tor_free(msg);
  519. free_options_test_data(tdata);
  520. tdata = get_options_test_data("");
  521. tdata->opt->Logs = NULL;
  522. tdata->opt->RunAsDaemon = 0;
  523. quiet_level = 2;
  524. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  525. tt_assert(!tdata->opt->Logs);
  526. tor_free(msg);
  527. free_options_test_data(tdata);
  528. tdata = get_options_test_data("");
  529. tdata->opt->Logs = NULL;
  530. tdata->opt->RunAsDaemon = 0;
  531. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 1, &msg);
  532. tt_assert(!tdata->opt->Logs);
  533. tor_free(msg);
  534. free_options_test_data(tdata);
  535. tdata = get_options_test_data("");
  536. tdata->opt->Logs = NULL;
  537. tdata->opt->RunAsDaemon = 1;
  538. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  539. tt_assert(!tdata->opt->Logs);
  540. tor_free(msg);
  541. free_options_test_data(tdata);
  542. tdata = get_options_test_data("");
  543. tdata->opt->RunAsDaemon = 0;
  544. config_line_t *cl=NULL;
  545. config_get_lines("Log foo", &cl, 1);
  546. tdata->opt->Logs = cl;
  547. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  548. tt_int_op((intptr_t)tdata->opt->Logs, OP_EQ, (intptr_t)cl);
  549. done:
  550. quiet_level = orig_quiet_level;
  551. free_options_test_data(tdata);
  552. tor_free(msg);
  553. }
  554. /* static config_line_t * */
  555. /* mock_config_line(const char *key, const char *val) */
  556. /* { */
  557. /* config_line_t *config_line = tor_malloc(sizeof(config_line_t)); */
  558. /* memset(config_line, 0, sizeof(config_line_t)); */
  559. /* config_line->key = tor_strdup(key); */
  560. /* config_line->value = tor_strdup(val); */
  561. /* return config_line; */
  562. /* } */
  563. static void
  564. test_options_validate__authdir(void *ignored)
  565. {
  566. (void)ignored;
  567. int ret;
  568. char *msg;
  569. setup_capture_of_logs(LOG_INFO);
  570. options_test_data_t *tdata = get_options_test_data(
  571. "AuthoritativeDirectory 1\n"
  572. "Address this.should.not_exist.example.org");
  573. sandbox_disable_getaddrinfo_cache();
  574. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  575. tt_int_op(ret, OP_EQ, -1);
  576. tt_str_op(msg, OP_EQ, "Failed to resolve/guess local address. See logs for"
  577. " details.");
  578. expect_log_msg("Could not resolve local Address "
  579. "'this.should.not_exist.example.org'. Failing.\n");
  580. tor_free(msg);
  581. free_options_test_data(tdata);
  582. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  583. "Address 100.200.10.1");
  584. mock_clean_saved_logs();
  585. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  586. tt_int_op(ret, OP_EQ, -1);
  587. tt_assert(!msg);
  588. free_options_test_data(tdata);
  589. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  590. "Address 100.200.10.1\n"
  591. "SchedulerHighWaterMark__ 42\n"
  592. "SchedulerLowWaterMark__ 10\n");
  593. mock_clean_saved_logs();
  594. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  595. tt_int_op(ret, OP_EQ, -1);
  596. tt_str_op(msg, OP_EQ,
  597. "Authoritative directory servers must set ContactInfo");
  598. tor_free(msg);
  599. free_options_test_data(tdata);
  600. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  601. "Address 100.200.10.1\n"
  602. "TestingTorNetwork 1\n"
  603. "SchedulerHighWaterMark__ 42\n"
  604. "SchedulerLowWaterMark__ 10\n");
  605. mock_clean_saved_logs();
  606. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  607. tt_int_op(ret, OP_EQ, -1);
  608. tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
  609. "AuthoritativeDir is set.");
  610. tor_free(msg);
  611. free_options_test_data(tdata);
  612. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  613. "Address 100.200.10.1\n"
  614. "ContactInfo hello@hello.com\n"
  615. "SchedulerHighWaterMark__ 42\n"
  616. "SchedulerLowWaterMark__ 10\n");
  617. mock_clean_saved_logs();
  618. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  619. tt_int_op(ret, OP_EQ, -1);
  620. tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
  621. "AuthoritativeDir is set.");
  622. tor_free(msg);
  623. free_options_test_data(tdata);
  624. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  625. "Address 100.200.10.1\n"
  626. "RecommendedVersions 1.2, 3.14\n"
  627. "ContactInfo hello@hello.com\n"
  628. "SchedulerHighWaterMark__ 42\n"
  629. "SchedulerLowWaterMark__ 10\n");
  630. mock_clean_saved_logs();
  631. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  632. tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "1.2, 3.14");
  633. tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "1.2, 3.14");
  634. tor_free(msg);
  635. free_options_test_data(tdata);
  636. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  637. "Address 100.200.10.1\n"
  638. "RecommendedVersions 1.2, 3.14\n"
  639. "RecommendedClientVersions 25\n"
  640. "RecommendedServerVersions 4.18\n"
  641. "ContactInfo hello@hello.com\n"
  642. "SchedulerHighWaterMark__ 42\n"
  643. "SchedulerLowWaterMark__ 10\n");
  644. mock_clean_saved_logs();
  645. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  646. tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "25");
  647. tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "4.18");
  648. tor_free(msg);
  649. free_options_test_data(tdata);
  650. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  651. "Address 100.200.10.1\n"
  652. "VersioningAuthoritativeDirectory 1\n"
  653. "RecommendedVersions 1.2, 3.14\n"
  654. "RecommendedClientVersions 25\n"
  655. "RecommendedServerVersions 4.18\n"
  656. "ContactInfo hello@hello.com\n"
  657. "SchedulerHighWaterMark__ 42\n"
  658. "SchedulerLowWaterMark__ 10\n");
  659. mock_clean_saved_logs();
  660. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  661. tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
  662. "AuthoritativeDir is set.");
  663. tor_free(msg);
  664. free_options_test_data(tdata);
  665. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  666. "Address 100.200.10.1\n"
  667. "VersioningAuthoritativeDirectory 1\n"
  668. "RecommendedServerVersions 4.18\n"
  669. "ContactInfo hello@hello.com\n"
  670. "SchedulerHighWaterMark__ 42\n"
  671. "SchedulerLowWaterMark__ 10\n");
  672. mock_clean_saved_logs();
  673. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  674. tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
  675. "Recommended*Versions.");
  676. tor_free(msg);
  677. free_options_test_data(tdata);
  678. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  679. "Address 100.200.10.1\n"
  680. "VersioningAuthoritativeDirectory 1\n"
  681. "RecommendedClientVersions 4.18\n"
  682. "ContactInfo hello@hello.com\n"
  683. "SchedulerHighWaterMark__ 42\n"
  684. "SchedulerLowWaterMark__ 10\n");
  685. mock_clean_saved_logs();
  686. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  687. tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
  688. "Recommended*Versions.");
  689. tor_free(msg);
  690. free_options_test_data(tdata);
  691. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  692. "Address 100.200.10.1\n"
  693. "UseEntryGuards 1\n"
  694. "ContactInfo hello@hello.com\n"
  695. "SchedulerHighWaterMark__ 42\n"
  696. "SchedulerLowWaterMark__ 10\n");
  697. mock_clean_saved_logs();
  698. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  699. expect_log_msg("Authoritative directory servers "
  700. "can't set UseEntryGuards. Disabling.\n");
  701. tt_int_op(tdata->opt->UseEntryGuards, OP_EQ, 0);
  702. tor_free(msg);
  703. free_options_test_data(tdata);
  704. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  705. "Address 100.200.10.1\n"
  706. "V3AuthoritativeDir 1\n"
  707. "ContactInfo hello@hello.com\n"
  708. "SchedulerHighWaterMark__ 42\n"
  709. "SchedulerLowWaterMark__ 10\n");
  710. mock_clean_saved_logs();
  711. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  712. expect_log_msg("Authoritative directories always try"
  713. " to download extra-info documents. Setting DownloadExtraInfo.\n");
  714. tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
  715. tor_free(msg);
  716. free_options_test_data(tdata);
  717. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  718. "Address 100.200.10.1\n"
  719. "DownloadExtraInfo 1\n"
  720. "V3AuthoritativeDir 1\n"
  721. "ContactInfo hello@hello.com\n"
  722. "SchedulerHighWaterMark__ 42\n"
  723. "SchedulerLowWaterMark__ 10\n");
  724. mock_clean_saved_logs();
  725. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  726. expect_no_log_msg("Authoritative directories always try"
  727. " to download extra-info documents. Setting DownloadExtraInfo.\n");
  728. tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
  729. tor_free(msg);
  730. free_options_test_data(tdata);
  731. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  732. "Address 100.200.10.1\n"
  733. "ContactInfo hello@hello.com\n"
  734. "SchedulerHighWaterMark__ 42\n"
  735. "SchedulerLowWaterMark__ 10\n");
  736. mock_clean_saved_logs();
  737. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  738. tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
  739. "AuthoritativeDir is set.");
  740. tor_free(msg);
  741. free_options_test_data(tdata);
  742. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  743. "Address 100.200.10.1\n"
  744. "BridgeAuthoritativeDir 1\n"
  745. "ContactInfo hello@hello.com\n"
  746. "V3BandwidthsFile non-existant-file\n"
  747. "SchedulerHighWaterMark__ 42\n"
  748. "SchedulerLowWaterMark__ 10\n");
  749. mock_clean_saved_logs();
  750. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  751. tt_str_op(msg, OP_EQ,
  752. "Running as authoritative directory, but no DirPort set.");
  753. tor_free(msg);
  754. free_options_test_data(tdata);
  755. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  756. "Address 100.200.10.1\n"
  757. "BridgeAuthoritativeDir 1\n"
  758. "ContactInfo hello@hello.com\n"
  759. "V3BandwidthsFile non-existant-file\n"
  760. "SchedulerHighWaterMark__ 42\n"
  761. "SchedulerLowWaterMark__ 10\n");
  762. mock_clean_saved_logs();
  763. options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
  764. tt_str_op(msg, OP_EQ,
  765. "Running as authoritative directory, but no DirPort set.");
  766. tor_free(msg);
  767. free_options_test_data(tdata);
  768. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  769. "Address 100.200.10.1\n"
  770. "BridgeAuthoritativeDir 1\n"
  771. "ContactInfo hello@hello.com\n"
  772. "GuardfractionFile non-existant-file\n"
  773. "SchedulerHighWaterMark__ 42\n"
  774. "SchedulerLowWaterMark__ 10\n");
  775. mock_clean_saved_logs();
  776. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  777. tt_str_op(msg, OP_EQ,
  778. "Running as authoritative directory, but no DirPort set.");
  779. tor_free(msg);
  780. free_options_test_data(tdata);
  781. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  782. "Address 100.200.10.1\n"
  783. "BridgeAuthoritativeDir 1\n"
  784. "ContactInfo hello@hello.com\n"
  785. "GuardfractionFile non-existant-file\n"
  786. "SchedulerHighWaterMark__ 42\n"
  787. "SchedulerLowWaterMark__ 10\n");
  788. mock_clean_saved_logs();
  789. options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
  790. tt_str_op(msg, OP_EQ,
  791. "Running as authoritative directory, but no DirPort set.");
  792. tor_free(msg);
  793. free_options_test_data(tdata);
  794. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  795. "Address 100.200.10.1\n"
  796. "BridgeAuthoritativeDir 1\n"
  797. "ContactInfo hello@hello.com\n"
  798. "SchedulerHighWaterMark__ 42\n"
  799. "SchedulerLowWaterMark__ 10\n");
  800. mock_clean_saved_logs();
  801. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  802. tt_int_op(ret, OP_EQ, -1);
  803. tt_str_op(msg, OP_EQ,
  804. "Running as authoritative directory, but no DirPort set.");
  805. tor_free(msg);
  806. free_options_test_data(tdata);
  807. tdata = get_options_test_data("AuthoritativeDirectory 1\n"
  808. "Address 100.200.10.1\n"
  809. "DirPort 999\n"
  810. "BridgeAuthoritativeDir 1\n"
  811. "ContactInfo hello@hello.com\n"
  812. "SchedulerHighWaterMark__ 42\n"
  813. "SchedulerLowWaterMark__ 10\n");
  814. mock_clean_saved_logs();
  815. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  816. tt_int_op(ret, OP_EQ, -1);
  817. tt_str_op(msg, OP_EQ,
  818. "Running as authoritative directory, but no ORPort set.");
  819. tor_free(msg);
  820. // TODO: This case can't be reached, since clientonly is used to
  821. // check when parsing port lines as well.
  822. /* free_options_test_data(tdata); */
  823. /* tdata = get_options_test_data("AuthoritativeDirectory 1\n" */
  824. /* "Address 100.200.10.1\n" */
  825. /* "DirPort 999\n" */
  826. /* "ORPort 888\n" */
  827. /* "ClientOnly 1\n" */
  828. /* "BridgeAuthoritativeDir 1\n" */
  829. /* "ContactInfo hello@hello.com\n" */
  830. /* "SchedulerHighWaterMark__ 42\n" */
  831. /* "SchedulerLowWaterMark__ 10\n"); */
  832. /* mock_clean_saved_logs(); */
  833. /* ret = options_validate(tdata->old_opt, tdata->opt, */
  834. /* tdata->def_opt, 0, &msg); */
  835. /* tt_int_op(ret, OP_EQ, -1); */
  836. /* tt_str_op(msg, OP_EQ, "Running as authoritative directory, " */
  837. /* "but ClientOnly also set."); */
  838. done:
  839. teardown_capture_of_logs();
  840. // sandbox_free_getaddrinfo_cache();
  841. free_options_test_data(tdata);
  842. tor_free(msg);
  843. }
  844. static void
  845. test_options_validate__relay_with_hidden_services(void *ignored)
  846. {
  847. (void)ignored;
  848. char *msg;
  849. setup_capture_of_logs(LOG_DEBUG);
  850. options_test_data_t *tdata = get_options_test_data(
  851. "ORListenAddress 127.0.0.1:5555\n"
  852. "ORPort 955\n"
  853. "HiddenServiceDir "
  854. "/Library/Tor/var/lib/tor/hidden_service/\n"
  855. "HiddenServicePort 80 127.0.0.1:8080\n"
  856. );
  857. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  858. expect_log_msg(
  859. "Tor is currently configured as a relay and a hidden service. "
  860. "That's not very secure: you should probably run your hidden servi"
  861. "ce in a separate Tor process, at least -- see "
  862. "https://trac.torproject.org/8742\n");
  863. done:
  864. teardown_capture_of_logs();
  865. free_options_test_data(tdata);
  866. tor_free(msg);
  867. }
  868. // TODO: it doesn't seem possible to hit the case of having no port lines at
  869. // all, since there will be a default created for SocksPort
  870. /* static void */
  871. /* test_options_validate__ports(void *ignored) */
  872. /* { */
  873. /* (void)ignored; */
  874. /* int ret; */
  875. /* char *msg; */
  876. /* setup_capture_of_logs(LOG_WARN); */
  877. /* options_test_data_t *tdata = get_options_test_data(""); */
  878. /* ret = options_validate(tdata->old_opt, tdata->opt, */
  879. /* tdata->def_opt, 0, &msg); */
  880. /* expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort " */
  881. /* "are all undefined, and there aren't any hidden services " */
  882. /* "configured. " */
  883. /* " Tor will still run, but probably won't do anything.\n"); */
  884. /* done: */
  885. /* teardown_capture_of_logs(); */
  886. /* free_options_test_data(tdata); */
  887. /* tor_free(msg); */
  888. /* } */
  889. static void
  890. test_options_validate__transproxy(void *ignored)
  891. {
  892. (void)ignored;
  893. int ret;
  894. char *msg;
  895. options_test_data_t *tdata;
  896. #ifdef USE_TRANSPARENT
  897. // Test default trans proxy
  898. tdata = get_options_test_data("TransProxyType default\n");
  899. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  900. tt_int_op(ret, OP_EQ, -1);
  901. tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_DEFAULT);
  902. tor_free(msg);
  903. // Test pf-divert trans proxy
  904. free_options_test_data(tdata);
  905. tdata = get_options_test_data("TransProxyType pf-divert\n");
  906. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  907. tt_int_op(ret, OP_EQ, -1);
  908. #if !defined(__OpenBSD__) && !defined( DARWIN )
  909. tt_str_op(msg, OP_EQ,
  910. "pf-divert is a OpenBSD-specific and OS X/Darwin-specific feature.");
  911. #else
  912. tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_PF_DIVERT);
  913. tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without "
  914. "any valid TransPort or TransListenAddress.");
  915. #endif
  916. tor_free(msg);
  917. // Test tproxy trans proxy
  918. free_options_test_data(tdata);
  919. tdata = get_options_test_data("TransProxyType tproxy\n");
  920. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  921. tt_int_op(ret, OP_EQ, -1);
  922. #if !defined(__linux__)
  923. tt_str_op(msg, OP_EQ, "TPROXY is a Linux-specific feature.");
  924. #else
  925. tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_TPROXY);
  926. tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without any valid "
  927. "TransPort or TransListenAddress.");
  928. #endif
  929. tor_free(msg);
  930. // Test ipfw trans proxy
  931. free_options_test_data(tdata);
  932. tdata = get_options_test_data("TransProxyType ipfw\n");
  933. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  934. tt_int_op(ret, OP_EQ, -1);
  935. #ifndef KERNEL_MAY_SUPPORT_IPFW
  936. tt_str_op(msg, OP_EQ, "ipfw is a FreeBSD-specificand OS X/Darwin-specific "
  937. "feature.");
  938. #else
  939. tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_IPFW);
  940. tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without any valid "
  941. "TransPort or TransListenAddress.");
  942. #endif
  943. tor_free(msg);
  944. // Test unknown trans proxy
  945. free_options_test_data(tdata);
  946. tdata = get_options_test_data("TransProxyType non-existant\n");
  947. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  948. tt_int_op(ret, OP_EQ, -1);
  949. tt_str_op(msg, OP_EQ, "Unrecognized value for TransProxyType");
  950. tor_free(msg);
  951. // Test trans proxy success
  952. free_options_test_data(tdata);
  953. tdata = NULL;
  954. #if defined(linux)
  955. tdata = get_options_test_data("TransProxyType tproxy\n"
  956. "TransPort 127.0.0.1:123\n");
  957. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  958. tt_int_op(ret, OP_EQ, -1);
  959. tt_assert(!msg);
  960. #endif
  961. #if defined(__FreeBSD_kernel__) || defined( DARWIN )
  962. tdata = get_options_test_data("TransProxyType ipfw\n"
  963. "TransPort 127.0.0.1:123\n");
  964. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  965. tt_int_op(ret, OP_EQ, -1);
  966. tt_assert(!msg);
  967. #endif
  968. #if defined(__OpenBSD__)
  969. tdata = get_options_test_data("TransProxyType pf-divert\n"
  970. "TransPort 127.0.0.1:123\n");
  971. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  972. tt_int_op(ret, OP_EQ, -1);
  973. tt_assert(!msg);
  974. #endif
  975. // Assert that a test has run for some TransProxyType
  976. tt_assert(tdata);
  977. #else
  978. tdata = get_options_test_data("TransPort 127.0.0.1:555\n");
  979. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  980. tt_int_op(ret, OP_EQ, -1);
  981. tt_str_op(msg, OP_EQ, "TransPort and TransListenAddress are disabled in "
  982. "this build.");
  983. tor_free(msg);
  984. #endif
  985. done:
  986. free_options_test_data(tdata);
  987. tor_free(msg);
  988. }
  989. NS_DECL(country_t, geoip_get_country, (const char *country));
  990. static country_t
  991. NS(geoip_get_country)(const char *countrycode)
  992. {
  993. (void)countrycode;
  994. CALLED(geoip_get_country)++;
  995. return 1;
  996. }
  997. static void
  998. test_options_validate__exclude_nodes(void *ignored)
  999. {
  1000. (void)ignored;
  1001. NS_MOCK(geoip_get_country);
  1002. int ret;
  1003. char *msg;
  1004. setup_capture_of_logs(LOG_WARN);
  1005. options_test_data_t *tdata = get_options_test_data(
  1006. "ExcludeExitNodes {us}\n");
  1007. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1008. tt_int_op(ret, OP_EQ, -1);
  1009. tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
  1010. tt_str_op((char *)
  1011. (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
  1012. OP_EQ, "{us}");
  1013. tor_free(msg);
  1014. free_options_test_data(tdata);
  1015. tdata = get_options_test_data("ExcludeNodes {cn}\n");
  1016. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1017. tt_int_op(ret, OP_EQ, -1);
  1018. tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
  1019. tt_str_op((char *)
  1020. (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
  1021. OP_EQ, "{cn}");
  1022. tor_free(msg);
  1023. free_options_test_data(tdata);
  1024. tdata = get_options_test_data("ExcludeNodes {cn}\n"
  1025. "ExcludeExitNodes {us} {cn}\n");
  1026. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1027. tt_int_op(ret, OP_EQ, -1);
  1028. tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 2);
  1029. tt_str_op((char *)
  1030. (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
  1031. OP_EQ, "{us} {cn}");
  1032. tt_str_op((char *)
  1033. (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 1)),
  1034. OP_EQ, "{cn}");
  1035. tor_free(msg);
  1036. free_options_test_data(tdata);
  1037. tdata = get_options_test_data("ExcludeNodes {cn}\n"
  1038. "StrictNodes 1\n"
  1039. "SchedulerHighWaterMark__ 42\n"
  1040. "SchedulerLowWaterMark__ 10\n");
  1041. mock_clean_saved_logs();
  1042. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1043. tt_int_op(ret, OP_EQ, -1);
  1044. expect_log_msg(
  1045. "You have asked to exclude certain relays from all positions "
  1046. "in your circuits. Expect hidden services and other Tor "
  1047. "features to be broken in unpredictable ways.\n");
  1048. tor_free(msg);
  1049. free_options_test_data(tdata);
  1050. tdata = get_options_test_data("ExcludeNodes {cn}\n"
  1051. "SchedulerHighWaterMark__ 42\n"
  1052. "SchedulerLowWaterMark__ 10\n");
  1053. mock_clean_saved_logs();
  1054. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1055. tt_int_op(ret, OP_EQ, -1);
  1056. expect_no_log_msg(
  1057. "You have asked to exclude certain relays from all positions "
  1058. "in your circuits. Expect hidden services and other Tor "
  1059. "features to be broken in unpredictable ways.\n");
  1060. tor_free(msg);
  1061. done:
  1062. NS_UNMOCK(geoip_get_country);
  1063. teardown_capture_of_logs();
  1064. free_options_test_data(tdata);
  1065. tor_free(msg);
  1066. }
  1067. static void
  1068. test_options_validate__scheduler(void *ignored)
  1069. {
  1070. (void)ignored;
  1071. int ret;
  1072. char *msg;
  1073. setup_capture_of_logs(LOG_DEBUG);
  1074. options_test_data_t *tdata = get_options_test_data(
  1075. "SchedulerLowWaterMark__ 0\n");
  1076. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1077. tt_int_op(ret, OP_EQ, -1);
  1078. expect_log_msg("Bad SchedulerLowWaterMark__ option\n");
  1079. tor_free(msg);
  1080. // TODO: this test cannot run on platforms where UINT32_MAX == UINT64_MAX.
  1081. // I suspect it's unlikely this branch can actually happen
  1082. /* free_options_test_data(tdata); */
  1083. /* tdata = get_options_test_data( */
  1084. /* "SchedulerLowWaterMark 10000000000000000000\n"); */
  1085. /* tdata->opt->SchedulerLowWaterMark__ = (uint64_t)UINT32_MAX; */
  1086. /* tdata->opt->SchedulerLowWaterMark__++; */
  1087. /* mock_clean_saved_logs(); */
  1088. /* ret = options_validate(tdata->old_opt, tdata->opt, */
  1089. /* tdata->def_opt, 0, &msg); */
  1090. /* tt_int_op(ret, OP_EQ, -1); */
  1091. /* expect_log_msg("Bad SchedulerLowWaterMark__ option\n"); */
  1092. free_options_test_data(tdata);
  1093. tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n"
  1094. "SchedulerHighWaterMark__ 42\n");
  1095. mock_clean_saved_logs();
  1096. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1097. tt_int_op(ret, OP_EQ, -1);
  1098. expect_log_msg("Bad SchedulerHighWaterMark option\n");
  1099. tor_free(msg);
  1100. done:
  1101. teardown_capture_of_logs();
  1102. free_options_test_data(tdata);
  1103. tor_free(msg);
  1104. }
  1105. static void
  1106. test_options_validate__node_families(void *ignored)
  1107. {
  1108. (void)ignored;
  1109. int ret;
  1110. char *msg;
  1111. options_test_data_t *tdata = get_options_test_data(
  1112. "NodeFamily flux, flax\n"
  1113. "NodeFamily somewhere\n"
  1114. "SchedulerHighWaterMark__ 42\n"
  1115. "SchedulerLowWaterMark__ 10\n");
  1116. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1117. tt_int_op(ret, OP_EQ, -1);
  1118. tt_assert(tdata->opt->NodeFamilySets);
  1119. tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 2);
  1120. tt_str_op((char *)(smartlist_get(
  1121. ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 0)),
  1122. OP_EQ, "flux");
  1123. tt_str_op((char *)(smartlist_get(
  1124. ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 1)),
  1125. OP_EQ, "flax");
  1126. tt_str_op((char *)(smartlist_get(
  1127. ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 1))->list, 0)),
  1128. OP_EQ, "somewhere");
  1129. tor_free(msg);
  1130. free_options_test_data(tdata);
  1131. tdata = get_options_test_data("SchedulerHighWaterMark__ 42\n"
  1132. "SchedulerLowWaterMark__ 10\n");
  1133. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1134. tt_int_op(ret, OP_EQ, -1);
  1135. tt_assert(!tdata->opt->NodeFamilySets);
  1136. tor_free(msg);
  1137. free_options_test_data(tdata);
  1138. tdata = get_options_test_data("NodeFamily !flux\n"
  1139. "SchedulerHighWaterMark__ 42\n"
  1140. "SchedulerLowWaterMark__ 10\n");
  1141. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1142. tt_int_op(ret, OP_EQ, -1);
  1143. tt_assert(tdata->opt->NodeFamilySets);
  1144. tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 0);
  1145. tor_free(msg);
  1146. done:
  1147. free_options_test_data(tdata);
  1148. tor_free(msg);
  1149. }
  1150. static void
  1151. test_options_validate__tlsec(void *ignored)
  1152. {
  1153. (void)ignored;
  1154. int ret;
  1155. char *msg;
  1156. setup_capture_of_logs(LOG_DEBUG);
  1157. options_test_data_t *tdata = get_options_test_data(
  1158. "TLSECGroup ed25519\n"
  1159. "SchedulerHighWaterMark__ 42\n"
  1160. "SchedulerLowWaterMark__ 10\n");
  1161. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1162. tt_int_op(ret, OP_EQ, -1);
  1163. expect_log_msg("Unrecognized TLSECGroup: Falling back to the default.\n");
  1164. tt_assert(!tdata->opt->TLSECGroup);
  1165. tor_free(msg);
  1166. free_options_test_data(tdata);
  1167. tdata = get_options_test_data("TLSECGroup P224\n"
  1168. "SchedulerHighWaterMark__ 42\n"
  1169. "SchedulerLowWaterMark__ 10\n");
  1170. mock_clean_saved_logs();
  1171. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1172. tt_int_op(ret, OP_EQ, -1);
  1173. expect_no_log_msg(
  1174. "Unrecognized TLSECGroup: Falling back to the default.\n");
  1175. tt_assert(tdata->opt->TLSECGroup);
  1176. tor_free(msg);
  1177. free_options_test_data(tdata);
  1178. tdata = get_options_test_data("TLSECGroup P256\n"
  1179. "SchedulerHighWaterMark__ 42\n"
  1180. "SchedulerLowWaterMark__ 10\n");
  1181. mock_clean_saved_logs();
  1182. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1183. tt_int_op(ret, OP_EQ, -1);
  1184. expect_no_log_msg(
  1185. "Unrecognized TLSECGroup: Falling back to the default.\n");
  1186. tt_assert(tdata->opt->TLSECGroup);
  1187. tor_free(msg);
  1188. done:
  1189. teardown_capture_of_logs();
  1190. free_options_test_data(tdata);
  1191. tor_free(msg);
  1192. }
  1193. static void
  1194. test_options_validate__token_bucket(void *ignored)
  1195. {
  1196. (void)ignored;
  1197. int ret;
  1198. char *msg;
  1199. options_test_data_t *tdata = get_options_test_data("");
  1200. tdata->opt->TokenBucketRefillInterval = 0;
  1201. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1202. tt_int_op(ret, OP_EQ, -1);
  1203. tt_str_op(msg, OP_EQ,
  1204. "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
  1205. tor_free(msg);
  1206. tdata->opt->TokenBucketRefillInterval = 1001;
  1207. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1208. tt_int_op(ret, OP_EQ, -1);
  1209. tt_str_op(msg, OP_EQ,
  1210. "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
  1211. tor_free(msg);
  1212. done:
  1213. free_options_test_data(tdata);
  1214. tor_free(msg);
  1215. }
  1216. static void
  1217. test_options_validate__recommended_packages(void *ignored)
  1218. {
  1219. (void)ignored;
  1220. int ret;
  1221. char *msg;
  1222. setup_capture_of_logs(LOG_WARN);
  1223. options_test_data_t *tdata = get_options_test_data(
  1224. "RecommendedPackages foo 1.2 http://foo.com sha1=123123123123\n"
  1225. "RecommendedPackages invalid-package-line\n"
  1226. "SchedulerHighWaterMark__ 42\n"
  1227. "SchedulerLowWaterMark__ 10\n");
  1228. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1229. tt_int_op(ret, OP_EQ, -1);
  1230. expect_no_log_msg("Invalid RecommendedPackage line "
  1231. "invalid-package-line will be ignored\n");
  1232. done:
  1233. escaped(NULL); // This will free the leaking memory from the previous escaped
  1234. teardown_capture_of_logs();
  1235. free_options_test_data(tdata);
  1236. tor_free(msg);
  1237. }
  1238. static void
  1239. test_options_validate__fetch_dir(void *ignored)
  1240. {
  1241. (void)ignored;
  1242. int ret;
  1243. char *msg;
  1244. options_test_data_t *tdata = get_options_test_data(
  1245. "FetchDirInfoExtraEarly 1\n"
  1246. "FetchDirInfoEarly 0\n"
  1247. "SchedulerHighWaterMark__ 42\n"
  1248. "SchedulerLowWaterMark__ 10\n");
  1249. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1250. tt_int_op(ret, OP_EQ, -1);
  1251. tt_str_op(msg, OP_EQ, "FetchDirInfoExtraEarly requires that you"
  1252. " also set FetchDirInfoEarly");
  1253. tor_free(msg);
  1254. free_options_test_data(tdata);
  1255. tdata = get_options_test_data("FetchDirInfoExtraEarly 1\n"
  1256. "FetchDirInfoEarly 1\n"
  1257. "SchedulerHighWaterMark__ 42\n"
  1258. "SchedulerLowWaterMark__ 10\n");
  1259. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1260. tt_int_op(ret, OP_EQ, -1);
  1261. tt_str_op(msg, OP_NE, "FetchDirInfoExtraEarly requires that you"
  1262. " also set FetchDirInfoEarly");
  1263. tor_free(msg);
  1264. done:
  1265. free_options_test_data(tdata);
  1266. tor_free(msg);
  1267. }
  1268. static void
  1269. test_options_validate__conn_limit(void *ignored)
  1270. {
  1271. (void)ignored;
  1272. int ret;
  1273. char *msg;
  1274. options_test_data_t *tdata = get_options_test_data(
  1275. "ConnLimit 0\n"
  1276. "SchedulerHighWaterMark__ 42\n"
  1277. "SchedulerLowWaterMark__ 10\n");
  1278. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1279. tt_int_op(ret, OP_EQ, -1);
  1280. tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
  1281. tor_free(msg);
  1282. free_options_test_data(tdata);
  1283. tdata = get_options_test_data("ConnLimit 1\n"
  1284. "SchedulerHighWaterMark__ 42\n"
  1285. "SchedulerLowWaterMark__ 10\n");
  1286. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1287. tt_int_op(ret, OP_EQ, -1);
  1288. tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024, "
  1289. "but was set to 0");
  1290. tor_free(msg);
  1291. done:
  1292. free_options_test_data(tdata);
  1293. tor_free(msg);
  1294. }
  1295. static void
  1296. test_options_validate__paths_needed(void *ignored)
  1297. {
  1298. (void)ignored;
  1299. int ret;
  1300. char *msg;
  1301. setup_capture_of_logs(LOG_WARN);
  1302. options_test_data_t *tdata = get_options_test_data(
  1303. "PathsNeededToBuildCircuits 0.1\n"
  1304. "ConnLimit 1\n"
  1305. "SchedulerHighWaterMark__ 42\n"
  1306. "SchedulerLowWaterMark__ 10\n");
  1307. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1308. tt_int_op(ret, OP_EQ, -1);
  1309. tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.24 &&
  1310. tdata->opt->PathsNeededToBuildCircuits < 0.26);
  1311. expect_log_msg("PathsNeededToBuildCircuits is too low. "
  1312. "Increasing to 0.25\n");
  1313. tor_free(msg);
  1314. free_options_test_data(tdata);
  1315. mock_clean_saved_logs();
  1316. tdata = get_options_test_data("PathsNeededToBuildCircuits 0.99\n"
  1317. "ConnLimit 1\n"
  1318. "SchedulerHighWaterMark__ 42\n"
  1319. "SchedulerLowWaterMark__ 10\n");
  1320. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1321. tt_int_op(ret, OP_EQ, -1);
  1322. tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.94 &&
  1323. tdata->opt->PathsNeededToBuildCircuits < 0.96);
  1324. expect_log_msg("PathsNeededToBuildCircuits is "
  1325. "too high. Decreasing to 0.95\n");
  1326. tor_free(msg);
  1327. free_options_test_data(tdata);
  1328. mock_clean_saved_logs();
  1329. tdata = get_options_test_data("PathsNeededToBuildCircuits 0.91\n"
  1330. "ConnLimit 1\n"
  1331. "SchedulerHighWaterMark__ 42\n"
  1332. "SchedulerLowWaterMark__ 10\n");
  1333. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1334. tt_int_op(ret, OP_EQ, -1);
  1335. tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 &&
  1336. tdata->opt->PathsNeededToBuildCircuits < 0.92);
  1337. expect_no_log_entry();
  1338. tor_free(msg);
  1339. done:
  1340. teardown_capture_of_logs();
  1341. free_options_test_data(tdata);
  1342. tor_free(msg);
  1343. }
  1344. static void
  1345. test_options_validate__max_client_circuits(void *ignored)
  1346. {
  1347. (void)ignored;
  1348. int ret;
  1349. char *msg;
  1350. options_test_data_t *tdata = get_options_test_data(
  1351. "MaxClientCircuitsPending 0\n"
  1352. "ConnLimit 1\n"
  1353. "SchedulerHighWaterMark__ 42\n"
  1354. "SchedulerLowWaterMark__ 10\n");
  1355. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1356. tt_int_op(ret, OP_EQ, -1);
  1357. tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
  1358. " but was set to 0");
  1359. tor_free(msg);
  1360. free_options_test_data(tdata);
  1361. tdata = get_options_test_data("MaxClientCircuitsPending 1025\n"
  1362. "ConnLimit 1\n"
  1363. "SchedulerHighWaterMark__ 42\n"
  1364. "SchedulerLowWaterMark__ 10\n");
  1365. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1366. tt_int_op(ret, OP_EQ, -1);
  1367. tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
  1368. " but was set to 1025");
  1369. tor_free(msg);
  1370. free_options_test_data(tdata);
  1371. tdata = get_options_test_data("MaxClientCircuitsPending 1\n"
  1372. "ConnLimit 1\n"
  1373. "SchedulerHighWaterMark__ 42\n"
  1374. "SchedulerLowWaterMark__ 10\n");
  1375. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1376. tt_int_op(ret, OP_EQ, -1);
  1377. tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
  1378. tor_free(msg);
  1379. done:
  1380. free_options_test_data(tdata);
  1381. tor_free(msg);
  1382. }
  1383. static void
  1384. test_options_validate__ports(void *ignored)
  1385. {
  1386. (void)ignored;
  1387. int ret;
  1388. char *msg;
  1389. options_test_data_t *tdata = get_options_test_data(
  1390. "FirewallPorts 65537\n"
  1391. "MaxClientCircuitsPending 1\n"
  1392. "ConnLimit 1\n"
  1393. "SchedulerHighWaterMark__ 42\n"
  1394. "SchedulerLowWaterMark__ 10\n");
  1395. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1396. tt_int_op(ret, OP_EQ, -1);
  1397. tt_str_op(msg, OP_EQ, "Port '65537' out of range in FirewallPorts");
  1398. tor_free(msg);
  1399. free_options_test_data(tdata);
  1400. tdata = get_options_test_data("FirewallPorts 1\n"
  1401. "LongLivedPorts 124444\n"
  1402. "MaxClientCircuitsPending 1\n"
  1403. "ConnLimit 1\n"
  1404. "SchedulerHighWaterMark__ 42\n"
  1405. "SchedulerLowWaterMark__ 10\n");
  1406. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1407. tt_int_op(ret, OP_EQ, -1);
  1408. tt_str_op(msg, OP_EQ, "Port '124444' out of range in LongLivedPorts");
  1409. tor_free(msg);
  1410. free_options_test_data(tdata);
  1411. tdata = get_options_test_data("FirewallPorts 1\n"
  1412. "LongLivedPorts 2\n"
  1413. "RejectPlaintextPorts 112233\n"
  1414. "MaxClientCircuitsPending 1\n"
  1415. "ConnLimit 1\n"
  1416. "SchedulerHighWaterMark__ 42\n"
  1417. "SchedulerLowWaterMark__ 10\n");
  1418. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1419. tt_int_op(ret, OP_EQ, -1);
  1420. tt_str_op(msg, OP_EQ, "Port '112233' out of range in RejectPlaintextPorts");
  1421. tor_free(msg);
  1422. free_options_test_data(tdata);
  1423. tdata = get_options_test_data("FirewallPorts 1\n"
  1424. "LongLivedPorts 2\n"
  1425. "RejectPlaintextPorts 3\n"
  1426. "WarnPlaintextPorts 65536\n"
  1427. "MaxClientCircuitsPending 1\n"
  1428. "ConnLimit 1\n"
  1429. "SchedulerHighWaterMark__ 42\n"
  1430. "SchedulerLowWaterMark__ 10\n");
  1431. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1432. tt_int_op(ret, OP_EQ, -1);
  1433. tt_str_op(msg, OP_EQ, "Port '65536' out of range in WarnPlaintextPorts");
  1434. tor_free(msg);
  1435. free_options_test_data(tdata);
  1436. tdata = get_options_test_data("FirewallPorts 1\n"
  1437. "LongLivedPorts 2\n"
  1438. "RejectPlaintextPorts 3\n"
  1439. "WarnPlaintextPorts 4\n"
  1440. "MaxClientCircuitsPending 1\n"
  1441. "ConnLimit 1\n"
  1442. "SchedulerHighWaterMark__ 42\n"
  1443. "SchedulerLowWaterMark__ 10\n");
  1444. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1445. tt_int_op(ret, OP_EQ, -1);
  1446. tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
  1447. tor_free(msg);
  1448. done:
  1449. free_options_test_data(tdata);
  1450. tor_free(msg);
  1451. }
  1452. static void
  1453. test_options_validate__reachable_addresses(void *ignored)
  1454. {
  1455. (void)ignored;
  1456. int ret;
  1457. char *msg;
  1458. setup_capture_of_logs(LOG_NOTICE);
  1459. options_test_data_t *tdata = get_options_test_data(
  1460. "FascistFirewall 1\n"
  1461. "MaxClientCircuitsPending 1\n"
  1462. "ConnLimit 1\n"
  1463. "SchedulerHighWaterMark__ 42\n"
  1464. "SchedulerLowWaterMark__ 10\n");
  1465. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1466. tt_int_op(ret, OP_EQ, -1);
  1467. expect_log_msg("Converting FascistFirewall config "
  1468. "option to new format: \"ReachableDirAddresses *:80\"\n");
  1469. tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:80");
  1470. expect_log_msg("Converting FascistFirewall config "
  1471. "option to new format: \"ReachableORAddresses *:443\"\n");
  1472. tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:443");
  1473. tor_free(msg);
  1474. free_options_test_data(tdata);
  1475. mock_clean_saved_logs();
  1476. tdata = get_options_test_data("FascistFirewall 1\n"
  1477. "ReachableDirAddresses *:81\n"
  1478. "ReachableORAddresses *:444\n"
  1479. "MaxClientCircuitsPending 1\n"
  1480. "ConnLimit 1\n"
  1481. "SchedulerHighWaterMark__ 42\n"
  1482. "SchedulerLowWaterMark__ 10\n");
  1483. tdata->opt->FirewallPorts = smartlist_new();
  1484. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1485. tt_int_op(ret, OP_EQ, -1);
  1486. expect_log_entry();
  1487. tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:81");
  1488. tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444");
  1489. tor_free(msg);
  1490. free_options_test_data(tdata);
  1491. mock_clean_saved_logs();
  1492. tdata = get_options_test_data("FascistFirewall 1\n"
  1493. "FirewallPort 123\n"
  1494. "MaxClientCircuitsPending 1\n"
  1495. "ConnLimit 1\n"
  1496. "SchedulerHighWaterMark__ 42\n"
  1497. "SchedulerLowWaterMark__ 10\n");
  1498. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1499. tt_int_op(ret, OP_EQ, -1);
  1500. expect_log_msg("Converting FascistFirewall and "
  1501. "FirewallPorts config options to new format: "
  1502. "\"ReachableAddresses *:123\"\n");
  1503. tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:123");
  1504. tor_free(msg);
  1505. free_options_test_data(tdata);
  1506. mock_clean_saved_logs();
  1507. tdata = get_options_test_data("FascistFirewall 1\n"
  1508. "ReachableAddresses *:82\n"
  1509. "ReachableAddresses *:83\n"
  1510. "ReachableAddresses reject *:*\n"
  1511. "MaxClientCircuitsPending 1\n"
  1512. "ConnLimit 1\n"
  1513. "SchedulerHighWaterMark__ 42\n"
  1514. "SchedulerLowWaterMark__ 10\n");
  1515. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1516. tt_int_op(ret, OP_EQ, -1);
  1517. expect_log_entry();
  1518. tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:82");
  1519. tor_free(msg);
  1520. #define SERVERS_REACHABLE_MSG "Servers must be able to freely connect to" \
  1521. " the rest of the Internet, so they must not set Reachable*Addresses or" \
  1522. " FascistFirewall or FirewallPorts or ClientUseIPv4 0."
  1523. free_options_test_data(tdata);
  1524. tdata = get_options_test_data("ReachableAddresses *:82\n"
  1525. "ORListenAddress 127.0.0.1:5555\n"
  1526. "ORPort 955\n"
  1527. "MaxClientCircuitsPending 1\n"
  1528. "ConnLimit 1\n"
  1529. "SchedulerHighWaterMark__ 42\n"
  1530. "SchedulerLowWaterMark__ 10\n");
  1531. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1532. tt_int_op(ret, OP_EQ, -1);
  1533. tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
  1534. tor_free(msg);
  1535. free_options_test_data(tdata);
  1536. tdata = get_options_test_data("ReachableORAddresses *:82\n"
  1537. "ORListenAddress 127.0.0.1:5555\n"
  1538. "ORPort 955\n"
  1539. "MaxClientCircuitsPending 1\n"
  1540. "ConnLimit 1\n"
  1541. "SchedulerHighWaterMark__ 42\n"
  1542. "SchedulerLowWaterMark__ 10\n");
  1543. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1544. tt_int_op(ret, OP_EQ, -1);
  1545. tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
  1546. tor_free(msg);
  1547. free_options_test_data(tdata);
  1548. tdata = get_options_test_data("ReachableDirAddresses *:82\n"
  1549. "ORListenAddress 127.0.0.1:5555\n"
  1550. "ORPort 955\n"
  1551. "MaxClientCircuitsPending 1\n"
  1552. "ConnLimit 1\n"
  1553. "SchedulerHighWaterMark__ 42\n"
  1554. "SchedulerLowWaterMark__ 10\n");
  1555. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1556. tt_int_op(ret, OP_EQ, -1);
  1557. tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
  1558. tor_free(msg);
  1559. free_options_test_data(tdata);
  1560. tdata = get_options_test_data("ClientUseIPv4 0\n"
  1561. "ORListenAddress 127.0.0.1:5555\n"
  1562. "ORPort 955\n"
  1563. "MaxClientCircuitsPending 1\n"
  1564. "ConnLimit 1\n"
  1565. "SchedulerHighWaterMark__ 42\n"
  1566. "SchedulerLowWaterMark__ 10\n");
  1567. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1568. tt_int_op(ret, OP_EQ, -1);
  1569. tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
  1570. tor_free(msg);
  1571. /* Test IPv4-only clients setting IPv6 preferences */
  1572. #define WARN_PLEASE_USE_IPV6_OR_LOG_MSG \
  1573. "ClientPreferIPv6ORPort 1 is ignored unless tor is using IPv6. " \
  1574. "Please set ClientUseIPv6 1, ClientUseIPv4 0, or configure bridges.\n"
  1575. #define WARN_PLEASE_USE_IPV6_DIR_LOG_MSG \
  1576. "ClientPreferIPv6DirPort 1 is ignored unless tor is using IPv6. " \
  1577. "Please set ClientUseIPv6 1, ClientUseIPv4 0, or configure bridges.\n"
  1578. free_options_test_data(tdata);
  1579. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1580. "ClientUseIPv4 1\n"
  1581. "ClientUseIPv6 0\n"
  1582. "UseBridges 0\n"
  1583. "ClientPreferIPv6ORPort 1\n");
  1584. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1585. tt_int_op(ret, OP_EQ, 0);
  1586. expect_log_msg(WARN_PLEASE_USE_IPV6_OR_LOG_MSG);
  1587. tor_free(msg);
  1588. free_options_test_data(tdata);
  1589. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1590. "ClientUseIPv4 1\n"
  1591. "ClientUseIPv6 0\n"
  1592. "UseBridges 0\n"
  1593. "ClientPreferIPv6DirPort 1\n");
  1594. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1595. tt_int_op(ret, OP_EQ, 0);
  1596. expect_log_msg(WARN_PLEASE_USE_IPV6_DIR_LOG_MSG);
  1597. tor_free(msg);
  1598. /* Now test an IPv4/IPv6 client setting IPv6 preferences */
  1599. free_options_test_data(tdata);
  1600. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1601. "ClientUseIPv4 1\n"
  1602. "ClientUseIPv6 1\n"
  1603. "ClientPreferIPv6ORPort 1\n"
  1604. "ClientPreferIPv6DirPort 1\n");
  1605. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1606. tt_int_op(ret, OP_EQ, 0);
  1607. tt_ptr_op(msg, OP_EQ, NULL);
  1608. /* Now test an IPv6 client setting IPv6 preferences */
  1609. free_options_test_data(tdata);
  1610. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1611. "ClientUseIPv6 1\n"
  1612. "ClientPreferIPv6ORPort 1\n"
  1613. "ClientPreferIPv6DirPort 1\n");
  1614. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1615. tt_int_op(ret, OP_EQ, 0);
  1616. tt_ptr_op(msg, OP_EQ, NULL);
  1617. /* And an implicit (IPv4 disabled) IPv6 client setting IPv6 preferences */
  1618. free_options_test_data(tdata);
  1619. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1620. "ClientUseIPv4 0\n"
  1621. "ClientPreferIPv6ORPort 1\n"
  1622. "ClientPreferIPv6DirPort 1\n");
  1623. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1624. tt_int_op(ret, OP_EQ, 0);
  1625. tt_ptr_op(msg, OP_EQ, NULL);
  1626. /* And an implicit (bridge) client setting IPv6 preferences */
  1627. free_options_test_data(tdata);
  1628. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1629. "UseBridges 1\n"
  1630. "Bridge 127.0.0.1:12345\n"
  1631. "ClientPreferIPv6ORPort 1\n"
  1632. "ClientPreferIPv6DirPort 1\n");
  1633. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1634. tt_int_op(ret, OP_EQ, 0);
  1635. tt_ptr_op(msg, OP_EQ, NULL);
  1636. done:
  1637. teardown_capture_of_logs();
  1638. free_options_test_data(tdata);
  1639. tor_free(msg);
  1640. }
  1641. static void
  1642. test_options_validate__use_bridges(void *ignored)
  1643. {
  1644. (void)ignored;
  1645. int ret;
  1646. char *msg;
  1647. options_test_data_t *tdata = get_options_test_data(
  1648. "UseBridges 1\n"
  1649. "ClientUseIPv4 1\n"
  1650. "ORListenAddress 127.0.0.1:5555\n"
  1651. "ORPort 955\n"
  1652. "MaxClientCircuitsPending 1\n"
  1653. "ConnLimit 1\n"
  1654. "SchedulerHighWaterMark__ 42\n"
  1655. "SchedulerLowWaterMark__ 10\n");
  1656. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1657. tt_int_op(ret, OP_EQ, -1);
  1658. tt_str_op(msg, OP_EQ, "Servers must be able to freely connect to the rest of"
  1659. " the Internet, so they must not set UseBridges.");
  1660. tor_free(msg);
  1661. free_options_test_data(tdata);
  1662. tdata = get_options_test_data("UseBridges 1\n"
  1663. "MaxClientCircuitsPending 1\n"
  1664. "ConnLimit 1\n"
  1665. "SchedulerHighWaterMark__ 42\n"
  1666. "SchedulerLowWaterMark__ 10\n");
  1667. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1668. tt_int_op(ret, OP_EQ, -1);
  1669. tt_str_op(msg, OP_NE, "Servers must be able to freely connect to the rest of"
  1670. " the Internet, so they must not set UseBridges.");
  1671. tor_free(msg);
  1672. NS_MOCK(geoip_get_country);
  1673. free_options_test_data(tdata);
  1674. tdata = get_options_test_data("UseBridges 1\n"
  1675. "EntryNodes {cn}\n"
  1676. "MaxClientCircuitsPending 1\n"
  1677. "ConnLimit 1\n"
  1678. "SchedulerHighWaterMark__ 42\n"
  1679. "SchedulerLowWaterMark__ 10\n");
  1680. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1681. tt_int_op(ret, OP_EQ, -1);
  1682. tt_str_op(msg, OP_EQ, "You cannot set both UseBridges and EntryNodes.");
  1683. tor_free(msg);
  1684. free_options_test_data(tdata);
  1685. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1686. "UseBridges 1\n");
  1687. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1688. tt_int_op(ret, OP_EQ, -1);
  1689. tt_str_op(msg, OP_EQ,
  1690. "If you set UseBridges, you must specify at least one bridge.");
  1691. tor_free(msg);
  1692. free_options_test_data(tdata);
  1693. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1694. "UseBridges 1\n"
  1695. "Bridge 10.0.0.1\n"
  1696. "Bridge !!!\n"
  1697. );
  1698. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1699. tt_int_op(ret, OP_EQ, -1);
  1700. tt_str_op(msg, OP_EQ, "Bridge line did not parse. See logs for details.");
  1701. tor_free(msg);
  1702. done:
  1703. NS_UNMOCK(geoip_get_country);
  1704. policies_free_all();
  1705. free_options_test_data(tdata);
  1706. tor_free(msg);
  1707. }
  1708. static void
  1709. test_options_validate__entry_nodes(void *ignored)
  1710. {
  1711. (void)ignored;
  1712. int ret;
  1713. char *msg;
  1714. NS_MOCK(geoip_get_country);
  1715. options_test_data_t *tdata = get_options_test_data(
  1716. "EntryNodes {cn}\n"
  1717. "UseEntryGuards 0\n"
  1718. "MaxClientCircuitsPending 1\n"
  1719. "ConnLimit 1\n"
  1720. "SchedulerHighWaterMark__ 42\n"
  1721. "SchedulerLowWaterMark__ 10\n");
  1722. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1723. tt_int_op(ret, OP_EQ, -1);
  1724. tt_str_op(msg, OP_EQ,
  1725. "If EntryNodes is set, UseEntryGuards must be enabled.");
  1726. tor_free(msg);
  1727. free_options_test_data(tdata);
  1728. tdata = get_options_test_data("EntryNodes {cn}\n"
  1729. "UseEntryGuards 1\n"
  1730. "MaxClientCircuitsPending 1\n"
  1731. "ConnLimit 1\n"
  1732. "SchedulerHighWaterMark__ 42\n"
  1733. "SchedulerLowWaterMark__ 10\n");
  1734. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1735. tt_int_op(ret, OP_EQ, -1);
  1736. tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
  1737. tor_free(msg);
  1738. done:
  1739. NS_UNMOCK(geoip_get_country);
  1740. free_options_test_data(tdata);
  1741. tor_free(msg);
  1742. }
  1743. static void
  1744. test_options_validate__invalid_nodes(void *ignored)
  1745. {
  1746. (void)ignored;
  1747. int ret;
  1748. char *msg;
  1749. options_test_data_t *tdata = get_options_test_data(
  1750. "AllowInvalidNodes something_stupid\n"
  1751. "MaxClientCircuitsPending 1\n"
  1752. "ConnLimit 1\n"
  1753. "SchedulerHighWaterMark__ 42\n"
  1754. "SchedulerLowWaterMark__ 10\n");
  1755. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1756. tt_int_op(ret, OP_EQ, -1);
  1757. tt_str_op(msg, OP_EQ,
  1758. "Unrecognized value 'something_stupid' in AllowInvalidNodes");
  1759. tor_free(msg);
  1760. free_options_test_data(tdata);
  1761. tdata = get_options_test_data("AllowInvalidNodes entry, middle, exit\n"
  1762. "MaxClientCircuitsPending 1\n"
  1763. "ConnLimit 1\n"
  1764. "SchedulerHighWaterMark__ 42\n"
  1765. "SchedulerLowWaterMark__ 10\n");
  1766. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1767. tt_int_op(ret, OP_EQ, -1);
  1768. tt_int_op(tdata->opt->AllowInvalid_, OP_EQ, ALLOW_INVALID_ENTRY |
  1769. ALLOW_INVALID_EXIT | ALLOW_INVALID_MIDDLE);
  1770. tor_free(msg);
  1771. free_options_test_data(tdata);
  1772. tdata = get_options_test_data("AllowInvalidNodes introduction, rendezvous\n"
  1773. "MaxClientCircuitsPending 1\n"
  1774. "ConnLimit 1\n"
  1775. "SchedulerHighWaterMark__ 42\n"
  1776. "SchedulerLowWaterMark__ 10\n");
  1777. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1778. tt_int_op(ret, OP_EQ, -1);
  1779. tt_int_op(tdata->opt->AllowInvalid_, OP_EQ, ALLOW_INVALID_INTRODUCTION |
  1780. ALLOW_INVALID_RENDEZVOUS);
  1781. tor_free(msg);
  1782. done:
  1783. free_options_test_data(tdata);
  1784. tor_free(msg);
  1785. }
  1786. static void
  1787. test_options_validate__safe_logging(void *ignored)
  1788. {
  1789. (void)ignored;
  1790. int ret;
  1791. char *msg;
  1792. options_test_data_t *tdata = get_options_test_data(
  1793. "MaxClientCircuitsPending 1\n"
  1794. "ConnLimit 1\n"
  1795. "SchedulerHighWaterMark__ 42\n"
  1796. "SchedulerLowWaterMark__ 10\n");
  1797. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1798. tt_int_op(ret, OP_EQ, -1);
  1799. tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
  1800. tor_free(msg);
  1801. free_options_test_data(tdata);
  1802. tdata = get_options_test_data("SafeLogging 0\n"
  1803. "MaxClientCircuitsPending 1\n"
  1804. "ConnLimit 1\n"
  1805. "SchedulerHighWaterMark__ 42\n"
  1806. "SchedulerLowWaterMark__ 10\n");
  1807. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1808. tt_int_op(ret, OP_EQ, -1);
  1809. tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
  1810. tor_free(msg);
  1811. free_options_test_data(tdata);
  1812. tdata = get_options_test_data("SafeLogging Relay\n"
  1813. "MaxClientCircuitsPending 1\n"
  1814. "ConnLimit 1\n"
  1815. "SchedulerHighWaterMark__ 42\n"
  1816. "SchedulerLowWaterMark__ 10\n");
  1817. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1818. tt_int_op(ret, OP_EQ, -1);
  1819. tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_RELAY);
  1820. tor_free(msg);
  1821. free_options_test_data(tdata);
  1822. tdata = get_options_test_data("SafeLogging 1\n"
  1823. "MaxClientCircuitsPending 1\n"
  1824. "ConnLimit 1\n"
  1825. "SchedulerHighWaterMark__ 42\n"
  1826. "SchedulerLowWaterMark__ 10\n");
  1827. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1828. tt_int_op(ret, OP_EQ, -1);
  1829. tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_ALL);
  1830. tor_free(msg);
  1831. free_options_test_data(tdata);
  1832. tdata = get_options_test_data("SafeLogging stuffy\n"
  1833. "MaxClientCircuitsPending 1\n"
  1834. "ConnLimit 1\n"
  1835. "SchedulerHighWaterMark__ 42\n"
  1836. "SchedulerLowWaterMark__ 10\n");
  1837. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1838. tt_int_op(ret, OP_EQ, -1);
  1839. tt_str_op(msg, OP_EQ, "Unrecognized value '\"stuffy\"' in SafeLogging");
  1840. tor_free(msg);
  1841. done:
  1842. escaped(NULL); // This will free the leaking memory from the previous escaped
  1843. free_options_test_data(tdata);
  1844. tor_free(msg);
  1845. }
  1846. static void
  1847. test_options_validate__publish_server_descriptor(void *ignored)
  1848. {
  1849. (void)ignored;
  1850. int ret;
  1851. char *msg;
  1852. setup_capture_of_logs(LOG_WARN);
  1853. options_test_data_t *tdata = get_options_test_data(
  1854. "PublishServerDescriptor bridge\n" TEST_OPTIONS_DEFAULT_VALUES
  1855. );
  1856. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1857. tt_int_op(ret, OP_EQ, 0);
  1858. tt_assert(!msg);
  1859. free_options_test_data(tdata);
  1860. tdata = get_options_test_data("PublishServerDescriptor humma\n"
  1861. TEST_OPTIONS_DEFAULT_VALUES);
  1862. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1863. tt_int_op(ret, OP_EQ, -1);
  1864. tt_str_op(msg, OP_EQ, "Unrecognized value in PublishServerDescriptor");
  1865. tor_free(msg);
  1866. free_options_test_data(tdata);
  1867. tdata = get_options_test_data("PublishServerDescriptor bridge, v3\n"
  1868. TEST_OPTIONS_DEFAULT_VALUES);
  1869. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1870. tt_int_op(ret, OP_EQ, -1);
  1871. tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
  1872. "descriptors to the directory authorities. Please correct your "
  1873. "PublishServerDescriptor line.");
  1874. tor_free(msg);
  1875. free_options_test_data(tdata);
  1876. tdata = get_options_test_data("BridgeRelay 1\n"
  1877. "PublishServerDescriptor v3\n"
  1878. TEST_OPTIONS_DEFAULT_VALUES);
  1879. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1880. tt_int_op(ret, OP_EQ, -1);
  1881. tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
  1882. "descriptors to the directory authorities. Please correct your "
  1883. "PublishServerDescriptor line.");
  1884. tor_free(msg);
  1885. free_options_test_data(tdata);
  1886. tdata = get_options_test_data("BridgeRelay 1\n" TEST_OPTIONS_DEFAULT_VALUES);
  1887. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1888. tt_int_op(ret, OP_EQ, -1);
  1889. tt_str_op(msg, OP_NE, "Bridges are not supposed to publish router "
  1890. "descriptors to the directory authorities. Please correct your "
  1891. "PublishServerDescriptor line.");
  1892. tor_free(msg);
  1893. free_options_test_data(tdata);
  1894. tdata = get_options_test_data("BridgeRelay 1\n"
  1895. "DirPort 999\n" TEST_OPTIONS_DEFAULT_VALUES);
  1896. mock_clean_saved_logs();
  1897. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1898. tt_int_op(ret, OP_EQ, -1);
  1899. expect_log_msg("Can't set a DirPort on a bridge "
  1900. "relay; disabling DirPort\n");
  1901. tt_assert(!tdata->opt->DirPort_lines);
  1902. tt_assert(!tdata->opt->DirPort_set);
  1903. done:
  1904. teardown_capture_of_logs();
  1905. policies_free_all();
  1906. free_options_test_data(tdata);
  1907. tor_free(msg);
  1908. }
  1909. static void
  1910. test_options_validate__testing(void *ignored)
  1911. {
  1912. (void)ignored;
  1913. int ret;
  1914. char *msg;
  1915. options_test_data_t *tdata = NULL;
  1916. #define ENSURE_DEFAULT(varname, varval) \
  1917. STMT_BEGIN \
  1918. free_options_test_data(tdata); \
  1919. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
  1920. #varname " " #varval "\n"); \
  1921. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  1922. tt_str_op(msg, OP_EQ, \
  1923. #varname " may only be changed in testing Tor networks!"); \
  1924. tt_int_op(ret, OP_EQ, -1); \
  1925. tor_free(msg); \
  1926. \
  1927. free_options_test_data(tdata); \
  1928. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
  1929. #varname " " #varval "\n" \
  1930. VALID_DIR_AUTH \
  1931. "TestingTorNetwork 1\n"); \
  1932. \
  1933. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  1934. if (msg) { \
  1935. tt_str_op(msg, OP_NE, \
  1936. #varname " may only be changed in testing Tor networks!"); \
  1937. tor_free(msg); \
  1938. } \
  1939. \
  1940. free_options_test_data(tdata); \
  1941. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
  1942. #varname " " #varval "\n" \
  1943. "___UsingTestNetworkDefaults 1\n"); \
  1944. \
  1945. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  1946. if (msg) { \
  1947. tt_str_op(msg, OP_NE, \
  1948. #varname " may only be changed in testing Tor networks!"); \
  1949. tor_free(msg); \
  1950. } \
  1951. STMT_END
  1952. ENSURE_DEFAULT(TestingV3AuthInitialVotingInterval, 3600);
  1953. ENSURE_DEFAULT(TestingV3AuthInitialVoteDelay, 3000);
  1954. ENSURE_DEFAULT(TestingV3AuthInitialDistDelay, 3000);
  1955. ENSURE_DEFAULT(TestingV3AuthVotingStartOffset, 3000);
  1956. ENSURE_DEFAULT(TestingAuthDirTimeToLearnReachability, 3000);
  1957. ENSURE_DEFAULT(TestingEstimatedDescriptorPropagationTime, 3000);
  1958. ENSURE_DEFAULT(TestingServerDownloadSchedule, 3000);
  1959. ENSURE_DEFAULT(TestingClientDownloadSchedule, 3000);
  1960. ENSURE_DEFAULT(TestingServerConsensusDownloadSchedule, 3000);
  1961. ENSURE_DEFAULT(TestingClientConsensusDownloadSchedule, 3000);
  1962. ENSURE_DEFAULT(TestingBridgeDownloadSchedule, 3000);
  1963. ENSURE_DEFAULT(TestingClientMaxIntervalWithoutRequest, 3000);
  1964. ENSURE_DEFAULT(TestingDirConnectionMaxStall, 3000);
  1965. ENSURE_DEFAULT(TestingConsensusMaxDownloadTries, 3000);
  1966. ENSURE_DEFAULT(TestingDescriptorMaxDownloadTries, 3000);
  1967. ENSURE_DEFAULT(TestingMicrodescMaxDownloadTries, 3000);
  1968. ENSURE_DEFAULT(TestingCertMaxDownloadTries, 3000);
  1969. ENSURE_DEFAULT(TestingAuthKeyLifetime, 3000);
  1970. ENSURE_DEFAULT(TestingLinkCertLifetime, 3000);
  1971. ENSURE_DEFAULT(TestingSigningKeySlop, 3000);
  1972. ENSURE_DEFAULT(TestingAuthKeySlop, 3000);
  1973. ENSURE_DEFAULT(TestingLinkKeySlop, 3000);
  1974. done:
  1975. escaped(NULL); // This will free the leaking memory from the previous escaped
  1976. policies_free_all();
  1977. free_options_test_data(tdata);
  1978. tor_free(msg);
  1979. }
  1980. static void
  1981. test_options_validate__hidserv(void *ignored)
  1982. {
  1983. (void)ignored;
  1984. int ret;
  1985. char *msg;
  1986. setup_capture_of_logs(LOG_WARN);
  1987. options_test_data_t *tdata = get_options_test_data(
  1988. TEST_OPTIONS_DEFAULT_VALUES);
  1989. tdata->opt->MinUptimeHidServDirectoryV2 = -1;
  1990. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  1991. tt_int_op(ret, OP_EQ, 0);
  1992. expect_log_msg("MinUptimeHidServDirectoryV2 "
  1993. "option must be at least 0 seconds. Changing to 0.\n");
  1994. tt_int_op(tdata->opt->MinUptimeHidServDirectoryV2, OP_EQ, 0);
  1995. tor_free(msg);
  1996. free_options_test_data(tdata);
  1997. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  1998. "RendPostPeriod 1\n" );
  1999. mock_clean_saved_logs();
  2000. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2001. tt_int_op(ret, OP_EQ, 0);
  2002. expect_log_msg("RendPostPeriod option is too short;"
  2003. " raising to 600 seconds.\n");
  2004. tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 600);
  2005. tor_free(msg);
  2006. free_options_test_data(tdata);
  2007. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2008. "RendPostPeriod 302401\n" );
  2009. mock_clean_saved_logs();
  2010. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2011. tt_int_op(ret, OP_EQ, 0);
  2012. expect_log_msg("RendPostPeriod is too large; "
  2013. "clipping to 302400s.\n");
  2014. tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 302400);
  2015. tor_free(msg);
  2016. done:
  2017. teardown_capture_of_logs();
  2018. policies_free_all();
  2019. free_options_test_data(tdata);
  2020. tor_free(msg);
  2021. }
  2022. static void
  2023. test_options_validate__predicted_ports(void *ignored)
  2024. {
  2025. (void)ignored;
  2026. int ret;
  2027. char *msg;
  2028. setup_capture_of_logs(LOG_WARN);
  2029. options_test_data_t *tdata = get_options_test_data(
  2030. "PredictedPortsRelevanceTime 100000000\n"
  2031. TEST_OPTIONS_DEFAULT_VALUES);
  2032. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2033. tt_int_op(ret, OP_EQ, 0);
  2034. expect_log_msg("PredictedPortsRelevanceTime is too "
  2035. "large; clipping to 3600s.\n");
  2036. tt_int_op(tdata->opt->PredictedPortsRelevanceTime, OP_EQ, 3600);
  2037. done:
  2038. teardown_capture_of_logs();
  2039. policies_free_all();
  2040. free_options_test_data(tdata);
  2041. tor_free(msg);
  2042. }
  2043. static void
  2044. test_options_validate__path_bias(void *ignored)
  2045. {
  2046. (void)ignored;
  2047. int ret;
  2048. char *msg;
  2049. options_test_data_t *tdata = get_options_test_data(
  2050. TEST_OPTIONS_DEFAULT_VALUES
  2051. "PathBiasNoticeRate 1.1\n");
  2052. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2053. tt_int_op(ret, OP_EQ, -1);
  2054. tt_str_op(msg, OP_EQ,
  2055. "PathBiasNoticeRate is too high. It must be between 0 and 1.0");
  2056. tor_free(msg);
  2057. free_options_test_data(tdata);
  2058. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2059. "PathBiasWarnRate 1.1\n");
  2060. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2061. tt_int_op(ret, OP_EQ, -1);
  2062. tt_str_op(msg, OP_EQ,
  2063. "PathBiasWarnRate is too high. It must be between 0 and 1.0");
  2064. tor_free(msg);
  2065. free_options_test_data(tdata);
  2066. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2067. "PathBiasExtremeRate 1.1\n");
  2068. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2069. tt_int_op(ret, OP_EQ, -1);
  2070. tt_str_op(msg, OP_EQ,
  2071. "PathBiasExtremeRate is too high. It must be between 0 and 1.0");
  2072. tor_free(msg);
  2073. free_options_test_data(tdata);
  2074. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2075. "PathBiasNoticeUseRate 1.1\n");
  2076. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2077. tt_int_op(ret, OP_EQ, -1);
  2078. tt_str_op(msg, OP_EQ,
  2079. "PathBiasNoticeUseRate is too high. It must be between 0 and 1.0");
  2080. tor_free(msg);
  2081. free_options_test_data(tdata);
  2082. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2083. "PathBiasExtremeUseRate 1.1\n");
  2084. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2085. tt_int_op(ret, OP_EQ, -1);
  2086. tt_str_op(msg, OP_EQ,
  2087. "PathBiasExtremeUseRate is too high. It must be between 0 and 1.0");
  2088. tor_free(msg);
  2089. done:
  2090. free_options_test_data(tdata);
  2091. tor_free(msg);
  2092. }
  2093. static void
  2094. test_options_validate__bandwidth(void *ignored)
  2095. {
  2096. (void)ignored;
  2097. int ret;
  2098. char *msg;
  2099. options_test_data_t *tdata = NULL;
  2100. #define ENSURE_BANDWIDTH_PARAM(p) \
  2101. STMT_BEGIN \
  2102. free_options_test_data(tdata); \
  2103. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES #p " 3Gb\n"); \
  2104. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  2105. tt_int_op(ret, OP_EQ, -1); \
  2106. tt_mem_op(msg, OP_EQ, #p " (3221225471) must be at most 2147483647", 40); \
  2107. tor_free(msg); \
  2108. STMT_END
  2109. ENSURE_BANDWIDTH_PARAM(BandwidthRate);
  2110. ENSURE_BANDWIDTH_PARAM(BandwidthBurst);
  2111. ENSURE_BANDWIDTH_PARAM(MaxAdvertisedBandwidth);
  2112. ENSURE_BANDWIDTH_PARAM(RelayBandwidthRate);
  2113. ENSURE_BANDWIDTH_PARAM(RelayBandwidthBurst);
  2114. ENSURE_BANDWIDTH_PARAM(PerConnBWRate);
  2115. ENSURE_BANDWIDTH_PARAM(PerConnBWBurst);
  2116. ENSURE_BANDWIDTH_PARAM(AuthDirFastGuarantee);
  2117. ENSURE_BANDWIDTH_PARAM(AuthDirGuardBWGuarantee);
  2118. free_options_test_data(tdata);
  2119. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2120. "RelayBandwidthRate 1000\n");
  2121. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2122. tt_int_op(ret, OP_EQ, 0);
  2123. tt_u64_op(tdata->opt->RelayBandwidthBurst, OP_EQ, 1000);
  2124. tor_free(msg);
  2125. free_options_test_data(tdata);
  2126. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2127. "RelayBandwidthBurst 1001\n");
  2128. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2129. tt_int_op(ret, OP_EQ, 0);
  2130. tt_u64_op(tdata->opt->RelayBandwidthRate, OP_EQ, 1001);
  2131. tor_free(msg);
  2132. free_options_test_data(tdata);
  2133. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2134. "RelayBandwidthRate 1001\n"
  2135. "RelayBandwidthBurst 1000\n");
  2136. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2137. tt_int_op(ret, OP_EQ, -1);
  2138. tt_str_op(msg, OP_EQ, "RelayBandwidthBurst must be at least equal to "
  2139. "RelayBandwidthRate.");
  2140. tor_free(msg);
  2141. free_options_test_data(tdata);
  2142. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2143. "BandwidthRate 1001\n"
  2144. "BandwidthBurst 1000\n");
  2145. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2146. tt_int_op(ret, OP_EQ, -1);
  2147. tt_str_op(msg, OP_EQ,
  2148. "BandwidthBurst must be at least equal to BandwidthRate.");
  2149. tor_free(msg);
  2150. free_options_test_data(tdata);
  2151. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2152. "RelayBandwidthRate 1001\n"
  2153. "BandwidthRate 1000\n"
  2154. "BandwidthBurst 1000\n"
  2155. );
  2156. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2157. tt_int_op(ret, OP_EQ, 0);
  2158. tt_u64_op(tdata->opt->BandwidthRate, OP_EQ, 1001);
  2159. tor_free(msg);
  2160. free_options_test_data(tdata);
  2161. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2162. "RelayBandwidthRate 1001\n"
  2163. "BandwidthRate 1000\n"
  2164. "RelayBandwidthBurst 1001\n"
  2165. "BandwidthBurst 1000\n"
  2166. );
  2167. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2168. tt_int_op(ret, OP_EQ, 0);
  2169. tt_u64_op(tdata->opt->BandwidthBurst, OP_EQ, 1001);
  2170. tor_free(msg);
  2171. free_options_test_data(tdata);
  2172. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2173. "ORListenAddress 127.0.0.1:5555\n"
  2174. "ORPort 955\n"
  2175. "BandwidthRate 1\n"
  2176. );
  2177. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2178. tt_int_op(ret, OP_EQ, -1);
  2179. tt_str_op(msg, OP_EQ, "BandwidthRate is set to 1 bytes/second. For servers,"
  2180. " it must be at least 76800.");
  2181. tor_free(msg);
  2182. free_options_test_data(tdata);
  2183. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2184. "ORListenAddress 127.0.0.1:5555\n"
  2185. "ORPort 955\n"
  2186. "BandwidthRate 76800\n"
  2187. "MaxAdvertisedBandwidth 30000\n"
  2188. );
  2189. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2190. tt_int_op(ret, OP_EQ, -1);
  2191. tt_str_op(msg, OP_EQ, "MaxAdvertisedBandwidth is set to 30000 bytes/second."
  2192. " For servers, it must be at least 38400.");
  2193. tor_free(msg);
  2194. free_options_test_data(tdata);
  2195. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2196. "ORListenAddress 127.0.0.1:5555\n"
  2197. "ORPort 955\n"
  2198. "BandwidthRate 76800\n"
  2199. "RelayBandwidthRate 1\n"
  2200. "MaxAdvertisedBandwidth 38400\n"
  2201. );
  2202. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2203. tt_int_op(ret, OP_EQ, -1);
  2204. tt_str_op(msg, OP_EQ, "RelayBandwidthRate is set to 1 bytes/second. For "
  2205. "servers, it must be at least 76800.");
  2206. tor_free(msg);
  2207. free_options_test_data(tdata);
  2208. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2209. "ORListenAddress 127.0.0.1:5555\n"
  2210. "ORPort 955\n"
  2211. "BandwidthRate 76800\n"
  2212. "BandwidthBurst 76800\n"
  2213. "RelayBandwidthRate 76800\n"
  2214. "MaxAdvertisedBandwidth 38400\n"
  2215. );
  2216. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2217. tt_int_op(ret, OP_EQ, 0);
  2218. tor_free(msg);
  2219. done:
  2220. policies_free_all();
  2221. free_options_test_data(tdata);
  2222. tor_free(msg);
  2223. }
  2224. static void
  2225. test_options_validate__circuits(void *ignored)
  2226. {
  2227. (void)ignored;
  2228. char *msg;
  2229. options_test_data_t *tdata = NULL;
  2230. setup_capture_of_logs(LOG_WARN);
  2231. free_options_test_data(tdata);
  2232. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2233. "MaxCircuitDirtiness 2592001\n");
  2234. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2235. expect_log_msg("MaxCircuitDirtiness option is too "
  2236. "high; setting to 30 days.\n");
  2237. tt_int_op(tdata->opt->MaxCircuitDirtiness, OP_EQ, 2592000);
  2238. tor_free(msg);
  2239. free_options_test_data(tdata);
  2240. mock_clean_saved_logs();
  2241. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2242. "CircuitStreamTimeout 1\n");
  2243. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2244. expect_log_msg("CircuitStreamTimeout option is too"
  2245. " short; raising to 10 seconds.\n");
  2246. tt_int_op(tdata->opt->CircuitStreamTimeout, OP_EQ, 10);
  2247. tor_free(msg);
  2248. free_options_test_data(tdata);
  2249. mock_clean_saved_logs();
  2250. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2251. "CircuitStreamTimeout 111\n");
  2252. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2253. expect_no_log_msg("CircuitStreamTimeout option is too"
  2254. " short; raising to 10 seconds.\n");
  2255. tt_int_op(tdata->opt->CircuitStreamTimeout, OP_EQ, 111);
  2256. tor_free(msg);
  2257. free_options_test_data(tdata);
  2258. mock_clean_saved_logs();
  2259. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2260. "HeartbeatPeriod 1\n");
  2261. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2262. expect_log_msg("HeartbeatPeriod option is too short;"
  2263. " raising to 1800 seconds.\n");
  2264. tt_int_op(tdata->opt->HeartbeatPeriod, OP_EQ, 1800);
  2265. tor_free(msg);
  2266. free_options_test_data(tdata);
  2267. mock_clean_saved_logs();
  2268. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2269. "HeartbeatPeriod 1982\n");
  2270. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2271. expect_no_log_msg("HeartbeatPeriod option is too short;"
  2272. " raising to 1800 seconds.\n");
  2273. tt_int_op(tdata->opt->HeartbeatPeriod, OP_EQ, 1982);
  2274. tor_free(msg);
  2275. free_options_test_data(tdata);
  2276. mock_clean_saved_logs();
  2277. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2278. "CircuitBuildTimeout 1\n"
  2279. );
  2280. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2281. expect_log_msg("CircuitBuildTimeout is shorter (1"
  2282. " seconds) than the recommended minimum (10 seconds), and "
  2283. "LearnCircuitBuildTimeout is disabled. If tor isn't working, "
  2284. "raise this value or enable LearnCircuitBuildTimeout.\n");
  2285. tor_free(msg);
  2286. free_options_test_data(tdata);
  2287. mock_clean_saved_logs();
  2288. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2289. "CircuitBuildTimeout 11\n"
  2290. );
  2291. options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2292. expect_no_log_msg("CircuitBuildTimeout is shorter (1 "
  2293. "seconds) than the recommended minimum (10 seconds), and "
  2294. "LearnCircuitBuildTimeout is disabled. If tor isn't working, "
  2295. "raise this value or enable LearnCircuitBuildTimeout.\n");
  2296. tor_free(msg);
  2297. done:
  2298. policies_free_all();
  2299. teardown_capture_of_logs();
  2300. free_options_test_data(tdata);
  2301. tor_free(msg);
  2302. }
  2303. static void
  2304. test_options_validate__port_forwarding(void *ignored)
  2305. {
  2306. (void)ignored;
  2307. int ret;
  2308. char *msg;
  2309. options_test_data_t *tdata = NULL;
  2310. free_options_test_data(tdata);
  2311. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2312. "PortForwarding 1\nSandbox 1\n");
  2313. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2314. tt_int_op(ret, OP_EQ, -1);
  2315. tt_str_op(msg, OP_EQ, "PortForwarding is not compatible with Sandbox;"
  2316. " at most one can be set");
  2317. tor_free(msg);
  2318. free_options_test_data(tdata);
  2319. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2320. "PortForwarding 1\nSandbox 0\n");
  2321. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2322. tt_int_op(ret, OP_EQ, 0);
  2323. tt_assert(!msg);
  2324. tor_free(msg);
  2325. done:
  2326. free_options_test_data(tdata);
  2327. policies_free_all();
  2328. tor_free(msg);
  2329. }
  2330. static void
  2331. test_options_validate__tor2web(void *ignored)
  2332. {
  2333. (void)ignored;
  2334. int ret;
  2335. char *msg;
  2336. options_test_data_t *tdata = NULL;
  2337. free_options_test_data(tdata);
  2338. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2339. "Tor2webRendezvousPoints 1\n");
  2340. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2341. tt_int_op(ret, OP_EQ, -1);
  2342. tt_str_op(msg, OP_EQ,
  2343. "Tor2webRendezvousPoints cannot be set without Tor2webMode.");
  2344. tor_free(msg);
  2345. free_options_test_data(tdata);
  2346. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2347. "Tor2webRendezvousPoints 1\nTor2webMode 1\n");
  2348. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2349. tt_int_op(ret, OP_EQ, 0);
  2350. tor_free(msg);
  2351. done:
  2352. policies_free_all();
  2353. free_options_test_data(tdata);
  2354. tor_free(msg);
  2355. }
  2356. static void
  2357. test_options_validate__rend(void *ignored)
  2358. {
  2359. (void)ignored;
  2360. int ret;
  2361. char *msg;
  2362. options_test_data_t *tdata = NULL;
  2363. setup_capture_of_logs(LOG_WARN);
  2364. free_options_test_data(tdata);
  2365. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2366. "UseEntryGuards 0\n"
  2367. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
  2368. "HiddenServicePort 80 127.0.0.1:8080\n"
  2369. );
  2370. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2371. tt_int_op(ret, OP_EQ, 0);
  2372. expect_log_msg("UseEntryGuards is disabled, but you"
  2373. " have configured one or more hidden services on this Tor "
  2374. "instance. Your hidden services will be very easy to locate using"
  2375. " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
  2376. "attack06 for details.\n");
  2377. tor_free(msg);
  2378. free_options_test_data(tdata);
  2379. tdata = get_options_test_data(
  2380. TEST_OPTIONS_DEFAULT_VALUES
  2381. "UseEntryGuards 1\n"
  2382. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
  2383. "HiddenServicePort 80 127.0.0.1:8080\n"
  2384. );
  2385. mock_clean_saved_logs();
  2386. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2387. tt_int_op(ret, OP_EQ, 0);
  2388. expect_no_log_msg("UseEntryGuards is disabled, but you"
  2389. " have configured one or more hidden services on this Tor "
  2390. "instance. Your hidden services will be very easy to locate using"
  2391. " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
  2392. "attack06 for details.\n");
  2393. free_options_test_data(tdata);
  2394. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2395. "HiddenServicePort 80 127.0.0.1:8080\n"
  2396. );
  2397. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2398. tt_int_op(ret, OP_EQ, -1);
  2399. tt_str_op(msg, OP_EQ,
  2400. "Failed to configure rendezvous options. See logs for details.");
  2401. tor_free(msg);
  2402. free_options_test_data(tdata);
  2403. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2404. "HidServAuth failed\n"
  2405. );
  2406. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2407. tt_int_op(ret, OP_EQ, -1);
  2408. tt_str_op(msg, OP_EQ, "Failed to configure client authorization for hidden "
  2409. "services. See logs for details.");
  2410. tor_free(msg);
  2411. done:
  2412. policies_free_all();
  2413. teardown_capture_of_logs();
  2414. free_options_test_data(tdata);
  2415. tor_free(msg);
  2416. }
  2417. static void
  2418. test_options_validate__accounting(void *ignored)
  2419. {
  2420. (void)ignored;
  2421. int ret;
  2422. char *msg;
  2423. options_test_data_t *tdata = NULL;
  2424. setup_capture_of_logs(LOG_WARN);
  2425. free_options_test_data(tdata);
  2426. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2427. "AccountingRule something_bad\n"
  2428. );
  2429. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2430. tt_int_op(ret, OP_EQ, -1);
  2431. tt_str_op(msg, OP_EQ, "AccountingRule must be 'sum', 'max', 'in', or 'out'");
  2432. tor_free(msg);
  2433. free_options_test_data(tdata);
  2434. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2435. "AccountingRule sum\n"
  2436. );
  2437. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2438. tt_int_op(ret, OP_EQ, 0);
  2439. tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_SUM);
  2440. tor_free(msg);
  2441. free_options_test_data(tdata);
  2442. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2443. "AccountingRule max\n"
  2444. );
  2445. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2446. tt_int_op(ret, OP_EQ, 0);
  2447. tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_MAX);
  2448. tor_free(msg);
  2449. free_options_test_data(tdata);
  2450. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2451. "AccountingStart fail\n"
  2452. );
  2453. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2454. tt_int_op(ret, OP_EQ, -1);
  2455. tt_str_op(msg, OP_EQ,
  2456. "Failed to parse accounting options. See logs for details.");
  2457. tor_free(msg);
  2458. free_options_test_data(tdata);
  2459. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2460. "AccountingMax 10\n"
  2461. );
  2462. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2463. tt_int_op(ret, OP_EQ, 0);
  2464. tor_free(msg);
  2465. free_options_test_data(tdata);
  2466. tdata = get_options_test_data(
  2467. TEST_OPTIONS_DEFAULT_VALUES
  2468. "ORListenAddress 127.0.0.1:5555\n"
  2469. "ORPort 955\n"
  2470. "BandwidthRate 76800\n"
  2471. "BandwidthBurst 76800\n"
  2472. "MaxAdvertisedBandwidth 38400\n"
  2473. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
  2474. "HiddenServicePort 80 127.0.0.1:8080\n"
  2475. "AccountingMax 10\n"
  2476. );
  2477. mock_clean_saved_logs();
  2478. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2479. tt_int_op(ret, OP_EQ, 0);
  2480. expect_log_msg("Using accounting with a hidden "
  2481. "service and an ORPort is risky: your hidden service(s) and "
  2482. "your public address will all turn off at the same time, "
  2483. "which may alert observers that they are being run by the "
  2484. "same party.\n");
  2485. tor_free(msg);
  2486. free_options_test_data(tdata);
  2487. tdata = get_options_test_data(
  2488. TEST_OPTIONS_DEFAULT_VALUES
  2489. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
  2490. "HiddenServicePort 80 127.0.0.1:8080\n"
  2491. "AccountingMax 10\n"
  2492. );
  2493. mock_clean_saved_logs();
  2494. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2495. tt_int_op(ret, OP_EQ, 0);
  2496. expect_no_log_msg("Using accounting with a hidden "
  2497. "service and an ORPort is risky: your hidden service(s) and "
  2498. "your public address will all turn off at the same time, "
  2499. "which may alert observers that they are being run by the "
  2500. "same party.\n");
  2501. tor_free(msg);
  2502. free_options_test_data(tdata);
  2503. tdata = get_options_test_data(
  2504. TEST_OPTIONS_DEFAULT_VALUES
  2505. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
  2506. "HiddenServicePort 80 127.0.0.1:8080\n"
  2507. "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service2/\n"
  2508. "HiddenServicePort 81 127.0.0.1:8081\n"
  2509. "AccountingMax 10\n"
  2510. );
  2511. mock_clean_saved_logs();
  2512. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2513. tt_int_op(ret, OP_EQ, 0);
  2514. expect_log_msg("Using accounting with multiple "
  2515. "hidden services is risky: they will all turn off at the same"
  2516. " time, which may alert observers that they are being run by "
  2517. "the same party.\n");
  2518. tor_free(msg);
  2519. done:
  2520. teardown_capture_of_logs();
  2521. policies_free_all();
  2522. free_options_test_data(tdata);
  2523. tor_free(msg);
  2524. }
  2525. static void
  2526. test_options_validate__proxy(void *ignored)
  2527. {
  2528. (void)ignored;
  2529. int ret;
  2530. char *msg;
  2531. options_test_data_t *tdata = NULL;
  2532. sandbox_disable_getaddrinfo_cache();
  2533. setup_capture_of_logs(LOG_WARN);
  2534. free_options_test_data(tdata);
  2535. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2536. "HttpProxy 127.0.42.1\n"
  2537. );
  2538. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2539. tt_int_op(ret, OP_EQ, 0);
  2540. tt_int_op(tdata->opt->HTTPProxyPort, OP_EQ, 80);
  2541. tor_free(msg);
  2542. free_options_test_data(tdata);
  2543. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2544. "HttpProxy 127.0.42.1:444\n"
  2545. );
  2546. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2547. tt_int_op(ret, OP_EQ, 0);
  2548. tt_int_op(tdata->opt->HTTPProxyPort, OP_EQ, 444);
  2549. tor_free(msg);
  2550. free_options_test_data(tdata);
  2551. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2552. "HttpProxy not_so_valid!\n"
  2553. );
  2554. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2555. tt_int_op(ret, OP_EQ, -1);
  2556. tt_str_op(msg, OP_EQ, "HTTPProxy failed to parse or resolve. Please fix.");
  2557. tor_free(msg);
  2558. free_options_test_data(tdata);
  2559. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2560. "HttpProxyAuthenticator "
  2561. "onetwothreonetwothreonetwothreonetwothreonetw"
  2562. "othreonetwothreonetwothreonetwothreonetwothre"
  2563. "onetwothreonetwothreonetwothreonetwothreonetw"
  2564. "othreonetwothreonetwothreonetwothreonetwothre"
  2565. "onetwothreonetwothreonetwothreonetwothreonetw"
  2566. "othreonetwothreonetwothreonetwothreonetwothre"
  2567. "onetwothreonetwothreonetwothreonetwothreonetw"
  2568. "othreonetwothreonetwothreonetwothreonetwothre"
  2569. "onetwothreonetwothreonetwothreonetwothreonetw"
  2570. "othreonetwothreonetwothreonetwothreonetwothre"
  2571. "onetwothreonetwothreonetwothreonetwothreonetw"
  2572. "othreonetwothreeonetwothreeonetwothree"
  2573. );
  2574. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2575. tt_int_op(ret, OP_EQ, -1);
  2576. tt_str_op(msg, OP_EQ, "HTTPProxyAuthenticator is too long (>= 512 chars).");
  2577. tor_free(msg);
  2578. free_options_test_data(tdata);
  2579. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2580. "HttpProxyAuthenticator validauth\n"
  2581. );
  2582. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2583. tt_int_op(ret, OP_EQ, 0);
  2584. tor_free(msg);
  2585. free_options_test_data(tdata);
  2586. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2587. "HttpsProxy 127.0.42.1\n"
  2588. );
  2589. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2590. tt_int_op(ret, OP_EQ, 0);
  2591. tt_int_op(tdata->opt->HTTPSProxyPort, OP_EQ, 443);
  2592. tor_free(msg);
  2593. free_options_test_data(tdata);
  2594. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2595. "HttpsProxy 127.0.42.1:444\n"
  2596. );
  2597. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2598. tt_int_op(ret, OP_EQ, 0);
  2599. tt_int_op(tdata->opt->HTTPSProxyPort, OP_EQ, 444);
  2600. tor_free(msg);
  2601. free_options_test_data(tdata);
  2602. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2603. "HttpsProxy not_so_valid!\n"
  2604. );
  2605. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2606. tt_int_op(ret, OP_EQ, -1);
  2607. tt_str_op(msg, OP_EQ, "HTTPSProxy failed to parse or resolve. Please fix.");
  2608. tor_free(msg);
  2609. free_options_test_data(tdata);
  2610. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2611. "HttpsProxyAuthenticator "
  2612. "onetwothreonetwothreonetwothreonetwothreonetw"
  2613. "othreonetwothreonetwothreonetwothreonetwothre"
  2614. "onetwothreonetwothreonetwothreonetwothreonetw"
  2615. "othreonetwothreonetwothreonetwothreonetwothre"
  2616. "onetwothreonetwothreonetwothreonetwothreonetw"
  2617. "othreonetwothreonetwothreonetwothreonetwothre"
  2618. "onetwothreonetwothreonetwothreonetwothreonetw"
  2619. "othreonetwothreonetwothreonetwothreonetwothre"
  2620. "onetwothreonetwothreonetwothreonetwothreonetw"
  2621. "othreonetwothreonetwothreonetwothreonetwothre"
  2622. "onetwothreonetwothreonetwothreonetwothreonetw"
  2623. "othreonetwothreeonetwothreeonetwothree"
  2624. );
  2625. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2626. tt_int_op(ret, OP_EQ, -1);
  2627. tt_str_op(msg, OP_EQ, "HTTPSProxyAuthenticator is too long (>= 512 chars).");
  2628. tor_free(msg);
  2629. free_options_test_data(tdata);
  2630. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2631. "HttpsProxyAuthenticator validauth\n"
  2632. );
  2633. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2634. tt_int_op(ret, OP_EQ, 0);
  2635. tor_free(msg);
  2636. free_options_test_data(tdata);
  2637. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2638. "Socks4Proxy 127.0.42.1\n"
  2639. );
  2640. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2641. tt_int_op(ret, OP_EQ, 0);
  2642. tt_int_op(tdata->opt->Socks4ProxyPort, OP_EQ, 1080);
  2643. tor_free(msg);
  2644. free_options_test_data(tdata);
  2645. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2646. "Socks4Proxy 127.0.42.1:444\n"
  2647. );
  2648. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2649. tt_int_op(ret, OP_EQ, 0);
  2650. tt_int_op(tdata->opt->Socks4ProxyPort, OP_EQ, 444);
  2651. tor_free(msg);
  2652. free_options_test_data(tdata);
  2653. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2654. "Socks4Proxy not_so_valid!\n"
  2655. );
  2656. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2657. tt_int_op(ret, OP_EQ, -1);
  2658. tt_str_op(msg, OP_EQ, "Socks4Proxy failed to parse or resolve. Please fix.");
  2659. tor_free(msg);
  2660. free_options_test_data(tdata);
  2661. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2662. "Socks5Proxy 127.0.42.1\n"
  2663. );
  2664. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2665. tt_int_op(ret, OP_EQ, 0);
  2666. tt_int_op(tdata->opt->Socks5ProxyPort, OP_EQ, 1080);
  2667. tor_free(msg);
  2668. free_options_test_data(tdata);
  2669. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2670. "Socks5Proxy 127.0.42.1:444\n"
  2671. );
  2672. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2673. tt_int_op(ret, OP_EQ, 0);
  2674. tt_int_op(tdata->opt->Socks5ProxyPort, OP_EQ, 444);
  2675. tor_free(msg);
  2676. free_options_test_data(tdata);
  2677. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2678. "Socks5Proxy not_so_valid!\n"
  2679. );
  2680. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2681. tt_int_op(ret, OP_EQ, -1);
  2682. tt_str_op(msg, OP_EQ, "Socks5Proxy failed to parse or resolve. Please fix.");
  2683. tor_free(msg);
  2684. free_options_test_data(tdata);
  2685. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2686. "Socks4Proxy 215.1.1.1\n"
  2687. "Socks5Proxy 215.1.1.2\n"
  2688. );
  2689. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2690. tt_int_op(ret, OP_EQ, -1);
  2691. tt_str_op(msg, OP_EQ, "You have configured more than one proxy type. "
  2692. "(Socks4Proxy|Socks5Proxy|HTTPSProxy)");
  2693. tor_free(msg);
  2694. free_options_test_data(tdata);
  2695. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2696. "HttpProxy 215.1.1.1\n"
  2697. );
  2698. mock_clean_saved_logs();
  2699. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2700. tt_int_op(ret, OP_EQ, 0);
  2701. expect_log_msg("HTTPProxy configured, but no SOCKS "
  2702. "proxy or HTTPS proxy configured. Watch out: this configuration "
  2703. "will proxy unencrypted directory connections only.\n");
  2704. tor_free(msg);
  2705. free_options_test_data(tdata);
  2706. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2707. "HttpProxy 215.1.1.1\n"
  2708. "Socks4Proxy 215.1.1.1\n"
  2709. );
  2710. mock_clean_saved_logs();
  2711. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2712. tt_int_op(ret, OP_EQ, 0);
  2713. expect_no_log_msg("HTTPProxy configured, but no SOCKS "
  2714. "proxy or HTTPS proxy configured. Watch out: this configuration "
  2715. "will proxy unencrypted directory connections only.\n");
  2716. tor_free(msg);
  2717. free_options_test_data(tdata);
  2718. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2719. "HttpProxy 215.1.1.1\n"
  2720. "Socks5Proxy 215.1.1.1\n"
  2721. );
  2722. mock_clean_saved_logs();
  2723. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2724. tt_int_op(ret, OP_EQ, 0);
  2725. expect_no_log_msg("HTTPProxy configured, but no SOCKS "
  2726. "proxy or HTTPS proxy configured. Watch out: this configuration "
  2727. "will proxy unencrypted directory connections only.\n");
  2728. tor_free(msg);
  2729. free_options_test_data(tdata);
  2730. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2731. "HttpProxy 215.1.1.1\n"
  2732. "HttpsProxy 215.1.1.1\n"
  2733. );
  2734. mock_clean_saved_logs();
  2735. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2736. tt_int_op(ret, OP_EQ, 0);
  2737. expect_no_log_msg(
  2738. "HTTPProxy configured, but no SOCKS proxy or HTTPS proxy "
  2739. "configured. Watch out: this configuration will proxy "
  2740. "unencrypted directory connections only.\n");
  2741. tor_free(msg);
  2742. free_options_test_data(tdata);
  2743. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2744. );
  2745. tdata->opt->Socks5ProxyUsername = tor_strdup("");
  2746. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2747. tt_int_op(ret, OP_EQ, -1);
  2748. tt_str_op(msg, OP_EQ,
  2749. "Socks5ProxyUsername must be between 1 and 255 characters.");
  2750. tor_free(msg);
  2751. free_options_test_data(tdata);
  2752. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2753. );
  2754. tdata->opt->Socks5ProxyUsername =
  2755. tor_strdup("ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789AB"
  2756. "CDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCD"
  2757. "EABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEA"
  2758. "BCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABC"
  2759. "DE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789");
  2760. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2761. tt_int_op(ret, OP_EQ, -1);
  2762. tt_str_op(msg, OP_EQ,
  2763. "Socks5ProxyUsername must be between 1 and 255 characters.");
  2764. tor_free(msg);
  2765. free_options_test_data(tdata);
  2766. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2767. "Socks5ProxyUsername hello_world\n"
  2768. );
  2769. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2770. tt_int_op(ret, OP_EQ, -1);
  2771. tt_str_op(msg, OP_EQ, "Socks5ProxyPassword must be included with "
  2772. "Socks5ProxyUsername.");
  2773. tor_free(msg);
  2774. free_options_test_data(tdata);
  2775. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2776. "Socks5ProxyUsername hello_world\n"
  2777. );
  2778. tdata->opt->Socks5ProxyPassword = tor_strdup("");
  2779. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2780. tt_int_op(ret, OP_EQ, -1);
  2781. tt_str_op(msg, OP_EQ,
  2782. "Socks5ProxyPassword must be between 1 and 255 characters.");
  2783. tor_free(msg);
  2784. free_options_test_data(tdata);
  2785. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2786. "Socks5ProxyUsername hello_world\n"
  2787. );
  2788. tdata->opt->Socks5ProxyPassword =
  2789. tor_strdup("ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789AB"
  2790. "CDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCD"
  2791. "EABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEA"
  2792. "BCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABC"
  2793. "DE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789");
  2794. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2795. tt_int_op(ret, OP_EQ, -1);
  2796. tt_str_op(msg, OP_EQ,
  2797. "Socks5ProxyPassword must be between 1 and 255 characters.");
  2798. tor_free(msg);
  2799. free_options_test_data(tdata);
  2800. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2801. "Socks5ProxyUsername hello_world\n"
  2802. "Socks5ProxyPassword world_hello\n"
  2803. );
  2804. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2805. tt_int_op(ret, OP_EQ, 0);
  2806. tor_free(msg);
  2807. free_options_test_data(tdata);
  2808. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2809. "Socks5ProxyPassword hello_world\n"
  2810. );
  2811. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2812. tt_int_op(ret, OP_EQ, -1);
  2813. tt_str_op(msg, OP_EQ, "Socks5ProxyPassword must be included with "
  2814. "Socks5ProxyUsername.");
  2815. tor_free(msg);
  2816. done:
  2817. teardown_capture_of_logs();
  2818. free_options_test_data(tdata);
  2819. policies_free_all();
  2820. // sandbox_free_getaddrinfo_cache();
  2821. tor_free(msg);
  2822. }
  2823. static void
  2824. test_options_validate__control(void *ignored)
  2825. {
  2826. (void)ignored;
  2827. int ret;
  2828. char *msg;
  2829. options_test_data_t *tdata = NULL;
  2830. setup_capture_of_logs(LOG_WARN);
  2831. free_options_test_data(tdata);
  2832. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2833. "HashedControlPassword something_incorrect\n"
  2834. );
  2835. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2836. tt_int_op(ret, OP_EQ, -1);
  2837. tt_str_op(msg, OP_EQ,
  2838. "Bad HashedControlPassword: wrong length or bad encoding");
  2839. tor_free(msg);
  2840. free_options_test_data(tdata);
  2841. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2842. "HashedControlPassword 16:872860B76453A77D60CA"
  2843. "2BB8C1A7042072093276A3D701AD684053EC4C\n"
  2844. );
  2845. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2846. tt_int_op(ret, OP_EQ, 0);
  2847. tor_free(msg);
  2848. free_options_test_data(tdata);
  2849. tdata = get_options_test_data(
  2850. TEST_OPTIONS_DEFAULT_VALUES
  2851. "__HashedControlSessionPassword something_incorrect\n"
  2852. );
  2853. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2854. tt_int_op(ret, OP_EQ, -1);
  2855. tt_str_op(msg, OP_EQ, "Bad HashedControlSessionPassword: wrong length or "
  2856. "bad encoding");
  2857. tor_free(msg);
  2858. free_options_test_data(tdata);
  2859. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2860. "__HashedControlSessionPassword 16:872860B7645"
  2861. "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
  2862. "4C\n"
  2863. );
  2864. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2865. tt_int_op(ret, OP_EQ, 0);
  2866. tor_free(msg);
  2867. free_options_test_data(tdata);
  2868. tdata = get_options_test_data(
  2869. TEST_OPTIONS_DEFAULT_VALUES
  2870. "__OwningControllerProcess something_incorrect\n"
  2871. );
  2872. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2873. tt_int_op(ret, OP_EQ, -1);
  2874. tt_str_op(msg, OP_EQ, "Bad OwningControllerProcess: invalid PID");
  2875. tor_free(msg);
  2876. free_options_test_data(tdata);
  2877. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2878. "__OwningControllerProcess 123\n"
  2879. );
  2880. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2881. tt_int_op(ret, OP_EQ, 0);
  2882. tor_free(msg);
  2883. free_options_test_data(tdata);
  2884. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2885. "ControlPort 127.0.0.1:1234\n"
  2886. );
  2887. mock_clean_saved_logs();
  2888. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2889. tt_int_op(ret, OP_EQ, 0);
  2890. expect_log_msg(
  2891. "ControlPort is open, but no authentication method has been "
  2892. "configured. This means that any program on your computer can "
  2893. "reconfigure your Tor. That's bad! You should upgrade your Tor"
  2894. " controller as soon as possible.\n");
  2895. tor_free(msg);
  2896. free_options_test_data(tdata);
  2897. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2898. "ControlPort 127.0.0.1:1234\n"
  2899. "HashedControlPassword 16:872860B76453A77D60CA"
  2900. "2BB8C1A7042072093276A3D701AD684053EC4C\n"
  2901. );
  2902. mock_clean_saved_logs();
  2903. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2904. tt_int_op(ret, OP_EQ, 0);
  2905. expect_no_log_msg(
  2906. "ControlPort is open, but no authentication method has been "
  2907. "configured. This means that any program on your computer can "
  2908. "reconfigure your Tor. That's bad! You should upgrade your Tor "
  2909. "controller as soon as possible.\n");
  2910. tor_free(msg);
  2911. free_options_test_data(tdata);
  2912. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2913. "ControlPort 127.0.0.1:1234\n"
  2914. "__HashedControlSessionPassword 16:872860B7645"
  2915. "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
  2916. "4C\n"
  2917. );
  2918. mock_clean_saved_logs();
  2919. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2920. tt_int_op(ret, OP_EQ, 0);
  2921. expect_no_log_msg(
  2922. "ControlPort is open, but no authentication method has been "
  2923. "configured. This means that any program on your computer can "
  2924. "reconfigure your Tor. That's bad! You should upgrade your Tor "
  2925. "controller as soon as possible.\n");
  2926. tor_free(msg);
  2927. free_options_test_data(tdata);
  2928. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2929. "ControlPort 127.0.0.1:1234\n"
  2930. "CookieAuthentication 1\n"
  2931. );
  2932. mock_clean_saved_logs();
  2933. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2934. tt_int_op(ret, OP_EQ, 0);
  2935. expect_no_log_msg(
  2936. "ControlPort is open, but no authentication method has been "
  2937. "configured. This means that any program on your computer can "
  2938. "reconfigure your Tor. That's bad! You should upgrade your Tor "
  2939. "controller as soon as possible.\n");
  2940. tor_free(msg);
  2941. #ifdef HAVE_SYS_UN_H
  2942. free_options_test_data(tdata);
  2943. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2944. "ControlSocket unix:/tmp WorldWritable\n"
  2945. );
  2946. mock_clean_saved_logs();
  2947. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2948. tt_int_op(ret, OP_EQ, 0);
  2949. expect_log_msg(
  2950. "ControlSocket is world writable, but no authentication method has"
  2951. " been configured. This means that any program on your computer "
  2952. "can reconfigure your Tor. That's bad! You should upgrade your "
  2953. "Tor controller as soon as possible.\n");
  2954. tor_free(msg);
  2955. free_options_test_data(tdata);
  2956. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2957. "ControlSocket unix:/tmp WorldWritable\n"
  2958. "HashedControlPassword 16:872860B76453A77D60CA"
  2959. "2BB8C1A7042072093276A3D701AD684053EC4C\n"
  2960. );
  2961. mock_clean_saved_logs();
  2962. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2963. tt_int_op(ret, OP_EQ, 0);
  2964. expect_no_log_msg(
  2965. "ControlSocket is world writable, but no authentication method has"
  2966. " been configured. This means that any program on your computer "
  2967. "can reconfigure your Tor. That's bad! You should upgrade your "
  2968. "Tor controller as soon as possible.\n");
  2969. tor_free(msg);
  2970. free_options_test_data(tdata);
  2971. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2972. "ControlSocket unix:/tmp WorldWritable\n"
  2973. "__HashedControlSessionPassword 16:872860B7645"
  2974. "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
  2975. "4C\n"
  2976. );
  2977. mock_clean_saved_logs();
  2978. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2979. tt_int_op(ret, OP_EQ, 0);
  2980. expect_no_log_msg(
  2981. "ControlSocket is world writable, but no authentication method has"
  2982. " been configured. This means that any program on your computer "
  2983. "can reconfigure your Tor. That's bad! You should upgrade your "
  2984. "Tor controller as soon as possible.\n");
  2985. tor_free(msg);
  2986. free_options_test_data(tdata);
  2987. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  2988. "ControlSocket unix:/tmp WorldWritable\n"
  2989. "CookieAuthentication 1\n"
  2990. );
  2991. mock_clean_saved_logs();
  2992. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  2993. tt_int_op(ret, OP_EQ, 0);
  2994. expect_no_log_msg(
  2995. "ControlSocket is world writable, but no authentication method has"
  2996. " been configured. This means that any program on your computer "
  2997. "can reconfigure your Tor. That's bad! You should upgrade your "
  2998. "Tor controller as soon as possible.\n");
  2999. tor_free(msg);
  3000. #endif
  3001. free_options_test_data(tdata);
  3002. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3003. "CookieAuthFileGroupReadable 1\n"
  3004. );
  3005. mock_clean_saved_logs();
  3006. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3007. tt_int_op(ret, OP_EQ, 0);
  3008. expect_log_msg(
  3009. "CookieAuthFileGroupReadable is set, but will have no effect: you "
  3010. "must specify an explicit CookieAuthFile to have it "
  3011. "group-readable.\n");
  3012. tor_free(msg);
  3013. free_options_test_data(tdata);
  3014. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3015. "CookieAuthFileGroupReadable 1\n"
  3016. "CookieAuthFile /tmp/somewhere\n"
  3017. );
  3018. mock_clean_saved_logs();
  3019. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3020. tt_int_op(ret, OP_EQ, 0);
  3021. expect_no_log_msg(
  3022. "CookieAuthFileGroupReadable is set, but will have no effect: you "
  3023. "must specify an explicit CookieAuthFile to have it "
  3024. "group-readable.\n");
  3025. tor_free(msg);
  3026. done:
  3027. teardown_capture_of_logs();
  3028. policies_free_all();
  3029. free_options_test_data(tdata);
  3030. tor_free(msg);
  3031. }
  3032. static void
  3033. test_options_validate__families(void *ignored)
  3034. {
  3035. (void)ignored;
  3036. int ret;
  3037. char *msg;
  3038. options_test_data_t *tdata = NULL;
  3039. setup_capture_of_logs(LOG_WARN);
  3040. free_options_test_data(tdata);
  3041. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3042. "MyFamily home\n"
  3043. "BridgeRelay 1\n"
  3044. "ORListenAddress 127.0.0.1:5555\n"
  3045. "ORPort 955\n"
  3046. "BandwidthRate 51300\n"
  3047. "BandwidthBurst 51300\n"
  3048. "MaxAdvertisedBandwidth 25700\n"
  3049. "DirCache 1\n"
  3050. );
  3051. mock_clean_saved_logs();
  3052. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3053. tt_int_op(ret, OP_EQ, 0);
  3054. expect_log_msg(
  3055. "Listing a family for a bridge relay is not supported: it can "
  3056. "reveal bridge fingerprints to censors. You should also make sure "
  3057. "you aren't listing this bridge's fingerprint in any other "
  3058. "MyFamily.\n");
  3059. tor_free(msg);
  3060. free_options_test_data(tdata);
  3061. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3062. "MyFamily home\n"
  3063. );
  3064. mock_clean_saved_logs();
  3065. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3066. tt_int_op(ret, OP_EQ, 0);
  3067. expect_no_log_msg(
  3068. "Listing a family for a bridge relay is not supported: it can "
  3069. "reveal bridge fingerprints to censors. You should also make sure "
  3070. "you aren't listing this bridge's fingerprint in any other "
  3071. "MyFamily.\n");
  3072. tor_free(msg);
  3073. free_options_test_data(tdata);
  3074. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3075. "MyFamily !\n"
  3076. );
  3077. mock_clean_saved_logs();
  3078. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3079. tt_int_op(ret, OP_EQ, -1);
  3080. tt_str_op(msg, OP_EQ, "Invalid nickname '!' in MyFamily line");
  3081. tor_free(msg);
  3082. free_options_test_data(tdata);
  3083. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3084. "NodeFamily foo\n"
  3085. "NodeFamily !\n"
  3086. );
  3087. mock_clean_saved_logs();
  3088. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3089. tt_int_op(ret, OP_EQ, -1);
  3090. tt_assert(!msg);
  3091. tor_free(msg);
  3092. done:
  3093. teardown_capture_of_logs();
  3094. policies_free_all();
  3095. free_options_test_data(tdata);
  3096. tor_free(msg);
  3097. }
  3098. static void
  3099. test_options_validate__addr_policies(void *ignored)
  3100. {
  3101. (void)ignored;
  3102. int ret;
  3103. char *msg;
  3104. options_test_data_t *tdata = NULL;
  3105. free_options_test_data(tdata);
  3106. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3107. "ExitPolicy !!!\n"
  3108. "ExitRelay 1\n"
  3109. );
  3110. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3111. tt_int_op(ret, OP_EQ, -1);
  3112. tt_str_op(msg, OP_EQ, "Error in ExitPolicy entry.");
  3113. tor_free(msg);
  3114. done:
  3115. policies_free_all();
  3116. free_options_test_data(tdata);
  3117. tor_free(msg);
  3118. }
  3119. static void
  3120. test_options_validate__dir_auth(void *ignored)
  3121. {
  3122. (void)ignored;
  3123. int ret;
  3124. char *msg;
  3125. options_test_data_t *tdata = NULL;
  3126. setup_capture_of_logs(LOG_WARN);
  3127. free_options_test_data(tdata);
  3128. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3129. VALID_DIR_AUTH
  3130. VALID_ALT_DIR_AUTH
  3131. );
  3132. mock_clean_saved_logs();
  3133. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3134. tt_int_op(ret, OP_EQ, -1);
  3135. tt_str_op(msg, OP_EQ,
  3136. "Directory authority/fallback line did not parse. See logs for "
  3137. "details.");
  3138. expect_log_msg(
  3139. "You cannot set both DirAuthority and Alternate*Authority.\n");
  3140. tor_free(msg);
  3141. free_options_test_data(tdata);
  3142. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3143. "TestingTorNetwork 1\n"
  3144. );
  3145. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3146. tt_int_op(ret, OP_EQ, -1);
  3147. tt_str_op(msg, OP_EQ,
  3148. "TestingTorNetwork may only be configured in combination with a "
  3149. "non-default set of DirAuthority or both of AlternateDirAuthority "
  3150. "and AlternateBridgeAuthority configured.");
  3151. tor_free(msg);
  3152. free_options_test_data(tdata);
  3153. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3154. VALID_DIR_AUTH
  3155. "TestingTorNetwork 1\n"
  3156. );
  3157. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3158. tt_int_op(ret, OP_EQ, 0);
  3159. tor_free(msg);
  3160. free_options_test_data(tdata);
  3161. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3162. "TestingTorNetwork 1\n"
  3163. VALID_ALT_DIR_AUTH
  3164. );
  3165. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3166. tt_int_op(ret, OP_EQ, -1);
  3167. tt_str_op(msg, OP_EQ,
  3168. "TestingTorNetwork may only be configured in combination with a "
  3169. "non-default set of DirAuthority or both of AlternateDirAuthority "
  3170. "and AlternateBridgeAuthority configured.");
  3171. tor_free(msg);
  3172. free_options_test_data(tdata);
  3173. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3174. "TestingTorNetwork 1\n"
  3175. VALID_ALT_BRIDGE_AUTH
  3176. );
  3177. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3178. tt_int_op(ret, OP_EQ, -1);
  3179. tt_str_op(msg, OP_EQ, "TestingTorNetwork may only be configured in "
  3180. "combination with a non-default set of DirAuthority or both of "
  3181. "AlternateDirAuthority and AlternateBridgeAuthority configured.");
  3182. tor_free(msg);
  3183. free_options_test_data(tdata);
  3184. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3185. VALID_ALT_DIR_AUTH
  3186. VALID_ALT_BRIDGE_AUTH
  3187. "TestingTorNetwork 1\n"
  3188. );
  3189. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3190. tt_int_op(ret, OP_EQ, 0);
  3191. tor_free(msg);
  3192. done:
  3193. policies_free_all();
  3194. teardown_capture_of_logs();
  3195. free_options_test_data(tdata);
  3196. tor_free(msg);
  3197. }
  3198. static void
  3199. test_options_validate__transport(void *ignored)
  3200. {
  3201. (void)ignored;
  3202. int ret;
  3203. char *msg;
  3204. options_test_data_t *tdata = NULL;
  3205. setup_capture_of_logs(LOG_NOTICE);
  3206. free_options_test_data(tdata);
  3207. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3208. "ClientTransportPlugin !!\n"
  3209. );
  3210. mock_clean_saved_logs();
  3211. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3212. tt_int_op(ret, OP_EQ, -1);
  3213. tt_str_op(msg, OP_EQ,
  3214. "Invalid client transport line. See logs for details.");
  3215. expect_log_msg(
  3216. "Too few arguments on ClientTransportPlugin line.\n");
  3217. tor_free(msg);
  3218. free_options_test_data(tdata);
  3219. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3220. "ClientTransportPlugin foo exec bar\n"
  3221. );
  3222. mock_clean_saved_logs();
  3223. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3224. tt_int_op(ret, OP_EQ, 0);
  3225. tor_free(msg);
  3226. free_options_test_data(tdata);
  3227. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3228. "ServerTransportPlugin !!\n"
  3229. );
  3230. mock_clean_saved_logs();
  3231. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3232. tt_int_op(ret, OP_EQ, -1);
  3233. tt_str_op(msg, OP_EQ,
  3234. "Invalid server transport line. See logs for details.");
  3235. expect_log_msg(
  3236. "Too few arguments on ServerTransportPlugin line.\n");
  3237. tor_free(msg);
  3238. free_options_test_data(tdata);
  3239. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3240. "ServerTransportPlugin foo exec bar\n"
  3241. );
  3242. mock_clean_saved_logs();
  3243. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3244. tt_int_op(ret, OP_EQ, 0);
  3245. expect_log_msg(
  3246. "Tor is not configured as a relay but you specified a "
  3247. "ServerTransportPlugin line (\"foo exec bar\"). The "
  3248. "ServerTransportPlugin line will be ignored.\n");
  3249. tor_free(msg);
  3250. free_options_test_data(tdata);
  3251. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3252. "ServerTransportPlugin foo exec bar\n"
  3253. "ORListenAddress 127.0.0.1:5555\n"
  3254. "ORPort 955\n"
  3255. "BandwidthRate 76900\n"
  3256. "BandwidthBurst 76900\n"
  3257. "MaxAdvertisedBandwidth 38500\n"
  3258. );
  3259. mock_clean_saved_logs();
  3260. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3261. tt_int_op(ret, OP_EQ, 0);
  3262. expect_no_log_msg(
  3263. "Tor is not configured as a relay but you specified a "
  3264. "ServerTransportPlugin line (\"foo exec bar\"). The "
  3265. "ServerTransportPlugin line will be ignored.\n");
  3266. tor_free(msg);
  3267. free_options_test_data(tdata);
  3268. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3269. "ServerTransportListenAddr foo 127.0.0.42:55\n"
  3270. "ServerTransportListenAddr !\n"
  3271. );
  3272. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3273. tt_int_op(ret, OP_EQ, -1);
  3274. tt_str_op(msg, OP_EQ,
  3275. "ServerTransportListenAddr did not parse. See logs for details.");
  3276. tor_free(msg);
  3277. free_options_test_data(tdata);
  3278. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3279. "ServerTransportListenAddr foo 127.0.0.42:55\n"
  3280. );
  3281. mock_clean_saved_logs();
  3282. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3283. tt_int_op(ret, OP_EQ, 0);
  3284. expect_log_msg(
  3285. "You need at least a single managed-proxy to specify a transport "
  3286. "listen address. The ServerTransportListenAddr line will be "
  3287. "ignored.\n");
  3288. tor_free(msg);
  3289. free_options_test_data(tdata);
  3290. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3291. "ServerTransportListenAddr foo 127.0.0.42:55\n"
  3292. "ServerTransportPlugin foo exec bar\n"
  3293. "ORListenAddress 127.0.0.1:5555\n"
  3294. "ORPort 955\n"
  3295. "BandwidthRate 76900\n"
  3296. "BandwidthBurst 76900\n"
  3297. "MaxAdvertisedBandwidth 38500\n"
  3298. );
  3299. mock_clean_saved_logs();
  3300. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3301. tt_int_op(ret, OP_EQ, 0);
  3302. expect_no_log_msg(
  3303. "You need at least a single managed-proxy to specify a transport "
  3304. "listen address. The ServerTransportListenAddr line will be "
  3305. "ignored.\n");
  3306. done:
  3307. escaped(NULL); // This will free the leaking memory from the previous escaped
  3308. policies_free_all();
  3309. teardown_capture_of_logs();
  3310. free_options_test_data(tdata);
  3311. tor_free(msg);
  3312. }
  3313. static void
  3314. test_options_validate__constrained_sockets(void *ignored)
  3315. {
  3316. (void)ignored;
  3317. int ret;
  3318. char *msg;
  3319. options_test_data_t *tdata = NULL;
  3320. setup_capture_of_logs(LOG_WARN);
  3321. free_options_test_data(tdata);
  3322. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3323. "ConstrainedSockets 1\n"
  3324. "ConstrainedSockSize 0\n"
  3325. );
  3326. mock_clean_saved_logs();
  3327. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3328. tt_int_op(ret, OP_EQ, -1);
  3329. tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
  3330. "between 2048 and 262144 in 1024 byte increments.");
  3331. tor_free(msg);
  3332. free_options_test_data(tdata);
  3333. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3334. "ConstrainedSockets 1\n"
  3335. "ConstrainedSockSize 263168\n"
  3336. );
  3337. mock_clean_saved_logs();
  3338. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3339. tt_int_op(ret, OP_EQ, -1);
  3340. tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
  3341. "between 2048 and 262144 in 1024 byte increments.");
  3342. tor_free(msg);
  3343. free_options_test_data(tdata);
  3344. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3345. "ConstrainedSockets 1\n"
  3346. "ConstrainedSockSize 2047\n"
  3347. );
  3348. mock_clean_saved_logs();
  3349. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3350. tt_int_op(ret, OP_EQ, -1);
  3351. tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
  3352. "between 2048 and 262144 in 1024 byte increments.");
  3353. tor_free(msg);
  3354. free_options_test_data(tdata);
  3355. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3356. "ConstrainedSockets 1\n"
  3357. "ConstrainedSockSize 2048\n"
  3358. "DirPort 999\n"
  3359. "DirCache 1\n"
  3360. );
  3361. mock_clean_saved_logs();
  3362. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3363. tt_int_op(ret, OP_EQ, 0);
  3364. expect_log_msg("You have requested constrained "
  3365. "socket buffers while also serving directory entries via DirPort."
  3366. " It is strongly suggested that you disable serving directory"
  3367. " requests when system TCP buffer resources are scarce.\n");
  3368. tor_free(msg);
  3369. free_options_test_data(tdata);
  3370. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3371. "ConstrainedSockets 1\n"
  3372. "ConstrainedSockSize 2048\n"
  3373. );
  3374. mock_clean_saved_logs();
  3375. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3376. tt_int_op(ret, OP_EQ, 0);
  3377. expect_no_log_msg(
  3378. "You have requested constrained socket buffers while also serving"
  3379. " directory entries via DirPort. It is strongly suggested that "
  3380. "you disable serving directory requests when system TCP buffer "
  3381. "resources are scarce.\n");
  3382. tor_free(msg);
  3383. done:
  3384. policies_free_all();
  3385. teardown_capture_of_logs();
  3386. free_options_test_data(tdata);
  3387. tor_free(msg);
  3388. }
  3389. static void
  3390. test_options_validate__v3_auth(void *ignored)
  3391. {
  3392. (void)ignored;
  3393. int ret;
  3394. char *msg;
  3395. options_test_data_t *tdata = NULL;
  3396. setup_capture_of_logs(LOG_WARN);
  3397. free_options_test_data(tdata);
  3398. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3399. "V3AuthVoteDelay 1000\n"
  3400. "V3AuthDistDelay 1000\n"
  3401. "V3AuthVotingInterval 1000\n"
  3402. );
  3403. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3404. tt_int_op(ret, OP_EQ, -1);
  3405. tt_str_op(msg, OP_EQ,
  3406. "V3AuthVoteDelay plus V3AuthDistDelay must be less than half "
  3407. "V3AuthVotingInterval");
  3408. tor_free(msg);
  3409. free_options_test_data(tdata);
  3410. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3411. "V3AuthVoteDelay 1\n"
  3412. );
  3413. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3414. tt_int_op(ret, OP_EQ, -1);
  3415. tt_str_op(msg, OP_EQ, "V3AuthVoteDelay is way too low.");
  3416. tor_free(msg);
  3417. free_options_test_data(tdata);
  3418. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3419. "V3AuthVoteDelay 1\n"
  3420. "TestingTorNetwork 1\n"
  3421. );
  3422. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3423. tt_int_op(ret, OP_EQ, -1);
  3424. tt_str_op(msg, OP_EQ, "V3AuthVoteDelay is way too low.");
  3425. tor_free(msg);
  3426. // TODO: we can't reach the case of v3authvotedelay lower
  3427. // than MIN_VOTE_SECONDS but not lower than MIN_VOTE_SECONDS_TESTING,
  3428. // since they are the same
  3429. free_options_test_data(tdata);
  3430. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3431. "V3AuthDistDelay 1\n"
  3432. );
  3433. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3434. tt_int_op(ret, OP_EQ, -1);
  3435. tt_str_op(msg, OP_EQ, "V3AuthDistDelay is way too low.");
  3436. tor_free(msg);
  3437. free_options_test_data(tdata);
  3438. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3439. "V3AuthDistDelay 1\n"
  3440. "TestingTorNetwork 1\n"
  3441. );
  3442. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3443. tt_int_op(ret, OP_EQ, -1);
  3444. tt_str_op(msg, OP_EQ, "V3AuthDistDelay is way too low.");
  3445. tor_free(msg);
  3446. // TODO: we can't reach the case of v3authdistdelay lower than
  3447. // MIN_DIST_SECONDS but not lower than MIN_DIST_SECONDS_TESTING,
  3448. // since they are the same
  3449. free_options_test_data(tdata);
  3450. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3451. "V3AuthNIntervalsValid 1\n"
  3452. );
  3453. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3454. tt_int_op(ret, OP_EQ, -1);
  3455. tt_str_op(msg, OP_EQ, "V3AuthNIntervalsValid must be at least 2.");
  3456. tor_free(msg);
  3457. free_options_test_data(tdata);
  3458. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3459. "V3AuthVoteDelay 49\n"
  3460. "V3AuthDistDelay 49\n"
  3461. "V3AuthVotingInterval 200\n"
  3462. );
  3463. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3464. tt_int_op(ret, OP_EQ, -1);
  3465. tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely low.");
  3466. tor_free(msg);
  3467. free_options_test_data(tdata);
  3468. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3469. "V3AuthVoteDelay 49\n"
  3470. "V3AuthDistDelay 49\n"
  3471. "V3AuthVotingInterval 200000\n"
  3472. );
  3473. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3474. tt_int_op(ret, OP_EQ, -1);
  3475. tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely high.");
  3476. tor_free(msg);
  3477. free_options_test_data(tdata);
  3478. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3479. "V3AuthVoteDelay 49\n"
  3480. "V3AuthDistDelay 49\n"
  3481. "V3AuthVotingInterval 1441\n"
  3482. );
  3483. mock_clean_saved_logs();
  3484. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3485. tt_int_op(ret, OP_EQ, 0);
  3486. expect_log_msg("V3AuthVotingInterval does not divide"
  3487. " evenly into 24 hours.\n");
  3488. tor_free(msg);
  3489. free_options_test_data(tdata);
  3490. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3491. "V3AuthVoteDelay 49\n"
  3492. "V3AuthDistDelay 49\n"
  3493. "V3AuthVotingInterval 1440\n"
  3494. );
  3495. mock_clean_saved_logs();
  3496. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3497. tt_int_op(ret, OP_EQ, 0);
  3498. expect_no_log_msg("V3AuthVotingInterval does not divide"
  3499. " evenly into 24 hours.\n");
  3500. tor_free(msg);
  3501. free_options_test_data(tdata);
  3502. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3503. "V3AuthVoteDelay 49\n"
  3504. "V3AuthDistDelay 49\n"
  3505. "V3AuthVotingInterval 299\n"
  3506. VALID_DIR_AUTH
  3507. "TestingTorNetwork 1\n"
  3508. );
  3509. mock_clean_saved_logs();
  3510. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3511. tt_int_op(ret, OP_EQ, 0);
  3512. expect_log_msg("V3AuthVotingInterval is very low. "
  3513. "This may lead to failure to synchronise for a consensus.\n");
  3514. tor_free(msg);
  3515. // TODO: It is impossible to reach the case of testingtor network, with
  3516. // v3authvotinginterval too low
  3517. /* free_options_test_data(tdata); */
  3518. /* tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES */
  3519. /* "V3AuthVoteDelay 1\n" */
  3520. /* "V3AuthDistDelay 1\n" */
  3521. /* "V3AuthVotingInterval 9\n" */
  3522. /* VALID_DIR_AUTH */
  3523. /* "TestingTorNetwork 1\n" */
  3524. /* ); */
  3525. /* ret = options_validate(tdata->old_opt, tdata->opt, */
  3526. /* tdata->def_opt, 0, &msg); */
  3527. /* tt_int_op(ret, OP_EQ, -1); */
  3528. /* tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely low."); */
  3529. free_options_test_data(tdata);
  3530. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3531. "TestingV3AuthInitialVoteDelay 1\n"
  3532. VALID_DIR_AUTH
  3533. "TestingTorNetwork 1\n"
  3534. );
  3535. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3536. tt_int_op(ret, OP_EQ, -1);
  3537. tt_str_op(msg, OP_EQ, "TestingV3AuthInitialVoteDelay is way too low.");
  3538. tor_free(msg);
  3539. free_options_test_data(tdata);
  3540. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3541. "TestingV3AuthInitialDistDelay 1\n"
  3542. VALID_DIR_AUTH
  3543. "TestingTorNetwork 1\n"
  3544. );
  3545. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3546. tt_int_op(ret, OP_EQ, -1);
  3547. tt_str_op(msg, OP_EQ, "TestingV3AuthInitialDistDelay is way too low.");
  3548. tor_free(msg);
  3549. free_options_test_data(tdata);
  3550. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3551. VALID_DIR_AUTH
  3552. "TestingTorNetwork 1\n"
  3553. );
  3554. tdata->opt->TestingV3AuthVotingStartOffset = 100000;
  3555. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3556. tt_int_op(ret, OP_EQ, -1);
  3557. tt_str_op(msg, OP_EQ, "TestingV3AuthVotingStartOffset is higher than the "
  3558. "voting interval.");
  3559. tor_free(msg);
  3560. free_options_test_data(tdata);
  3561. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3562. VALID_DIR_AUTH
  3563. "TestingTorNetwork 1\n"
  3564. );
  3565. tdata->opt->TestingV3AuthVotingStartOffset = -1;
  3566. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3567. tt_int_op(ret, OP_EQ, -1);
  3568. tt_str_op(msg, OP_EQ,
  3569. "TestingV3AuthVotingStartOffset must be non-negative.");
  3570. tor_free(msg);
  3571. free_options_test_data(tdata);
  3572. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3573. VALID_DIR_AUTH
  3574. "TestingTorNetwork 1\n"
  3575. "TestingV3AuthInitialVotingInterval 4\n"
  3576. );
  3577. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3578. tt_int_op(ret, OP_EQ, -1);
  3579. tt_str_op(msg, OP_EQ, "TestingV3AuthInitialVotingInterval is insanely low.");
  3580. tor_free(msg);
  3581. done:
  3582. policies_free_all();
  3583. teardown_capture_of_logs();
  3584. free_options_test_data(tdata);
  3585. tor_free(msg);
  3586. }
  3587. static void
  3588. test_options_validate__virtual_addr(void *ignored)
  3589. {
  3590. (void)ignored;
  3591. int ret;
  3592. char *msg;
  3593. options_test_data_t *tdata = NULL;
  3594. free_options_test_data(tdata);
  3595. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3596. "VirtualAddrNetworkIPv4 !!"
  3597. );
  3598. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3599. tt_int_op(ret, OP_EQ, -1);
  3600. tt_str_op(msg, OP_EQ, "Error parsing VirtualAddressNetwork !!");
  3601. tor_free(msg);
  3602. free_options_test_data(tdata);
  3603. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3604. "VirtualAddrNetworkIPv6 !!"
  3605. );
  3606. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3607. tt_int_op(ret, OP_EQ, -1);
  3608. tt_str_op(msg, OP_EQ, "Error parsing VirtualAddressNetworkIPv6 !!");
  3609. tor_free(msg);
  3610. done:
  3611. escaped(NULL); // This will free the leaking memory from the previous escaped
  3612. policies_free_all();
  3613. free_options_test_data(tdata);
  3614. tor_free(msg);
  3615. }
  3616. static void
  3617. test_options_validate__exits(void *ignored)
  3618. {
  3619. (void)ignored;
  3620. int ret;
  3621. char *msg;
  3622. options_test_data_t *tdata = NULL;
  3623. setup_capture_of_logs(LOG_WARN);
  3624. free_options_test_data(tdata);
  3625. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3626. "AllowSingleHopExits 1"
  3627. );
  3628. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3629. tt_int_op(ret, OP_EQ, 0);
  3630. expect_log_msg("You have set AllowSingleHopExits; "
  3631. "now your relay will allow others to make one-hop exits. However,"
  3632. " since by default most clients avoid relays that set this option,"
  3633. " most clients will ignore you.\n");
  3634. tor_free(msg);
  3635. free_options_test_data(tdata);
  3636. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3637. "AllowSingleHopExits 1\n"
  3638. VALID_DIR_AUTH
  3639. );
  3640. mock_clean_saved_logs();
  3641. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3642. tt_int_op(ret, OP_EQ, 0);
  3643. expect_no_log_msg("You have set AllowSingleHopExits; "
  3644. "now your relay will allow others to make one-hop exits. However,"
  3645. " since by default most clients avoid relays that set this option,"
  3646. " most clients will ignore you.\n");
  3647. tor_free(msg);
  3648. done:
  3649. policies_free_all();
  3650. teardown_capture_of_logs();
  3651. free_options_test_data(tdata);
  3652. tor_free(msg);
  3653. }
  3654. static void
  3655. test_options_validate__testing_options(void *ignored)
  3656. {
  3657. (void)ignored;
  3658. int ret;
  3659. char *msg;
  3660. options_test_data_t *tdata = NULL;
  3661. setup_capture_of_logs(LOG_WARN);
  3662. #define TEST_TESTING_OPTION(name, low_val, high_val, err_low) \
  3663. STMT_BEGIN \
  3664. free_options_test_data(tdata); \
  3665. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
  3666. VALID_DIR_AUTH \
  3667. "TestingTorNetwork 1\n" \
  3668. ); \
  3669. tdata->opt-> name = low_val; \
  3670. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  3671. tt_int_op(ret, OP_EQ, -1); \
  3672. tt_str_op(msg, OP_EQ, #name " " err_low); \
  3673. tor_free(msg); \
  3674. \
  3675. free_options_test_data(tdata); \
  3676. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
  3677. VALID_DIR_AUTH \
  3678. "TestingTorNetwork 1\n" \
  3679. ); \
  3680. tdata->opt-> name = high_val; \
  3681. mock_clean_saved_logs(); \
  3682. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
  3683. tt_int_op(ret, OP_EQ, 0); \
  3684. expect_log_msg( #name " is insanely high.\n"); \
  3685. tor_free(msg); \
  3686. STMT_END
  3687. TEST_TESTING_OPTION(TestingAuthDirTimeToLearnReachability, -1, 8000,
  3688. "must be non-negative.");
  3689. TEST_TESTING_OPTION(TestingEstimatedDescriptorPropagationTime, -1, 3601,
  3690. "must be non-negative.");
  3691. TEST_TESTING_OPTION(TestingClientMaxIntervalWithoutRequest, -1, 3601,
  3692. "is way too low.");
  3693. TEST_TESTING_OPTION(TestingDirConnectionMaxStall, 1, 3601,
  3694. "is way too low.");
  3695. // TODO: I think this points to a bug/regression in options_validate
  3696. TEST_TESTING_OPTION(TestingConsensusMaxDownloadTries, 1, 801,
  3697. "must be greater than 2.");
  3698. TEST_TESTING_OPTION(TestingDescriptorMaxDownloadTries, 1, 801,
  3699. "must be greater than 1.");
  3700. TEST_TESTING_OPTION(TestingMicrodescMaxDownloadTries, 1, 801,
  3701. "must be greater than 1.");
  3702. TEST_TESTING_OPTION(TestingCertMaxDownloadTries, 1, 801,
  3703. "must be greater than 1.");
  3704. free_options_test_data(tdata);
  3705. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3706. "TestingEnableConnBwEvent 1\n"
  3707. );
  3708. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3709. tt_int_op(ret, OP_EQ, -1);
  3710. tt_str_op(msg, OP_EQ, "TestingEnableConnBwEvent may only be changed in "
  3711. "testing Tor networks!");
  3712. tor_free(msg);
  3713. free_options_test_data(tdata);
  3714. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3715. "TestingEnableConnBwEvent 1\n"
  3716. VALID_DIR_AUTH
  3717. "TestingTorNetwork 1\n"
  3718. "___UsingTestNetworkDefaults 0\n"
  3719. );
  3720. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3721. tt_int_op(ret, OP_EQ, 0);
  3722. tt_assert(!msg);
  3723. tor_free(msg);
  3724. free_options_test_data(tdata);
  3725. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3726. "TestingEnableConnBwEvent 1\n"
  3727. VALID_DIR_AUTH
  3728. "TestingTorNetwork 0\n"
  3729. "___UsingTestNetworkDefaults 1\n"
  3730. );
  3731. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3732. tt_int_op(ret, OP_EQ, 0);
  3733. tt_assert(!msg);
  3734. tor_free(msg);
  3735. free_options_test_data(tdata);
  3736. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3737. "TestingEnableCellStatsEvent 1\n"
  3738. );
  3739. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3740. tt_int_op(ret, OP_EQ, -1);
  3741. tt_str_op(msg, OP_EQ, "TestingEnableCellStatsEvent may only be changed in "
  3742. "testing Tor networks!");
  3743. tor_free(msg);
  3744. free_options_test_data(tdata);
  3745. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3746. "TestingEnableCellStatsEvent 1\n"
  3747. VALID_DIR_AUTH
  3748. "TestingTorNetwork 1\n"
  3749. "___UsingTestNetworkDefaults 0\n"
  3750. );
  3751. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3752. tt_int_op(ret, OP_EQ, 0);
  3753. tt_assert(!msg);
  3754. tor_free(msg);
  3755. free_options_test_data(tdata);
  3756. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3757. "TestingEnableCellStatsEvent 1\n"
  3758. VALID_DIR_AUTH
  3759. "TestingTorNetwork 0\n"
  3760. "___UsingTestNetworkDefaults 1\n"
  3761. );
  3762. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3763. tt_int_op(ret, OP_EQ, 0);
  3764. tt_assert(!msg);
  3765. tor_free(msg);
  3766. free_options_test_data(tdata);
  3767. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3768. "TestingEnableTbEmptyEvent 1\n"
  3769. );
  3770. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3771. tt_int_op(ret, OP_EQ, -1);
  3772. tt_str_op(msg, OP_EQ, "TestingEnableTbEmptyEvent may only be changed "
  3773. "in testing Tor networks!");
  3774. tor_free(msg);
  3775. free_options_test_data(tdata);
  3776. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3777. "TestingEnableTbEmptyEvent 1\n"
  3778. VALID_DIR_AUTH
  3779. "TestingTorNetwork 1\n"
  3780. "___UsingTestNetworkDefaults 0\n"
  3781. );
  3782. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3783. tt_int_op(ret, OP_EQ, 0);
  3784. tt_assert(!msg);
  3785. tor_free(msg);
  3786. free_options_test_data(tdata);
  3787. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3788. "TestingEnableTbEmptyEvent 1\n"
  3789. VALID_DIR_AUTH
  3790. "TestingTorNetwork 0\n"
  3791. "___UsingTestNetworkDefaults 1\n"
  3792. );
  3793. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3794. tt_int_op(ret, OP_EQ, 0);
  3795. tt_assert(!msg);
  3796. tor_free(msg);
  3797. done:
  3798. policies_free_all();
  3799. teardown_capture_of_logs();
  3800. free_options_test_data(tdata);
  3801. tor_free(msg);
  3802. }
  3803. static void
  3804. test_options_validate__accel(void *ignored)
  3805. {
  3806. (void)ignored;
  3807. int ret;
  3808. char *msg;
  3809. options_test_data_t *tdata = NULL;
  3810. free_options_test_data(tdata);
  3811. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3812. "AccelName foo\n"
  3813. );
  3814. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3815. tt_int_op(ret, OP_EQ, 0);
  3816. tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 1);
  3817. tor_free(msg);
  3818. free_options_test_data(tdata);
  3819. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3820. "AccelName foo\n"
  3821. );
  3822. tdata->opt->HardwareAccel = 2;
  3823. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3824. tt_int_op(ret, OP_EQ, 0);
  3825. tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 2);
  3826. tor_free(msg);
  3827. free_options_test_data(tdata);
  3828. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3829. "AccelDir 1\n"
  3830. );
  3831. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3832. tt_int_op(ret, OP_EQ, -1);
  3833. tt_str_op(msg, OP_EQ,
  3834. "Can't use hardware crypto accelerator dir without engine name.");
  3835. tor_free(msg);
  3836. free_options_test_data(tdata);
  3837. tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
  3838. "AccelDir 1\n"
  3839. "AccelName something\n"
  3840. );
  3841. ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
  3842. tt_int_op(ret, OP_EQ, 0);
  3843. tor_free(msg);
  3844. done:
  3845. policies_free_all();
  3846. free_options_test_data(tdata);
  3847. tor_free(msg);
  3848. }
  3849. #define LOCAL_VALIDATE_TEST(name) \
  3850. { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
  3851. struct testcase_t options_tests[] = {
  3852. { "validate", test_options_validate, TT_FORK, NULL, NULL },
  3853. { "mem_dircache", test_have_enough_mem_for_dircache, TT_FORK, NULL, NULL },
  3854. LOCAL_VALIDATE_TEST(uname_for_server),
  3855. LOCAL_VALIDATE_TEST(outbound_addresses),
  3856. LOCAL_VALIDATE_TEST(data_directory),
  3857. LOCAL_VALIDATE_TEST(nickname),
  3858. LOCAL_VALIDATE_TEST(contactinfo),
  3859. LOCAL_VALIDATE_TEST(logs),
  3860. LOCAL_VALIDATE_TEST(authdir),
  3861. LOCAL_VALIDATE_TEST(relay_with_hidden_services),
  3862. LOCAL_VALIDATE_TEST(transproxy),
  3863. LOCAL_VALIDATE_TEST(exclude_nodes),
  3864. LOCAL_VALIDATE_TEST(scheduler),
  3865. LOCAL_VALIDATE_TEST(node_families),
  3866. LOCAL_VALIDATE_TEST(tlsec),
  3867. LOCAL_VALIDATE_TEST(token_bucket),
  3868. LOCAL_VALIDATE_TEST(recommended_packages),
  3869. LOCAL_VALIDATE_TEST(fetch_dir),
  3870. LOCAL_VALIDATE_TEST(conn_limit),
  3871. LOCAL_VALIDATE_TEST(paths_needed),
  3872. LOCAL_VALIDATE_TEST(max_client_circuits),
  3873. LOCAL_VALIDATE_TEST(ports),
  3874. LOCAL_VALIDATE_TEST(reachable_addresses),
  3875. LOCAL_VALIDATE_TEST(use_bridges),
  3876. LOCAL_VALIDATE_TEST(entry_nodes),
  3877. LOCAL_VALIDATE_TEST(invalid_nodes),
  3878. LOCAL_VALIDATE_TEST(safe_logging),
  3879. LOCAL_VALIDATE_TEST(publish_server_descriptor),
  3880. LOCAL_VALIDATE_TEST(testing),
  3881. LOCAL_VALIDATE_TEST(hidserv),
  3882. LOCAL_VALIDATE_TEST(predicted_ports),
  3883. LOCAL_VALIDATE_TEST(path_bias),
  3884. LOCAL_VALIDATE_TEST(bandwidth),
  3885. LOCAL_VALIDATE_TEST(circuits),
  3886. LOCAL_VALIDATE_TEST(port_forwarding),
  3887. LOCAL_VALIDATE_TEST(tor2web),
  3888. LOCAL_VALIDATE_TEST(rend),
  3889. LOCAL_VALIDATE_TEST(accounting),
  3890. LOCAL_VALIDATE_TEST(proxy),
  3891. LOCAL_VALIDATE_TEST(control),
  3892. LOCAL_VALIDATE_TEST(families),
  3893. LOCAL_VALIDATE_TEST(addr_policies),
  3894. LOCAL_VALIDATE_TEST(dir_auth),
  3895. LOCAL_VALIDATE_TEST(transport),
  3896. LOCAL_VALIDATE_TEST(constrained_sockets),
  3897. LOCAL_VALIDATE_TEST(v3_auth),
  3898. LOCAL_VALIDATE_TEST(virtual_addr),
  3899. LOCAL_VALIDATE_TEST(exits),
  3900. LOCAL_VALIDATE_TEST(testing_options),
  3901. LOCAL_VALIDATE_TEST(accel),
  3902. END_OF_TESTCASES /* */
  3903. };