123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551 |
- /* Copyright (c) 2001-2004, Roger Dingledine.
- * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2016, The Tor Project, Inc. */
- /* See LICENSE for licensing information */
- #define CONFIG_PRIVATE
- #include "or.h"
- #include "confparse.h"
- #include "config.h"
- #include "test.h"
- #include "geoip.h"
- #define ROUTERSET_PRIVATE
- #include "routerset.h"
- #include "main.h"
- #include "log_test_helpers.h"
- #include "sandbox.h"
- #include "memarea.h"
- #include "policies.h"
- #define NS_MODULE test_options
- typedef struct {
- int severity;
- uint32_t domain;
- char *msg;
- } logmsg_t;
- static smartlist_t *messages = NULL;
- static void
- log_cback(int severity, uint32_t domain, const char *msg)
- {
- logmsg_t *x = tor_malloc(sizeof(*x));
- x->severity = severity;
- x->domain = domain;
- x->msg = tor_strdup(msg);
- if (!messages)
- messages = smartlist_new();
- smartlist_add(messages, x);
- }
- static void
- setup_log_callback(void)
- {
- log_severity_list_t lst;
- memset(&lst, 0, sizeof(lst));
- lst.masks[LOG_ERR - LOG_ERR] = ~0;
- lst.masks[LOG_WARN - LOG_ERR] = ~0;
- lst.masks[LOG_NOTICE - LOG_ERR] = ~0;
- add_callback_log(&lst, log_cback);
- mark_logs_temp();
- }
- static char *
- dump_logs(void)
- {
- smartlist_t *msgs;
- char *out;
- if (! messages)
- return tor_strdup("");
- msgs = smartlist_new();
- SMARTLIST_FOREACH_BEGIN(messages, logmsg_t *, x) {
- smartlist_add_asprintf(msgs, "[%s] %s",
- log_level_to_string(x->severity), x->msg);
- } SMARTLIST_FOREACH_END(x);
- out = smartlist_join_strings(msgs, "", 0, NULL);
- SMARTLIST_FOREACH(msgs, char *, cp, tor_free(cp));
- smartlist_free(msgs);
- return out;
- }
- static void
- clear_log_messages(void)
- {
- if (!messages)
- return;
- SMARTLIST_FOREACH(messages, logmsg_t *, m,
- { tor_free(m->msg); tor_free(m); });
- smartlist_free(messages);
- messages = NULL;
- }
- #define setup_options(opt,dflt) \
- do { \
- opt = options_new(); \
- opt->command = CMD_RUN_TOR; \
- options_init(opt); \
- \
- dflt = config_dup(&options_format, opt); \
- clear_log_messages(); \
- } while (0)
- #define VALID_DIR_AUTH "DirAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- #define VALID_ALT_BRIDGE_AUTH \
- "AlternateBridgeAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- #define VALID_ALT_DIR_AUTH \
- "AlternateDirAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- static void
- test_options_validate_impl(const char *configuration,
- const char *expect_errmsg,
- int expect_log_severity,
- const char *expect_log)
- {
- or_options_t *opt=NULL;
- or_options_t *dflt;
- config_line_t *cl=NULL;
- char *msg=NULL;
- int r;
- setup_options(opt, dflt);
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- r = options_validate(NULL, opt, dflt, 0, &msg);
- if (expect_errmsg && !msg) {
- TT_DIE(("Expected error message <%s> from <%s>, but got none.",
- expect_errmsg, configuration));
- } else if (expect_errmsg && !strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- } else if (!expect_errmsg && msg) {
- TT_DIE(("Expected no error message from <%s> but got <%s>.",
- configuration, msg));
- }
- tt_int_op((r == 0), OP_EQ, (msg == NULL));
- if (expect_log) {
- int found = 0;
- if (messages) {
- SMARTLIST_FOREACH_BEGIN(messages, logmsg_t *, m) {
- if (m->severity == expect_log_severity &&
- strstr(m->msg, expect_log)) {
- found = 1;
- break;
- }
- } SMARTLIST_FOREACH_END(m);
- }
- if (!found) {
- tor_free(msg);
- msg = dump_logs();
- TT_DIE(("Expected log message [%s] %s from <%s>, but got <%s>.",
- log_level_to_string(expect_log_severity), expect_log,
- configuration, msg));
- }
- }
- done:
- escaped(NULL);
- policies_free_all();
- config_free_lines(cl);
- or_options_free(opt);
- or_options_free(dflt);
- tor_free(msg);
- clear_log_messages();
- }
- #define WANT_ERR(config, msg) \
- test_options_validate_impl((config), (msg), 0, NULL)
- #define WANT_LOG(config, severity, msg) \
- test_options_validate_impl((config), NULL, (severity), (msg))
- #define WANT_ERR_LOG(config, msg, severity, logmsg) \
- test_options_validate_impl((config), (msg), (severity), (logmsg))
- #define OK(config) \
- test_options_validate_impl((config), NULL, 0, NULL)
- static void
- test_options_validate(void *arg)
- {
- (void)arg;
- setup_log_callback();
- sandbox_disable_getaddrinfo_cache();
- WANT_ERR("ExtORPort 500000", "Invalid ExtORPort");
- WANT_ERR_LOG("ServerTransportOptions trebuchet",
- "ServerTransportOptions did not parse",
- LOG_WARN, "Too few arguments");
- OK("ServerTransportOptions trebuchet sling=snappy");
- OK("ServerTransportOptions trebuchet sling=");
- WANT_ERR_LOG("ServerTransportOptions trebuchet slingsnappy",
- "ServerTransportOptions did not parse",
- LOG_WARN, "\"slingsnappy\" is not a k=v");
- WANT_ERR("DirPort 8080\nDirCache 0",
- "DirPort configured but DirCache disabled.");
- WANT_ERR("BridgeRelay 1\nDirCache 0",
- "We're a bridge but DirCache is disabled.");
- close_temp_logs();
- clear_log_messages();
- return;
- }
- #define MEGABYTEIFY(mb) (U64_LITERAL(mb) << 20)
- static void
- test_have_enough_mem_for_dircache(void *arg)
- {
- (void)arg;
- or_options_t *opt=NULL;
- or_options_t *dflt=NULL;
- config_line_t *cl=NULL;
- char *msg=NULL;;
- int r;
- const char *configuration = "ORPort 8080\nDirCache 1", *expect_errmsg;
- setup_options(opt, dflt);
- setup_log_callback();
- (void)dflt;
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 300 MB RAM available, DirCache enabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 200 MB RAM available, DirCache enabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "Being a directory cache (default) with less than ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- config_free_lines(cl); cl = NULL;
- configuration = "ORPort 8080\nDirCache 1\nBridgeRelay 1";
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 300 MB RAM available, DirCache enabled, Bridge */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 200 MB RAM available, DirCache enabled, Bridge */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "Running a Bridge with less than ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- config_free_lines(cl); cl = NULL;
- configuration = "ORPort 8080\nDirCache 0";
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 200 MB RAM available, DirCache disabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 300 MB RAM available, DirCache disabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "DirCache is disabled and we are configured as a ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- clear_log_messages();
- done:
- if (msg)
- tor_free(msg);
- or_options_free(dflt);
- or_options_free(opt);
- config_free_lines(cl);
- return;
- }
- static const char *fixed_get_uname_result = NULL;
- static const char *
- fixed_get_uname(void)
- {
- return fixed_get_uname_result;
- }
- #define TEST_OPTIONS_OLD_VALUES "TestingV3AuthInitialVotingInterval 1800\n" \
- "ClientBootstrapConsensusMaxDownloadTries 7\n" \
- "ClientBootstrapConsensusAuthorityOnlyMaxDownloadTries 4\n" \
- "ClientBootstrapConsensusMaxInProgressTries 3\n" \
- "TestingV3AuthInitialVoteDelay 300\n" \
- "TestingV3AuthInitialDistDelay 300\n" \
- "TestingClientMaxIntervalWithoutRequest 600\n" \
- "TestingDirConnectionMaxStall 600\n" \
- "TestingConsensusMaxDownloadTries 8\n" \
- "TestingDescriptorMaxDownloadTries 8\n" \
- "TestingMicrodescMaxDownloadTries 8\n" \
- "TestingCertMaxDownloadTries 8\n"
- #define TEST_OPTIONS_DEFAULT_VALUES TEST_OPTIONS_OLD_VALUES \
- "MaxClientCircuitsPending 1\n" \
- "RendPostPeriod 1000\n" \
- "KeepAlivePeriod 1\n" \
- "ConnLimit 1\n" \
- "V3AuthVotingInterval 300\n" \
- "V3AuthVoteDelay 20\n" \
- "V3AuthDistDelay 20\n" \
- "V3AuthNIntervalsValid 3\n" \
- "ClientUseIPv4 1\n" \
- "VirtualAddrNetworkIPv4 127.192.0.0/10\n" \
- "VirtualAddrNetworkIPv6 [FE80::]/10\n" \
- "SchedulerHighWaterMark__ 42\n" \
- "SchedulerLowWaterMark__ 10\n"
- typedef struct {
- or_options_t *old_opt;
- or_options_t *opt;
- or_options_t *def_opt;
- } options_test_data_t;
- static void free_options_test_data(options_test_data_t *td);
- static options_test_data_t *
- get_options_test_data(const char *conf)
- {
- int rv = -1;
- char *msg = NULL;
- config_line_t *cl=NULL;
- options_test_data_t *result = tor_malloc(sizeof(options_test_data_t));
- result->opt = options_new();
- result->old_opt = options_new();
- result->def_opt = options_new();
- rv = config_get_lines(conf, &cl, 1);
- tt_assert(rv == 0);
- rv = config_assign(&options_format, result->opt, cl, 0, &msg);
- if (msg) {
- /* Display the parse error message by comparing it with an empty string */
- tt_str_op(msg, OP_EQ, "");
- }
- tt_assert(rv == 0);
- config_free_lines(cl);
- result->opt->LogTimeGranularity = 1;
- result->opt->TokenBucketRefillInterval = 1;
- rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
- tt_assert(rv == 0);
- rv = config_assign(&options_format, result->def_opt, cl, 0, &msg);
- if (msg) {
- /* Display the parse error message by comparing it with an empty string */
- tt_str_op(msg, OP_EQ, "");
- }
- tt_assert(rv == 0);
- done:
- config_free_lines(cl);
- if (rv != 0) {
- free_options_test_data(result);
- result = NULL;
- /* Callers expect a non-NULL result, so just die if we can't provide one.
- */
- tor_assert(0);
- }
- return result;
- }
- static void
- free_options_test_data(options_test_data_t *td)
- {
- if (!td) return;
- or_options_free(td->old_opt);
- or_options_free(td->opt);
- or_options_free(td->def_opt);
- tor_free(td);
- }
- static void
- test_options_validate__uname_for_server(void *ignored)
- {
- (void)ignored;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "ORListenAddress 127.0.0.1:5555");
- setup_capture_of_logs(LOG_WARN);
- MOCK(get_uname, fixed_get_uname);
- fixed_get_uname_result = "Windows 95";
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Tor is running as a server, but you"
- " are running Windows 95; this probably won't work. See https://www"
- ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
- tor_free(msg);
- fixed_get_uname_result = "Windows 98";
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Tor is running as a server, but you"
- " are running Windows 98; this probably won't work. See https://www"
- ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
- tor_free(msg);
- fixed_get_uname_result = "Windows Me";
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Tor is running as a server, but you"
- " are running Windows Me; this probably won't work. See https://www"
- ".torproject.org/docs/faq.html#BestOSForRelay for details.\n");
- tor_free(msg);
- fixed_get_uname_result = "Windows 2000";
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_entry();
- tor_free(msg);
- done:
- UNMOCK(get_uname);
- free_options_test_data(tdata);
- tor_free(msg);
- teardown_capture_of_logs();
- }
- static void
- test_options_validate__outbound_addresses(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "OutboundBindAddress xxyy!!!sdfaf");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__data_directory(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "DataDirectory longreallyl"
- "ongLONGLONGlongreallylong"
- "LONGLONGlongreallylongLON"
- "GLONGlongreallylongLONGLO"
- "NGlongreallylongLONGLONGl"
- "ongreallylongLONGLONGlong"
- "reallylongLONGLONGlongrea"
- "llylongLONGLONGlongreally"
- "longLONGLONGlongreallylon"
- "gLONGLONGlongreallylongLO"
- "NGLONGlongreallylongLONGL"
- "ONGlongreallylongLONGLONG"
- "longreallylongLONGLONGlon"
- "greallylongLONGLONGlongre"
- "allylongLONGLONGlongreall"
- "ylongLONGLONGlongreallylo"
- "ngLONGLONGlongreallylongL"
- "ONGLONGlongreallylongLONG"
- "LONG"); // 440 characters
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Invalid DataDirectory");
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__nickname(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "Nickname ThisNickNameIsABitTooLong");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Nickname 'ThisNickNameIsABitTooLong', nicknames must be between "
- "1 and 19 characters inclusive, and must contain only the "
- "characters [a-zA-Z0-9].");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("Nickname AMoreValidNick");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("DataDirectory /tmp/somewhere");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__contactinfo(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "ORListenAddress 127.0.0.1:5555\nORPort 955");
- setup_capture_of_logs(LOG_DEBUG);
- tdata->opt->ContactInfo = NULL;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg(
- "Your ContactInfo config option is not"
- " set. Please consider setting it, so we can contact you if your"
- " server is misconfigured or something else goes wrong.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ORListenAddress 127.0.0.1:5555\nORPort 955\n"
- "ContactInfo hella@example.org");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg(
- "Your ContactInfo config option is not"
- " set. Please consider setting it, so we can contact you if your"
- " server is misconfigured or something else goes wrong.\n");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__logs(void *ignored)
- {
- (void)ignored;
- int ret;
- (void)ret;
- char *msg;
- int orig_quiet_level = quiet_level;
- options_test_data_t *tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log");
- tt_str_op(tdata->opt->Logs->value, OP_EQ, "notice stdout");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- quiet_level = 1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log");
- tt_str_op(tdata->opt->Logs->value, OP_EQ, "warn stdout");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- quiet_level = 2;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 1, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->RunAsDaemon = 0;
- config_line_t *cl=NULL;
- config_get_lines("Log foo", &cl, 1);
- tdata->opt->Logs = cl;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op((intptr_t)tdata->opt->Logs, OP_EQ, (intptr_t)cl);
- done:
- quiet_level = orig_quiet_level;
- free_options_test_data(tdata);
- tor_free(msg);
- }
- /* static config_line_t * */
- /* mock_config_line(const char *key, const char *val) */
- /* { */
- /* config_line_t *config_line = tor_malloc(sizeof(config_line_t)); */
- /* memset(config_line, 0, sizeof(config_line_t)); */
- /* config_line->key = tor_strdup(key); */
- /* config_line->value = tor_strdup(val); */
- /* return config_line; */
- /* } */
- static void
- test_options_validate__authdir(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_INFO);
- options_test_data_t *tdata = get_options_test_data(
- "AuthoritativeDirectory 1\n"
- "Address this.should.not_exist.example.org");
- sandbox_disable_getaddrinfo_cache();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Failed to resolve/guess local address. See logs for"
- " details.");
- expect_log_msg("Could not resolve local Address "
- "'this.should.not_exist.example.org'. Failing.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Authoritative directory servers must set ContactInfo");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "TestingTorNetwork 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "1.2, 3.14");
- tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "1.2, 3.14");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "RecommendedClientVersions 25\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "25");
- tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "4.18");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "RecommendedClientVersions 25\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
- "Recommended*Versions.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedClientVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
- "Recommended*Versions.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "UseEntryGuards 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Authoritative directory servers "
- "can't set UseEntryGuards. Disabling.\n");
- tt_int_op(tdata->opt->UseEntryGuards, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "V3AuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Authoritative directories always try"
- " to download extra-info documents. Setting DownloadExtraInfo.\n");
- tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "DownloadExtraInfo 1\n"
- "V3AuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_no_log_msg("Authoritative directories always try"
- " to download extra-info documents. Setting DownloadExtraInfo.\n");
- tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "V3BandwidthsFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "V3BandwidthsFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "GuardfractionFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "GuardfractionFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "DirPort 999\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no ORPort set.");
- tor_free(msg);
- // TODO: This case can't be reached, since clientonly is used to
- // check when parsing port lines as well.
- /* free_options_test_data(tdata); */
- /* tdata = get_options_test_data("AuthoritativeDirectory 1\n" */
- /* "Address 100.200.10.1\n" */
- /* "DirPort 999\n" */
- /* "ORPort 888\n" */
- /* "ClientOnly 1\n" */
- /* "BridgeAuthoritativeDir 1\n" */
- /* "ContactInfo hello@hello.com\n" */
- /* "SchedulerHighWaterMark__ 42\n" */
- /* "SchedulerLowWaterMark__ 10\n"); */
- /* mock_clean_saved_logs(); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* tt_int_op(ret, OP_EQ, -1); */
- /* tt_str_op(msg, OP_EQ, "Running as authoritative directory, " */
- /* "but ClientOnly also set."); */
- done:
- teardown_capture_of_logs();
- // sandbox_free_getaddrinfo_cache();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__relay_with_hidden_services(void *ignored)
- {
- (void)ignored;
- char *msg;
- setup_capture_of_logs(LOG_DEBUG);
- options_test_data_t *tdata = get_options_test_data(
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "HiddenServiceDir "
- "/Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg(
- "Tor is currently configured as a relay and a hidden service. "
- "That's not very secure: you should probably run your hidden servi"
- "ce in a separate Tor process, at least -- see "
- "https://trac.torproject.org/8742\n");
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- // TODO: it doesn't seem possible to hit the case of having no port lines at
- // all, since there will be a default created for SocksPort
- /* static void */
- /* test_options_validate__ports(void *ignored) */
- /* { */
- /* (void)ignored; */
- /* int ret; */
- /* char *msg; */
- /* setup_capture_of_logs(LOG_WARN); */
- /* options_test_data_t *tdata = get_options_test_data(""); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort " */
- /* "are all undefined, and there aren't any hidden services " */
- /* "configured. " */
- /* " Tor will still run, but probably won't do anything.\n"); */
- /* done: */
- /* teardown_capture_of_logs(); */
- /* free_options_test_data(tdata); */
- /* tor_free(msg); */
- /* } */
- static void
- test_options_validate__transproxy(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata;
- #ifdef USE_TRANSPARENT
- // Test default trans proxy
- tdata = get_options_test_data("TransProxyType default\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_DEFAULT);
- tor_free(msg);
- // Test pf-divert trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType pf-divert\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- #if !defined(__OpenBSD__) && !defined( DARWIN )
- tt_str_op(msg, OP_EQ,
- "pf-divert is a OpenBSD-specific and OS X/Darwin-specific feature.");
- #else
- tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_PF_DIVERT);
- tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without "
- "any valid TransPort or TransListenAddress.");
- #endif
- tor_free(msg);
- // Test tproxy trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType tproxy\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- #if !defined(__linux__)
- tt_str_op(msg, OP_EQ, "TPROXY is a Linux-specific feature.");
- #else
- tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_TPROXY);
- tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without any valid "
- "TransPort or TransListenAddress.");
- #endif
- tor_free(msg);
- // Test ipfw trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType ipfw\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- #ifndef KERNEL_MAY_SUPPORT_IPFW
- tt_str_op(msg, OP_EQ, "ipfw is a FreeBSD-specific and OS X/Darwin-specific "
- "feature.");
- #else
- tt_int_op(tdata->opt->TransProxyType_parsed, OP_EQ, TPT_IPFW);
- tt_str_op(msg, OP_EQ, "Cannot use TransProxyType without any valid "
- "TransPort or TransListenAddress.");
- #endif
- tor_free(msg);
- // Test unknown trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType non-existant\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value for TransProxyType");
- tor_free(msg);
- // Test trans proxy success
- free_options_test_data(tdata);
- tdata = NULL;
- #if defined(__linux__)
- tdata = get_options_test_data("TransProxyType tproxy\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(KERNEL_MAY_SUPPORT_IPFW)
- tdata = get_options_test_data("TransProxyType ipfw\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(__OpenBSD__)
- tdata = get_options_test_data("TransProxyType pf-divert\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(__NetBSD__)
- tdata = get_options_test_data("TransProxyType default\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #endif
- // Assert that a test has run for some TransProxyType
- tt_assert(tdata);
- #else
- tdata = get_options_test_data("TransPort 127.0.0.1:555\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TransPort and TransListenAddress are disabled in "
- "this build.");
- tor_free(msg);
- #endif
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- NS_DECL(country_t, geoip_get_country, (const char *country));
- static country_t
- NS(geoip_get_country)(const char *countrycode)
- {
- (void)countrycode;
- CALLED(geoip_get_country)++;
- return 1;
- }
- static void
- test_options_validate__exclude_nodes(void *ignored)
- {
- (void)ignored;
- NS_MOCK(geoip_get_country);
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "ExcludeExitNodes {us}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{us}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{cn}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "ExcludeExitNodes {us} {cn}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 2);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{us} {cn}");
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 1)),
- OP_EQ, "{cn}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "StrictNodes 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg(
- "You have asked to exclude certain relays from all positions "
- "in your circuits. Expect hidden services and other Tor "
- "features to be broken in unpredictable ways.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg(
- "You have asked to exclude certain relays from all positions "
- "in your circuits. Expect hidden services and other Tor "
- "features to be broken in unpredictable ways.\n");
- tor_free(msg);
- done:
- NS_UNMOCK(geoip_get_country);
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__scheduler(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_DEBUG);
- options_test_data_t *tdata = get_options_test_data(
- "SchedulerLowWaterMark__ 0\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Bad SchedulerLowWaterMark__ option\n");
- tor_free(msg);
- // TODO: this test cannot run on platforms where UINT32_MAX == UINT64_MAX.
- // I suspect it's unlikely this branch can actually happen
- /* free_options_test_data(tdata); */
- /* tdata = get_options_test_data( */
- /* "SchedulerLowWaterMark 10000000000000000000\n"); */
- /* tdata->opt->SchedulerLowWaterMark__ = (uint64_t)UINT32_MAX; */
- /* tdata->opt->SchedulerLowWaterMark__++; */
- /* mock_clean_saved_logs(); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* tt_int_op(ret, OP_EQ, -1); */
- /* expect_log_msg("Bad SchedulerLowWaterMark__ option\n"); */
- free_options_test_data(tdata);
- tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n"
- "SchedulerHighWaterMark__ 42\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Bad SchedulerHighWaterMark option\n");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__node_families(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "NodeFamily flux, flax\n"
- "NodeFamily somewhere\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->NodeFamilySets);
- tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 2);
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 0)),
- OP_EQ, "flux");
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 1)),
- OP_EQ, "flax");
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 1))->list, 0)),
- OP_EQ, "somewhere");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!tdata->opt->NodeFamilySets);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("NodeFamily !flux\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->NodeFamilySets);
- tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 0);
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__tlsec(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_DEBUG);
- options_test_data_t *tdata = get_options_test_data(
- "TLSECGroup ed25519\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Unrecognized TLSECGroup: Falling back to the default.\n");
- tt_assert(!tdata->opt->TLSECGroup);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("TLSECGroup P224\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg(
- "Unrecognized TLSECGroup: Falling back to the default.\n");
- tt_assert(tdata->opt->TLSECGroup);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("TLSECGroup P256\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg(
- "Unrecognized TLSECGroup: Falling back to the default.\n");
- tt_assert(tdata->opt->TLSECGroup);
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__token_bucket(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data("");
- tdata->opt->TokenBucketRefillInterval = 0;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
- tor_free(msg);
- tdata->opt->TokenBucketRefillInterval = 1001;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__recommended_packages(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "RecommendedPackages foo 1.2 http://foo.com sha1=123123123123\n"
- "RecommendedPackages invalid-package-line\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg("Invalid RecommendedPackage line "
- "invalid-package-line will be ignored\n");
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__fetch_dir(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "FetchDirInfoExtraEarly 1\n"
- "FetchDirInfoEarly 0\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "FetchDirInfoExtraEarly requires that you"
- " also set FetchDirInfoEarly");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FetchDirInfoExtraEarly 1\n"
- "FetchDirInfoEarly 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "FetchDirInfoExtraEarly requires that you"
- " also set FetchDirInfoEarly");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__conn_limit(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "ConnLimit 0\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024, "
- "but was set to 0");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__paths_needed(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PathsNeededToBuildCircuits 0.1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.24 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.26);
- expect_log_msg("PathsNeededToBuildCircuits is too low. "
- "Increasing to 0.25\n");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("PathsNeededToBuildCircuits 0.99\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.94 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.96);
- expect_log_msg("PathsNeededToBuildCircuits is "
- "too high. Decreasing to 0.95\n");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("PathsNeededToBuildCircuits 0.91\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.92);
- expect_no_log_entry();
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__max_client_circuits(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "MaxClientCircuitsPending 0\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
- " but was set to 0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("MaxClientCircuitsPending 1025\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
- " but was set to 1025");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__ports(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "FirewallPorts 65537\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '65537' out of range in FirewallPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 124444\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '124444' out of range in LongLivedPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 112233\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '112233' out of range in RejectPlaintextPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 3\n"
- "WarnPlaintextPorts 65536\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '65536' out of range in WarnPlaintextPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 3\n"
- "WarnPlaintextPorts 4\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__reachable_addresses(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_NOTICE);
- options_test_data_t *tdata = get_options_test_data(
- "FascistFirewall 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Converting FascistFirewall config "
- "option to new format: \"ReachableDirAddresses *:80\"\n");
- tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:80");
- expect_log_msg("Converting FascistFirewall config "
- "option to new format: \"ReachableORAddresses *:443\"\n");
- tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:443");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "ReachableDirAddresses *:81\n"
- "ReachableORAddresses *:444\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- tdata->opt->FirewallPorts = smartlist_new();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_entry();
- tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:81");
- tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "FirewallPort 123\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Converting FascistFirewall and "
- "FirewallPorts config options to new format: "
- "\"ReachableAddresses *:123\"\n");
- tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:123");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "ReachableAddresses *:82\n"
- "ReachableAddresses *:83\n"
- "ReachableAddresses reject *:*\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_entry();
- tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:82");
- tor_free(msg);
- #define SERVERS_REACHABLE_MSG "Servers must be able to freely connect to" \
- " the rest of the Internet, so they must not set Reachable*Addresses or" \
- " FascistFirewall or FirewallPorts or ClientUseIPv4 0."
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableAddresses *:82\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableORAddresses *:82\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableDirAddresses *:82\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ClientUseIPv4 0\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- /* Test IPv4-only clients setting IPv6 preferences */
- #define WARN_PLEASE_USE_IPV6_OR_LOG_MSG \
- "ClientPreferIPv6ORPort 1 is ignored unless tor is using IPv6. " \
- "Please set ClientUseIPv6 1, ClientUseIPv4 0, or configure bridges.\n"
- #define WARN_PLEASE_USE_IPV6_DIR_LOG_MSG \
- "ClientPreferIPv6DirPort 1 is ignored unless tor is using IPv6. " \
- "Please set ClientUseIPv6 1, ClientUseIPv4 0, or configure bridges.\n"
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientUseIPv4 1\n"
- "ClientUseIPv6 0\n"
- "UseBridges 0\n"
- "ClientPreferIPv6ORPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(WARN_PLEASE_USE_IPV6_OR_LOG_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientUseIPv4 1\n"
- "ClientUseIPv6 0\n"
- "UseBridges 0\n"
- "ClientPreferIPv6DirPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(WARN_PLEASE_USE_IPV6_DIR_LOG_MSG);
- tor_free(msg);
- /* Now test an IPv4/IPv6 client setting IPv6 preferences */
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientUseIPv4 1\n"
- "ClientUseIPv6 1\n"
- "ClientPreferIPv6ORPort 1\n"
- "ClientPreferIPv6DirPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- /* Now test an IPv6 client setting IPv6 preferences */
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientUseIPv6 1\n"
- "ClientPreferIPv6ORPort 1\n"
- "ClientPreferIPv6DirPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- /* And an implicit (IPv4 disabled) IPv6 client setting IPv6 preferences */
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientUseIPv4 0\n"
- "ClientPreferIPv6ORPort 1\n"
- "ClientPreferIPv6DirPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- /* And an implicit (bridge) client setting IPv6 preferences */
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseBridges 1\n"
- "Bridge 127.0.0.1:12345\n"
- "ClientPreferIPv6ORPort 1\n"
- "ClientPreferIPv6DirPort 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__use_bridges(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "UseBridges 1\n"
- "ClientUseIPv4 1\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Servers must be able to freely connect to the rest of"
- " the Internet, so they must not set UseBridges.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("UseBridges 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "Servers must be able to freely connect to the rest of"
- " the Internet, so they must not set UseBridges.");
- tor_free(msg);
- NS_MOCK(geoip_get_country);
- free_options_test_data(tdata);
- tdata = get_options_test_data("UseBridges 1\n"
- "EntryNodes {cn}\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "You cannot set both UseBridges and EntryNodes.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseBridges 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "If you set UseBridges, you must specify at least one bridge.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseBridges 1\n"
- "Bridge 10.0.0.1\n"
- "Bridge !!!\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bridge line did not parse. See logs for details.");
- tor_free(msg);
- done:
- NS_UNMOCK(geoip_get_country);
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__entry_nodes(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- NS_MOCK(geoip_get_country);
- options_test_data_t *tdata = get_options_test_data(
- "EntryNodes {cn}\n"
- "UseEntryGuards 0\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "If EntryNodes is set, UseEntryGuards must be enabled.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("EntryNodes {cn}\n"
- "UseEntryGuards 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- NS_UNMOCK(geoip_get_country);
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__invalid_nodes(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "AllowInvalidNodes something_stupid\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Unrecognized value 'something_stupid' in AllowInvalidNodes");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AllowInvalidNodes entry, middle, exit\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->AllowInvalid_, OP_EQ, ALLOW_INVALID_ENTRY |
- ALLOW_INVALID_EXIT | ALLOW_INVALID_MIDDLE);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AllowInvalidNodes introduction, rendezvous\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->AllowInvalid_, OP_EQ, ALLOW_INVALID_INTRODUCTION |
- ALLOW_INVALID_RENDEZVOUS);
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__safe_logging(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging 0\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging Relay\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_RELAY);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_ALL);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging stuffy\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value '\"stuffy\"' in SafeLogging");
- tor_free(msg);
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__publish_server_descriptor(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PublishServerDescriptor bridge\n" TEST_OPTIONS_DEFAULT_VALUES
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("PublishServerDescriptor humma\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value in PublishServerDescriptor");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("PublishServerDescriptor bridge, v3\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n"
- "PublishServerDescriptor v3\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n" TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n"
- "DirPort 999\n" TEST_OPTIONS_DEFAULT_VALUES);
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Can't set a DirPort on a bridge "
- "relay; disabling DirPort\n");
- tt_assert(!tdata->opt->DirPort_lines);
- tt_assert(!tdata->opt->DirPort_set);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__testing(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- #define ENSURE_DEFAULT(varname, varval) \
- STMT_BEGIN \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n"); \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- tt_str_op(msg, OP_EQ, \
- #varname " may only be changed in testing Tor networks!"); \
- tt_int_op(ret, OP_EQ, -1); \
- tor_free(msg); \
- \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n" \
- VALID_DIR_AUTH \
- "TestingTorNetwork 1\n"); \
- \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- if (msg) { \
- tt_str_op(msg, OP_NE, \
- #varname " may only be changed in testing Tor networks!"); \
- tor_free(msg); \
- } \
- \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n" \
- "___UsingTestNetworkDefaults 1\n"); \
- \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- if (msg) { \
- tt_str_op(msg, OP_NE, \
- #varname " may only be changed in testing Tor networks!"); \
- tor_free(msg); \
- } \
- STMT_END
- ENSURE_DEFAULT(TestingV3AuthInitialVotingInterval, 3600);
- ENSURE_DEFAULT(TestingV3AuthInitialVoteDelay, 3000);
- ENSURE_DEFAULT(TestingV3AuthInitialDistDelay, 3000);
- ENSURE_DEFAULT(TestingV3AuthVotingStartOffset, 3000);
- ENSURE_DEFAULT(TestingAuthDirTimeToLearnReachability, 3000);
- ENSURE_DEFAULT(TestingEstimatedDescriptorPropagationTime, 3000);
- ENSURE_DEFAULT(TestingServerDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingServerConsensusDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientConsensusDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingBridgeDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientMaxIntervalWithoutRequest, 3000);
- ENSURE_DEFAULT(TestingDirConnectionMaxStall, 3000);
- ENSURE_DEFAULT(TestingConsensusMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingDescriptorMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingMicrodescMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingCertMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingAuthKeyLifetime, 3000);
- ENSURE_DEFAULT(TestingLinkCertLifetime, 3000);
- ENSURE_DEFAULT(TestingSigningKeySlop, 3000);
- ENSURE_DEFAULT(TestingAuthKeySlop, 3000);
- ENSURE_DEFAULT(TestingLinkKeySlop, 3000);
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__hidserv(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES);
- tdata->opt->MinUptimeHidServDirectoryV2 = -1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("MinUptimeHidServDirectoryV2 "
- "option must be at least 0 seconds. Changing to 0.\n");
- tt_int_op(tdata->opt->MinUptimeHidServDirectoryV2, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RendPostPeriod 1\n" );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("RendPostPeriod option is too short;"
- " raising to 600 seconds.\n");
- tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 600);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RendPostPeriod 302401\n" );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("RendPostPeriod is too large; "
- "clipping to 302400s.\n");
- tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 302400);
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__predicted_ports(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PredictedPortsRelevanceTime 100000000\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("PredictedPortsRelevanceTime is too "
- "large; clipping to 3600s.\n");
- tt_int_op(tdata->opt->PredictedPortsRelevanceTime, OP_EQ, 3600);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__path_bias(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "PathBiasNoticeRate 1.1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "PathBiasNoticeRate is too high. It must be between 0 and 1.0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PathBiasWarnRate 1.1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "PathBiasWarnRate is too high. It must be between 0 and 1.0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PathBiasExtremeRate 1.1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "PathBiasExtremeRate is too high. It must be between 0 and 1.0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PathBiasNoticeUseRate 1.1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "PathBiasNoticeUseRate is too high. It must be between 0 and 1.0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PathBiasExtremeUseRate 1.1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "PathBiasExtremeUseRate is too high. It must be between 0 and 1.0");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__bandwidth(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- #define ENSURE_BANDWIDTH_PARAM(p) \
- STMT_BEGIN \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES #p " 3Gb\n"); \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- tt_int_op(ret, OP_EQ, -1); \
- tt_mem_op(msg, OP_EQ, #p " (3221225471) must be at most 2147483647", 40); \
- tor_free(msg); \
- STMT_END
- ENSURE_BANDWIDTH_PARAM(BandwidthRate);
- ENSURE_BANDWIDTH_PARAM(BandwidthBurst);
- ENSURE_BANDWIDTH_PARAM(MaxAdvertisedBandwidth);
- ENSURE_BANDWIDTH_PARAM(RelayBandwidthRate);
- ENSURE_BANDWIDTH_PARAM(RelayBandwidthBurst);
- ENSURE_BANDWIDTH_PARAM(PerConnBWRate);
- ENSURE_BANDWIDTH_PARAM(PerConnBWBurst);
- ENSURE_BANDWIDTH_PARAM(AuthDirFastGuarantee);
- ENSURE_BANDWIDTH_PARAM(AuthDirGuardBWGuarantee);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RelayBandwidthRate 1000\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_u64_op(tdata->opt->RelayBandwidthBurst, OP_EQ, 1000);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RelayBandwidthBurst 1001\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_u64_op(tdata->opt->RelayBandwidthRate, OP_EQ, 1001);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RelayBandwidthRate 1001\n"
- "RelayBandwidthBurst 1000\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "RelayBandwidthBurst must be at least equal to "
- "RelayBandwidthRate.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "BandwidthRate 1001\n"
- "BandwidthBurst 1000\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "BandwidthBurst must be at least equal to BandwidthRate.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RelayBandwidthRate 1001\n"
- "BandwidthRate 1000\n"
- "BandwidthBurst 1000\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_u64_op(tdata->opt->BandwidthRate, OP_EQ, 1001);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RelayBandwidthRate 1001\n"
- "BandwidthRate 1000\n"
- "RelayBandwidthBurst 1001\n"
- "BandwidthBurst 1000\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_u64_op(tdata->opt->BandwidthBurst, OP_EQ, 1001);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "BandwidthRate is set to 1 bytes/second. For servers,"
- " it must be at least 76800.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76800\n"
- "MaxAdvertisedBandwidth 30000\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxAdvertisedBandwidth is set to 30000 bytes/second."
- " For servers, it must be at least 38400.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76800\n"
- "RelayBandwidthRate 1\n"
- "MaxAdvertisedBandwidth 38400\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "RelayBandwidthRate is set to 1 bytes/second. For "
- "servers, it must be at least 76800.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76800\n"
- "BandwidthBurst 76800\n"
- "RelayBandwidthRate 76800\n"
- "MaxAdvertisedBandwidth 38400\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__circuits(void *ignored)
- {
- (void)ignored;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "MaxCircuitDirtiness 2592001\n");
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("MaxCircuitDirtiness option is too "
- "high; setting to 30 days.\n");
- tt_int_op(tdata->opt->MaxCircuitDirtiness, OP_EQ, 2592000);
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CircuitStreamTimeout 1\n");
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("CircuitStreamTimeout option is too"
- " short; raising to 10 seconds.\n");
- tt_int_op(tdata->opt->CircuitStreamTimeout, OP_EQ, 10);
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CircuitStreamTimeout 111\n");
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_no_log_msg("CircuitStreamTimeout option is too"
- " short; raising to 10 seconds.\n");
- tt_int_op(tdata->opt->CircuitStreamTimeout, OP_EQ, 111);
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HeartbeatPeriod 1\n");
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("HeartbeatPeriod option is too short;"
- " raising to 1800 seconds.\n");
- tt_int_op(tdata->opt->HeartbeatPeriod, OP_EQ, 1800);
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HeartbeatPeriod 1982\n");
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_no_log_msg("HeartbeatPeriod option is too short;"
- " raising to 1800 seconds.\n");
- tt_int_op(tdata->opt->HeartbeatPeriod, OP_EQ, 1982);
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CircuitBuildTimeout 1\n"
- );
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("CircuitBuildTimeout is shorter (1"
- " seconds) than the recommended minimum (10 seconds), and "
- "LearnCircuitBuildTimeout is disabled. If tor isn't working, "
- "raise this value or enable LearnCircuitBuildTimeout.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CircuitBuildTimeout 11\n"
- );
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_no_log_msg("CircuitBuildTimeout is shorter (1 "
- "seconds) than the recommended minimum (10 seconds), and "
- "LearnCircuitBuildTimeout is disabled. If tor isn't working, "
- "raise this value or enable LearnCircuitBuildTimeout.\n");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__port_forwarding(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PortForwarding 1\nSandbox 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "PortForwarding is not compatible with Sandbox;"
- " at most one can be set");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PortForwarding 1\nSandbox 0\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- policies_free_all();
- tor_free(msg);
- }
- static void
- test_options_validate__tor2web(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Tor2webRendezvousPoints 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Tor2webRendezvousPoints cannot be set without Tor2webMode.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Tor2webRendezvousPoints 1\nTor2webMode 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__rend(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseEntryGuards 0\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("UseEntryGuards is disabled, but you"
- " have configured one or more hidden services on this Tor "
- "instance. Your hidden services will be very easy to locate using"
- " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
- "attack06 for details.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "UseEntryGuards 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("UseEntryGuards is disabled, but you"
- " have configured one or more hidden services on this Tor "
- "instance. Your hidden services will be very easy to locate using"
- " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
- "attack06 for details.\n");
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Failed to configure rendezvous options. See logs for details.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HidServAuth failed\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Failed to configure client authorization for hidden "
- "services. See logs for details.");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__single_onion(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- /* Test that HiddenServiceSingleHopMode must come with
- * HiddenServiceNonAnonymousMode */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceSingleHopMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceNonAnonymousMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceSingleHopMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceNonAnonymousMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- /* Test that SOCKSPort must come with Tor2webMode if
- * HiddenServiceSingleHopMode is 1 */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode is incompatible with "
- "using Tor as an anonymous client. Please set "
- "Socks/Trans/NATD/DNSPort to 0, or HiddenServiceNonAnonymousMode "
- "to 0, or use the non-anonymous Tor2webMode.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 0\n"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- "Tor2webMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- /* Test that a hidden service can't be run with Tor2web
- * Use HiddenServiceNonAnonymousMode instead of Tor2webMode, because
- * Tor2webMode requires a compilation #define */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceSingleHopMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceSingleHopMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- "HiddenServiceSingleHopMode 1\n"
- "SOCKSPort 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__accounting(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule something_bad\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AccountingRule must be 'sum', 'max', 'in', or 'out'");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule sum\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_SUM);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule max\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_MAX);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingStart fail\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Failed to parse accounting options. See logs for details.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingMax 10\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76800\n"
- "BandwidthBurst 76800\n"
- "MaxAdvertisedBandwidth 38400\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- "AccountingMax 10\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("Using accounting with a hidden "
- "service and an ORPort is risky: your hidden service(s) and "
- "your public address will all turn off at the same time, "
- "which may alert observers that they are being run by the "
- "same party.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- "AccountingMax 10\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("Using accounting with a hidden "
- "service and an ORPort is risky: your hidden service(s) and "
- "your public address will all turn off at the same time, "
- "which may alert observers that they are being run by the "
- "same party.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service2/\n"
- "HiddenServicePort 81 127.0.0.1:8081\n"
- "AccountingMax 10\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("Using accounting with multiple "
- "hidden services is risky: they will all turn off at the same"
- " time, which may alert observers that they are being run by "
- "the same party.\n");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__proxy(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- sandbox_disable_getaddrinfo_cache();
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 127.0.42.1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HTTPProxyPort, OP_EQ, 80);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 127.0.42.1:444\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HTTPProxyPort, OP_EQ, 444);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy not_so_valid!\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HTTPProxy failed to parse or resolve. Please fix.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxyAuthenticator "
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreeonetwothreeonetwothree"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HTTPProxyAuthenticator is too long (>= 512 chars).");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxyAuthenticator validauth\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpsProxy 127.0.42.1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HTTPSProxyPort, OP_EQ, 443);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpsProxy 127.0.42.1:444\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HTTPSProxyPort, OP_EQ, 444);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpsProxy not_so_valid!\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HTTPSProxy failed to parse or resolve. Please fix.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpsProxyAuthenticator "
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreonetwothreonetwothreonetwothre"
- "onetwothreonetwothreonetwothreonetwothreonetw"
- "othreonetwothreeonetwothreeonetwothree"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HTTPSProxyAuthenticator is too long (>= 512 chars).");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpsProxyAuthenticator validauth\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks4Proxy 127.0.42.1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->Socks4ProxyPort, OP_EQ, 1080);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks4Proxy 127.0.42.1:444\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->Socks4ProxyPort, OP_EQ, 444);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks4Proxy not_so_valid!\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Socks4Proxy failed to parse or resolve. Please fix.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5Proxy 127.0.42.1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->Socks5ProxyPort, OP_EQ, 1080);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5Proxy 127.0.42.1:444\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->Socks5ProxyPort, OP_EQ, 444);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5Proxy not_so_valid!\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Socks5Proxy failed to parse or resolve. Please fix.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks4Proxy 215.1.1.1\n"
- "Socks5Proxy 215.1.1.2\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "You have configured more than one proxy type. "
- "(Socks4Proxy|Socks5Proxy|HTTPSProxy)");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 215.1.1.1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("HTTPProxy configured, but no SOCKS "
- "proxy or HTTPS proxy configured. Watch out: this configuration "
- "will proxy unencrypted directory connections only.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 215.1.1.1\n"
- "Socks4Proxy 215.1.1.1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("HTTPProxy configured, but no SOCKS "
- "proxy or HTTPS proxy configured. Watch out: this configuration "
- "will proxy unencrypted directory connections only.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 215.1.1.1\n"
- "Socks5Proxy 215.1.1.1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("HTTPProxy configured, but no SOCKS "
- "proxy or HTTPS proxy configured. Watch out: this configuration "
- "will proxy unencrypted directory connections only.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HttpProxy 215.1.1.1\n"
- "HttpsProxy 215.1.1.1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "HTTPProxy configured, but no SOCKS proxy or HTTPS proxy "
- "configured. Watch out: this configuration will proxy "
- "unencrypted directory connections only.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- );
- tdata->opt->Socks5ProxyUsername = tor_strdup("");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Socks5ProxyUsername must be between 1 and 255 characters.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- );
- tdata->opt->Socks5ProxyUsername =
- tor_strdup("ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789AB"
- "CDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCD"
- "EABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEA"
- "BCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABC"
- "DE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Socks5ProxyUsername must be between 1 and 255 characters.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5ProxyUsername hello_world\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Socks5ProxyPassword must be included with "
- "Socks5ProxyUsername.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5ProxyUsername hello_world\n"
- );
- tdata->opt->Socks5ProxyPassword = tor_strdup("");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Socks5ProxyPassword must be between 1 and 255 characters.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5ProxyUsername hello_world\n"
- );
- tdata->opt->Socks5ProxyPassword =
- tor_strdup("ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789AB"
- "CDEABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCD"
- "EABCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEA"
- "BCDE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789ABCDEABC"
- "DE0123456789ABCDEABCDE0123456789ABCDEABCDE0123456789");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Socks5ProxyPassword must be between 1 and 255 characters.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5ProxyUsername hello_world\n"
- "Socks5ProxyPassword world_hello\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Socks5ProxyPassword hello_world\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Socks5ProxyPassword must be included with "
- "Socks5ProxyUsername.");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- policies_free_all();
- // sandbox_free_getaddrinfo_cache();
- tor_free(msg);
- }
- static void
- test_options_validate__control(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HashedControlPassword something_incorrect\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Bad HashedControlPassword: wrong length or bad encoding");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HashedControlPassword 16:872860B76453A77D60CA"
- "2BB8C1A7042072093276A3D701AD684053EC4C\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "__HashedControlSessionPassword something_incorrect\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bad HashedControlSessionPassword: wrong length or "
- "bad encoding");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "__HashedControlSessionPassword 16:872860B7645"
- "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
- "4C\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "__OwningControllerProcess something_incorrect\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bad OwningControllerProcess: invalid PID");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "__OwningControllerProcess 123\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlPort 127.0.0.1:1234\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "ControlPort is open, but no authentication method has been "
- "configured. This means that any program on your computer can "
- "reconfigure your Tor. That's bad! You should upgrade your Tor"
- " controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlPort 127.0.0.1:1234\n"
- "HashedControlPassword 16:872860B76453A77D60CA"
- "2BB8C1A7042072093276A3D701AD684053EC4C\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlPort is open, but no authentication method has been "
- "configured. This means that any program on your computer can "
- "reconfigure your Tor. That's bad! You should upgrade your Tor "
- "controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlPort 127.0.0.1:1234\n"
- "__HashedControlSessionPassword 16:872860B7645"
- "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
- "4C\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlPort is open, but no authentication method has been "
- "configured. This means that any program on your computer can "
- "reconfigure your Tor. That's bad! You should upgrade your Tor "
- "controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlPort 127.0.0.1:1234\n"
- "CookieAuthentication 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlPort is open, but no authentication method has been "
- "configured. This means that any program on your computer can "
- "reconfigure your Tor. That's bad! You should upgrade your Tor "
- "controller as soon as possible.\n");
- tor_free(msg);
- #ifdef HAVE_SYS_UN_H
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlSocket unix:/tmp WorldWritable\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "ControlSocket is world writable, but no authentication method has"
- " been configured. This means that any program on your computer "
- "can reconfigure your Tor. That's bad! You should upgrade your "
- "Tor controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlSocket unix:/tmp WorldWritable\n"
- "HashedControlPassword 16:872860B76453A77D60CA"
- "2BB8C1A7042072093276A3D701AD684053EC4C\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlSocket is world writable, but no authentication method has"
- " been configured. This means that any program on your computer "
- "can reconfigure your Tor. That's bad! You should upgrade your "
- "Tor controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlSocket unix:/tmp WorldWritable\n"
- "__HashedControlSessionPassword 16:872860B7645"
- "3A77D60CA2BB8C1A7042072093276A3D701AD684053EC"
- "4C\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlSocket is world writable, but no authentication method has"
- " been configured. This means that any program on your computer "
- "can reconfigure your Tor. That's bad! You should upgrade your "
- "Tor controller as soon as possible.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ControlSocket unix:/tmp WorldWritable\n"
- "CookieAuthentication 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "ControlSocket is world writable, but no authentication method has"
- " been configured. This means that any program on your computer "
- "can reconfigure your Tor. That's bad! You should upgrade your "
- "Tor controller as soon as possible.\n");
- tor_free(msg);
- #endif
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CookieAuthFileGroupReadable 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "CookieAuthFileGroupReadable is set, but will have no effect: you "
- "must specify an explicit CookieAuthFile to have it "
- "group-readable.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "CookieAuthFileGroupReadable 1\n"
- "CookieAuthFile /tmp/somewhere\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "CookieAuthFileGroupReadable is set, but will have no effect: you "
- "must specify an explicit CookieAuthFile to have it "
- "group-readable.\n");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__families(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "MyFamily home\n"
- "BridgeRelay 1\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 51300\n"
- "BandwidthBurst 51300\n"
- "MaxAdvertisedBandwidth 25700\n"
- "DirCache 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "Listing a family for a bridge relay is not supported: it can "
- "reveal bridge fingerprints to censors. You should also make sure "
- "you aren't listing this bridge's fingerprint in any other "
- "MyFamily.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "MyFamily home\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "Listing a family for a bridge relay is not supported: it can "
- "reveal bridge fingerprints to censors. You should also make sure "
- "you aren't listing this bridge's fingerprint in any other "
- "MyFamily.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "MyFamily !\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Invalid nickname '!' in MyFamily line");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "NodeFamily foo\n"
- "NodeFamily !\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__addr_policies(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ExitPolicy !!!\n"
- "ExitRelay 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Error in ExitPolicy entry.");
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__dir_auth(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_DIR_AUTH
- VALID_ALT_DIR_AUTH
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Directory authority/fallback line did not parse. See logs for "
- "details.");
- expect_log_msg(
- "You cannot set both DirAuthority and Alternate*Authority.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TestingTorNetwork may only be configured in combination with a "
- "non-default set of DirAuthority or both of AlternateDirAuthority "
- "and AlternateBridgeAuthority configured.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingTorNetwork 1\n"
- VALID_ALT_DIR_AUTH
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TestingTorNetwork may only be configured in combination with a "
- "non-default set of DirAuthority or both of AlternateDirAuthority "
- "and AlternateBridgeAuthority configured.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingTorNetwork 1\n"
- VALID_ALT_BRIDGE_AUTH
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingTorNetwork may only be configured in "
- "combination with a non-default set of DirAuthority or both of "
- "AlternateDirAuthority and AlternateBridgeAuthority configured.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_ALT_DIR_AUTH
- VALID_ALT_BRIDGE_AUTH
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__transport(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_NOTICE);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientTransportPlugin !!\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Invalid client transport line. See logs for details.");
- expect_log_msg(
- "Too few arguments on ClientTransportPlugin line.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ClientTransportPlugin foo exec bar\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportPlugin !!\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Invalid server transport line. See logs for details.");
- expect_log_msg(
- "Too few arguments on ServerTransportPlugin line.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportPlugin foo exec bar\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "Tor is not configured as a relay but you specified a "
- "ServerTransportPlugin line (\"foo exec bar\"). The "
- "ServerTransportPlugin line will be ignored.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportPlugin foo exec bar\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76900\n"
- "BandwidthBurst 76900\n"
- "MaxAdvertisedBandwidth 38500\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "Tor is not configured as a relay but you specified a "
- "ServerTransportPlugin line (\"foo exec bar\"). The "
- "ServerTransportPlugin line will be ignored.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportListenAddr foo 127.0.0.42:55\n"
- "ServerTransportListenAddr !\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "ServerTransportListenAddr did not parse. See logs for details.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportListenAddr foo 127.0.0.42:55\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg(
- "You need at least a single managed-proxy to specify a transport "
- "listen address. The ServerTransportListenAddr line will be "
- "ignored.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ServerTransportListenAddr foo 127.0.0.42:55\n"
- "ServerTransportPlugin foo exec bar\n"
- "ORListenAddress 127.0.0.1:5555\n"
- "ORPort 955\n"
- "BandwidthRate 76900\n"
- "BandwidthBurst 76900\n"
- "MaxAdvertisedBandwidth 38500\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "You need at least a single managed-proxy to specify a transport "
- "listen address. The ServerTransportListenAddr line will be "
- "ignored.\n");
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__constrained_sockets(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ConstrainedSockets 1\n"
- "ConstrainedSockSize 0\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
- "between 2048 and 262144 in 1024 byte increments.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ConstrainedSockets 1\n"
- "ConstrainedSockSize 263168\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
- "between 2048 and 262144 in 1024 byte increments.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ConstrainedSockets 1\n"
- "ConstrainedSockSize 2047\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "ConstrainedSockSize is invalid. Must be a value "
- "between 2048 and 262144 in 1024 byte increments.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ConstrainedSockets 1\n"
- "ConstrainedSockSize 2048\n"
- "DirPort 999\n"
- "DirCache 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("You have requested constrained "
- "socket buffers while also serving directory entries via DirPort."
- " It is strongly suggested that you disable serving directory"
- " requests when system TCP buffer resources are scarce.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "ConstrainedSockets 1\n"
- "ConstrainedSockSize 2048\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg(
- "You have requested constrained socket buffers while also serving"
- " directory entries via DirPort. It is strongly suggested that "
- "you disable serving directory requests when system TCP buffer "
- "resources are scarce.\n");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__v3_auth(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 1000\n"
- "V3AuthDistDelay 1000\n"
- "V3AuthVotingInterval 1000\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "V3AuthVoteDelay plus V3AuthDistDelay must be less than half "
- "V3AuthVotingInterval");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthVoteDelay is way too low.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 1\n"
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthVoteDelay is way too low.");
- tor_free(msg);
- // TODO: we can't reach the case of v3authvotedelay lower
- // than MIN_VOTE_SECONDS but not lower than MIN_VOTE_SECONDS_TESTING,
- // since they are the same
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthDistDelay 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthDistDelay is way too low.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthDistDelay 1\n"
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthDistDelay is way too low.");
- tor_free(msg);
- // TODO: we can't reach the case of v3authdistdelay lower than
- // MIN_DIST_SECONDS but not lower than MIN_DIST_SECONDS_TESTING,
- // since they are the same
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthNIntervalsValid 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthNIntervalsValid must be at least 2.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 49\n"
- "V3AuthDistDelay 49\n"
- "V3AuthVotingInterval 200\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely low.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 49\n"
- "V3AuthDistDelay 49\n"
- "V3AuthVotingInterval 200000\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely high.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 49\n"
- "V3AuthDistDelay 49\n"
- "V3AuthVotingInterval 1441\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("V3AuthVotingInterval does not divide"
- " evenly into 24 hours.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 49\n"
- "V3AuthDistDelay 49\n"
- "V3AuthVotingInterval 1440\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("V3AuthVotingInterval does not divide"
- " evenly into 24 hours.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "V3AuthVoteDelay 49\n"
- "V3AuthDistDelay 49\n"
- "V3AuthVotingInterval 299\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("V3AuthVotingInterval is very low. "
- "This may lead to failure to synchronise for a consensus.\n");
- tor_free(msg);
- // TODO: It is impossible to reach the case of testingtor network, with
- // v3authvotinginterval too low
- /* free_options_test_data(tdata); */
- /* tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES */
- /* "V3AuthVoteDelay 1\n" */
- /* "V3AuthDistDelay 1\n" */
- /* "V3AuthVotingInterval 9\n" */
- /* VALID_DIR_AUTH */
- /* "TestingTorNetwork 1\n" */
- /* ); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* tt_int_op(ret, OP_EQ, -1); */
- /* tt_str_op(msg, OP_EQ, "V3AuthVotingInterval is insanely low."); */
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingV3AuthInitialVoteDelay 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingV3AuthInitialVoteDelay is way too low.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingV3AuthInitialDistDelay 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingV3AuthInitialDistDelay is way too low.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- tdata->opt->TestingV3AuthVotingStartOffset = 100000;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingV3AuthVotingStartOffset is higher than the "
- "voting interval.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- );
- tdata->opt->TestingV3AuthVotingStartOffset = -1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TestingV3AuthVotingStartOffset must be non-negative.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "TestingV3AuthInitialVotingInterval 4\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingV3AuthInitialVotingInterval is insanely low.");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__virtual_addr(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "VirtualAddrNetworkIPv4 !!"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Error parsing VirtualAddressNetwork !!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "VirtualAddrNetworkIPv6 !!"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Error parsing VirtualAddressNetworkIPv6 !!");
- tor_free(msg);
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__exits(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AllowSingleHopExits 1"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("You have set AllowSingleHopExits; "
- "now your relay will allow others to make one-hop exits. However,"
- " since by default most clients avoid relays that set this option,"
- " most clients will ignore you.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AllowSingleHopExits 1\n"
- VALID_DIR_AUTH
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("You have set AllowSingleHopExits; "
- "now your relay will allow others to make one-hop exits. However,"
- " since by default most clients avoid relays that set this option,"
- " most clients will ignore you.\n");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__testing_options(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- #define TEST_TESTING_OPTION(name, low_val, high_val, err_low) \
- STMT_BEGIN \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- VALID_DIR_AUTH \
- "TestingTorNetwork 1\n" \
- ); \
- tdata->opt-> name = low_val; \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- tt_int_op(ret, OP_EQ, -1); \
- tt_str_op(msg, OP_EQ, #name " " err_low); \
- tor_free(msg); \
- \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- VALID_DIR_AUTH \
- "TestingTorNetwork 1\n" \
- ); \
- tdata->opt-> name = high_val; \
- mock_clean_saved_logs(); \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- tt_int_op(ret, OP_EQ, 0); \
- expect_log_msg( #name " is insanely high.\n"); \
- tor_free(msg); \
- STMT_END
- TEST_TESTING_OPTION(TestingAuthDirTimeToLearnReachability, -1, 8000,
- "must be non-negative.");
- TEST_TESTING_OPTION(TestingEstimatedDescriptorPropagationTime, -1, 3601,
- "must be non-negative.");
- TEST_TESTING_OPTION(TestingClientMaxIntervalWithoutRequest, -1, 3601,
- "is way too low.");
- TEST_TESTING_OPTION(TestingDirConnectionMaxStall, 1, 3601,
- "is way too low.");
- // TODO: I think this points to a bug/regression in options_validate
- TEST_TESTING_OPTION(TestingConsensusMaxDownloadTries, 1, 801,
- "must be greater than 2.");
- TEST_TESTING_OPTION(TestingDescriptorMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- TEST_TESTING_OPTION(TestingMicrodescMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- TEST_TESTING_OPTION(TestingCertMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableConnBwEvent may only be changed in "
- "testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableCellStatsEvent may only be changed in "
- "testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableTbEmptyEvent may only be changed "
- "in testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__accel(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelName foo\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelName foo\n"
- );
- tdata->opt->HardwareAccel = 2;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 2);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelDir 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Can't use hardware crypto accelerator dir without engine name.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelDir 1\n"
- "AccelName something\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- #define LOCAL_VALIDATE_TEST(name) \
- { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
- struct testcase_t options_tests[] = {
- { "validate", test_options_validate, TT_FORK, NULL, NULL },
- { "mem_dircache", test_have_enough_mem_for_dircache, TT_FORK, NULL, NULL },
- LOCAL_VALIDATE_TEST(uname_for_server),
- LOCAL_VALIDATE_TEST(outbound_addresses),
- LOCAL_VALIDATE_TEST(data_directory),
- LOCAL_VALIDATE_TEST(nickname),
- LOCAL_VALIDATE_TEST(contactinfo),
- LOCAL_VALIDATE_TEST(logs),
- LOCAL_VALIDATE_TEST(authdir),
- LOCAL_VALIDATE_TEST(relay_with_hidden_services),
- LOCAL_VALIDATE_TEST(transproxy),
- LOCAL_VALIDATE_TEST(exclude_nodes),
- LOCAL_VALIDATE_TEST(scheduler),
- LOCAL_VALIDATE_TEST(node_families),
- LOCAL_VALIDATE_TEST(tlsec),
- LOCAL_VALIDATE_TEST(token_bucket),
- LOCAL_VALIDATE_TEST(recommended_packages),
- LOCAL_VALIDATE_TEST(fetch_dir),
- LOCAL_VALIDATE_TEST(conn_limit),
- LOCAL_VALIDATE_TEST(paths_needed),
- LOCAL_VALIDATE_TEST(max_client_circuits),
- LOCAL_VALIDATE_TEST(ports),
- LOCAL_VALIDATE_TEST(reachable_addresses),
- LOCAL_VALIDATE_TEST(use_bridges),
- LOCAL_VALIDATE_TEST(entry_nodes),
- LOCAL_VALIDATE_TEST(invalid_nodes),
- LOCAL_VALIDATE_TEST(safe_logging),
- LOCAL_VALIDATE_TEST(publish_server_descriptor),
- LOCAL_VALIDATE_TEST(testing),
- LOCAL_VALIDATE_TEST(hidserv),
- LOCAL_VALIDATE_TEST(predicted_ports),
- LOCAL_VALIDATE_TEST(path_bias),
- LOCAL_VALIDATE_TEST(bandwidth),
- LOCAL_VALIDATE_TEST(circuits),
- LOCAL_VALIDATE_TEST(port_forwarding),
- LOCAL_VALIDATE_TEST(tor2web),
- LOCAL_VALIDATE_TEST(rend),
- LOCAL_VALIDATE_TEST(single_onion),
- LOCAL_VALIDATE_TEST(accounting),
- LOCAL_VALIDATE_TEST(proxy),
- LOCAL_VALIDATE_TEST(control),
- LOCAL_VALIDATE_TEST(families),
- LOCAL_VALIDATE_TEST(addr_policies),
- LOCAL_VALIDATE_TEST(dir_auth),
- LOCAL_VALIDATE_TEST(transport),
- LOCAL_VALIDATE_TEST(constrained_sockets),
- LOCAL_VALIDATE_TEST(v3_auth),
- LOCAL_VALIDATE_TEST(virtual_addr),
- LOCAL_VALIDATE_TEST(exits),
- LOCAL_VALIDATE_TEST(testing_options),
- LOCAL_VALIDATE_TEST(accel),
- END_OF_TESTCASES /* */
- };
|