12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217 |
- /* Copyright (c) 2001-2004, Roger Dingledine.
- * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2019, The Tor Project, Inc. */
- /* See LICENSE for licensing information */
- #define CONFIG_PRIVATE
- #include "core/or/or.h"
- #include "lib/confmgt/confparse.h"
- #include "app/config/config.h"
- #include "test/test.h"
- #include "lib/geoip/geoip.h"
- #define ROUTERSET_PRIVATE
- #include "feature/nodelist/routerset.h"
- #include "core/mainloop/mainloop.h"
- #include "test/log_test_helpers.h"
- #include "test/resolve_test_helpers.h"
- #include "lib/sandbox/sandbox.h"
- #include "lib/memarea/memarea.h"
- #include "lib/osinfo/uname.h"
- #include "lib/encoding/confline.h"
- #include "core/or/policies.h"
- #include "test/test_helpers.h"
- #include "lib/net/resolve.h"
- #ifdef HAVE_SYS_PARAM_H
- #include <sys/param.h>
- #endif
- #define NS_MODULE test_options
- typedef struct {
- int severity;
- log_domain_mask_t domain;
- char *msg;
- } logmsg_t;
- static smartlist_t *messages = NULL;
- static void
- log_cback(int severity, log_domain_mask_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[SEVERITY_MASK_IDX(LOG_ERR)] = LD_ALL_DOMAINS;
- lst.masks[SEVERITY_MASK_IDX(LOG_WARN)] = LD_ALL_DOMAINS;
- lst.masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = LD_ALL_DOMAINS;
- 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(get_options_mgr(), 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 int
- test_options_checklog(const char *configuration, int expect_log_severity,
- const char *expect_log)
- {
- int found = 0, ret = -1;
- char *actual_log = NULL;
- 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) {
- actual_log = dump_logs();
- TT_DIE(("Expected log message [%s] %s from <%s>, but got <%s>.",
- log_level_to_string(expect_log_severity), expect_log,
- configuration, actual_log));
- }
- ret = 0;
- done:
- tor_free(actual_log);
- return ret;
- }
- static int
- test_options_checkmsgs(const char *configuration,
- const char *expect_errmsg,
- int expect_log_severity,
- const char *expect_log,
- char *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));
- }
- if (expect_log) {
- return test_options_checklog(configuration, expect_log_severity,
- expect_log);
- }
- return 0;
- done:
- return -1;
- }
- /* Which phases of config parsing/validation to check for messages/logs */
- enum { PH_GETLINES, PH_ASSIGN, PH_VALIDATE };
- static void
- test_options_validate_impl(const char *configuration,
- const char *expect_errmsg,
- int expect_log_severity,
- const char *expect_log,
- int phase)
- {
- 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);
- if (phase == PH_GETLINES) {
- if (test_options_checkmsgs(configuration, expect_errmsg,
- expect_log_severity,
- expect_log, msg))
- goto done;
- }
- if (r)
- goto done;
- r = config_assign(get_options_mgr(), opt, cl, 0, &msg);
- if (phase == PH_ASSIGN) {
- if (test_options_checkmsgs(configuration, expect_errmsg,
- expect_log_severity,
- expect_log, msg))
- goto done;
- }
- tt_int_op((r == 0), OP_EQ, (msg == NULL));
- if (r)
- goto done;
- r = options_validate(NULL, opt, dflt, 0, &msg);
- if (phase == PH_VALIDATE) {
- if (test_options_checkmsgs(configuration, expect_errmsg,
- expect_log_severity,
- expect_log, msg))
- goto done;
- }
- tt_int_op((r == 0), OP_EQ, (msg == NULL));
- 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, ph) \
- test_options_validate_impl((config), (msg), 0, NULL, (ph))
- #define WANT_LOG(config, severity, msg, ph) \
- test_options_validate_impl((config), NULL, (severity), (msg), (ph))
- #define WANT_ERR_LOG(config, msg, severity, logmsg, ph) \
- test_options_validate_impl((config), (msg), (severity), (logmsg), (ph))
- #define OK(config, ph) \
- test_options_validate_impl((config), NULL, 0, NULL, (ph))
- static void
- test_options_validate(void *arg)
- {
- (void)arg;
- setup_log_callback();
- sandbox_disable_getaddrinfo_cache();
- mock_hostname_resolver();
- WANT_ERR("ExtORPort 500000", "Invalid ExtORPort", PH_VALIDATE);
- WANT_ERR_LOG("ServerTransportOptions trebuchet",
- "ServerTransportOptions did not parse",
- LOG_WARN, "Too few arguments", PH_VALIDATE);
- OK("ServerTransportOptions trebuchet sling=snappy", PH_VALIDATE);
- OK("ServerTransportOptions trebuchet sling=", PH_VALIDATE);
- WANT_ERR_LOG("ServerTransportOptions trebuchet slingsnappy",
- "ServerTransportOptions did not parse",
- LOG_WARN, "\"slingsnappy\" is not a k=v", PH_VALIDATE);
- WANT_ERR("DirPort 8080\nDirCache 0",
- "DirPort configured but DirCache disabled.", PH_VALIDATE);
- WANT_ERR("BridgeRelay 1\nDirCache 0",
- "We're a bridge but DirCache is disabled.", PH_VALIDATE);
- // XXXX We should replace this with a more full error message once #29211
- // XXXX is done. It is truncated for now because at the current stage
- // XXXX of refactoring, we can't give a full error message like before.
- WANT_ERR_LOG("HeartbeatPeriod 21 snarks",
- "malformed or out of bounds", LOG_WARN,
- "Unknown unit 'snarks'.",
- PH_ASSIGN);
- // XXXX As above.
- WANT_ERR_LOG("LogTimeGranularity 21 snarks",
- "malformed or out of bounds", LOG_WARN,
- "Unknown unit 'snarks'.",
- PH_ASSIGN);
- OK("HeartbeatPeriod 1 hour", PH_VALIDATE);
- OK("LogTimeGranularity 100 milliseconds", PH_VALIDATE);
- WANT_LOG("ControlSocket \"string with trailing garbage\" bogus", LOG_WARN,
- "Error while parsing configuration: "
- "Excess data after quoted string", PH_GETLINES);
- WANT_LOG("ControlSocket \"bogus escape \\@\"", LOG_WARN,
- "Error while parsing configuration: "
- "Invalid escape sequence in quoted string", PH_GETLINES);
- close_temp_logs();
- clear_log_messages();
- unmock_hostname_resolver();
- return;
- }
- #define MEGABYTEIFY(mb) (UINT64_C(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(get_options_mgr(), 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_ptr_op(msg, OP_EQ, NULL);
- /* 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(get_options_mgr(), 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_ptr_op(msg, OP_EQ, NULL);
- /* 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(get_options_mgr(), 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_ptr_op(msg, OP_EQ, NULL);
- /* 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" \
- "ClientBootstrapConsensusMaxInProgressTries 3\n" \
- "TestingV3AuthInitialVoteDelay 300\n" \
- "TestingV3AuthInitialDistDelay 300\n" \
- "TestingClientMaxIntervalWithoutRequest 600\n" \
- "TestingDirConnectionMaxStall 600\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" \
- "UseEntryGuards 1\n" \
- "Schedulers Vanilla\n" \
- "ClientDNSRejectInternalAddresses 1\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();
- // XXX: Really, all of these options should be set to defaults
- // with options_init(), but about a dozen tests break when I do that.
- // Being kinda lame and just fixing the immedate breakage for now..
- result->opt->ConnectionPadding = -1; // default must be "auto"
- result->opt->DormantClientTimeout = 1800; // must be over 600.
- result->opt->CircuitPadding = 1; // default must be "1"
- rv = config_get_lines(conf, &cl, 1);
- tt_int_op(rv, OP_EQ, 0);
- rv = config_assign(get_options_mgr(), 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_int_op(rv, OP_EQ, 0);
- config_free_lines(cl);
- result->opt->LogTimeGranularity = 1;
- result->opt->TokenBucketRefillInterval = 1;
- rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
- tt_int_op(rv, OP_EQ, 0);
- rv = config_assign(get_options_mgr(), 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_int_op(rv, OP_EQ, 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;
- #ifndef _WIN32
- int unset_home_env = 0;
- if (setenv("HOME", "/home/john", 0) == 0)
- unset_home_env = 1;
- #endif
- options_test_data_t *tdata = get_options_test_data(
- "ORPort 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_no_log_entry();
- tor_free(msg);
- done:
- UNMOCK(get_uname);
- free_options_test_data(tdata);
- tor_free(msg);
- teardown_capture_of_logs();
- #ifndef _WIN32
- if (unset_home_env)
- unsetenv("HOME");
- #endif
- }
- 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);
- tt_str_op(msg, OP_EQ, "Multiple outbound bind addresses configured: "
- "xxyy!!!sdfaf");
- 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_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("DataDirectory /tmp/somewhere");
- 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");
- 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(
- "ORPort 127.0.0.1:5555");
- 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("ORPort 127.0.0.1:5555\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);
- tt_int_op(ret, OP_EQ, -1);
- 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);
- tt_int_op(ret, OP_EQ, -1);
- 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);
- tt_int_op(ret, OP_EQ, -1);
- 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);
- tt_int_op(ret, OP_EQ, -1);
- 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);
- tt_int_op(ret, OP_EQ, -1);
- 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);
- tt_int_op(ret, OP_EQ, -1);
- 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();
- MOCK(tor_addr_lookup, mock_tor_addr_lookup__fail_on_bad_addrs);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- UNMOCK(tor_addr_lookup);
- 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_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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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-existent-file\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-existent-file\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-existent-file\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-existent-file\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");
- 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");
- 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" ); */
- /* 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(
- "ORPort 127.0.0.1:5555\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.");
- #endif /* !defined(OpenBSD) && !defined( DARWIN ) */
- 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.");
- #endif /* !defined(__linux__) */
- 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.");
- #endif /* !defined(KERNEL_MAY_SUPPORT_IPFW) */
- tor_free(msg);
- // Test unknown trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType non-existent\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);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- #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);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- tor_free(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);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- tor_free(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);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- tor_free(msg);
- #endif /* defined(__linux__) || ... */
- // Assert that a test has run for some TransProxyType
- tt_assert(tdata);
- #else /* !defined(USE_TRANSPARENT) */
- 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 is disabled in this build.");
- tor_free(msg);
- #endif /* defined(USE_TRANSPARENT) */
- 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");
- 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");
- 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__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");
- 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("");
- 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");
- 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__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__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");
- 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");
- 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");
- 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");
- 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;
- #ifndef _WIN32
- int unset_home_env = 0;
- if (setenv("HOME", "/home/john", 0) == 0)
- unset_home_env = 1;
- #endif
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PathsNeededToBuildCircuits 0.1\n"
- "ConnLimit 1\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");
- 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");
- 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);
- #ifndef _WIN32
- if (unset_home_env)
- unsetenv("HOME");
- #endif
- }
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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");
- 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);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "ReachableAddresses *:82\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_ptr_op(tdata->opt->ReachableAddresses->next, OP_EQ, NULL);
- 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"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 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, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableORAddresses *:82\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 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, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableDirAddresses *:82\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 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, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ClientUseIPv4 0\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 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, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- /* Test IPv4-only clients setting IPv6 preferences */
- 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);
- 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);
- 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"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 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, "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");
- 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");
- 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"
- "UseEntryGuards 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,
- "Setting UseBridges requires also setting UseEntryGuards.");
- 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");
- 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");
- 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__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");
- 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");
- 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");
- 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");
- 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");
- 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(TestingServerDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingClientDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingServerConsensusDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingClientConsensusDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingBridgeDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingBridgeBootstrapDownloadInitialDelay, 3000);
- ENSURE_DEFAULT(TestingClientMaxIntervalWithoutRequest, 3000);
- ENSURE_DEFAULT(TestingDirConnectionMaxStall, 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__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
- "ORPort 127.0.0.1:5555\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
- "ORPort 127.0.0.1:5555\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
- "ORPort 127.0.0.1:5555\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
- "ORPort 127.0.0.1:5555\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__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 if HiddenServiceSingleHopMode is 1 */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\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, -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 revert "
- "HiddenServiceNonAnonymousMode to 0.");
- 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);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 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);
- /* Test that a hidden service can't be run in non anonymous mode. */
- 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
- "ORPort 127.0.0.1:5555\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);
- MOCK(tor_addr_lookup, mock_tor_addr_lookup__fail_on_bad_addrs);
- 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);
- UNMOCK(tor_addr_lookup);
- }
- 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 /* defined(HAVE_SYS_UN_H) */
- 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"
- "ORPort 127.0.0.1:5555\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"
- "ORPort 127.0.0.1:5555\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"
- "ORPort 127.0.0.1:5555\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__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.");
- 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"
- 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(node_families),
- LOCAL_VALIDATE_TEST(token_bucket),
- 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(safe_logging),
- LOCAL_VALIDATE_TEST(publish_server_descriptor),
- LOCAL_VALIDATE_TEST(testing),
- LOCAL_VALIDATE_TEST(hidserv),
- LOCAL_VALIDATE_TEST(path_bias),
- LOCAL_VALIDATE_TEST(bandwidth),
- LOCAL_VALIDATE_TEST(circuits),
- 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(testing_options),
- LOCAL_VALIDATE_TEST(accel),
- END_OF_TESTCASES /* */
- };
|