1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453 |
- /* Copyright (c) 2001-2004, Roger Dingledine.
- * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
- * Copyright (c) 2007-2017, The Tor Project, Inc. */
- /* See LICENSE for licensing information */
- #define CONFIG_PRIVATE
- #include "or.h"
- #include "confparse.h"
- #include "config.h"
- #include "test.h"
- #include "geoip.h"
- #define ROUTERSET_PRIVATE
- #include "routerset.h"
- #include "main.h"
- #include "log_test_helpers.h"
- #include "sandbox.h"
- #include "memarea.h"
- #include "policies.h"
- #include "test_helpers.h"
- #define NS_MODULE test_options
- typedef struct {
- int severity;
- uint32_t domain;
- char *msg;
- } logmsg_t;
- static smartlist_t *messages = NULL;
- static void
- log_cback(int severity, uint32_t domain, const char *msg)
- {
- logmsg_t *x = tor_malloc(sizeof(*x));
- x->severity = severity;
- x->domain = domain;
- x->msg = tor_strdup(msg);
- if (!messages)
- messages = smartlist_new();
- smartlist_add(messages, x);
- }
- static void
- setup_log_callback(void)
- {
- log_severity_list_t lst;
- memset(&lst, 0, sizeof(lst));
- lst.masks[LOG_ERR - LOG_ERR] = ~0;
- lst.masks[LOG_WARN - LOG_ERR] = ~0;
- lst.masks[LOG_NOTICE - LOG_ERR] = ~0;
- add_callback_log(&lst, log_cback);
- mark_logs_temp();
- }
- static char *
- dump_logs(void)
- {
- smartlist_t *msgs;
- char *out;
- if (! messages)
- return tor_strdup("");
- msgs = smartlist_new();
- SMARTLIST_FOREACH_BEGIN(messages, logmsg_t *, x) {
- smartlist_add_asprintf(msgs, "[%s] %s",
- log_level_to_string(x->severity), x->msg);
- } SMARTLIST_FOREACH_END(x);
- out = smartlist_join_strings(msgs, "", 0, NULL);
- SMARTLIST_FOREACH(msgs, char *, cp, tor_free(cp));
- smartlist_free(msgs);
- return out;
- }
- static void
- clear_log_messages(void)
- {
- if (!messages)
- return;
- SMARTLIST_FOREACH(messages, logmsg_t *, m,
- { tor_free(m->msg); tor_free(m); });
- smartlist_free(messages);
- messages = NULL;
- }
- #define setup_options(opt,dflt) \
- do { \
- opt = options_new(); \
- opt->command = CMD_RUN_TOR; \
- options_init(opt); \
- \
- dflt = config_dup(&options_format, opt); \
- clear_log_messages(); \
- } while (0)
- #define VALID_DIR_AUTH "DirAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- #define VALID_ALT_BRIDGE_AUTH \
- "AlternateBridgeAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- #define VALID_ALT_DIR_AUTH \
- "AlternateDirAuthority dizum orport=443 v3ident=E8A9C45" \
- "EDE6D711294FADF8E7951F4DE6CA56B58 194.109.206.212:80 7EA6 EAD6 FD83" \
- " 083C 538F 4403 8BBF A077 587D D755\n"
- static 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(&options_format, 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();
- 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);
- WANT_ERR_LOG("HeartbeatPeriod 21 snarks",
- "Interval 'HeartbeatPeriod 21 snarks' is malformed or"
- " out of bounds.", LOG_WARN, "Unknown unit 'snarks'.",
- PH_ASSIGN);
- WANT_ERR_LOG("LogTimeGranularity 21 snarks",
- "Msec interval 'LogTimeGranularity 21 snarks' is 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();
- return;
- }
- #define MEGABYTEIFY(mb) (U64_LITERAL(mb) << 20)
- static void
- test_have_enough_mem_for_dircache(void *arg)
- {
- (void)arg;
- or_options_t *opt=NULL;
- or_options_t *dflt=NULL;
- config_line_t *cl=NULL;
- char *msg=NULL;;
- int r;
- const char *configuration = "ORPort 8080\nDirCache 1", *expect_errmsg;
- setup_options(opt, dflt);
- setup_log_callback();
- (void)dflt;
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 300 MB RAM available, DirCache enabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 200 MB RAM available, DirCache enabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "Being a directory cache (default) with less than ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- config_free_lines(cl); cl = NULL;
- configuration = "ORPort 8080\nDirCache 1\nBridgeRelay 1";
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 300 MB RAM available, DirCache enabled, Bridge */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 200 MB RAM available, DirCache enabled, Bridge */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "Running a Bridge with less than ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- config_free_lines(cl); cl = NULL;
- configuration = "ORPort 8080\nDirCache 0";
- r = config_get_lines(configuration, &cl, 1);
- tt_int_op(r, OP_EQ, 0);
- r = config_assign(&options_format, opt, cl, 0, &msg);
- tt_int_op(r, OP_EQ, 0);
- /* 200 MB RAM available, DirCache disabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(200), &msg);
- tt_int_op(r, OP_EQ, 0);
- tt_assert(!msg);
- /* 300 MB RAM available, DirCache disabled */
- r = have_enough_mem_for_dircache(opt, MEGABYTEIFY(300), &msg);
- tt_int_op(r, OP_EQ, -1);
- expect_errmsg = "DirCache is disabled and we are configured as a ";
- if (!strstr(msg, expect_errmsg)) {
- TT_DIE(("Expected error message <%s> from <%s>, but got <%s>.",
- expect_errmsg, configuration, msg));
- }
- tor_free(msg);
- clear_log_messages();
- done:
- if (msg)
- tor_free(msg);
- or_options_free(dflt);
- or_options_free(opt);
- config_free_lines(cl);
- return;
- }
- static const char *fixed_get_uname_result = NULL;
- static const char *
- fixed_get_uname(void)
- {
- return fixed_get_uname_result;
- }
- #define TEST_OPTIONS_OLD_VALUES "TestingV3AuthInitialVotingInterval 1800\n" \
- "ClientBootstrapConsensusMaxDownloadTries 7\n" \
- "ClientBootstrapConsensusAuthorityOnlyMaxDownloadTries 4\n" \
- "ClientBootstrapConsensusMaxInProgressTries 3\n" \
- "TestingV3AuthInitialVoteDelay 300\n" \
- "TestingV3AuthInitialDistDelay 300\n" \
- "TestingClientMaxIntervalWithoutRequest 600\n" \
- "TestingDirConnectionMaxStall 600\n" \
- "TestingConsensusMaxDownloadTries 8\n" \
- "TestingDescriptorMaxDownloadTries 8\n" \
- "TestingMicrodescMaxDownloadTries 8\n" \
- "TestingCertMaxDownloadTries 8\n"
- #define TEST_OPTIONS_DEFAULT_VALUES TEST_OPTIONS_OLD_VALUES \
- "MaxClientCircuitsPending 1\n" \
- "RendPostPeriod 1000\n" \
- "KeepAlivePeriod 1\n" \
- "ConnLimit 1\n" \
- "V3AuthVotingInterval 300\n" \
- "V3AuthVoteDelay 20\n" \
- "V3AuthDistDelay 20\n" \
- "V3AuthNIntervalsValid 3\n" \
- "ClientUseIPv4 1\n" \
- "VirtualAddrNetworkIPv4 127.192.0.0/10\n" \
- "VirtualAddrNetworkIPv6 [FE80::]/10\n" \
- "SchedulerHighWaterMark__ 42\n" \
- "SchedulerLowWaterMark__ 10\n" \
- "UseEntryGuards 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"
- rv = config_get_lines(conf, &cl, 1);
- tt_assert(rv == 0);
- rv = config_assign(&options_format, result->opt, cl, 0, &msg);
- if (msg) {
- /* Display the parse error message by comparing it with an empty string */
- tt_str_op(msg, OP_EQ, "");
- }
- tt_assert(rv == 0);
- config_free_lines(cl);
- result->opt->LogTimeGranularity = 1;
- result->opt->TokenBucketRefillInterval = 1;
- rv = config_get_lines(TEST_OPTIONS_OLD_VALUES, &cl, 1);
- tt_assert(rv == 0);
- rv = config_assign(&options_format, result->def_opt, cl, 0, &msg);
- if (msg) {
- /* Display the parse error message by comparing it with an empty string */
- tt_str_op(msg, OP_EQ, "");
- }
- tt_assert(rv == 0);
- done:
- config_free_lines(cl);
- if (rv != 0) {
- free_options_test_data(result);
- result = NULL;
- /* Callers expect a non-NULL result, so just die if we can't provide one.
- */
- tor_assert(0);
- }
- return result;
- }
- static void
- free_options_test_data(options_test_data_t *td)
- {
- if (!td) return;
- or_options_free(td->old_opt);
- or_options_free(td->opt);
- or_options_free(td->def_opt);
- tor_free(td);
- }
- static void
- test_options_validate__uname_for_server(void *ignored)
- {
- (void)ignored;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "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_log_entry();
- tor_free(msg);
- done:
- UNMOCK(get_uname);
- free_options_test_data(tdata);
- tor_free(msg);
- teardown_capture_of_logs();
- }
- static void
- test_options_validate__outbound_addresses(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "OutboundBindAddress xxyy!!!sdfaf");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__data_directory(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "DataDirectory longreallyl"
- "ongLONGLONGlongreallylong"
- "LONGLONGlongreallylongLON"
- "GLONGlongreallylongLONGLO"
- "NGlongreallylongLONGLONGl"
- "ongreallylongLONGLONGlong"
- "reallylongLONGLONGlongrea"
- "llylongLONGLONGlongreally"
- "longLONGLONGlongreallylon"
- "gLONGLONGlongreallylongLO"
- "NGLONGlongreallylongLONGL"
- "ONGlongreallylongLONGLONG"
- "longreallylongLONGLONGlon"
- "greallylongLONGLONGlongre"
- "allylongLONGLONGlongreall"
- "ylongLONGLONGlongreallylo"
- "ngLONGLONGlongreallylongL"
- "ONGLONGlongreallylongLONG"
- "LONG"); // 440 characters
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Invalid DataDirectory");
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__nickname(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "Nickname ThisNickNameIsABitTooLong");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Nickname 'ThisNickNameIsABitTooLong', nicknames must be between "
- "1 and 19 characters inclusive, and must contain only the "
- "characters [a-zA-Z0-9].");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("Nickname AMoreValidNick");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("DataDirectory /tmp/somewhere");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__contactinfo(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "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);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- quiet_level = 1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->Logs->key, OP_EQ, "Log");
- tt_str_op(tdata->opt->Logs->value, OP_EQ, "warn stdout");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- quiet_level = 2;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 0;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 1, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->Logs = NULL;
- tdata->opt->RunAsDaemon = 1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_assert(!tdata->opt->Logs);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("");
- tdata->opt->RunAsDaemon = 0;
- config_line_t *cl=NULL;
- config_get_lines("Log foo", &cl, 1);
- tdata->opt->Logs = cl;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op((intptr_t)tdata->opt->Logs, OP_EQ, (intptr_t)cl);
- done:
- quiet_level = orig_quiet_level;
- free_options_test_data(tdata);
- tor_free(msg);
- }
- /* static config_line_t * */
- /* mock_config_line(const char *key, const char *val) */
- /* { */
- /* config_line_t *config_line = tor_malloc(sizeof(config_line_t)); */
- /* memset(config_line, 0, sizeof(config_line_t)); */
- /* config_line->key = tor_strdup(key); */
- /* config_line->value = tor_strdup(val); */
- /* return config_line; */
- /* } */
- static void
- test_options_validate__authdir(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_INFO);
- options_test_data_t *tdata = get_options_test_data(
- "AuthoritativeDirectory 1\n"
- "Address this.should.not!exist!.example.org");
- sandbox_disable_getaddrinfo_cache();
- 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_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Authoritative directory servers must set ContactInfo");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "TestingTorNetwork 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "1.2, 3.14");
- tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "1.2, 3.14");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "RecommendedClientVersions 25\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(tdata->opt->RecommendedClientVersions->value, OP_EQ, "25");
- tt_str_op(tdata->opt->RecommendedServerVersions->value, OP_EQ, "4.18");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedVersions 1.2, 3.14\n"
- "RecommendedClientVersions 25\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedServerVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
- "Recommended*Versions.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "VersioningAuthoritativeDirectory 1\n"
- "RecommendedClientVersions 4.18\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "Versioning authoritative dir servers must set "
- "Recommended*Versions.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "UseEntryGuards 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Authoritative directory servers "
- "can't set UseEntryGuards. Disabling.\n");
- tt_int_op(tdata->opt->UseEntryGuards, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "V3AuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_log_msg("Authoritative directories always try"
- " to download extra-info documents. Setting DownloadExtraInfo.\n");
- tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "DownloadExtraInfo 1\n"
- "V3AuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- expect_no_log_msg("Authoritative directories always try"
- " to download extra-info documents. Setting DownloadExtraInfo.\n");
- tt_int_op(tdata->opt->DownloadExtraInfo, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ, "AuthoritativeDir is set, but none of (Bridge/V3)"
- "AuthoritativeDir is set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "V3BandwidthsFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "V3BandwidthsFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "GuardfractionFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "GuardfractionFile non-existant-file\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- options_validate(NULL, tdata->opt, tdata->def_opt, 0, &msg);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no DirPort set.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("AuthoritativeDirectory 1\n"
- "Address 100.200.10.1\n"
- "DirPort 999\n"
- "BridgeAuthoritativeDir 1\n"
- "ContactInfo hello@hello.com\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Running as authoritative directory, but no ORPort set.");
- tor_free(msg);
- // TODO: This case can't be reached, since clientonly is used to
- // check when parsing port lines as well.
- /* free_options_test_data(tdata); */
- /* tdata = get_options_test_data("AuthoritativeDirectory 1\n" */
- /* "Address 100.200.10.1\n" */
- /* "DirPort 999\n" */
- /* "ORPort 888\n" */
- /* "ClientOnly 1\n" */
- /* "BridgeAuthoritativeDir 1\n" */
- /* "ContactInfo hello@hello.com\n" */
- /* "SchedulerHighWaterMark__ 42\n" */
- /* "SchedulerLowWaterMark__ 10\n"); */
- /* mock_clean_saved_logs(); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* tt_int_op(ret, OP_EQ, -1); */
- /* tt_str_op(msg, OP_EQ, "Running as authoritative directory, " */
- /* "but ClientOnly also set."); */
- done:
- teardown_capture_of_logs();
- // sandbox_free_getaddrinfo_cache();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__relay_with_hidden_services(void *ignored)
- {
- (void)ignored;
- char *msg;
- setup_capture_of_logs(LOG_DEBUG);
- options_test_data_t *tdata = get_options_test_data(
- "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
- 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
- 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
- tor_free(msg);
- // Test unknown trans proxy
- free_options_test_data(tdata);
- tdata = get_options_test_data("TransProxyType non-existant\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value for TransProxyType");
- tor_free(msg);
- // Test trans proxy success
- free_options_test_data(tdata);
- tdata = NULL;
- #if defined(__linux__)
- tdata = get_options_test_data("TransProxyType tproxy\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(KERNEL_MAY_SUPPORT_IPFW)
- tdata = get_options_test_data("TransProxyType ipfw\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(OpenBSD)
- tdata = get_options_test_data("TransProxyType pf-divert\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #elif defined(__NetBSD__)
- tdata = get_options_test_data("TransProxyType default\n"
- "TransPort 127.0.0.1:123\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- if (msg) {
- TT_DIE(("Expected NULL but got '%s'", msg));
- }
- #endif
- // Assert that a test has run for some TransProxyType
- tt_assert(tdata);
- #else
- tdata = get_options_test_data("TransPort 127.0.0.1:555\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TransPort is disabled in this build.");
- tor_free(msg);
- #endif
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- NS_DECL(country_t, geoip_get_country, (const char *country));
- static country_t
- NS(geoip_get_country)(const char *countrycode)
- {
- (void)countrycode;
- CALLED(geoip_get_country)++;
- return 1;
- }
- static void
- test_options_validate__exclude_nodes(void *ignored)
- {
- (void)ignored;
- NS_MOCK(geoip_get_country);
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "ExcludeExitNodes {us}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{us}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 1);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{cn}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "ExcludeExitNodes {us} {cn}\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(smartlist_len(tdata->opt->ExcludeExitNodesUnion_->list), OP_EQ, 2);
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 0)),
- OP_EQ, "{us} {cn}");
- tt_str_op((char *)
- (smartlist_get(tdata->opt->ExcludeExitNodesUnion_->list, 1)),
- OP_EQ, "{cn}");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "StrictNodes 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg(
- "You have asked to exclude certain relays from all positions "
- "in your circuits. Expect hidden services and other Tor "
- "features to be broken in unpredictable ways.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ExcludeNodes {cn}\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg(
- "You have asked to exclude certain relays from all positions "
- "in your circuits. Expect hidden services and other Tor "
- "features to be broken in unpredictable ways.\n");
- tor_free(msg);
- done:
- NS_UNMOCK(geoip_get_country);
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__scheduler(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_DEBUG);
- options_test_data_t *tdata = get_options_test_data(
- "SchedulerLowWaterMark__ 0\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Bad SchedulerLowWaterMark__ option\n");
- tor_free(msg);
- // TODO: this test cannot run on platforms where UINT32_MAX == UINT64_MAX.
- // I suspect it's unlikely this branch can actually happen
- /* free_options_test_data(tdata); */
- /* tdata = get_options_test_data( */
- /* "SchedulerLowWaterMark 10000000000000000000\n"); */
- /* tdata->opt->SchedulerLowWaterMark__ = (uint64_t)UINT32_MAX; */
- /* tdata->opt->SchedulerLowWaterMark__++; */
- /* mock_clean_saved_logs(); */
- /* ret = options_validate(tdata->old_opt, tdata->opt, */
- /* tdata->def_opt, 0, &msg); */
- /* tt_int_op(ret, OP_EQ, -1); */
- /* expect_log_msg("Bad SchedulerLowWaterMark__ option\n"); */
- free_options_test_data(tdata);
- tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n"
- "SchedulerHighWaterMark__ 42\n");
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Bad SchedulerHighWaterMark option\n");
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__node_families(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "NodeFamily flux, flax\n"
- "NodeFamily somewhere\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->NodeFamilySets);
- tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 2);
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 0)),
- OP_EQ, "flux");
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 0))->list, 1)),
- OP_EQ, "flax");
- tt_str_op((char *)(smartlist_get(
- ((routerset_t *)smartlist_get(tdata->opt->NodeFamilySets, 1))->list, 0)),
- OP_EQ, "somewhere");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(!tdata->opt->NodeFamilySets);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("NodeFamily !flux\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->NodeFamilySets);
- tt_int_op(smartlist_len(tdata->opt->NodeFamilySets), OP_EQ, 0);
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__token_bucket(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data("");
- tdata->opt->TokenBucketRefillInterval = 0;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
- tor_free(msg);
- tdata->opt->TokenBucketRefillInterval = 1001;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "TokenBucketRefillInterval must be between 1 and 1000 inclusive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__recommended_packages(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "RecommendedPackages foo 1.2 http://foo.com sha1=123123123123\n"
- "RecommendedPackages invalid-package-line\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_no_log_msg("Invalid RecommendedPackage line "
- "invalid-package-line will be ignored\n");
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__fetch_dir(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "FetchDirInfoExtraEarly 1\n"
- "FetchDirInfoEarly 0\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "FetchDirInfoExtraEarly requires that you"
- " also set FetchDirInfoEarly");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FetchDirInfoExtraEarly 1\n"
- "FetchDirInfoEarly 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "FetchDirInfoExtraEarly requires that you"
- " also set FetchDirInfoEarly");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__conn_limit(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "ConnLimit 0\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "ConnLimit must be greater than 0, but was set to 0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024, "
- "but was set to 0");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__paths_needed(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PathsNeededToBuildCircuits 0.1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.24 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.26);
- expect_log_msg("PathsNeededToBuildCircuits is too low. "
- "Increasing to 0.25\n");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("PathsNeededToBuildCircuits 0.99\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.94 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.96);
- expect_log_msg("PathsNeededToBuildCircuits is "
- "too high. Decreasing to 0.95\n");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("PathsNeededToBuildCircuits 0.91\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 &&
- tdata->opt->PathsNeededToBuildCircuits < 0.92);
- expect_no_log_entry();
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__max_client_circuits(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "MaxClientCircuitsPending 0\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
- " but was set to 0");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("MaxClientCircuitsPending 1025\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "MaxClientCircuitsPending must be between 1 and 1024,"
- " but was set to 1025");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__ports(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "FirewallPorts 65537\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '65537' out of range in FirewallPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 124444\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '124444' out of range in LongLivedPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 112233\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '112233' out of range in RejectPlaintextPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 3\n"
- "WarnPlaintextPorts 65536\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Port '65536' out of range in WarnPlaintextPorts");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("FirewallPorts 1\n"
- "LongLivedPorts 2\n"
- "RejectPlaintextPorts 3\n"
- "WarnPlaintextPorts 4\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__reachable_addresses(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_NOTICE);
- options_test_data_t *tdata = get_options_test_data(
- "FascistFirewall 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Converting FascistFirewall config "
- "option to new format: \"ReachableDirAddresses *:80\"\n");
- tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:80");
- expect_log_msg("Converting FascistFirewall config "
- "option to new format: \"ReachableORAddresses *:443\"\n");
- tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:443");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "ReachableDirAddresses *:81\n"
- "ReachableORAddresses *:444\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- tdata->opt->FirewallPorts = smartlist_new();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_entry();
- tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:81");
- tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "FirewallPort 123\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Converting FascistFirewall and "
- "FirewallPorts config options to new format: "
- "\"ReachableAddresses *:123\"\n");
- tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:123");
- tor_free(msg);
- free_options_test_data(tdata);
- mock_clean_saved_logs();
- tdata = get_options_test_data("FascistFirewall 1\n"
- "ReachableAddresses *:82\n"
- "ReachableAddresses *:83\n"
- "ReachableAddresses reject *:*\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_entry();
- tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:82");
- tor_free(msg);
- #define SERVERS_REACHABLE_MSG "Servers must be able to freely connect to" \
- " the rest of the Internet, so they must not set Reachable*Addresses or" \
- " FascistFirewall or FirewallPorts or ClientUseIPv4 0."
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableAddresses *:82\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableORAddresses *:82\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ReachableDirAddresses *:82\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("ClientUseIPv4 0\n"
- "ORPort 127.0.0.1:5555\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, SERVERS_REACHABLE_MSG);
- tor_free(msg);
- /* Test IPv4-only clients setting IPv6 preferences */
- 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"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Servers must be able to freely connect to the rest of"
- " the Internet, so they must not set UseBridges.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("UseBridges 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "Servers must be able to freely connect to the rest of"
- " the Internet, so they must not set UseBridges.");
- tor_free(msg);
- NS_MOCK(geoip_get_country);
- free_options_test_data(tdata);
- tdata = get_options_test_data("UseBridges 1\n"
- "EntryNodes {cn}\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "You cannot set both UseBridges and EntryNodes.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseBridges 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "If you set UseBridges, you must specify at least one bridge.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseBridges 1\n"
- "Bridge 10.0.0.1\n"
- "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"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "If EntryNodes is set, UseEntryGuards must be enabled.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("EntryNodes {cn}\n"
- "UseEntryGuards 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "KeepalivePeriod option must be positive.");
- tor_free(msg);
- done:
- NS_UNMOCK(geoip_get_country);
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__safe_logging(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = get_options_test_data(
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging 0\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_NONE);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging Relay\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_RELAY);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging 1\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_int_op(tdata->opt->SafeLogging_, OP_EQ, SAFELOG_SCRUB_ALL);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("SafeLogging stuffy\n"
- "MaxClientCircuitsPending 1\n"
- "ConnLimit 1\n"
- "SchedulerHighWaterMark__ 42\n"
- "SchedulerLowWaterMark__ 10\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value '\"stuffy\"' in SafeLogging");
- tor_free(msg);
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__publish_server_descriptor(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- "PublishServerDescriptor bridge\n" TEST_OPTIONS_DEFAULT_VALUES
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("PublishServerDescriptor humma\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Unrecognized value in PublishServerDescriptor");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("PublishServerDescriptor bridge, v3\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n"
- "PublishServerDescriptor v3\n"
- TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n" TEST_OPTIONS_DEFAULT_VALUES);
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_NE, "Bridges are not supposed to publish router "
- "descriptors to the directory authorities. Please correct your "
- "PublishServerDescriptor line.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data("BridgeRelay 1\n"
- "DirPort 999\n" TEST_OPTIONS_DEFAULT_VALUES);
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- expect_log_msg("Can't set a DirPort on a bridge "
- "relay; disabling DirPort\n");
- tt_assert(!tdata->opt->DirPort_lines);
- tt_assert(!tdata->opt->DirPort_set);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__testing(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- #define ENSURE_DEFAULT(varname, varval) \
- STMT_BEGIN \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n"); \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- tt_str_op(msg, OP_EQ, \
- #varname " may only be changed in testing Tor networks!"); \
- tt_int_op(ret, OP_EQ, -1); \
- tor_free(msg); \
- \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n" \
- VALID_DIR_AUTH \
- "TestingTorNetwork 1\n"); \
- \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- if (msg) { \
- tt_str_op(msg, OP_NE, \
- #varname " may only be changed in testing Tor networks!"); \
- tor_free(msg); \
- } \
- \
- free_options_test_data(tdata); \
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES \
- #varname " " #varval "\n" \
- "___UsingTestNetworkDefaults 1\n"); \
- \
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);\
- if (msg) { \
- tt_str_op(msg, OP_NE, \
- #varname " may only be changed in testing Tor networks!"); \
- tor_free(msg); \
- } \
- STMT_END
- ENSURE_DEFAULT(TestingV3AuthInitialVotingInterval, 3600);
- ENSURE_DEFAULT(TestingV3AuthInitialVoteDelay, 3000);
- ENSURE_DEFAULT(TestingV3AuthInitialDistDelay, 3000);
- ENSURE_DEFAULT(TestingV3AuthVotingStartOffset, 3000);
- ENSURE_DEFAULT(TestingAuthDirTimeToLearnReachability, 3000);
- ENSURE_DEFAULT(TestingEstimatedDescriptorPropagationTime, 3000);
- ENSURE_DEFAULT(TestingServerDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingServerConsensusDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientConsensusDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingBridgeDownloadSchedule, 3000);
- ENSURE_DEFAULT(TestingClientMaxIntervalWithoutRequest, 3000);
- ENSURE_DEFAULT(TestingDirConnectionMaxStall, 3000);
- ENSURE_DEFAULT(TestingConsensusMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingDescriptorMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingMicrodescMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingCertMaxDownloadTries, 3000);
- ENSURE_DEFAULT(TestingAuthKeyLifetime, 3000);
- ENSURE_DEFAULT(TestingLinkCertLifetime, 3000);
- ENSURE_DEFAULT(TestingSigningKeySlop, 3000);
- ENSURE_DEFAULT(TestingAuthKeySlop, 3000);
- ENSURE_DEFAULT(TestingLinkKeySlop, 3000);
- done:
- escaped(NULL); // This will free the leaking memory from the previous escaped
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__hidserv(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- setup_capture_of_logs(LOG_WARN);
- options_test_data_t *tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES);
- tdata->opt->MinUptimeHidServDirectoryV2 = -1;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("MinUptimeHidServDirectoryV2 "
- "option must be at least 0 seconds. Changing to 0.\n");
- tt_int_op(tdata->opt->MinUptimeHidServDirectoryV2, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RendPostPeriod 1\n" );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("RendPostPeriod option is too short;"
- " raising to 600 seconds.\n");
- tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 600);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "RendPostPeriod 302401\n" );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("RendPostPeriod is too large; "
- "clipping to 302400s.\n");
- tt_int_op(tdata->opt->RendPostPeriod, OP_EQ, 302400);
- tor_free(msg);
- done:
- teardown_capture_of_logs();
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__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__port_forwarding(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PortForwarding 1\nSandbox 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "PortForwarding is not compatible with Sandbox;"
- " at most one can be set");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "PortForwarding 1\nSandbox 0\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- done:
- free_options_test_data(tdata);
- policies_free_all();
- tor_free(msg);
- }
- static void
- test_options_validate__tor2web(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Tor2webRendezvousPoints 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Tor2webRendezvousPoints cannot be set without Tor2webMode.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "Tor2webRendezvousPoints 1\nTor2webMode 1\n");
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__rend(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "UseEntryGuards 0\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_log_msg("UseEntryGuards is disabled, but you"
- " have configured one or more hidden services on this Tor "
- "instance. Your hidden services will be very easy to locate using"
- " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
- "attack06 for details.\n");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "UseEntryGuards 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- mock_clean_saved_logs();
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- expect_no_log_msg("UseEntryGuards is disabled, but you"
- " have configured one or more hidden services on this Tor "
- "instance. Your hidden services will be very easy to locate using"
- " a well-known attack -- see http://freehaven.net/anonbib/#hs-"
- "attack06 for details.\n");
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Failed to configure rendezvous options. See logs for details.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HidServAuth failed\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "Failed to configure client authorization for hidden "
- "services. See logs for details.");
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__single_onion(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- /* Test that HiddenServiceSingleHopMode must come with
- * HiddenServiceNonAnonymousMode */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceSingleHopMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceNonAnonymousMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceSingleHopMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceNonAnonymousMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 0\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- /* Test that SOCKSPort must come with Tor2webMode if
- * HiddenServiceSingleHopMode is 1 */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode is incompatible with "
- "using Tor as an anonymous client. Please set "
- "Socks/Trans/NATD/DNSPort to 0, or 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"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 0\n"
- "Tor2webMode 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "SOCKSPort 5000\n"
- "HiddenServiceSingleHopMode 1\n"
- "HiddenServiceNonAnonymousMode 1\n"
- "Tor2webMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- /* Test that a hidden service can't be run with Tor2web
- * Use HiddenServiceNonAnonymousMode instead of Tor2webMode, because
- * Tor2webMode requires a compilation #define */
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceSingleHopMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "HiddenServiceNonAnonymousMode does not provide any "
- "server anonymity. It must be used with "
- "HiddenServiceSingleHopMode set to 1.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "HiddenServiceNonAnonymousMode 1\n"
- "HiddenServiceDir /Library/Tor/var/lib/tor/hidden_service/\n"
- "HiddenServicePort 80 127.0.0.1:8080\n"
- "HiddenServiceSingleHopMode 1\n"
- "SOCKSPort 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_ptr_op(msg, OP_EQ, NULL);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__accounting(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- setup_capture_of_logs(LOG_WARN);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule something_bad\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "AccountingRule must be 'sum', 'max', 'in', or 'out'");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule sum\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_SUM);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingRule max\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_MAX);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingStart fail\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Failed to parse accounting options. See logs for details.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccountingMax 10\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(
- TEST_OPTIONS_DEFAULT_VALUES
- "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
- 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.");
- // TODO: I think this points to a bug/regression in options_validate
- TEST_TESTING_OPTION(TestingConsensusMaxDownloadTries, 1, 801,
- "must be greater than 2.");
- TEST_TESTING_OPTION(TestingDescriptorMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- TEST_TESTING_OPTION(TestingMicrodescMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- TEST_TESTING_OPTION(TestingCertMaxDownloadTries, 1, 801,
- "must be greater than 1.");
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableConnBwEvent may only be changed in "
- "testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableConnBwEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableCellStatsEvent may only be changed in "
- "testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableCellStatsEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ, "TestingEnableTbEmptyEvent may only be changed "
- "in testing Tor networks!");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 1\n"
- "___UsingTestNetworkDefaults 0\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "TestingEnableTbEmptyEvent 1\n"
- VALID_DIR_AUTH
- "TestingTorNetwork 0\n"
- "___UsingTestNetworkDefaults 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_assert(!msg);
- tor_free(msg);
- done:
- policies_free_all();
- teardown_capture_of_logs();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- static void
- test_options_validate__accel(void *ignored)
- {
- (void)ignored;
- int ret;
- char *msg;
- options_test_data_t *tdata = NULL;
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelName foo\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 1);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelName foo\n"
- );
- tdata->opt->HardwareAccel = 2;
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tt_int_op(tdata->opt->HardwareAccel, OP_EQ, 2);
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelDir 1\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, -1);
- tt_str_op(msg, OP_EQ,
- "Can't use hardware crypto accelerator dir without engine name.");
- tor_free(msg);
- free_options_test_data(tdata);
- tdata = get_options_test_data(TEST_OPTIONS_DEFAULT_VALUES
- "AccelDir 1\n"
- "AccelName something\n"
- );
- ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
- tt_int_op(ret, OP_EQ, 0);
- tor_free(msg);
- done:
- policies_free_all();
- free_options_test_data(tdata);
- tor_free(msg);
- }
- #define LOCAL_VALIDATE_TEST(name) \
- { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
- struct testcase_t options_tests[] = {
- { "validate", test_options_validate, TT_FORK, NULL, NULL },
- { "mem_dircache", test_have_enough_mem_for_dircache, TT_FORK, NULL, NULL },
- LOCAL_VALIDATE_TEST(uname_for_server),
- LOCAL_VALIDATE_TEST(outbound_addresses),
- LOCAL_VALIDATE_TEST(data_directory),
- LOCAL_VALIDATE_TEST(nickname),
- LOCAL_VALIDATE_TEST(contactinfo),
- LOCAL_VALIDATE_TEST(logs),
- LOCAL_VALIDATE_TEST(authdir),
- LOCAL_VALIDATE_TEST(relay_with_hidden_services),
- LOCAL_VALIDATE_TEST(transproxy),
- LOCAL_VALIDATE_TEST(exclude_nodes),
- LOCAL_VALIDATE_TEST(scheduler),
- LOCAL_VALIDATE_TEST(node_families),
- LOCAL_VALIDATE_TEST(token_bucket),
- LOCAL_VALIDATE_TEST(recommended_packages),
- LOCAL_VALIDATE_TEST(fetch_dir),
- LOCAL_VALIDATE_TEST(conn_limit),
- LOCAL_VALIDATE_TEST(paths_needed),
- LOCAL_VALIDATE_TEST(max_client_circuits),
- LOCAL_VALIDATE_TEST(ports),
- LOCAL_VALIDATE_TEST(reachable_addresses),
- LOCAL_VALIDATE_TEST(use_bridges),
- LOCAL_VALIDATE_TEST(entry_nodes),
- LOCAL_VALIDATE_TEST(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(port_forwarding),
- LOCAL_VALIDATE_TEST(tor2web),
- LOCAL_VALIDATE_TEST(rend),
- LOCAL_VALIDATE_TEST(single_onion),
- LOCAL_VALIDATE_TEST(accounting),
- LOCAL_VALIDATE_TEST(proxy),
- LOCAL_VALIDATE_TEST(control),
- LOCAL_VALIDATE_TEST(families),
- LOCAL_VALIDATE_TEST(addr_policies),
- LOCAL_VALIDATE_TEST(dir_auth),
- LOCAL_VALIDATE_TEST(transport),
- LOCAL_VALIDATE_TEST(constrained_sockets),
- LOCAL_VALIDATE_TEST(v3_auth),
- LOCAL_VALIDATE_TEST(virtual_addr),
- LOCAL_VALIDATE_TEST(testing_options),
- LOCAL_VALIDATE_TEST(accel),
- END_OF_TESTCASES /* */
- };
|