database_unittest.cc 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #include "faked_nsec3.h"
  15. #include <exceptions/exceptions.h>
  16. #include <dns/masterload.h>
  17. #include <dns/name.h>
  18. #include <dns/rrttl.h>
  19. #include <dns/rrset.h>
  20. #include <dns/nsec3hash.h>
  21. #include <exceptions/exceptions.h>
  22. #include <datasrc/database.h>
  23. #include <datasrc/zone.h>
  24. #include <datasrc/data_source.h>
  25. #include <datasrc/iterator.h>
  26. #include <datasrc/sqlite3_accessor.h>
  27. #include <testutils/dnsmessage_test.h>
  28. #include <gtest/gtest.h>
  29. #include <boost/bind.hpp>
  30. #include <boost/shared_ptr.hpp>
  31. #include <boost/lexical_cast.hpp>
  32. #include <cstdlib>
  33. #include <map>
  34. #include <vector>
  35. using namespace isc::datasrc;
  36. using namespace std;
  37. // don't import the entire boost namespace. It will unexpectedly hide uint32_t
  38. // for some systems.
  39. using boost::dynamic_pointer_cast;
  40. using boost::lexical_cast;
  41. using namespace isc::dns;
  42. using namespace isc::testutils;
  43. using namespace isc::datasrc::test;
  44. namespace {
  45. // Imaginary zone IDs used in the mock accessor below.
  46. const int READONLY_ZONE_ID = 42;
  47. const int WRITABLE_ZONE_ID = 4200;
  48. // Commonly used test data
  49. const char* const TEST_RECORDS[][5] = {
  50. // some plain data
  51. {"www.example.org.", "A", "3600", "", "192.0.2.1"},
  52. {"www.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  53. {"www.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  54. {"www.example.org.", "NSEC", "3600", "", "www2.example.org. A AAAA NSEC RRSIG"},
  55. {"www.example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  56. {"www2.example.org.", "A", "3600", "", "192.0.2.1"},
  57. {"www2.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  58. {"www2.example.org.", "A", "3600", "", "192.0.2.2"},
  59. {"cname.example.org.", "CNAME", "3600", "", "www.example.org."},
  60. // some DNSSEC-'signed' data
  61. {"signed1.example.org.", "A", "3600", "", "192.0.2.1"},
  62. {"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  63. {"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
  64. {"signed1.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  65. {"signed1.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  66. {"signed1.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  67. {"signedcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
  68. {"signedcname1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  69. // special case might fail; sig is for cname, which isn't there (should be ignored)
  70. // (ignoring of 'normal' other type is done above by www.)
  71. {"acnamesig1.example.org.", "A", "3600", "", "192.0.2.1"},
  72. {"acnamesig1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  73. {"acnamesig1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  74. // let's pretend we have a database that is not careful
  75. // about the order in which it returns data
  76. {"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  77. {"signed2.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  78. {"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
  79. {"signed2.example.org.", "A", "3600", "", "192.0.2.1"},
  80. {"signed2.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  81. {"signed2.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  82. {"signedcname2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  83. {"signedcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
  84. {"acnamesig2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  85. {"acnamesig2.example.org.", "A", "3600", "", "192.0.2.1"},
  86. {"acnamesig2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  87. {"acnamesig3.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  88. {"acnamesig3.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  89. {"acnamesig3.example.org.", "A", "3600", "", "192.0.2.1"},
  90. {"ttldiff1.example.org.", "A", "3600", "", "192.0.2.1"},
  91. {"ttldiff1.example.org.", "A", "360", "", "192.0.2.2"},
  92. {"ttldiff2.example.org.", "A", "360", "", "192.0.2.1"},
  93. {"ttldiff2.example.org.", "A", "3600", "", "192.0.2.2"},
  94. // also add some intentionally bad data
  95. {"badcname1.example.org.", "A", "3600", "", "192.0.2.1"},
  96. {"badcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
  97. {"badcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
  98. {"badcname2.example.org.", "A", "3600", "", "192.0.2.1"},
  99. {"badcname3.example.org.", "CNAME", "3600", "", "www.example.org."},
  100. {"badcname3.example.org.", "CNAME", "3600", "", "www.example2.org."},
  101. {"badrdata.example.org.", "A", "3600", "", "bad"},
  102. {"badtype.example.org.", "BAD_TYPE", "3600", "", "192.0.2.1"},
  103. {"badttl.example.org.", "A", "badttl", "", "192.0.2.1"},
  104. {"badsig.example.org.", "A", "badttl", "", "192.0.2.1"},
  105. {"badsig.example.org.", "RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  106. {"badsigtype.example.org.", "A", "3600", "", "192.0.2.1"},
  107. {"badsigtype.example.org.", "RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  108. // Data for testing delegation (with NS and DNAME)
  109. {"delegation.example.org.", "NS", "3600", "", "ns.example.com."},
  110. {"delegation.example.org.", "NS", "3600", "",
  111. "ns.delegation.example.org."},
  112. {"delegation.example.org.", "DS", "3600", "", "1 RSAMD5 2 abcd"},
  113. {"delegation.example.org.", "RRSIG", "3600", "", "NS 5 3 3600 "
  114. "20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  115. {"ns.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
  116. {"deep.below.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
  117. {"dname.example.org.", "A", "3600", "", "192.0.2.1"},
  118. {"dname.example.org.", "DNAME", "3600", "", "dname.example.com."},
  119. {"dname.example.org.", "RRSIG", "3600", "",
  120. "DNAME 5 3 3600 20000101000000 20000201000000 12345 "
  121. "example.org. FAKEFAKEFAKE"},
  122. {"below.dname.example.org.", "A", "3600", "", "192.0.2.1"},
  123. // Broken NS
  124. {"brokenns1.example.org.", "A", "3600", "", "192.0.2.1"},
  125. {"brokenns1.example.org.", "NS", "3600", "", "ns.example.com."},
  126. {"brokenns2.example.org.", "NS", "3600", "", "ns.example.com."},
  127. {"brokenns2.example.org.", "A", "3600", "", "192.0.2.1"},
  128. // Now double DNAME, to test failure mode
  129. {"baddname.example.org.", "DNAME", "3600", "", "dname1.example.com."},
  130. {"baddname.example.org.", "DNAME", "3600", "", "dname2.example.com."},
  131. // Put some data into apex (including NS) so we can check our NS
  132. // doesn't break anything
  133. {"example.org.", "SOA", "3600", "", "ns1.example.org. admin.example.org. "
  134. "1234 3600 1800 2419200 7200" },
  135. {"example.org.", "NS", "3600", "", "ns.example.com."},
  136. {"example.org.", "A", "3600", "", "192.0.2.1"},
  137. // Note that the RDATA text is "normalized", i.e., identical to what
  138. // Rdata::toText() would produce. some tests rely on that behavior.
  139. {"example.org.", "NSEC", "3600", "",
  140. "acnamesig1.example.org. A NS RRSIG NSEC"},
  141. {"example.org.", "RRSIG", "3600", "", "SOA 5 3 3600 20000101000000 "
  142. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  143. {"example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 "
  144. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  145. {"example.org.", "RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
  146. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  147. // This is because of empty domain test
  148. {"a.b.example.org.", "A", "3600", "", "192.0.2.1"},
  149. // Something for wildcards
  150. {"*.wild.example.org.", "A", "3600", "", "192.0.2.5"},
  151. {"*.wild.example.org.", "RRSIG", "3600", "A", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  152. {"*.wild.example.org.", "NSEC", "3600", "", "cancel.here.wild.example.org. A NSEC RRSIG"},
  153. {"*.wild.example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  154. {"cancel.here.wild.example.org.", "AAAA", "3600", "", "2001:db8::5"},
  155. {"delegatedwild.example.org.", "NS", "3600", "", "ns.example.com."},
  156. {"*.delegatedwild.example.org.", "A", "3600", "", "192.0.2.5"},
  157. {"wild.*.foo.example.org.", "A", "3600", "", "192.0.2.5"},
  158. {"wild.*.foo.*.bar.example.org.", "A", "3600", "", "192.0.2.5"},
  159. {"wild.*.foo.*.bar.example.org.", "NSEC", "3600", "",
  160. "brokenns1.example.org. A NSEC"},
  161. {"bao.example.org.", "NSEC", "3600", "", "wild.*.foo.*.bar.example.org. NSEC"},
  162. {"*.cnamewild.example.org.", "CNAME", "3600", "", "www.example.org."},
  163. {"*.dnamewild.example.org.", "DNAME", "3600", "", "dname.example.com."},
  164. {"*.nswild.example.org.", "NS", "3600", "", "ns.example.com."},
  165. // For NSEC empty non-terminal
  166. {"l.example.org.", "NSEC", "3600", "", "empty.nonterminal.example.org. NSEC"},
  167. {"empty.nonterminal.example.org.", "A", "3600", "", "192.0.2.1"},
  168. // Invalid rdata
  169. {"invalidrdata.example.org.", "A", "3600", "", "Bunch of nonsense"},
  170. {"invalidrdata2.example.org.", "A", "3600", "", "192.0.2.1"},
  171. {"invalidrdata2.example.org.", "RRSIG", "3600", "", "Nonsense"},
  172. {NULL, NULL, NULL, NULL, NULL},
  173. };
  174. // FIXME: Taken from a different test. Fill with proper data when creating a test.
  175. const char* TEST_NSEC3_RECORDS[][5] = {
  176. {apex_hash, "NSEC3", "300", "", "1 1 12 AABBCCDD 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"},
  177. {apex_hash, "RRSIG", "300", "", "NSEC3 5 4 7200 20100410172647 20100311172647 63192 example.org. gNIVj4T8t51fEU6kOPpvK7HOGBFZGbalN5ZK mInyrww6UWZsUNdw07ge6/U6HfG+/s61RZ/L is2M6yUWHyXbNbj/QqwqgadG5dhxTArfuR02 xP600x0fWX8LXzW4yLMdKVxGbzYT+vvGz71o 8gHSY5vYTtothcZQa4BMKhmGQEk="},
  178. {ns1_hash, "NSEC3", "300", "", "1 1 12 AABBCCDD 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"},
  179. {ns1_hash, "RRSIG", "300", "", "NSEC3 5 4 7200 20100410172647 20100311172647 63192 example.org. gNIVj4T8t51fEU6kOPpvK7HOGBFZGbalN5ZK mInyrww6UWZsUNdw07ge6/U6HfG+/s61RZ/L is2M6yUWHyXbNbj/QqwqgadG5dhxTArfuR02 xP600x0fWX8LXzW4yLMdKVxGbzYT+vvGz71o 8gHSY5vYTtothcZQa4BMKhmGQEk="},
  180. {w_hash, "NSEC3", "300", "", "1 1 12 AABBCCDD 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"},
  181. {w_hash, "RRSIG", "300", "", "NSEC3 5 4 7200 20100410172647 20100311172647 63192 example.org. gNIVj4T8t51fEU6kOPpvK7HOGBFZGbalN5ZK mInyrww6UWZsUNdw07ge6/U6HfG+/s61RZ/L is2M6yUWHyXbNbj/QqwqgadG5dhxTArfuR02 xP600x0fWX8LXzW4yLMdKVxGbzYT+vvGz71o 8gHSY5vYTtothcZQa4BMKhmGQEk="},
  182. {zzz_hash, "NSEC3", "300", "", "1 1 12 AABBCCDD 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG"},
  183. {zzz_hash, "RRSIG", "300", "", "NSEC3 5 4 7200 20100410172647 20100311172647 63192 example.org. gNIVj4T8t51fEU6kOPpvK7HOGBFZGbalN5ZK mInyrww6UWZsUNdw07ge6/U6HfG+/s61RZ/L is2M6yUWHyXbNbj/QqwqgadG5dhxTArfuR02 xP600x0fWX8LXzW4yLMdKVxGbzYT+vvGz71o 8gHSY5vYTtothcZQa4BMKhmGQEk="},
  184. {NULL, NULL, NULL, NULL, NULL}
  185. };
  186. /*
  187. * An accessor with minimum implementation, keeping the original
  188. * "NotImplemented" methods.
  189. */
  190. class NopAccessor : public DatabaseAccessor {
  191. public:
  192. NopAccessor() : database_name_("mock_database")
  193. { }
  194. virtual std::pair<bool, int> getZone(const std::string& name) const {
  195. if (name == "example.org.") {
  196. return (std::pair<bool, int>(true, READONLY_ZONE_ID));
  197. } else if (name == "null.example.org.") {
  198. return (std::pair<bool, int>(true, 13));
  199. } else if (name == "empty.example.org.") {
  200. return (std::pair<bool, int>(true, 0));
  201. } else if (name == "bad.example.org.") {
  202. return (std::pair<bool, int>(true, -1));
  203. } else {
  204. return (std::pair<bool, int>(false, 0));
  205. }
  206. }
  207. virtual boost::shared_ptr<DatabaseAccessor> clone() {
  208. // This accessor is stateless, so we can simply return a new instance.
  209. return (boost::shared_ptr<DatabaseAccessor>(new NopAccessor));
  210. }
  211. virtual std::pair<bool, int> startUpdateZone(const std::string&, bool) {
  212. // return dummy value. unused anyway.
  213. return (pair<bool, int>(true, 0));
  214. }
  215. virtual void startTransaction() {}
  216. virtual void commit() {}
  217. virtual void rollback() {}
  218. virtual void addRecordToZone(const string (&)[ADD_COLUMN_COUNT]) {}
  219. virtual void addNSEC3RecordToZone(const string (&)[ADD_NSEC3_COLUMN_COUNT])
  220. {}
  221. virtual void deleteRecordInZone(const string (&)[DEL_PARAM_COUNT]) {}
  222. virtual void deleteNSEC3RecordInZone(const string (&)[DEL_PARAM_COUNT]) {}
  223. virtual void addRecordDiff(int, uint32_t, DiffOperation,
  224. const std::string (&)[DIFF_PARAM_COUNT]) {}
  225. virtual const std::string& getDBName() const {
  226. return (database_name_);
  227. }
  228. virtual IteratorContextPtr getRecords(const std::string&, int, bool)
  229. const
  230. {
  231. isc_throw(isc::NotImplemented,
  232. "This database datasource can't be iterated");
  233. }
  234. virtual IteratorContextPtr getNSEC3Records(const std::string&, int) const {
  235. isc_throw(isc::NotImplemented, "This test database datasource won't "
  236. "give you any NSEC3. Ever. Ask someone else.");
  237. }
  238. virtual IteratorContextPtr getAllRecords(int) const {
  239. isc_throw(isc::NotImplemented,
  240. "This database datasource can't be iterated");
  241. }
  242. virtual IteratorContextPtr getDiffs(int, uint32_t, uint32_t) const {
  243. isc_throw(isc::NotImplemented,
  244. "This database datasource doesn't support diffs");
  245. }
  246. virtual std::string findPreviousName(int, const std::string&) const {
  247. isc_throw(isc::NotImplemented,
  248. "This data source doesn't support DNSSEC");
  249. }
  250. virtual std::string findPreviousNSEC3Hash(int, const std::string&) const {
  251. isc_throw(isc::NotImplemented,
  252. "This test database knows nothing about NSEC3 nor order");
  253. }
  254. private:
  255. const std::string database_name_;
  256. };
  257. /**
  258. * Single journal entry in the mock database.
  259. *
  260. * All the members there are public for simplicity, as it only stores data.
  261. * We use the implicit constructor and operator. The members can't be const
  262. * because of the assignment operator (used in the vectors).
  263. */
  264. struct JournalEntry {
  265. JournalEntry(int id, uint32_t serial,
  266. DatabaseAccessor::DiffOperation operation,
  267. const std::string (&data)[DatabaseAccessor::DIFF_PARAM_COUNT])
  268. : id_(id), serial_(serial), operation_(operation)
  269. {
  270. data_[DatabaseAccessor::DIFF_NAME] = data[DatabaseAccessor::DIFF_NAME];
  271. data_[DatabaseAccessor::DIFF_TYPE] = data[DatabaseAccessor::DIFF_TYPE];
  272. data_[DatabaseAccessor::DIFF_TTL] = data[DatabaseAccessor::DIFF_TTL];
  273. data_[DatabaseAccessor::DIFF_RDATA] =
  274. data[DatabaseAccessor::DIFF_RDATA];
  275. }
  276. JournalEntry(int id, uint32_t serial,
  277. DatabaseAccessor::DiffOperation operation,
  278. const std::string& name, const std::string& type,
  279. const std::string& ttl, const std::string& rdata):
  280. id_(id), serial_(serial), operation_(operation)
  281. {
  282. data_[DatabaseAccessor::DIFF_NAME] = name;
  283. data_[DatabaseAccessor::DIFF_TYPE] = type;
  284. data_[DatabaseAccessor::DIFF_TTL] = ttl;
  285. data_[DatabaseAccessor::DIFF_RDATA] = rdata;
  286. }
  287. int id_;
  288. uint32_t serial_;
  289. DatabaseAccessor::DiffOperation operation_;
  290. std::string data_[DatabaseAccessor::DIFF_PARAM_COUNT];
  291. bool operator==(const JournalEntry& other) const {
  292. for (size_t i = 0; i < DatabaseAccessor::DIFF_PARAM_COUNT; ++ i) {
  293. if (data_[i] != other.data_[i]) {
  294. return false;
  295. }
  296. }
  297. // No need to check data here, checked above
  298. return (id_ == other.id_ && serial_ == other.serial_ &&
  299. operation_ == other.operation_);
  300. }
  301. };
  302. /*
  303. * A virtual database accessor that pretends it contains single zone --
  304. * example.org.
  305. *
  306. * It has the same getZone method as NopConnection, but it provides
  307. * implementation of the optional functionality.
  308. */
  309. class MockAccessor : public NopAccessor {
  310. // Type of mock database "row"s. This is a map whose keys are the
  311. // own names. We internally sort them by the name comparison order.
  312. struct NameCompare : public binary_function<string, string, bool> {
  313. bool operator()(const string& n1, const string& n2) const {
  314. return (Name(n1).compare(Name(n2)).getOrder() < 0);
  315. }
  316. };
  317. typedef std::map<std::string,
  318. std::vector< std::vector<std::string> >,
  319. NameCompare > Domains;
  320. public:
  321. MockAccessor() : rollbacked_(false), did_transaction_(false) {
  322. readonly_records_ = &readonly_records_master_;
  323. update_records_ = &update_records_master_;
  324. nsec3_namespace_ = &nsec3_namespace_master_;
  325. update_nsec3_namespace_ = &update_nsec3_namespace_master_;
  326. empty_records_ = &empty_records_master_;
  327. journal_entries_ = &journal_entries_master_;
  328. fillData();
  329. }
  330. virtual boost::shared_ptr<DatabaseAccessor> clone() {
  331. boost::shared_ptr<MockAccessor> cloned_accessor(new MockAccessor());
  332. cloned_accessor->readonly_records_ = &readonly_records_master_;
  333. cloned_accessor->update_records_ = &update_records_master_;
  334. cloned_accessor->nsec3_namespace_ = &nsec3_namespace_master_;
  335. cloned_accessor->update_nsec3_namespace_ =
  336. &update_nsec3_namespace_master_;
  337. cloned_accessor->empty_records_ = &empty_records_master_;
  338. cloned_accessor->journal_entries_ = &journal_entries_master_;
  339. latest_clone_ = cloned_accessor;
  340. return (cloned_accessor);
  341. }
  342. virtual void startTransaction() {
  343. // Currently we only use this transaction for simple read-only
  344. // operations. So we just make a local copy of the data (we don't
  345. // care about what happens after commit() or rollback()).
  346. // Obviously as a consequence, if a test case tries to make multiple
  347. // transactions on a single mock accessor it will fail.
  348. // Check any attempt of multiple transactions
  349. if (did_transaction_) {
  350. isc_throw(isc::Unexpected, "MockAccessor::startTransaction() "
  351. "called multiple times - likely a bug in the test");
  352. }
  353. readonly_records_copy_ = *readonly_records_;
  354. readonly_records_ = &readonly_records_copy_;
  355. did_transaction_ = true;
  356. }
  357. private:
  358. class DomainIterator : public IteratorContext {
  359. public:
  360. DomainIterator(const std::vector<std::vector<std::string> >& domain) :
  361. domain_(domain),
  362. position_(domain_.begin())
  363. {}
  364. virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) {
  365. if (position_ == domain_.end()) {
  366. return (false);
  367. } else {
  368. for (size_t i(0); i < COLUMN_COUNT; ++ i) {
  369. columns[i] = (*position_)[i];
  370. }
  371. ++ position_;
  372. return (true);
  373. }
  374. }
  375. private:
  376. const std::vector<std::vector<std::string> > domain_;
  377. std::vector<std::vector<std::string> >::const_iterator position_;
  378. };
  379. class MockNameIteratorContext : public IteratorContext {
  380. public:
  381. MockNameIteratorContext(const MockAccessor& mock_accessor, int zone_id,
  382. const std::string& name, bool subdomains) :
  383. searched_name_(name), cur_record_(0)
  384. {
  385. // 'hardcoded' names to trigger exceptions
  386. // On these names some exceptions are thrown, to test the robustness
  387. // of the find() method.
  388. if (searched_name_ == "dsexception.example.org.") {
  389. isc_throw(DataSourceError, "datasource exception on search");
  390. } else if (searched_name_ == "iscexception.example.org.") {
  391. isc_throw(isc::Exception, "isc exception on search");
  392. } else if (searched_name_ == "basicexception.example.org.") {
  393. throw std::exception();
  394. }
  395. cur_record_ = 0;
  396. const Domains& cur_records = mock_accessor.getMockRecords(zone_id);
  397. if (cur_records.count(name) > 0) {
  398. // we're not aiming for efficiency in this test, simply
  399. // copy the relevant vector from records
  400. cur_name = cur_records.find(name)->second;
  401. } else if (subdomains) {
  402. cur_name.clear();
  403. // Just walk everything and check if it is a subdomain.
  404. // If it is, just copy all data from there.
  405. for (Domains::const_iterator i = cur_records.begin();
  406. i != cur_records.end(); ++i) {
  407. const Name local(i->first);
  408. if (local.compare(Name(name)).getRelation() ==
  409. isc::dns::NameComparisonResult::SUBDOMAIN) {
  410. cur_name.insert(cur_name.end(), i->second.begin(),
  411. i->second.end());
  412. }
  413. }
  414. } else {
  415. cur_name.clear();
  416. }
  417. }
  418. virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) {
  419. if (searched_name_ == "dsexception.getnext.example.org.") {
  420. isc_throw(DataSourceError, "datasource exception on getnextrecord");
  421. } else if (searched_name_ == "iscexception.getnext.example.org.") {
  422. isc_throw(isc::Exception, "isc exception on getnextrecord");
  423. } else if (searched_name_ ==
  424. "basicexception.getnext.example.org.") {
  425. throw std::exception();
  426. }
  427. if (cur_record_ < cur_name.size()) {
  428. for (size_t i = 0; i < COLUMN_COUNT; ++i) {
  429. columns[i] = cur_name[cur_record_][i];
  430. }
  431. cur_record_++;
  432. return (true);
  433. } else {
  434. return (false);
  435. }
  436. }
  437. private:
  438. const std::string searched_name_;
  439. size_t cur_record_;
  440. std::vector< std::vector<std::string> > cur_name;
  441. };
  442. class MockIteratorContext : public IteratorContext {
  443. private:
  444. int step;
  445. const Domains& domains_;
  446. public:
  447. MockIteratorContext(const Domains& domains) :
  448. step(0), domains_(domains)
  449. { }
  450. virtual bool getNext(string (&data)[COLUMN_COUNT]) {
  451. // A special case: if the given set of domains is already empty,
  452. // we always return false.
  453. if (domains_.empty()) {
  454. return (false);
  455. }
  456. // Return faked data for tests
  457. // This is the sequence of zone data in the order of appearance
  458. // in the returned sequence from this iterator.
  459. typedef const char* ColumnText[4];
  460. const ColumnText zone_data[] = {
  461. // A couple of basic RRs at the zone origin.
  462. {"example.org", "A", "3600", "192.0.2.1"},
  463. {"example.org", "SOA", "3600", "ns1.example.org. "
  464. "admin.example.org. 1234 3600 1800 2419200 7200"},
  465. // RRsets sharing the same owner name with multiple RRs.
  466. {"x.example.org", "A", "300", "192.0.2.1"},
  467. {"x.example.org", "A", "300", "192.0.2.2"},
  468. {"x.example.org", "AAAA", "300", "2001:db8::1"},
  469. {"x.example.org", "AAAA", "300", "2001:db8::2"},
  470. // RRSIGs. Covered types are different and these two should
  471. // be distinguished.
  472. {"x.example.org", "RRSIG", "300",
  473. "A 5 3 3600 20000101000000 20000201000000 12345 "
  474. "example.org. FAKEFAKEFAKE"},
  475. {"x.example.org", "RRSIG", "300",
  476. "AAAA 5 3 3600 20000101000000 20000201000000 12345 "
  477. "example.org. FAKEFAKEFAKEFAKE"},
  478. // Mixture of different TTLs. Covering both cases of small
  479. // then large and large then small. In either case the smaller
  480. // TTL should win.
  481. {"ttldiff.example.org", "A", "300", "192.0.2.1"},
  482. {"ttldiff.example.org", "A", "600", "192.0.2.2"},
  483. {"ttldiff2.example.org", "AAAA", "600", "2001:db8::1"},
  484. {"ttldiff2.example.org", "AAAA", "300", "2001:db8::2"}};
  485. const size_t num_rrs = sizeof(zone_data) / sizeof(zone_data[0]);
  486. if (step > num_rrs) {
  487. ADD_FAILURE() << "Request past the end of iterator context";
  488. } else if (step < num_rrs) {
  489. data[DatabaseAccessor::NAME_COLUMN] = zone_data[step][0];
  490. data[DatabaseAccessor::TYPE_COLUMN] = zone_data[step][1];
  491. data[DatabaseAccessor::TTL_COLUMN] = zone_data[step][2];
  492. data[DatabaseAccessor::RDATA_COLUMN] = zone_data[step][3];
  493. ++step;
  494. return (true);
  495. }
  496. return (false);
  497. }
  498. };
  499. class EmptyIteratorContext : public IteratorContext {
  500. public:
  501. virtual bool getNext(string(&)[COLUMN_COUNT]) {
  502. return (false);
  503. }
  504. };
  505. class BadIteratorContext : public IteratorContext {
  506. private:
  507. int step;
  508. public:
  509. BadIteratorContext() :
  510. step(0)
  511. { }
  512. virtual bool getNext(string (&data)[COLUMN_COUNT]) {
  513. switch (step ++) {
  514. case 0:
  515. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  516. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  517. data[DatabaseAccessor::TTL_COLUMN] = "300";
  518. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
  519. return (true);
  520. case 1:
  521. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  522. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  523. data[DatabaseAccessor::TTL_COLUMN] = "301";
  524. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
  525. return (true);
  526. default:
  527. ADD_FAILURE() <<
  528. "Request past the end of iterator context";
  529. case 2:
  530. return (false);
  531. }
  532. }
  533. };
  534. class MockDiffIteratorContext : public IteratorContext {
  535. const vector<JournalEntry> diffs_;
  536. vector<JournalEntry>::const_iterator it_;
  537. public:
  538. MockDiffIteratorContext(const vector<JournalEntry>& diffs) :
  539. diffs_(diffs), it_(diffs_.begin())
  540. {}
  541. virtual bool getNext(string (&data)[COLUMN_COUNT]) {
  542. if (it_ == diffs_.end()) {
  543. return (false);
  544. }
  545. data[DatabaseAccessor::NAME_COLUMN] =
  546. (*it_).data_[DatabaseAccessor::DIFF_NAME];
  547. data[DatabaseAccessor::TYPE_COLUMN] =
  548. (*it_).data_[DatabaseAccessor::DIFF_TYPE];
  549. data[DatabaseAccessor::TTL_COLUMN] =
  550. (*it_).data_[DatabaseAccessor::DIFF_TTL];
  551. data[DatabaseAccessor::RDATA_COLUMN] =
  552. (*it_).data_[DatabaseAccessor::DIFF_RDATA];
  553. ++it_;
  554. return (true);
  555. }
  556. };
  557. public:
  558. virtual IteratorContextPtr getAllRecords(int id) const {
  559. if (id == READONLY_ZONE_ID) {
  560. return (IteratorContextPtr(new MockIteratorContext(
  561. *readonly_records_)));
  562. } else if (id == 13) {
  563. return (IteratorContextPtr());
  564. } else if (id == 0) {
  565. return (IteratorContextPtr(new EmptyIteratorContext()));
  566. } else if (id == -1) {
  567. return (IteratorContextPtr(new BadIteratorContext()));
  568. } else {
  569. isc_throw(isc::Unexpected, "Unknown zone ID");
  570. }
  571. }
  572. virtual IteratorContextPtr getRecords(const std::string& name, int id,
  573. bool subdomains) const
  574. {
  575. if (id == READONLY_ZONE_ID || id == WRITABLE_ZONE_ID) {
  576. return (IteratorContextPtr(
  577. new MockNameIteratorContext(*this, id, name,
  578. subdomains)));
  579. } else {
  580. // This iterator is bogus, but for the cases tested below that's
  581. // sufficient.
  582. return (IteratorContextPtr(
  583. new MockNameIteratorContext(*this, READONLY_ZONE_ID,
  584. name, subdomains)));
  585. }
  586. }
  587. virtual IteratorContextPtr getNSEC3Records(const std::string& hash,
  588. int) const
  589. {
  590. Domains::const_iterator it(nsec3_namespace_->find(hash));
  591. if (it == nsec3_namespace_->end()) {
  592. return (IteratorContextPtr(new EmptyIteratorContext()));
  593. } else {
  594. return (IteratorContextPtr(new DomainIterator(it->second)));
  595. }
  596. }
  597. virtual pair<bool, int> startUpdateZone(const std::string& zone_name,
  598. bool replace)
  599. {
  600. const pair<bool, int> zone_info = getZone(zone_name);
  601. if (!zone_info.first) {
  602. return (pair<bool, int>(false, 0));
  603. }
  604. // Prepare the record set for update. If replacing the existing one,
  605. // we use an empty set; otherwise we use a writable copy of the
  606. // original.
  607. if (replace) {
  608. update_records_->clear();
  609. update_nsec3_namespace_->clear();
  610. } else {
  611. *update_records_ = *readonly_records_;
  612. *update_nsec3_namespace_ = nsec3_namespace_master_;
  613. }
  614. if (zone_name == "bad.example.org.") {
  615. return (pair<bool, int>(true, -1));
  616. } else if (zone_name == "null.example.org.") {
  617. return (pair<bool, int>(true, 13));
  618. } else {
  619. return (pair<bool, int>(true, WRITABLE_ZONE_ID));
  620. }
  621. }
  622. virtual void commit() {
  623. *readonly_records_ = *update_records_;
  624. *nsec3_namespace_ = *update_nsec3_namespace_;
  625. }
  626. virtual void rollback() {
  627. // Special hook: if something with a name of "throw.example.org"
  628. // has been added, trigger an imaginary unexpected event with an
  629. // exception.
  630. if (update_records_->count("throw.example.org.") > 0) {
  631. isc_throw(DataSourceError, "unexpected failure in rollback");
  632. }
  633. rollbacked_ = true;
  634. }
  635. private:
  636. // Common subroutine for addRecordToZone and addNSEC3RecordToZone.
  637. void addRecord(Domains& domains,
  638. const string (&columns)[ADD_COLUMN_COUNT])
  639. {
  640. // Copy the current value to cur_name. If it doesn't exist,
  641. // operator[] will create a new one.
  642. cur_name_ = domains[columns[ADD_NAME]];
  643. vector<string> record_columns;
  644. record_columns.push_back(columns[ADD_TYPE]);
  645. record_columns.push_back(columns[ADD_TTL]);
  646. record_columns.push_back(columns[ADD_SIGTYPE]);
  647. record_columns.push_back(columns[ADD_RDATA]);
  648. record_columns.push_back(columns[ADD_NAME]);
  649. // copy back the added entry
  650. cur_name_.push_back(record_columns);
  651. domains[columns[DatabaseAccessor::ADD_NAME]] = cur_name_;
  652. // remember this one so that test cases can check it.
  653. copy(columns, columns + DatabaseAccessor::ADD_COLUMN_COUNT,
  654. columns_lastadded_);
  655. }
  656. public:
  657. virtual void addRecordToZone(const string (&columns)[ADD_COLUMN_COUNT]) {
  658. addRecord(*update_records_, columns);
  659. }
  660. virtual void addNSEC3RecordToZone(
  661. const string (&columns)[ADD_NSEC3_COLUMN_COUNT])
  662. {
  663. // Convert the NSEC3 parameters in the normal (non NSEC3) style so
  664. // we can share the merge code, and then update using addRecord().
  665. string normal_columns[ADD_COLUMN_COUNT];
  666. normal_columns[ADD_TYPE] = columns[ADD_NSEC3_TYPE];
  667. normal_columns[ADD_TTL] = columns[ADD_NSEC3_TTL];
  668. normal_columns[ADD_SIGTYPE] = "";
  669. normal_columns[ADD_RDATA] = columns[ADD_NSEC3_RDATA];
  670. normal_columns[ADD_NAME] = columns[ADD_NSEC3_HASH];
  671. addRecord(*update_nsec3_namespace_, normal_columns);
  672. }
  673. private:
  674. // Helper predicate class used in deleteRecordInZone().
  675. struct deleteMatch {
  676. deleteMatch(const string& type, const string& rdata) :
  677. type_(type), rdata_(rdata)
  678. {}
  679. bool operator()(const vector<string>& row) const {
  680. return (row[0] == type_ && row[3] == rdata_);
  681. }
  682. const string& type_;
  683. const string& rdata_;
  684. };
  685. // Common subroutine for deleteRecordinZone and deleteNSEC3RecordInZone.
  686. void deleteRecord(Domains& domains,
  687. const string (&params)[DEL_PARAM_COUNT])
  688. {
  689. vector<vector<string> >& records =
  690. domains[params[DatabaseAccessor::DEL_NAME]];
  691. records.erase(remove_if(records.begin(), records.end(),
  692. deleteMatch(
  693. params[DatabaseAccessor::DEL_TYPE],
  694. params[DatabaseAccessor::DEL_RDATA])),
  695. records.end());
  696. if (records.empty()) {
  697. domains.erase(params[DatabaseAccessor::DEL_NAME]);
  698. }
  699. }
  700. public:
  701. virtual void deleteRecordInZone(const string (&params)[DEL_PARAM_COUNT]) {
  702. deleteRecord(*update_records_, params);
  703. }
  704. virtual void deleteNSEC3RecordInZone(
  705. const string (&params)[DEL_PARAM_COUNT])
  706. {
  707. deleteRecord(*update_nsec3_namespace_, params);
  708. }
  709. //
  710. // Helper methods to keep track of some update related activities
  711. //
  712. bool isRollbacked() const {
  713. return (rollbacked_);
  714. }
  715. const string* getLastAdded() const {
  716. return (columns_lastadded_);
  717. }
  718. // This allows the test code to get the accessor used in an update context
  719. boost::shared_ptr<const MockAccessor> getLatestClone() const {
  720. return (latest_clone_);
  721. }
  722. virtual std::string findPreviousName(int id, const std::string& rname)
  723. const
  724. {
  725. if (id == -1) {
  726. isc_throw(isc::NotImplemented, "Test not implemented behaviour");
  727. } else if (id == READONLY_ZONE_ID) {
  728. // For some specific names we intentionally return broken or
  729. // unexpected result.
  730. if (rname == "org.example.badnsec2.") {
  731. return ("badnsec1.example.org.");
  732. } else if (rname == "org.example.brokenname.") {
  733. return ("brokenname...example.org.");
  734. } else if (rname == "org.example.notimplnsec." ||
  735. rname == "org.example.wild.here.") {
  736. isc_throw(isc::NotImplemented, "Not implemented in this test");
  737. }
  738. // For the general case, we search for the first name N in the
  739. // domains that meets N >= reverse(rname) using lower_bound.
  740. // The "previous name" is the name of the previous entry of N.
  741. // Note that Domains are internally sorted by the Name comparison
  742. // order. Due to the API requirement we are given a reversed
  743. // name (rname), so we need to reverse it again to convert it
  744. // to the original name.
  745. Domains::const_iterator it(readonly_records_->lower_bound(
  746. Name(rname).reverse().toText()));
  747. if (it == readonly_records_->begin()) {
  748. isc_throw(isc::Unexpected, "Unexpected name");
  749. }
  750. if (it == readonly_records_->end()) {
  751. return ((*readonly_records_->rbegin()).first);
  752. }
  753. return ((*(--it)).first);
  754. } else {
  755. isc_throw(isc::Unexpected, "Unknown zone ID");
  756. }
  757. }
  758. virtual std::string findPreviousNSEC3Hash(int,
  759. const std::string& hash) const
  760. {
  761. // TODO: Provide some broken data, but it is not known yet how broken
  762. // they'll have to be.
  763. Domains::const_iterator it(nsec3_namespace_->lower_bound(hash));
  764. // We got just after the one we want
  765. if (it == nsec3_namespace_->begin()) {
  766. // Hmm, we got something really small. So we wrap around.
  767. // This is one after the last, so after decreasing it we'll get
  768. // the biggest.
  769. it = nsec3_namespace_->end();
  770. }
  771. return ((--it)->first);
  772. }
  773. virtual void addRecordDiff(int id, uint32_t serial,
  774. DiffOperation operation,
  775. const std::string (&data)[DIFF_PARAM_COUNT])
  776. {
  777. if (id == 13) { // The null zone doesn't support journaling
  778. isc_throw(isc::NotImplemented, "Test not implemented behaviour");
  779. } else if (id == -1) { // Bad zone throws
  780. isc_throw(DataSourceError, "Test error");
  781. } else {
  782. journal_entries_->push_back(JournalEntry(id, serial, operation,
  783. data));
  784. }
  785. }
  786. virtual IteratorContextPtr getDiffs(int id, uint32_t start,
  787. uint32_t end) const
  788. {
  789. vector<JournalEntry> selected_jnl;
  790. for (vector<JournalEntry>::const_iterator it =
  791. journal_entries_->begin();
  792. it != journal_entries_->end(); ++it)
  793. {
  794. // For simplicity we assume this method is called for the
  795. // "readonly" zone possibly after making updates on the "writable"
  796. // copy and committing them.
  797. if (id != READONLY_ZONE_ID) {
  798. continue;
  799. }
  800. // Note: the following logic is not 100% accurate in terms of
  801. // serial number arithmetic; we prefer brevity for testing.
  802. // Skip until we see the starting serial. Once we started
  803. // recording this condition is ignored (to support wrap-around
  804. // case). Also, it ignores the RR type; it only checks the
  805. // versions.
  806. if ((*it).serial_ < start && selected_jnl.empty()) {
  807. continue;
  808. }
  809. if ((*it).serial_ > end) { // gone over the end serial. we're done.
  810. break;
  811. }
  812. selected_jnl.push_back(*it);
  813. }
  814. // Check if we've found the requested range. If not, throw.
  815. if (selected_jnl.empty() || selected_jnl.front().serial_ != start ||
  816. selected_jnl.back().serial_ != end) {
  817. isc_throw(NoSuchSerial, "requested diff range is not found");
  818. }
  819. return (IteratorContextPtr(new MockDiffIteratorContext(selected_jnl)));
  820. }
  821. // Check the journal is as expected and clear the journal
  822. void checkJournal(const std::vector<JournalEntry> &expected) const {
  823. std::vector<JournalEntry> journal;
  824. // Clean the journal, but keep local copy to check
  825. journal.swap(*journal_entries_);
  826. ASSERT_EQ(expected.size(), journal.size());
  827. for (size_t i = 0; i < expected.size(); ++ i) {
  828. EXPECT_TRUE(expected[i] == journal[i]);
  829. }
  830. }
  831. private:
  832. // The following member variables are storage and/or update work space
  833. // of the test zone. The "master"s are the real objects that contain
  834. // the data, and they are shared among all accessors cloned from
  835. // an initially created one. The "copy" data will be used for read-only
  836. // transaction. The pointer members allow the sharing.
  837. // "readonly" is for normal lookups. "update" is the workspace for
  838. // updates. When update starts it will be initialized either as an
  839. // empty set (when replacing the entire zone) or as a copy of the
  840. // "readonly" one. "empty" is a sentinel to produce negative results.
  841. Domains readonly_records_master_;
  842. Domains readonly_records_copy_;
  843. Domains* readonly_records_;
  844. Domains update_records_master_;
  845. Domains* update_records_;
  846. Domains nsec3_namespace_master_;
  847. Domains* nsec3_namespace_;
  848. Domains update_nsec3_namespace_master_;
  849. Domains* update_nsec3_namespace_;
  850. const Domains empty_records_master_;
  851. const Domains* empty_records_;
  852. // The journal data
  853. std::vector<JournalEntry> journal_entries_master_;
  854. std::vector<JournalEntry>* journal_entries_;
  855. // used as temporary storage after searchForRecord() and during
  856. // getNextRecord() calls, as well as during the building of the
  857. // fake data
  858. std::vector< std::vector<std::string> > cur_name_;
  859. // The columns that were most recently added via addRecordToZone()
  860. string columns_lastadded_[ADD_COLUMN_COUNT];
  861. // Whether rollback operation has been performed for the database.
  862. // Not useful except for purely testing purpose.
  863. bool rollbacked_;
  864. // Remember the mock accessor that was last cloned
  865. boost::shared_ptr<MockAccessor> latest_clone_;
  866. // Internal flag for duplicate check
  867. bool did_transaction_;
  868. const Domains& getMockRecords(int zone_id) const {
  869. if (zone_id == READONLY_ZONE_ID) {
  870. return (*readonly_records_);
  871. } else if (zone_id == WRITABLE_ZONE_ID) {
  872. return (*update_records_);
  873. }
  874. return (*empty_records_);
  875. }
  876. // Adds one record to the current name in the database
  877. // The actual data will not be added to 'records' until
  878. // addCurName() is called
  879. void addRecord(const std::string& type,
  880. const std::string& ttl,
  881. const std::string& sigtype,
  882. const std::string& rdata) {
  883. std::vector<std::string> columns;
  884. columns.push_back(type);
  885. columns.push_back(ttl);
  886. columns.push_back(sigtype);
  887. columns.push_back(rdata);
  888. cur_name_.push_back(columns);
  889. }
  890. // Adds all records we just built with calls to addRecords
  891. // to the actual fake database. This will clear cur_name_,
  892. // so we can immediately start adding new records.
  893. void addCurName(const std::string& name) {
  894. ASSERT_EQ(0, readonly_records_->count(name));
  895. // Append the name to all of them
  896. for (std::vector<std::vector<std::string> >::iterator
  897. i = cur_name_.begin(); i != cur_name_.end(); ++ i) {
  898. i->push_back(name);
  899. }
  900. (*readonly_records_)[name] = cur_name_;
  901. cur_name_.clear();
  902. }
  903. // Works in a similar way to addCurName, but it is added to
  904. // the NSEC3 namespace. You don't provide the full name, only
  905. // the hash part.
  906. void addCurHash(const std::string& hash) {
  907. ASSERT_EQ(0, nsec3_namespace_->count(hash));
  908. // Append the name to all of them
  909. for (std::vector<std::vector<std::string> >::iterator
  910. i = cur_name_.begin(); i != cur_name_.end(); ++ i) {
  911. i->push_back(hash);
  912. }
  913. (*nsec3_namespace_)[hash] = cur_name_;
  914. cur_name_.clear();
  915. }
  916. // Fills the database with zone data.
  917. // This method constructs a number of resource records (with addRecord),
  918. // which will all be added for one domain name to the fake database
  919. // (with addCurName). So for instance the first set of calls create
  920. // data for the name 'www.example.org', which will consist of one A RRset
  921. // of one record, and one AAAA RRset of two records.
  922. // The order in which they are added is the order in which getNextRecord()
  923. // will return them (so we can test whether find() etc. support data that
  924. // might not come in 'normal' order)
  925. // It shall immediately fail if you try to add the same name twice.
  926. void fillData() {
  927. const char* prev_name = NULL;
  928. for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
  929. if (prev_name != NULL &&
  930. strcmp(prev_name, TEST_RECORDS[i][0]) != 0) {
  931. addCurName(prev_name);
  932. }
  933. prev_name = TEST_RECORDS[i][0];
  934. addRecord(TEST_RECORDS[i][1], TEST_RECORDS[i][2],
  935. TEST_RECORDS[i][3], TEST_RECORDS[i][4]);
  936. }
  937. addCurName(prev_name);
  938. prev_name = NULL;
  939. for (int i = 0; TEST_NSEC3_RECORDS[i][0] != NULL; ++i) {
  940. if (prev_name != NULL &&
  941. strcmp(prev_name, TEST_NSEC3_RECORDS[i][0]) != 0) {
  942. addCurHash(prev_name);
  943. }
  944. prev_name = TEST_NSEC3_RECORDS[i][0];
  945. addRecord(TEST_NSEC3_RECORDS[i][1], TEST_NSEC3_RECORDS[i][2],
  946. TEST_NSEC3_RECORDS[i][3], TEST_NSEC3_RECORDS[i][4]);
  947. }
  948. addCurHash(prev_name);
  949. }
  950. public:
  951. // This adds the NSEC3PARAM into the apex, so we can perform some NSEC3
  952. // tests. Note that the NSEC3 namespace is available in other tests, but
  953. // it should not be accessed at that time.
  954. void enableNSEC3() {
  955. // We place the signature first, so it's in the block with the other
  956. // signatures
  957. vector<string> signature;
  958. signature.push_back("RRSIG");
  959. signature.push_back("3600");
  960. signature.push_back("");
  961. signature.push_back("NSEC3PARAM 5 3 3600 20000101000000 20000201000000 "
  962. "12345 example.org. FAKEFAKEFAKE");
  963. signature.push_back("exmaple.org.");
  964. (*readonly_records_)["example.org."].push_back(signature);
  965. // Now the NSEC3 param itself
  966. vector<string> param;
  967. param.push_back("NSEC3PARAM");
  968. param.push_back("3600");
  969. param.push_back("");
  970. param.push_back("1 0 12 aabbccdd");
  971. param.push_back("example.org.");
  972. (*readonly_records_)["example.org."].push_back(param);
  973. }
  974. };
  975. // This tests the default getRecords behaviour, throwing NotImplemented
  976. TEST(DatabaseConnectionTest, getRecords) {
  977. EXPECT_THROW(NopAccessor().getRecords(".", 1, false),
  978. isc::NotImplemented);
  979. }
  980. // This tests the default getAllRecords behaviour, throwing NotImplemented
  981. TEST(DatabaseConnectionTest, getAllRecords) {
  982. // The parameters don't matter
  983. EXPECT_THROW(NopAccessor().getAllRecords(1),
  984. isc::NotImplemented);
  985. }
  986. // This test fixture is templated so that we can share (most of) the test
  987. // cases with different types of data sources. Note that in test cases
  988. // we need to use 'this' to refer to member variables of the test class.
  989. template <typename ACCESSOR_TYPE>
  990. class DatabaseClientTest : public ::testing::Test {
  991. public:
  992. DatabaseClientTest() : zname_("example.org"), qname_("www.example.org"),
  993. qclass_(RRClass::IN()), qtype_(RRType::A()),
  994. rrttl_(3600)
  995. {
  996. createClient();
  997. // set up the commonly used finder.
  998. DataSourceClient::FindResult zone(client_->findZone(zname_));
  999. assert(zone.code == result::SUCCESS);
  1000. finder_ = dynamic_pointer_cast<DatabaseClient::Finder>(
  1001. zone.zone_finder);
  1002. // Test IN/A RDATA to be added in update tests. Intentionally using
  1003. // different data than the initial data configured in the MockAccessor.
  1004. rrset_.reset(new RRset(qname_, qclass_, qtype_, rrttl_));
  1005. rrset_->addRdata(rdata::createRdata(rrset_->getType(),
  1006. rrset_->getClass(), "192.0.2.2"));
  1007. soa_.reset(new RRset(zname_, qclass_, RRType::SOA(), rrttl_));
  1008. soa_->addRdata(rdata::createRdata(soa_->getType(), soa_->getClass(),
  1009. "ns1.example.org. admin.example.org. "
  1010. "1234 3600 1800 2419200 7200"));
  1011. // And its RRSIG. Also different from the configured one.
  1012. rrsigset_.reset(new RRset(qname_, qclass_, RRType::RRSIG(),
  1013. rrttl_));
  1014. rrsigset_->addRdata(rdata::createRdata(rrsigset_->getType(),
  1015. rrsigset_->getClass(),
  1016. "A 5 3 0 20000101000000 "
  1017. "20000201000000 0 example.org. "
  1018. "FAKEFAKEFAKE"));
  1019. }
  1020. ~ DatabaseClientTest() {
  1021. // Make sure we return the default creator no matter if we set it or not
  1022. setNSEC3HashCreator(NULL);
  1023. }
  1024. /*
  1025. * We initialize the client from a function, so we can call it multiple
  1026. * times per test.
  1027. */
  1028. void createClient() {
  1029. // To make sure we always have empty diffs table at the beginning of
  1030. // each test, we re-install the writable data source here.
  1031. // Note: this is SQLite3 specific and a waste (though otherwise
  1032. // harmless) for other types of data sources. If and when we support
  1033. // more types of data sources in this test framework, we should
  1034. // probably move this to some specialized templated method specific
  1035. // to SQLite3 (or for even a longer term we should add an API to
  1036. // purge the diffs table).
  1037. const char* const install_cmd = INSTALL_PROG " -c " TEST_DATA_COMMONDIR
  1038. "/rwtest.sqlite3 " TEST_DATA_BUILDDIR
  1039. "/rwtest.sqlite3.copied";
  1040. if (system(install_cmd) != 0) {
  1041. // any exception will do, this is failure in test setup, but nice
  1042. // to show the command that fails, and shouldn't be caught
  1043. isc_throw(isc::Exception,
  1044. "Error setting up; command failed: " << install_cmd);
  1045. }
  1046. current_accessor_ = new ACCESSOR_TYPE();
  1047. is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_) != NULL);
  1048. client_.reset(new DatabaseClient(qclass_,
  1049. boost::shared_ptr<ACCESSOR_TYPE>(
  1050. current_accessor_)));
  1051. }
  1052. /**
  1053. * Check the zone finder is a valid one and references the zone ID and
  1054. * database available here.
  1055. */
  1056. void checkZoneFinder(const DataSourceClient::FindResult& zone) {
  1057. ASSERT_NE(ZoneFinderPtr(), zone.zone_finder) << "No zone finder";
  1058. boost::shared_ptr<DatabaseClient::Finder> finder(
  1059. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  1060. ASSERT_NE(boost::shared_ptr<DatabaseClient::Finder>(), finder) <<
  1061. "Wrong type of finder";
  1062. if (is_mock_) {
  1063. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  1064. }
  1065. EXPECT_EQ(current_accessor_, &finder->getAccessor());
  1066. }
  1067. boost::shared_ptr<DatabaseClient::Finder> getFinder() {
  1068. DataSourceClient::FindResult zone(client_->findZone(zname_));
  1069. EXPECT_EQ(result::SUCCESS, zone.code);
  1070. boost::shared_ptr<DatabaseClient::Finder> finder(
  1071. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  1072. if (is_mock_) {
  1073. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  1074. }
  1075. return (finder);
  1076. }
  1077. // Helper methods for update tests
  1078. bool isRollbacked(bool expected = false) const {
  1079. if (is_mock_) {
  1080. const MockAccessor& mock_accessor =
  1081. dynamic_cast<const MockAccessor&>(*update_accessor_);
  1082. return (mock_accessor.isRollbacked());
  1083. } else {
  1084. return (expected);
  1085. }
  1086. }
  1087. void checkLastAdded(const char* const expected[]) const {
  1088. if (is_mock_) {
  1089. const MockAccessor* mock_accessor =
  1090. dynamic_cast<const MockAccessor*>(current_accessor_);
  1091. for (int i = 0; i < DatabaseAccessor::ADD_COLUMN_COUNT; ++i) {
  1092. EXPECT_EQ(expected[i],
  1093. mock_accessor->getLatestClone()->getLastAdded()[i]);
  1094. }
  1095. }
  1096. }
  1097. void setUpdateAccessor() {
  1098. if (is_mock_) {
  1099. const MockAccessor* mock_accessor =
  1100. dynamic_cast<const MockAccessor*>(current_accessor_);
  1101. update_accessor_ = mock_accessor->getLatestClone();
  1102. }
  1103. }
  1104. void checkJournal(const vector<JournalEntry>& expected) {
  1105. if (is_mock_) {
  1106. const MockAccessor* mock_accessor =
  1107. dynamic_cast<const MockAccessor*>(current_accessor_);
  1108. mock_accessor->checkJournal(expected);
  1109. } else {
  1110. // For other generic databases, retrieve the diff using the
  1111. // reader class and compare the resulting sequence of RRset.
  1112. // For simplicity we only consider the case where the expected
  1113. // sequence is not empty.
  1114. ASSERT_FALSE(expected.empty());
  1115. const Name zone_name(expected.front().
  1116. data_[DatabaseAccessor::DIFF_NAME]);
  1117. ZoneJournalReaderPtr jnl_reader =
  1118. client_->getJournalReader(zone_name,
  1119. expected.front().serial_,
  1120. expected.back().serial_).second;
  1121. ASSERT_TRUE(jnl_reader);
  1122. ConstRRsetPtr rrset;
  1123. vector<JournalEntry>::const_iterator it = expected.begin();
  1124. for (rrset = jnl_reader->getNextDiff();
  1125. rrset && it != expected.end();
  1126. rrset = jnl_reader->getNextDiff(), ++it) {
  1127. typedef DatabaseAccessor Accessor;
  1128. RRsetPtr expected_rrset(
  1129. new RRset(Name((*it).data_[Accessor::DIFF_NAME]),
  1130. qclass_,
  1131. RRType((*it).data_[Accessor::DIFF_TYPE]),
  1132. RRTTL((*it).data_[Accessor::DIFF_TTL])));
  1133. expected_rrset->addRdata(
  1134. rdata::createRdata(expected_rrset->getType(),
  1135. expected_rrset->getClass(),
  1136. (*it).data_[Accessor::DIFF_RDATA]));
  1137. rrsetCheck(expected_rrset, rrset);
  1138. }
  1139. // We should have examined all entries of both expected and
  1140. // actual data.
  1141. EXPECT_TRUE(it == expected.end());
  1142. ASSERT_FALSE(rrset);
  1143. }
  1144. }
  1145. // Some tests only work for MockAccessor. We remember whether our accessor
  1146. // is of that type.
  1147. bool is_mock_;
  1148. // Will be deleted by client_, just keep the current value for comparison.
  1149. ACCESSOR_TYPE* current_accessor_;
  1150. boost::shared_ptr<DatabaseClient> client_;
  1151. const std::string database_name_;
  1152. // The zone finder of the test zone commonly used in various tests.
  1153. boost::shared_ptr<DatabaseClient::Finder> finder_;
  1154. // Some shortcut variables for commonly used test parameters
  1155. const Name zname_; // the zone name stored in the test data source
  1156. const Name qname_; // commonly used name to be found
  1157. const RRClass qclass_; // commonly used RR class used with qname
  1158. const RRType qtype_; // commonly used RR type used with qname
  1159. const RRTTL rrttl_; // commonly used RR TTL
  1160. RRsetPtr rrset_; // for adding/deleting an RRset
  1161. RRsetPtr rrsigset_; // for adding/deleting an RRset
  1162. RRsetPtr soa_; // for adding/deleting an RRset
  1163. // update related objects to be tested
  1164. ZoneUpdaterPtr updater_;
  1165. boost::shared_ptr<const DatabaseAccessor> update_accessor_;
  1166. // placeholders
  1167. const std::vector<std::string> empty_rdatas_; // for NXRRSET/NXDOMAIN
  1168. std::vector<std::string> expected_rdatas_;
  1169. std::vector<std::string> expected_sig_rdatas_;
  1170. // A creator for use in several NSEC3 related tests.
  1171. TestNSEC3HashCreator test_nsec3_hash_creator_;
  1172. };
  1173. class TestSQLite3Accessor : public SQLite3Accessor {
  1174. public:
  1175. TestSQLite3Accessor() : SQLite3Accessor(
  1176. TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied", "IN")
  1177. {
  1178. startUpdateZone("example.org.", true);
  1179. string columns[ADD_COLUMN_COUNT];
  1180. for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
  1181. columns[ADD_NAME] = TEST_RECORDS[i][0];
  1182. columns[ADD_REV_NAME] = Name(columns[ADD_NAME]).reverse().toText();
  1183. columns[ADD_TYPE] = TEST_RECORDS[i][1];
  1184. columns[ADD_TTL] = TEST_RECORDS[i][2];
  1185. columns[ADD_SIGTYPE] = TEST_RECORDS[i][3];
  1186. columns[ADD_RDATA] = TEST_RECORDS[i][4];
  1187. addRecordToZone(columns);
  1188. }
  1189. commit();
  1190. }
  1191. };
  1192. // The following two lines instantiate test cases with concrete accessor
  1193. // classes to be tested.
  1194. // XXX: clang++ installed on our FreeBSD buildbot cannot complete compiling
  1195. // this file, seemingly due to the size of the code. We'll consider more
  1196. // complete workaround, but for a short term workaround we'll reduce the
  1197. // number of tested accessor classes (thus reducing the amount of code
  1198. // to be compiled) for this particular environment.
  1199. #if defined(__clang__) && defined(__FreeBSD__)
  1200. typedef ::testing::Types<MockAccessor> TestAccessorTypes;
  1201. #else
  1202. typedef ::testing::Types<MockAccessor, TestSQLite3Accessor> TestAccessorTypes;
  1203. #endif
  1204. TYPED_TEST_CASE(DatabaseClientTest, TestAccessorTypes);
  1205. // In some cases the entire test fixture is for the mock accessor only.
  1206. // We use the usual TEST_F for them with the corresponding specialized class
  1207. // to make the code simpler.
  1208. typedef DatabaseClientTest<MockAccessor> MockDatabaseClientTest;
  1209. TYPED_TEST(DatabaseClientTest, zoneNotFound) {
  1210. DataSourceClient::FindResult zone(
  1211. this->client_->findZone(Name("example.com")));
  1212. EXPECT_EQ(result::NOTFOUND, zone.code);
  1213. }
  1214. TYPED_TEST(DatabaseClientTest, exactZone) {
  1215. DataSourceClient::FindResult zone(
  1216. this->client_->findZone(Name("example.org")));
  1217. EXPECT_EQ(result::SUCCESS, zone.code);
  1218. this->checkZoneFinder(zone);
  1219. }
  1220. TYPED_TEST(DatabaseClientTest, superZone) {
  1221. DataSourceClient::FindResult zone(this->client_->findZone(Name(
  1222. "sub.example.org")));
  1223. EXPECT_EQ(result::PARTIALMATCH, zone.code);
  1224. this->checkZoneFinder(zone);
  1225. }
  1226. // This test doesn't depend on derived accessor class, so we use TEST().
  1227. TEST(GenericDatabaseClientTest, noAccessorException) {
  1228. // We need a dummy variable here; some compiler would regard it a mere
  1229. // declaration instead of an instantiation and make the test fail.
  1230. EXPECT_THROW(DatabaseClient dummy(RRClass::IN(),
  1231. boost::shared_ptr<DatabaseAccessor>()),
  1232. isc::InvalidParameter);
  1233. }
  1234. // If the zone doesn't exist, exception is thrown
  1235. TYPED_TEST(DatabaseClientTest, noZoneIterator) {
  1236. EXPECT_THROW(this->client_->getIterator(Name("example.com")),
  1237. DataSourceError);
  1238. }
  1239. // If the zone doesn't exist and iteration is not implemented, it still throws
  1240. // the exception it doesn't exist
  1241. TEST(GenericDatabaseClientTest, noZoneNotImplementedIterator) {
  1242. EXPECT_THROW(DatabaseClient(RRClass::IN(),
  1243. boost::shared_ptr<DatabaseAccessor>(
  1244. new NopAccessor())).getIterator(
  1245. Name("example.com")),
  1246. DataSourceError);
  1247. }
  1248. TEST(GenericDatabaseClientTest, notImplementedIterator) {
  1249. EXPECT_THROW(DatabaseClient(RRClass::IN(),
  1250. boost::shared_ptr<DatabaseAccessor>(
  1251. new NopAccessor())).getIterator(Name("example.org")),
  1252. isc::NotImplemented);
  1253. }
  1254. // Pretend a bug in the connection and pass NULL as the context
  1255. // Should not crash, but gracefully throw. Works for the mock accessor only.
  1256. TEST_F(MockDatabaseClientTest, nullIteratorContext) {
  1257. EXPECT_THROW(this->client_->getIterator(Name("null.example.org")),
  1258. isc::Unexpected);
  1259. }
  1260. // It doesn't crash or anything if the zone is completely empty.
  1261. // Works for the mock accessor only.
  1262. TEST_F(MockDatabaseClientTest, emptyIterator) {
  1263. ZoneIteratorPtr it(this->client_->getIterator(Name("empty.example.org")));
  1264. EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
  1265. // This is past the end, it should throw
  1266. EXPECT_THROW(it->getNextRRset(), isc::Unexpected);
  1267. }
  1268. // checks if the given rrset matches the
  1269. // given name, class, type and rdatas
  1270. void
  1271. checkRRset(isc::dns::ConstRRsetPtr rrset,
  1272. const isc::dns::Name& name,
  1273. const isc::dns::RRClass& rrclass,
  1274. const isc::dns::RRType& rrtype,
  1275. const isc::dns::RRTTL& rrttl,
  1276. const std::vector<std::string>& rdatas) {
  1277. isc::dns::RRsetPtr expected_rrset(
  1278. new isc::dns::RRset(name, rrclass, rrtype, rrttl));
  1279. for (unsigned int i = 0; i < rdatas.size(); ++i) {
  1280. expected_rrset->addRdata(
  1281. isc::dns::rdata::createRdata(rrtype, rrclass,
  1282. rdatas[i]));
  1283. }
  1284. rrsetCheck(expected_rrset, rrset);
  1285. }
  1286. // Iterate through a zone, common case
  1287. TYPED_TEST(DatabaseClientTest, iterator) {
  1288. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
  1289. ConstRRsetPtr rrset(it->getNextRRset());
  1290. ASSERT_NE(ConstRRsetPtr(), rrset);
  1291. // The first name should be the zone origin.
  1292. EXPECT_EQ(this->zname_, rrset->getName());
  1293. }
  1294. // Supplemental structure used in the couple of tests below. It represents
  1295. // parameters of an expected RRset containing up to two RDATAs. If it contains
  1296. // only one RDATA, rdata2 is NULL.
  1297. struct ExpectedRRset {
  1298. const char* const name;
  1299. const RRType rrtype;
  1300. const RRTTL rrttl;
  1301. const char* const rdata1;
  1302. const char* const rdata2;
  1303. };
  1304. // Common checker for the iterator tests below. It extracts RRsets from the
  1305. // give iterator and compare them to the expected sequence.
  1306. void
  1307. checkIteratorSequence(ZoneIterator& it, ExpectedRRset expected_sequence[],
  1308. size_t num_rrsets)
  1309. {
  1310. vector<string> expected_rdatas;
  1311. for (size_t i = 0; i < num_rrsets; ++i) {
  1312. const ConstRRsetPtr rrset = it.getNextRRset();
  1313. ASSERT_TRUE(rrset);
  1314. expected_rdatas.clear();
  1315. expected_rdatas.push_back(expected_sequence[i].rdata1);
  1316. if (expected_sequence[i].rdata2 != NULL) {
  1317. expected_rdatas.push_back(expected_sequence[i].rdata2);
  1318. }
  1319. checkRRset(rrset, Name(expected_sequence[i].name), RRClass::IN(),
  1320. expected_sequence[i].rrtype, expected_sequence[i].rrttl,
  1321. expected_rdatas);
  1322. }
  1323. EXPECT_FALSE(it.getNextRRset());
  1324. }
  1325. TEST_F(MockDatabaseClientTest, iterator) {
  1326. // This version of test creates an iterator that combines same types of
  1327. // RRs into single RRsets.
  1328. ExpectedRRset expected_sequence[] = {
  1329. {"example.org", RRType::A(), rrttl_, "192.0.2.1", NULL},
  1330. {"example.org", RRType::SOA(), rrttl_,
  1331. "ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200",
  1332. NULL},
  1333. {"x.example.org", RRType::A(), RRTTL(300), "192.0.2.1", "192.0.2.2"},
  1334. {"x.example.org", RRType::AAAA(), RRTTL(300),
  1335. "2001:db8::1", "2001:db8::2"},
  1336. {"x.example.org", RRType::RRSIG(), RRTTL(300),
  1337. "A 5 3 3600 20000101000000 20000201000000 12345 example.org. "
  1338. "FAKEFAKEFAKE", NULL},
  1339. {"x.example.org", RRType::RRSIG(), RRTTL(300),
  1340. "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. "
  1341. "FAKEFAKEFAKEFAKE", NULL},
  1342. {"ttldiff.example.org", RRType::A(), RRTTL(300),
  1343. "192.0.2.1", "192.0.2.2"},
  1344. {"ttldiff2.example.org", RRType::AAAA(), RRTTL(300),
  1345. "2001:db8::1", "2001:db8::2"}
  1346. };
  1347. checkIteratorSequence(*client_->getIterator(Name("example.org")),
  1348. expected_sequence,
  1349. sizeof(expected_sequence) /
  1350. sizeof(expected_sequence[0]));
  1351. }
  1352. TEST_F(MockDatabaseClientTest, iteratorSeparateRRs) {
  1353. // This version of test creates an iterator that separates all RRs as
  1354. // individual RRsets. In particular, it preserves the TTLs of an RRset
  1355. // even if they are different.
  1356. ExpectedRRset expected_sequence[] = {
  1357. {"example.org", RRType::A(), rrttl_, "192.0.2.1", NULL},
  1358. {"example.org", RRType::SOA(), rrttl_,
  1359. "ns1.example.org. admin.example.org. 1234 3600 1800 2419200 7200",
  1360. NULL},
  1361. {"x.example.org", RRType::A(), RRTTL(300), "192.0.2.1", NULL},
  1362. {"x.example.org", RRType::A(), RRTTL(300), "192.0.2.2", NULL},
  1363. {"x.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::1", NULL},
  1364. {"x.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::2", NULL},
  1365. {"x.example.org", RRType::RRSIG(), RRTTL(300),
  1366. "A 5 3 3600 20000101000000 20000201000000 12345 example.org. "
  1367. "FAKEFAKEFAKE", NULL},
  1368. {"x.example.org", RRType::RRSIG(), RRTTL(300),
  1369. "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. "
  1370. "FAKEFAKEFAKEFAKE", NULL},
  1371. {"ttldiff.example.org", RRType::A(), RRTTL(300), "192.0.2.1", NULL},
  1372. {"ttldiff.example.org", RRType::A(), RRTTL(600), "192.0.2.2", NULL},
  1373. {"ttldiff2.example.org", RRType::AAAA(), RRTTL(600), "2001:db8::1",
  1374. NULL},
  1375. {"ttldiff2.example.org", RRType::AAAA(), RRTTL(300), "2001:db8::2",
  1376. NULL}
  1377. };
  1378. checkIteratorSequence(*client_->getIterator(Name("example.org"), true),
  1379. expected_sequence,
  1380. sizeof(expected_sequence) /
  1381. sizeof(expected_sequence[0]));
  1382. }
  1383. // This has inconsistent TTL in the set (the rest, like nonsense in
  1384. // the data is handled in rdata itself). Works for the mock accessor only.
  1385. TEST_F(MockDatabaseClientTest, badIterator) {
  1386. // It should not throw, but get the lowest one of them
  1387. ZoneIteratorPtr it(this->client_->getIterator(Name("bad.example.org")));
  1388. EXPECT_EQ(it->getNextRRset()->getTTL(), isc::dns::RRTTL(300));
  1389. }
  1390. TYPED_TEST(DatabaseClientTest, getSOAFromIterator) {
  1391. vector<string> soa_data;
  1392. soa_data.push_back("ns1.example.org. admin.example.org. "
  1393. "1234 3600 1800 2419200 7200");
  1394. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1395. ASSERT_TRUE(it);
  1396. checkRRset(it->getSOA(), this->zname_, this->qclass_, RRType::SOA(),
  1397. this->rrttl_, soa_data);
  1398. // Iterate over the zone until we find an SOA. Although there's a broken
  1399. // RDATA that would trigger an exception in getNextRRset(), we should
  1400. // reach the SOA as the sequence should be sorted and the SOA is at
  1401. // the origin name (which has no bogus data).
  1402. ConstRRsetPtr rrset;
  1403. while ((rrset = it->getNextRRset()) != ConstRRsetPtr() &&
  1404. rrset->getType() != RRType::SOA()) {
  1405. ;
  1406. }
  1407. ASSERT_TRUE(rrset);
  1408. // It should be identical to the result of getSOA().
  1409. rrsetCheck(it->getSOA(), rrset);
  1410. }
  1411. TYPED_TEST(DatabaseClientTest, noSOAFromIterator) {
  1412. // First, empty the zone.
  1413. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1414. this->updater_->commit();
  1415. // Then getSOA() should return NULL.
  1416. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1417. ASSERT_TRUE(it);
  1418. EXPECT_FALSE(it->getSOA());
  1419. }
  1420. TYPED_TEST(DatabaseClientTest, iterateThenUpdate) {
  1421. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1422. ASSERT_TRUE(it);
  1423. // Try to empty the zone after getting the iterator. Depending on the
  1424. // underlying data source, it may result in an exception due to the
  1425. // transaction for the iterator. In either case the integrity of the
  1426. // iterator result should be reserved.
  1427. try {
  1428. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1429. this->updater_->commit();
  1430. // Confirm at least it doesn't contain any SOA
  1431. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  1432. this->getFinder()->find(this->zname_, RRType::SOA())->code);
  1433. } catch (const DataSourceError&) {}
  1434. ConstRRsetPtr rrset;
  1435. while ((rrset = it->getNextRRset()) != ConstRRsetPtr() &&
  1436. rrset->getType() != RRType::SOA()) {
  1437. ;
  1438. }
  1439. ASSERT_TRUE(rrset);
  1440. // It should be identical to the result of getSOA().
  1441. rrsetCheck(it->getSOA(), rrset);
  1442. }
  1443. TYPED_TEST(DatabaseClientTest, updateThenIterateThenUpdate) {
  1444. // First clear the zone.
  1445. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1446. this->updater_->commit();
  1447. // Then iterate over it. It should immediately reach the end, at which
  1448. // point the transaction should be committed.
  1449. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1450. ASSERT_TRUE(it);
  1451. EXPECT_FALSE(it->getNextRRset());
  1452. // So another update attempt should succeed, too.
  1453. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1454. this->updater_->commit();
  1455. }
  1456. TYPED_TEST(DatabaseClientTest, updateAfterDeleteIterator) {
  1457. // Similar to the previous case, but we delete the iterator in the
  1458. // middle of zone. The transaction should be canceled (actually no
  1459. // different from commit though) at that point.
  1460. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1461. ASSERT_TRUE(it);
  1462. EXPECT_TRUE(it->getNextRRset());
  1463. it.reset();
  1464. // So another update attempt should succeed.
  1465. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1466. this->updater_->commit();
  1467. }
  1468. void
  1469. doFindTest(ZoneFinder& finder,
  1470. const isc::dns::Name& name,
  1471. const isc::dns::RRType& type,
  1472. const isc::dns::RRType& expected_type,
  1473. const isc::dns::RRTTL expected_ttl,
  1474. ZoneFinder::Result expected_result,
  1475. const std::vector<std::string>& expected_rdatas,
  1476. const std::vector<std::string>& expected_sig_rdatas,
  1477. ZoneFinder::FindResultFlags expected_flags =
  1478. ZoneFinder::RESULT_DEFAULT,
  1479. const isc::dns::Name& expected_name = isc::dns::Name::ROOT_NAME(),
  1480. const ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT)
  1481. {
  1482. SCOPED_TRACE("doFindTest " + name.toText() + " " + type.toText());
  1483. ConstZoneFinderContextPtr result = finder.find(name, type, options);
  1484. ASSERT_EQ(expected_result, result->code) << name << " " << type;
  1485. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_WILDCARD) != 0,
  1486. result->isWildcard());
  1487. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC_SIGNED) != 0,
  1488. result->isNSECSigned());
  1489. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC3_SIGNED) != 0,
  1490. result->isNSEC3Signed());
  1491. if (!expected_rdatas.empty() && result->rrset) {
  1492. checkRRset(result->rrset, expected_name != Name(".") ? expected_name :
  1493. name, finder.getClass(), expected_type, expected_ttl,
  1494. expected_rdatas);
  1495. if (!expected_sig_rdatas.empty() && result->rrset->getRRsig()) {
  1496. checkRRset(result->rrset->getRRsig(), expected_name != Name(".") ?
  1497. expected_name : name, finder.getClass(),
  1498. isc::dns::RRType::RRSIG(), expected_ttl,
  1499. expected_sig_rdatas);
  1500. } else if (expected_sig_rdatas.empty()) {
  1501. EXPECT_EQ(isc::dns::RRsetPtr(), result->rrset->getRRsig()) <<
  1502. "Unexpected RRSIG: " << result->rrset->getRRsig()->toText();
  1503. } else {
  1504. ADD_FAILURE() << "Missing RRSIG";
  1505. }
  1506. } else if (expected_rdatas.empty()) {
  1507. EXPECT_EQ(isc::dns::RRsetPtr(), result->rrset) <<
  1508. "Unexpected RRset: " << result->rrset->toText();
  1509. } else {
  1510. ADD_FAILURE() << "Missing result";
  1511. }
  1512. }
  1513. void
  1514. doFindAllTestResult(ZoneFinder& finder, const isc::dns::Name& name,
  1515. ZoneFinder::Result expected_result,
  1516. const isc::dns::RRType expected_type,
  1517. std::vector<std::string> expected_rdata,
  1518. const isc::dns::Name& expected_name =
  1519. isc::dns::Name::ROOT_NAME(),
  1520. const ZoneFinder::FindOptions options =
  1521. ZoneFinder::FIND_DEFAULT,
  1522. ZoneFinder::FindResultFlags expected_flags =
  1523. ZoneFinder::RESULT_DEFAULT)
  1524. {
  1525. SCOPED_TRACE("All test for " + name.toText());
  1526. std::vector<ConstRRsetPtr> target;
  1527. ConstZoneFinderContextPtr result(finder.findAll(name, target, options));
  1528. EXPECT_TRUE(target.empty());
  1529. EXPECT_EQ(expected_result, result->code);
  1530. EXPECT_EQ(expected_type, result->rrset->getType());
  1531. if (expected_flags != ZoneFinder::RESULT_DEFAULT){
  1532. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_WILDCARD) != 0,
  1533. result->isWildcard());
  1534. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC_SIGNED) != 0,
  1535. result->isNSECSigned());
  1536. EXPECT_EQ((expected_flags & ZoneFinder::RESULT_NSEC3_SIGNED) != 0,
  1537. result->isNSEC3Signed());
  1538. }
  1539. RdataIteratorPtr it(result->rrset->getRdataIterator());
  1540. std::vector<std::string> rdata;
  1541. while (!it->isLast()) {
  1542. rdata.push_back(it->getCurrent().toText());
  1543. it->next();
  1544. }
  1545. std::sort(rdata.begin(), rdata.end());
  1546. std::sort(expected_rdata.begin(), expected_rdata.end());
  1547. ASSERT_EQ(expected_rdata.size(), rdata.size());
  1548. for (size_t i(0); i < expected_rdata.size(); ++ i) {
  1549. EXPECT_EQ(expected_rdata[i], rdata[i]);
  1550. }
  1551. EXPECT_TRUE(expected_rdata == rdata);
  1552. EXPECT_EQ(expected_name == isc::dns::Name::ROOT_NAME() ? name :
  1553. expected_name, result->rrset->getName());
  1554. }
  1555. // When asking for an RRset where RRs somehow have different TTLs, it should
  1556. // convert to the lowest one.
  1557. TEST_F(MockDatabaseClientTest, ttldiff) {
  1558. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
  1559. // Walk through the full iterator, we should see 1 rrset with name
  1560. // ttldiff1.example.org., and two rdatas. Same for ttldiff2
  1561. Name name("ttldiff.example.org.");
  1562. bool found = false;
  1563. //bool found2 = false;
  1564. ConstRRsetPtr rrset = it->getNextRRset();
  1565. while(rrset != ConstRRsetPtr()) {
  1566. if (rrset->getName() == name) {
  1567. ASSERT_FALSE(found);
  1568. ASSERT_EQ(2, rrset->getRdataCount());
  1569. ASSERT_EQ(RRTTL(300), rrset->getTTL());
  1570. found = true;
  1571. }
  1572. rrset = it->getNextRRset();
  1573. }
  1574. ASSERT_TRUE(found);
  1575. }
  1576. // Unless we ask for individual RRs in our iterator request. In that case
  1577. // every RR should go into its own 'rrset'
  1578. TEST_F(MockDatabaseClientTest, ttldiff_separate_rrs) {
  1579. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org"), true));
  1580. // Walk through the full iterator, we should see 1 rrset with name
  1581. // ttldiff1.example.org., and two rdatas. Same for ttldiff2
  1582. Name name("ttldiff.example.org.");
  1583. int found1 = false;
  1584. int found2 = false;
  1585. ConstRRsetPtr rrset = it->getNextRRset();
  1586. while(rrset != ConstRRsetPtr()) {
  1587. if (rrset->getName() == name) {
  1588. ASSERT_EQ(1, rrset->getRdataCount());
  1589. // We should find 1 'rrset' with TTL 300 and one with TTL 600
  1590. if (rrset->getTTL() == RRTTL(300)) {
  1591. ASSERT_FALSE(found1);
  1592. found1 = true;
  1593. } else if (rrset->getTTL() == RRTTL(600)) {
  1594. ASSERT_FALSE(found2);
  1595. found2 = true;
  1596. } else {
  1597. FAIL() << "Found unexpected TTL: " <<
  1598. rrset->getTTL().toText();
  1599. }
  1600. }
  1601. rrset = it->getNextRRset();
  1602. }
  1603. ASSERT_TRUE(found1);
  1604. ASSERT_TRUE(found2);
  1605. }
  1606. TYPED_TEST(DatabaseClientTest, find) {
  1607. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1608. this->expected_rdatas_.clear();
  1609. this->expected_sig_rdatas_.clear();
  1610. this->expected_rdatas_.push_back("192.0.2.1");
  1611. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1612. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1613. this->expected_rdatas_, this->expected_sig_rdatas_);
  1614. this->expected_rdatas_.clear();
  1615. this->expected_sig_rdatas_.clear();
  1616. this->expected_rdatas_.push_back("192.0.2.1");
  1617. this->expected_rdatas_.push_back("192.0.2.2");
  1618. doFindTest(*finder, isc::dns::Name("www2.example.org."),
  1619. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1620. this->expected_rdatas_, this->expected_sig_rdatas_);
  1621. this->expected_rdatas_.clear();
  1622. this->expected_sig_rdatas_.clear();
  1623. this->expected_rdatas_.push_back("2001:db8::1");
  1624. this->expected_rdatas_.push_back("2001:db8::2");
  1625. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1626. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1627. this->rrttl_,
  1628. ZoneFinder::SUCCESS,
  1629. this->expected_rdatas_, this->expected_sig_rdatas_);
  1630. this->expected_rdatas_.clear();
  1631. this->expected_sig_rdatas_.clear();
  1632. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1633. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
  1634. this->rrttl_,
  1635. ZoneFinder::NXRRSET,
  1636. this->expected_rdatas_, this->expected_sig_rdatas_);
  1637. this->expected_rdatas_.clear();
  1638. this->expected_sig_rdatas_.clear();
  1639. this->expected_rdatas_.push_back("www.example.org.");
  1640. doFindTest(*finder, isc::dns::Name("cname.example.org."),
  1641. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1642. ZoneFinder::CNAME, this->expected_rdatas_,
  1643. this->expected_sig_rdatas_);
  1644. this->expected_rdatas_.clear();
  1645. this->expected_sig_rdatas_.clear();
  1646. this->expected_rdatas_.push_back("www.example.org.");
  1647. doFindTest(*finder, isc::dns::Name("cname.example.org."),
  1648. isc::dns::RRType::CNAME(), isc::dns::RRType::CNAME(),
  1649. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1650. this->expected_sig_rdatas_);
  1651. this->expected_rdatas_.clear();
  1652. this->expected_sig_rdatas_.clear();
  1653. doFindTest(*finder, isc::dns::Name("doesnotexist.example.org."),
  1654. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1655. this->expected_rdatas_, this->expected_sig_rdatas_);
  1656. this->expected_rdatas_.clear();
  1657. this->expected_sig_rdatas_.clear();
  1658. this->expected_rdatas_.push_back("192.0.2.1");
  1659. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1660. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  1661. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1662. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1663. this->expected_rdatas_, this->expected_sig_rdatas_);
  1664. this->expected_rdatas_.clear();
  1665. this->expected_sig_rdatas_.clear();
  1666. this->expected_rdatas_.push_back("2001:db8::1");
  1667. this->expected_rdatas_.push_back("2001:db8::2");
  1668. this->expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1669. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1670. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1671. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1672. this->expected_sig_rdatas_);
  1673. this->expected_rdatas_.clear();
  1674. this->expected_sig_rdatas_.clear();
  1675. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1676. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(), this->rrttl_,
  1677. ZoneFinder::NXRRSET, this->expected_rdatas_,
  1678. this->expected_sig_rdatas_);
  1679. this->expected_rdatas_.clear();
  1680. this->expected_sig_rdatas_.clear();
  1681. this->expected_rdatas_.push_back("www.example.org.");
  1682. this->expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1683. doFindTest(*finder, isc::dns::Name("signedcname1.example.org."),
  1684. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1685. ZoneFinder::CNAME, this->expected_rdatas_,
  1686. this->expected_sig_rdatas_);
  1687. this->expected_rdatas_.clear();
  1688. this->expected_sig_rdatas_.clear();
  1689. this->expected_rdatas_.push_back("192.0.2.1");
  1690. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1691. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  1692. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1693. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1694. this->expected_rdatas_, this->expected_sig_rdatas_);
  1695. this->expected_rdatas_.clear();
  1696. this->expected_sig_rdatas_.clear();
  1697. this->expected_rdatas_.push_back("2001:db8::2");
  1698. this->expected_rdatas_.push_back("2001:db8::1");
  1699. this->expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1700. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1701. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1702. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1703. this->expected_sig_rdatas_);
  1704. this->expected_rdatas_.clear();
  1705. this->expected_sig_rdatas_.clear();
  1706. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1707. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(), this->rrttl_,
  1708. ZoneFinder::NXRRSET, this->expected_rdatas_,
  1709. this->expected_sig_rdatas_);
  1710. this->expected_rdatas_.clear();
  1711. this->expected_sig_rdatas_.clear();
  1712. this->expected_rdatas_.push_back("www.example.org.");
  1713. this->expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1714. doFindTest(*finder, isc::dns::Name("signedcname2.example.org."),
  1715. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1716. ZoneFinder::CNAME, this->expected_rdatas_,
  1717. this->expected_sig_rdatas_);
  1718. this->expected_rdatas_.clear();
  1719. this->expected_sig_rdatas_.clear();
  1720. this->expected_rdatas_.push_back("192.0.2.1");
  1721. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1722. doFindTest(*finder, isc::dns::Name("acnamesig1.example.org."),
  1723. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1724. this->expected_rdatas_, this->expected_sig_rdatas_);
  1725. this->expected_rdatas_.clear();
  1726. this->expected_sig_rdatas_.clear();
  1727. this->expected_rdatas_.push_back("192.0.2.1");
  1728. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1729. doFindTest(*finder, isc::dns::Name("acnamesig2.example.org."),
  1730. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1731. this->expected_rdatas_, this->expected_sig_rdatas_);
  1732. this->expected_rdatas_.clear();
  1733. this->expected_sig_rdatas_.clear();
  1734. this->expected_rdatas_.push_back("192.0.2.1");
  1735. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1736. doFindTest(*finder, isc::dns::Name("acnamesig3.example.org."),
  1737. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1738. this->expected_rdatas_, this->expected_sig_rdatas_);
  1739. this->expected_rdatas_.clear();
  1740. this->expected_sig_rdatas_.clear();
  1741. this->expected_rdatas_.push_back("192.0.2.1");
  1742. this->expected_rdatas_.push_back("192.0.2.2");
  1743. doFindTest(*finder, isc::dns::Name("ttldiff1.example.org."),
  1744. this->qtype_, this->qtype_, isc::dns::RRTTL(360),
  1745. ZoneFinder::SUCCESS, this->expected_rdatas_,
  1746. this->expected_sig_rdatas_);
  1747. this->expected_rdatas_.clear();
  1748. this->expected_sig_rdatas_.clear();
  1749. this->expected_rdatas_.push_back("192.0.2.1");
  1750. this->expected_rdatas_.push_back("192.0.2.2");
  1751. doFindTest(*finder, isc::dns::Name("ttldiff2.example.org."),
  1752. this->qtype_, this->qtype_, isc::dns::RRTTL(360),
  1753. ZoneFinder::SUCCESS, this->expected_rdatas_,
  1754. this->expected_sig_rdatas_);
  1755. EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
  1756. this->qtype_,
  1757. ZoneFinder::FIND_DEFAULT),
  1758. DataSourceError);
  1759. EXPECT_THROW(finder->find(isc::dns::Name("badcname2.example.org."),
  1760. this->qtype_,
  1761. ZoneFinder::FIND_DEFAULT),
  1762. DataSourceError);
  1763. EXPECT_THROW(finder->find(isc::dns::Name("badcname3.example.org."),
  1764. this->qtype_,
  1765. ZoneFinder::FIND_DEFAULT),
  1766. DataSourceError);
  1767. EXPECT_THROW(finder->find(isc::dns::Name("badrdata.example.org."),
  1768. this->qtype_,
  1769. ZoneFinder::FIND_DEFAULT),
  1770. DataSourceError);
  1771. EXPECT_THROW(finder->find(isc::dns::Name("badtype.example.org."),
  1772. this->qtype_,
  1773. ZoneFinder::FIND_DEFAULT),
  1774. DataSourceError);
  1775. EXPECT_THROW(finder->find(isc::dns::Name("badttl.example.org."),
  1776. this->qtype_,
  1777. ZoneFinder::FIND_DEFAULT),
  1778. DataSourceError);
  1779. EXPECT_THROW(finder->find(isc::dns::Name("badsig.example.org."),
  1780. this->qtype_,
  1781. ZoneFinder::FIND_DEFAULT),
  1782. DataSourceError);
  1783. // Trigger the hardcoded exceptions and see if find() has cleaned up
  1784. if (this->is_mock_) {
  1785. EXPECT_THROW(finder->find(Name("dsexception.example.org."),
  1786. this->qtype_,
  1787. ZoneFinder::FIND_DEFAULT),
  1788. DataSourceError);
  1789. EXPECT_THROW(finder->find(Name("iscexception.example.org."),
  1790. this->qtype_,
  1791. ZoneFinder::FIND_DEFAULT),
  1792. isc::Exception);
  1793. EXPECT_THROW(finder->find(Name("basicexception.example.org."),
  1794. this->qtype_,
  1795. ZoneFinder::FIND_DEFAULT),
  1796. std::exception);
  1797. EXPECT_THROW(finder->find(Name("dsexception.getnext.example.org"),
  1798. this->qtype_,
  1799. ZoneFinder::FIND_DEFAULT),
  1800. DataSourceError);
  1801. EXPECT_THROW(finder->find(Name("iscexception.getnext.example.org."),
  1802. this->qtype_,
  1803. ZoneFinder::FIND_DEFAULT),
  1804. isc::Exception);
  1805. EXPECT_THROW(finder->find(Name("basicexception.getnext.example.org."),
  1806. this->qtype_,
  1807. ZoneFinder::FIND_DEFAULT),
  1808. std::exception);
  1809. }
  1810. // This RRSIG has the wrong sigtype field, which should be
  1811. // an error if we decide to keep using that field
  1812. // Right now the field is ignored, so it does not error
  1813. this->expected_rdatas_.clear();
  1814. this->expected_sig_rdatas_.clear();
  1815. this->expected_rdatas_.push_back("192.0.2.1");
  1816. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1817. doFindTest(*finder, isc::dns::Name("badsigtype.example.org."),
  1818. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1819. this->expected_rdatas_, this->expected_sig_rdatas_);
  1820. }
  1821. TYPED_TEST(DatabaseClientTest, findOutOfZone) {
  1822. // If the query name is out-of-zone it should result in an exception
  1823. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1824. vector<ConstRRsetPtr> target;
  1825. // Superdomain
  1826. EXPECT_THROW(finder->find(Name("org"), this->qtype_), OutOfZone);
  1827. EXPECT_THROW(finder->findAll(Name("org"), target), OutOfZone);
  1828. // sharing a common ancestor
  1829. EXPECT_THROW(finder->find(Name("noexample.org"), this->qtype_), OutOfZone);
  1830. EXPECT_THROW(finder->findAll(Name("noexample.org"), target), OutOfZone);
  1831. // totally unrelated domain, smaller number of labels
  1832. EXPECT_THROW(finder->find(Name("com"), this->qtype_), OutOfZone);
  1833. EXPECT_THROW(finder->findAll(Name("com"), target), OutOfZone);
  1834. // totally unrelated domain, same number of labels
  1835. EXPECT_THROW(finder->find(Name("example.com"), this->qtype_), OutOfZone);
  1836. EXPECT_THROW(finder->findAll(Name("example.com"), target), OutOfZone);
  1837. // totally unrelated domain, larger number of labels
  1838. EXPECT_THROW(finder->find(Name("more.example.com"), this->qtype_),
  1839. OutOfZone);
  1840. EXPECT_THROW(finder->findAll(Name("more.example.com"), target), OutOfZone);
  1841. }
  1842. TYPED_TEST(DatabaseClientTest, findDelegation) {
  1843. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1844. // The apex should not be considered delegation point and we can access
  1845. // data
  1846. this->expected_rdatas_.clear();
  1847. this->expected_sig_rdatas_.clear();
  1848. this->expected_rdatas_.push_back("192.0.2.1");
  1849. doFindTest(*finder, isc::dns::Name("example.org."),
  1850. this->qtype_, this->qtype_,
  1851. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1852. this->expected_sig_rdatas_);
  1853. this->expected_rdatas_.clear();
  1854. this->expected_rdatas_.push_back("ns.example.com.");
  1855. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
  1856. "12345 example.org. FAKEFAKEFAKE");
  1857. doFindTest(*finder, isc::dns::Name("example.org."),
  1858. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1859. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1860. this->expected_sig_rdatas_);
  1861. // Check when we ask for something below delegation point, we get the NS
  1862. // (Both when the RRset there exists and doesn't)
  1863. this->expected_rdatas_.clear();
  1864. this->expected_sig_rdatas_.clear();
  1865. this->expected_rdatas_.push_back("ns.example.com.");
  1866. this->expected_rdatas_.push_back("ns.delegation.example.org.");
  1867. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
  1868. "12345 example.org. FAKEFAKEFAKE");
  1869. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1870. this->qtype_, isc::dns::RRType::NS(),
  1871. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1872. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1873. isc::dns::Name("delegation.example.org."));
  1874. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1875. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1876. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1877. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1878. isc::dns::Name("delegation.example.org."));
  1879. doFindTest(*finder, isc::dns::Name("deep.below.delegation.example.org."),
  1880. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1881. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1882. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1883. isc::dns::Name("delegation.example.org."));
  1884. // Even when we check directly at the delegation point, we should get
  1885. // the NS
  1886. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1887. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1888. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1889. this->expected_sig_rdatas_);
  1890. // And when we ask direcly for the NS, we should still get delegation
  1891. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1892. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1893. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1894. this->expected_sig_rdatas_);
  1895. // Now test delegation. If it is below the delegation point, we should get
  1896. // the DNAME (the one with data under DNAME is invalid zone, but we test
  1897. // the behaviour anyway just to make sure)
  1898. this->expected_rdatas_.clear();
  1899. this->expected_rdatas_.push_back("dname.example.com.");
  1900. this->expected_sig_rdatas_.clear();
  1901. this->expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
  1902. "20000201000000 12345 example.org. "
  1903. "FAKEFAKEFAKE");
  1904. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1905. this->qtype_, isc::dns::RRType::DNAME(),
  1906. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1907. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1908. isc::dns::Name("dname.example.org."));
  1909. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1910. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  1911. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1912. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1913. isc::dns::Name("dname.example.org."));
  1914. doFindTest(*finder, isc::dns::Name("really.deep.below.dname.example.org."),
  1915. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  1916. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1917. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  1918. isc::dns::Name("dname.example.org."));
  1919. // Asking direcly for DNAME should give SUCCESS
  1920. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1921. isc::dns::RRType::DNAME(), isc::dns::RRType::DNAME(),
  1922. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1923. this->expected_sig_rdatas_);
  1924. // But we don't delegate at DNAME point
  1925. this->expected_rdatas_.clear();
  1926. this->expected_rdatas_.push_back("192.0.2.1");
  1927. this->expected_sig_rdatas_.clear();
  1928. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1929. this->qtype_, this->qtype_,
  1930. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1931. this->expected_sig_rdatas_);
  1932. this->expected_rdatas_.clear();
  1933. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1934. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1935. this->rrttl_, ZoneFinder::NXRRSET, this->expected_rdatas_,
  1936. this->expected_sig_rdatas_);
  1937. // This is broken dname, it contains two targets
  1938. EXPECT_THROW(finder->find(isc::dns::Name("below.baddname.example.org."),
  1939. this->qtype_,
  1940. ZoneFinder::FIND_DEFAULT),
  1941. DataSourceError);
  1942. // Broken NS - it lives together with something else
  1943. EXPECT_THROW(finder->find(isc::dns::Name("brokenns1.example.org."),
  1944. this->qtype_,
  1945. ZoneFinder::FIND_DEFAULT),
  1946. DataSourceError);
  1947. EXPECT_THROW(finder->find(isc::dns::Name("brokenns2.example.org."),
  1948. this->qtype_,
  1949. ZoneFinder::FIND_DEFAULT),
  1950. DataSourceError);
  1951. }
  1952. TYPED_TEST(DatabaseClientTest, emptyDomain) {
  1953. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1954. // This domain doesn't exist, but a subdomain of it does.
  1955. // Therefore we should pretend the domain is there, but contains no RRsets
  1956. doFindTest(*finder, isc::dns::Name("b.example.org."), this->qtype_,
  1957. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  1958. this->expected_rdatas_, this->expected_sig_rdatas_);
  1959. }
  1960. // Glue-OK mode. Just go through NS delegations down (but not through
  1961. // DNAME) and pretend it is not there.
  1962. TYPED_TEST(DatabaseClientTest, glueOK) {
  1963. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1964. this->expected_rdatas_.clear();
  1965. this->expected_sig_rdatas_.clear();
  1966. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1967. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1968. this->rrttl_, ZoneFinder::NXRRSET,
  1969. this->expected_rdatas_, this->expected_sig_rdatas_,
  1970. ZoneFinder::RESULT_DEFAULT,
  1971. isc::dns::Name("ns.delegation.example.org."),
  1972. ZoneFinder::FIND_GLUE_OK);
  1973. doFindTest(*finder, isc::dns::Name("nothere.delegation.example.org."),
  1974. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1975. this->rrttl_, ZoneFinder::NXDOMAIN,
  1976. this->expected_rdatas_, this->expected_sig_rdatas_,
  1977. ZoneFinder::RESULT_DEFAULT,
  1978. isc::dns::Name("nothere.delegation.example.org."),
  1979. ZoneFinder::FIND_GLUE_OK);
  1980. this->expected_rdatas_.push_back("192.0.2.1");
  1981. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1982. this->qtype_, this->qtype_,
  1983. this->rrttl_, ZoneFinder::SUCCESS,
  1984. this->expected_rdatas_, this->expected_sig_rdatas_,
  1985. ZoneFinder::RESULT_DEFAULT,
  1986. isc::dns::Name("ns.delegation.example.org."),
  1987. ZoneFinder::FIND_GLUE_OK);
  1988. this->expected_rdatas_.clear();
  1989. this->expected_rdatas_.push_back("ns.example.com.");
  1990. this->expected_rdatas_.push_back("ns.delegation.example.org.");
  1991. this->expected_sig_rdatas_.clear();
  1992. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 "
  1993. "20000201000000 12345 example.org. "
  1994. "FAKEFAKEFAKE");
  1995. // When we request the NS, it should be SUCCESS, not DELEGATION
  1996. // (different in GLUE_OK)
  1997. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1998. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1999. this->rrttl_, ZoneFinder::SUCCESS,
  2000. this->expected_rdatas_, this->expected_sig_rdatas_,
  2001. ZoneFinder::RESULT_DEFAULT,
  2002. isc::dns::Name("delegation.example.org."),
  2003. ZoneFinder::FIND_GLUE_OK);
  2004. this->expected_rdatas_.clear();
  2005. this->expected_rdatas_.push_back("dname.example.com.");
  2006. this->expected_sig_rdatas_.clear();
  2007. this->expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
  2008. "20000201000000 12345 example.org. "
  2009. "FAKEFAKEFAKE");
  2010. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  2011. this->qtype_, isc::dns::RRType::DNAME(),
  2012. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  2013. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2014. isc::dns::Name("dname.example.org."), ZoneFinder::FIND_GLUE_OK);
  2015. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  2016. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  2017. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  2018. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2019. isc::dns::Name("dname.example.org."), ZoneFinder::FIND_GLUE_OK);
  2020. }
  2021. TYPED_TEST(DatabaseClientTest, wildcard) {
  2022. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2023. // First, simple wildcard match
  2024. // Check also that the RRSIG is added from the wildcard (not modified)
  2025. this->expected_rdatas_.push_back("192.0.2.5");
  2026. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  2027. "20000201000000 12345 example.org. "
  2028. "FAKEFAKEFAKE");
  2029. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  2030. this->qtype_, this->qtype_, this->rrttl_,
  2031. ZoneFinder::SUCCESS, this->expected_rdatas_,
  2032. this->expected_sig_rdatas_, ZoneFinder::RESULT_WILDCARD);
  2033. doFindTest(*finder, isc::dns::Name("b.a.wild.example.org"),
  2034. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2035. this->expected_rdatas_, this->expected_sig_rdatas_,
  2036. ZoneFinder::RESULT_WILDCARD);
  2037. this->expected_rdatas_.clear();
  2038. this->expected_sig_rdatas_.clear();
  2039. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  2040. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  2041. this->rrttl_, ZoneFinder::NXRRSET,
  2042. this->expected_rdatas_, this->expected_sig_rdatas_,
  2043. ZoneFinder::RESULT_WILDCARD);
  2044. doFindTest(*finder, isc::dns::Name("b.a.wild.example.org"),
  2045. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  2046. this->rrttl_, ZoneFinder::NXRRSET,
  2047. this->expected_rdatas_, this->expected_sig_rdatas_,
  2048. ZoneFinder::RESULT_WILDCARD);
  2049. // Direct request for this wildcard
  2050. this->expected_rdatas_.push_back("192.0.2.5");
  2051. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  2052. "20000201000000 12345 example.org. "
  2053. "FAKEFAKEFAKE");
  2054. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  2055. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2056. this->expected_rdatas_, this->expected_sig_rdatas_);
  2057. this->expected_rdatas_.clear();
  2058. this->expected_sig_rdatas_.clear();
  2059. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  2060. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  2061. this->rrttl_, ZoneFinder::NXRRSET, this->expected_rdatas_,
  2062. this->expected_sig_rdatas_);
  2063. // This is nonsense, but check it doesn't match by some stupid accident
  2064. doFindTest(*finder, isc::dns::Name("a.*.wild.example.org"),
  2065. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2066. this->expected_rdatas_, this->expected_sig_rdatas_);
  2067. // These should be canceled, since it is below a domain which exitsts
  2068. doFindTest(*finder, isc::dns::Name("nothing.here.wild.example.org"),
  2069. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2070. this->expected_rdatas_, this->expected_sig_rdatas_);
  2071. doFindTest(*finder, isc::dns::Name("cancel.here.wild.example.org"),
  2072. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2073. this->expected_rdatas_, this->expected_sig_rdatas_);
  2074. doFindTest(*finder,
  2075. isc::dns::Name("below.cancel.here.wild.example.org"),
  2076. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2077. this->expected_rdatas_, this->expected_sig_rdatas_);
  2078. // And this should be just plain empty non-terminal domain, check
  2079. // the wildcard doesn't hurt it
  2080. doFindTest(*finder, isc::dns::Name("here.wild.example.org"),
  2081. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2082. this->expected_rdatas_, this->expected_sig_rdatas_);
  2083. // Also make sure that the wildcard doesn't hurt the original data
  2084. // below the wildcard
  2085. this->expected_rdatas_.push_back("2001:db8::5");
  2086. doFindTest(*finder, isc::dns::Name("cancel.here.wild.example.org"),
  2087. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  2088. this->rrttl_, ZoneFinder::SUCCESS,
  2089. this->expected_rdatas_, this->expected_sig_rdatas_);
  2090. this->expected_rdatas_.clear();
  2091. // How wildcard go together with delegation
  2092. this->expected_rdatas_.push_back("ns.example.com.");
  2093. doFindTest(*finder, isc::dns::Name("below.delegatedwild.example.org"),
  2094. this->qtype_, isc::dns::RRType::NS(), this->rrttl_,
  2095. ZoneFinder::DELEGATION, this->expected_rdatas_,
  2096. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2097. isc::dns::Name("delegatedwild.example.org"));
  2098. // FIXME: This doesn't look logically OK, GLUE_OK should make it transparent,
  2099. // so the match should either work or be canceled, but return NXDOMAIN
  2100. doFindTest(*finder, isc::dns::Name("below.delegatedwild.example.org"),
  2101. this->qtype_, isc::dns::RRType::NS(), this->rrttl_,
  2102. ZoneFinder::DELEGATION, this->expected_rdatas_,
  2103. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2104. isc::dns::Name("delegatedwild.example.org"),
  2105. ZoneFinder::FIND_GLUE_OK);
  2106. this->expected_rdatas_.clear();
  2107. this->expected_rdatas_.push_back("192.0.2.5");
  2108. // These are direct matches
  2109. const char* positive_names[] = {
  2110. "wild.*.foo.example.org.",
  2111. "wild.*.foo.*.bar.example.org.",
  2112. NULL
  2113. };
  2114. for (const char** name = positive_names; *name != NULL; ++ name) {
  2115. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  2116. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2117. this->expected_rdatas_,
  2118. this->expected_sig_rdatas_);
  2119. }
  2120. // These are wildcard matches against empty nonterminal asterisk
  2121. this->expected_rdatas_.clear();
  2122. const char* negative_names[] = {
  2123. "a.foo.example.org.",
  2124. "wild.bar.foo.example.org.",
  2125. "baz.foo.*.bar.example.org",
  2126. "baz.foo.baz.bar.example.org",
  2127. "*.foo.baz.bar.example.org",
  2128. NULL
  2129. };
  2130. // Unless FIND_DNSSEC is specified, this is no different from other
  2131. // NXRRSET case.
  2132. for (const char** name = negative_names; *name != NULL; ++ name) {
  2133. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  2134. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2135. this->expected_rdatas_, this->expected_sig_rdatas_,
  2136. ZoneFinder::RESULT_WILDCARD);
  2137. }
  2138. // With FIND_DNSSEC, it should have NSEC_SIGNED flag.
  2139. const char* negative_dnssec_names[] = {
  2140. "a.bar.example.org.",
  2141. "foo.baz.bar.example.org.",
  2142. "a.foo.bar.example.org.",
  2143. NULL
  2144. };
  2145. this->expected_rdatas_.clear();
  2146. this->expected_rdatas_.push_back("wild.*.foo.*.bar.example.org. NSEC");
  2147. this->expected_sig_rdatas_.clear();
  2148. for (const char** name = negative_dnssec_names; *name != NULL; ++ name) {
  2149. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  2150. RRType::NSEC(), this->rrttl_, ZoneFinder::NXRRSET,
  2151. this->expected_rdatas_, this->expected_sig_rdatas_,
  2152. ZoneFinder::RESULT_WILDCARD | ZoneFinder::RESULT_NSEC_SIGNED,
  2153. Name("bao.example.org."), ZoneFinder::FIND_DNSSEC);
  2154. }
  2155. // CNAME on a wildcard. Maybe not so common, but not disallowed.
  2156. this->expected_rdatas_.clear();
  2157. this->expected_rdatas_.push_back("www.example.org.");
  2158. this->expected_sig_rdatas_.clear();
  2159. doFindTest(*finder, isc::dns::Name("a.cnamewild.example.org."),
  2160. isc::dns::RRType::TXT(), isc::dns::RRType::CNAME(),
  2161. this->rrttl_, ZoneFinder::CNAME,
  2162. this->expected_rdatas_, this->expected_sig_rdatas_,
  2163. ZoneFinder::RESULT_WILDCARD);
  2164. // DNAME on a wildcard. In our implementation we ignore DNAMEs on a
  2165. // wildcard, but at a higher level we say the behavior is "unspecified".
  2166. // rfc2672bis strongly discourages the mixture of DNAME and wildcard
  2167. // (with SHOULD NOT).
  2168. doFindTest(*finder, Name("a.dnamewild.example.org."),
  2169. this->qtype_, this->qtype_, this->rrttl_,
  2170. ZoneFinder::NXRRSET, this->empty_rdatas_,
  2171. this->empty_rdatas_, ZoneFinder::RESULT_WILDCARD);
  2172. // Some strange things in the wild node
  2173. this->expected_rdatas_.clear();
  2174. this->expected_rdatas_.push_back("ns.example.com.");
  2175. doFindTest(*finder, isc::dns::Name("a.nswild.example.org."),
  2176. isc::dns::RRType::TXT(), isc::dns::RRType::NS(),
  2177. this->rrttl_, ZoneFinder::DELEGATION,
  2178. this->expected_rdatas_, this->empty_rdatas_,
  2179. ZoneFinder::RESULT_WILDCARD);
  2180. }
  2181. TYPED_TEST(DatabaseClientTest, noWildcard) {
  2182. // Tests with the NO_WILDCARD flag.
  2183. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2184. // This would match *.wild.example.org, but with NO_WILDCARD should
  2185. // result in NXDOMAIN.
  2186. this->expected_rdatas_.push_back("cancel.here.wild.example.org. A "
  2187. "NSEC RRSIG");
  2188. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  2189. "20000201000000 12345 example.org. "
  2190. "FAKEFAKEFAKE");
  2191. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  2192. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  2193. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  2194. this->expected_sig_rdatas_, ZoneFinder::RESULT_NSEC_SIGNED,
  2195. Name("*.wild.example.org."),
  2196. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  2197. // Should be the same without FIND_DNSSEC (but in this case no RRsets
  2198. // will be returned)
  2199. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  2200. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  2201. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2202. this->empty_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2203. Name::ROOT_NAME(), // name is dummy
  2204. ZoneFinder::NO_WILDCARD);
  2205. // Same for wildcard empty non terminal.
  2206. this->expected_rdatas_.clear();
  2207. this->expected_rdatas_.push_back("brokenns1.example.org. A NSEC");
  2208. doFindTest(*finder, isc::dns::Name("a.bar.example.org"),
  2209. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  2210. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  2211. this->empty_rdatas_, ZoneFinder::RESULT_NSEC_SIGNED,
  2212. Name("wild.*.foo.*.bar.example.org"),
  2213. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  2214. // Search for a wildcard name with NO_WILDCARD. There should be no
  2215. // difference. This is, for example, necessary to provide non existence
  2216. // of matching wildcard for isnx.nonterminal.example.org.
  2217. this->expected_rdatas_.clear();
  2218. this->expected_rdatas_.push_back("empty.nonterminal.example.org. NSEC");
  2219. doFindTest(*finder, isc::dns::Name("*.nonterminal.example.org"),
  2220. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  2221. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  2222. this->empty_rdatas_, ZoneFinder::RESULT_NSEC_SIGNED,
  2223. Name("l.example.org"),
  2224. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  2225. // On the other hand, if there's exact match for the wildcard name
  2226. // it should be found regardless of NO_WILDCARD.
  2227. this->expected_rdatas_.clear();
  2228. this->expected_rdatas_.push_back("192.0.2.5");
  2229. this->expected_sig_rdatas_.clear();
  2230. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  2231. "20000201000000 12345 example.org. "
  2232. "FAKEFAKEFAKE");
  2233. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  2234. this->qtype_, this->qtype_, this->rrttl_,
  2235. ZoneFinder::SUCCESS, this->expected_rdatas_,
  2236. this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
  2237. Name("*.wild.example.org"), ZoneFinder::NO_WILDCARD);
  2238. }
  2239. TYPED_TEST(DatabaseClientTest, NXRRSET_NSEC) {
  2240. // The domain exists, but doesn't have this RRType
  2241. // So we should get its NSEC
  2242. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2243. this->expected_rdatas_.push_back("www2.example.org. A AAAA NSEC RRSIG");
  2244. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  2245. "20000201000000 12345 example.org. "
  2246. "FAKEFAKEFAKE");
  2247. doFindTest(*finder, isc::dns::Name("www.example.org."),
  2248. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  2249. this->rrttl_, ZoneFinder::NXRRSET,
  2250. this->expected_rdatas_, this->expected_sig_rdatas_,
  2251. ZoneFinder::RESULT_NSEC_SIGNED, Name::ROOT_NAME(),
  2252. ZoneFinder::FIND_DNSSEC);
  2253. }
  2254. TYPED_TEST(DatabaseClientTest, wildcardNXRRSET_NSEC) {
  2255. // The domain exists, but doesn't have this RRType
  2256. // So we should get its NSEC
  2257. //
  2258. // The user will have to query us again to get the correct
  2259. // answer (eg. prove there's not an exact match)
  2260. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2261. this->expected_rdatas_.push_back("cancel.here.wild.example.org. A NSEC "
  2262. "RRSIG");
  2263. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  2264. "20000201000000 12345 example.org. "
  2265. "FAKEFAKEFAKE");
  2266. // Note that the NSEC name should NOT be synthesized.
  2267. doFindTest(*finder, isc::dns::Name("a.wild.example.org."),
  2268. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  2269. this->rrttl_, ZoneFinder::NXRRSET,
  2270. this->expected_rdatas_, this->expected_sig_rdatas_,
  2271. ZoneFinder::RESULT_WILDCARD | ZoneFinder::RESULT_NSEC_SIGNED,
  2272. Name("*.wild.example.org"), ZoneFinder::FIND_DNSSEC);
  2273. }
  2274. // Subroutine for dnssecFlagCheck defined below. It performs some simple
  2275. // checks regarding DNSSEC related result flags for findAll().
  2276. void
  2277. dnssecFlagCheckForAny(ZoneFinder& finder, const Name& name,
  2278. ZoneFinder::FindResultFlags sec_flag)
  2279. {
  2280. std::vector<ConstRRsetPtr> target; // just for placeholder
  2281. ConstZoneFinderContextPtr all_result =
  2282. finder.findAll(name, target, ZoneFinder::FIND_DNSSEC);
  2283. EXPECT_EQ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0,
  2284. all_result->isNSECSigned());
  2285. EXPECT_EQ((sec_flag & ZoneFinder::RESULT_NSEC3_SIGNED) != 0,
  2286. all_result->isNSEC3Signed());
  2287. }
  2288. // Common tests about DNSSEC related result flags. Shared for the NSEC
  2289. // and NSEC3 cases.
  2290. void
  2291. dnssecFlagCheck(ZoneFinder& finder, ZoneFinder::FindResultFlags sec_flag) {
  2292. std::vector<std::string> expected_rdatas;
  2293. std::vector<std::string> expected_sig_rdatas;
  2294. // Check NXDOMAIN case in NSEC signed zone, and RESULT_NSEC_SIGNED flag
  2295. // should be returned to upper layer caller.
  2296. if ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
  2297. expected_rdatas.push_back("www2.example.org. A AAAA NSEC RRSIG");
  2298. expected_sig_rdatas.push_back("NSEC 5 3 3600 20000101000000 "
  2299. "20000201000000 12345 example.org. "
  2300. "FAKEFAKEFAKE");
  2301. }
  2302. doFindTest(finder, Name("www1.example.org"), RRType::A(), RRType::NSEC(),
  2303. RRTTL(3600), ZoneFinder::NXDOMAIN, expected_rdatas,
  2304. expected_sig_rdatas, sec_flag, Name("www.example.org."),
  2305. ZoneFinder::FIND_DNSSEC);
  2306. dnssecFlagCheckForAny(finder, Name("www1.example.org"), sec_flag);
  2307. // Check NXRRSET case in NSEC signed zone, and RESULT_NSEC_SIGNED flag
  2308. // should be return.
  2309. // No "findAll" test case for this because NXRRSET shouldn't happen for it.
  2310. expected_rdatas.clear();
  2311. expected_sig_rdatas.clear();
  2312. if ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
  2313. expected_rdatas.push_back("www2.example.org. A AAAA NSEC RRSIG");
  2314. expected_sig_rdatas.push_back("NSEC 5 3 3600 20000101000000 "
  2315. "20000201000000 12345 example.org. "
  2316. "FAKEFAKEFAKE");
  2317. }
  2318. doFindTest(finder, Name("www.example.org."), RRType::TXT(), RRType::NSEC(),
  2319. RRTTL(3600), ZoneFinder::NXRRSET, expected_rdatas,
  2320. expected_sig_rdatas, sec_flag, Name::ROOT_NAME(),
  2321. ZoneFinder::FIND_DNSSEC);
  2322. // Empty name, should result in NXRRSET (in this test setup the NSEC
  2323. // doesn't have RRSIG).
  2324. expected_rdatas.clear();
  2325. expected_sig_rdatas.clear();
  2326. if ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
  2327. expected_rdatas.push_back("empty.nonterminal.example.org. NSEC");
  2328. }
  2329. doFindTest(finder, Name("nonterminal.example.org."), RRType::A(),
  2330. RRType::NSEC(), RRTTL(3600), ZoneFinder::NXRRSET,
  2331. expected_rdatas,expected_sig_rdatas, sec_flag,
  2332. Name("l.example.org."), ZoneFinder::FIND_DNSSEC);
  2333. dnssecFlagCheckForAny(finder, Name("nonterminal.example.org"), sec_flag);
  2334. // Wildcard match
  2335. expected_rdatas.clear();
  2336. expected_sig_rdatas.clear();
  2337. expected_rdatas.push_back("192.0.2.5");
  2338. expected_sig_rdatas.push_back("A 5 3 3600 20000101000000 "
  2339. "20000201000000 12345 example.org. "
  2340. "FAKEFAKEFAKE");
  2341. doFindTest(finder, Name("b.a.wild.example.org"), RRType::A(),
  2342. RRType::A(), RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas,
  2343. expected_sig_rdatas, (ZoneFinder::RESULT_WILDCARD | sec_flag),
  2344. Name("b.a.wild.example.org"), ZoneFinder::FIND_DNSSEC);
  2345. dnssecFlagCheckForAny(finder, Name("b.a.wild.example.org"), sec_flag);
  2346. // Wildcard + NXRRSET (no "findAll" test for this case)
  2347. expected_rdatas.clear();
  2348. expected_sig_rdatas.clear();
  2349. if ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
  2350. expected_rdatas.push_back("cancel.here.wild.example.org. "
  2351. "A NSEC RRSIG");
  2352. expected_sig_rdatas.push_back("NSEC 5 3 3600 20000101000000 "
  2353. "20000201000000 12345 example.org. "
  2354. "FAKEFAKEFAKE");
  2355. }
  2356. doFindTest(finder, Name("b.a.wild.example.org"),
  2357. RRType::TXT(), RRType::NSEC(), RRTTL(3600), ZoneFinder::NXRRSET,
  2358. expected_rdatas, expected_sig_rdatas,
  2359. (ZoneFinder::RESULT_WILDCARD | sec_flag),
  2360. Name("*.wild.example.org"), ZoneFinder::FIND_DNSSEC);
  2361. // Empty wildcard (this NSEC doesn't have RRSIG in our test data)
  2362. expected_rdatas.clear();
  2363. expected_sig_rdatas.clear();
  2364. if ((sec_flag & ZoneFinder::RESULT_NSEC_SIGNED) != 0) {
  2365. expected_rdatas.push_back("wild.*.foo.*.bar.example.org. NSEC");
  2366. }
  2367. doFindTest(finder, Name("foo.wild.bar.example.org"),
  2368. RRType::TXT(), RRType::NSEC(), RRTTL(3600), ZoneFinder::NXRRSET,
  2369. expected_rdatas, expected_sig_rdatas,
  2370. (ZoneFinder::RESULT_WILDCARD | sec_flag),
  2371. Name("bao.example.org"), ZoneFinder::FIND_DNSSEC);
  2372. dnssecFlagCheckForAny(finder, Name("foo.wild.bar.example.org"), sec_flag);
  2373. }
  2374. TYPED_TEST(DatabaseClientTest, dnssecResultFlags) {
  2375. // ZoneFinder::find() for negative cases and wildcard cases should check
  2376. // whether the zone is signed with NSEC or NSEC3.
  2377. // In the default test setup, the zone should be considered NSEC-signed
  2378. // (the apex node has an NSEC RR).
  2379. {
  2380. SCOPED_TRACE("NSEC only");
  2381. dnssecFlagCheck(*this->getFinder(), ZoneFinder::RESULT_NSEC_SIGNED);
  2382. }
  2383. // Then add an NSEC3PARAM RRset at the apex (it may look weird if the
  2384. // zone only has NSEC3PARM RRset (but no NSEC3s), but it is okay for the
  2385. // purpose of this test). The zone should now be considered NSEC3-signed.
  2386. // Note that the apex NSEC still exists; NSEC3 should override NSEC.
  2387. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2388. this->rrset_.reset(new RRset(this->zname_, this->qclass_,
  2389. RRType::NSEC3PARAM(), this->rrttl_));
  2390. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2391. this->rrset_->getClass(),
  2392. "1 0 12 aabbccdd"));
  2393. this->updater_->addRRset(*this->rrset_);
  2394. {
  2395. SCOPED_TRACE("NSEC and NSEC3");
  2396. dnssecFlagCheck(this->updater_->getFinder(),
  2397. ZoneFinder::RESULT_NSEC3_SIGNED);
  2398. }
  2399. // Next, delete the apex NSEC. Since NSEC3PARAM remains, the zone should
  2400. // still be considered NSEC3-signed.
  2401. RRsetPtr nsec_rrset(new RRset(this->zname_, this->qclass_, RRType::NSEC(),
  2402. this->rrttl_));
  2403. nsec_rrset->addRdata(rdata::createRdata(RRType::NSEC(), this->qclass_,
  2404. "acnamesig1.example.org. NS A "
  2405. "NSEC RRSIG"));
  2406. this->updater_->deleteRRset(*nsec_rrset);
  2407. {
  2408. SCOPED_TRACE("NSEC3 only");
  2409. dnssecFlagCheck(this->updater_->getFinder(),
  2410. ZoneFinder::RESULT_NSEC3_SIGNED);
  2411. }
  2412. // Finally, delete the NSEC3PARAM we just added above. The zone should
  2413. // then be considered unsigned.
  2414. this->updater_->deleteRRset(*this->rrset_);
  2415. {
  2416. SCOPED_TRACE("unsigned");
  2417. dnssecFlagCheck(this->updater_->getFinder(),
  2418. ZoneFinder::RESULT_DEFAULT);
  2419. }
  2420. }
  2421. TYPED_TEST(DatabaseClientTest, NXDOMAIN_NSEC) {
  2422. // The domain doesn't exist, so we must get the right NSEC
  2423. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2424. this->expected_rdatas_.push_back("www2.example.org. A AAAA NSEC RRSIG");
  2425. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  2426. "20000201000000 12345 example.org. "
  2427. "FAKEFAKEFAKE");
  2428. doFindTest(*finder, isc::dns::Name("www1.example.org."),
  2429. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  2430. this->rrttl_, ZoneFinder::NXDOMAIN,
  2431. this->expected_rdatas_, this->expected_sig_rdatas_,
  2432. ZoneFinder::RESULT_NSEC_SIGNED, Name("www.example.org."),
  2433. ZoneFinder::FIND_DNSSEC);
  2434. this->expected_rdatas_.clear();
  2435. this->expected_rdatas_.push_back("acnamesig1.example.org. NS A NSEC RRSIG");
  2436. // This tests it works correctly in apex (there was a bug, where a check
  2437. // for NS-alone was there and it would throw).
  2438. doFindTest(*finder, isc::dns::Name("aa.example.org."),
  2439. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  2440. this->rrttl_, ZoneFinder::NXDOMAIN,
  2441. this->expected_rdatas_, this->expected_sig_rdatas_,
  2442. ZoneFinder::RESULT_NSEC_SIGNED, Name("example.org."),
  2443. ZoneFinder::FIND_DNSSEC);
  2444. // Check that if the DB doesn't support it, the exception from there
  2445. // is not propagated and it only does not include the NSEC
  2446. if (!this->is_mock_) {
  2447. return; // We don't make the real DB to throw
  2448. }
  2449. // In this case the accessor doesn't support findPreviousName(), but the
  2450. // zone apex has NSEC, and the zone itself is considered NSEC-signed.
  2451. doFindTest(*finder, Name("notimplnsec.example.org."),
  2452. RRType::TXT(), RRType::NSEC(), this->rrttl_,
  2453. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2454. this->empty_rdatas_, ZoneFinder::RESULT_NSEC_SIGNED,
  2455. Name::ROOT_NAME(), ZoneFinder::FIND_DNSSEC);
  2456. }
  2457. TYPED_TEST(DatabaseClientTest, emptyNonterminalNSEC) {
  2458. // Same as NXDOMAIN_NSEC, but with empty non-terminal
  2459. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2460. this->expected_rdatas_.push_back("empty.nonterminal.example.org. NSEC");
  2461. doFindTest(*finder, isc::dns::Name("nonterminal.example.org."),
  2462. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(), this->rrttl_,
  2463. ZoneFinder::NXRRSET, this->expected_rdatas_,
  2464. this->expected_sig_rdatas_,
  2465. ZoneFinder::RESULT_NSEC_SIGNED, Name("l.example.org."),
  2466. ZoneFinder::FIND_DNSSEC);
  2467. // Check that if the DB doesn't support it, the exception from there
  2468. // is not propagated and it only does not include the NSEC
  2469. if (!this->is_mock_) {
  2470. return; // We don't make the real DB to throw
  2471. }
  2472. // See the corresponding case of NXDOMAIN_NSEC.
  2473. doFindTest(*finder, Name("here.wild.example.org."),
  2474. RRType::TXT(), RRType::NSEC(), this->rrttl_,
  2475. ZoneFinder::NXRRSET, this->empty_rdatas_,
  2476. this->empty_rdatas_, ZoneFinder::RESULT_NSEC_SIGNED,
  2477. Name::ROOT_NAME(), ZoneFinder::FIND_DNSSEC);
  2478. }
  2479. TYPED_TEST(DatabaseClientTest, anyFromFind) {
  2480. // Find will reject answering an ANY query
  2481. EXPECT_THROW(this->getFinder()->find(isc::dns::Name("www2.example.org."),
  2482. RRType::ANY()), isc::Unexpected);
  2483. }
  2484. // Test the findAll method.
  2485. TYPED_TEST(DatabaseClientTest, getAll) {
  2486. // The domain doesn't exist, so we must get the right NSEC
  2487. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2488. // It should act the same on the "failures"
  2489. std::vector<ConstRRsetPtr> target;
  2490. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  2491. finder->findAll(isc::dns::Name("nothere.example.org."),
  2492. target)->code);
  2493. EXPECT_TRUE(target.empty());
  2494. EXPECT_EQ(ZoneFinder::NXRRSET,
  2495. finder->findAll(isc::dns::Name("here.wild.example.org."),
  2496. target)->code);
  2497. this->expected_rdatas_.push_back("ns.delegation.example.org.");
  2498. this->expected_rdatas_.push_back("ns.example.com.");
  2499. doFindAllTestResult(*finder, isc::dns::Name("xx.delegation.example.org."),
  2500. ZoneFinder::DELEGATION, RRType::NS(),
  2501. this->expected_rdatas_,
  2502. isc::dns::Name("delegation.example.org."));
  2503. this->expected_rdatas_.clear();
  2504. this->expected_rdatas_.push_back("www.example.org.");
  2505. doFindAllTestResult(*finder, isc::dns::Name("cname.example.org"),
  2506. ZoneFinder::CNAME, RRType::CNAME(),
  2507. this->expected_rdatas_);
  2508. this->expected_rdatas_.clear();
  2509. this->expected_rdatas_.push_back("dname.example.com.");
  2510. doFindAllTestResult(*finder, isc::dns::Name("a.dname.example.org"),
  2511. ZoneFinder::DNAME, RRType::DNAME(),
  2512. this->expected_rdatas_,
  2513. isc::dns::Name("dname.example.org."));
  2514. // It should get the data on success
  2515. EXPECT_EQ(ZoneFinder::SUCCESS,
  2516. finder->findAll(isc::dns::Name("www2.example.org."),
  2517. target)->code);
  2518. ASSERT_EQ(2, target.size());
  2519. size_t a_idx(target[1]->getType() == RRType::A());
  2520. EXPECT_EQ(RRType::A(), target[a_idx]->getType());
  2521. std::string previous;
  2522. size_t count(0);
  2523. for (RdataIteratorPtr it(target[a_idx]->getRdataIterator());
  2524. !it->isLast(); it->next()) {
  2525. count ++;
  2526. EXPECT_NE(previous, it->getCurrent().toText());
  2527. EXPECT_TRUE(it->getCurrent().toText() == "192.0.2.1" ||
  2528. it->getCurrent().toText() == "192.0.2.2");
  2529. previous = it->getCurrent().toText();
  2530. }
  2531. EXPECT_EQ(2, count);
  2532. EXPECT_EQ(RRType::AAAA(), target[1 - a_idx]->getType());
  2533. RdataIteratorPtr it(target[1 - a_idx]->getRdataIterator());
  2534. ASSERT_FALSE(it->isLast());
  2535. EXPECT_EQ("2001:db8::1", it->getCurrent().toText());
  2536. it->next();
  2537. EXPECT_TRUE(it->isLast());
  2538. // And on wildcard. Check the signatures as well.
  2539. target.clear();
  2540. ConstZoneFinderContextPtr result =
  2541. finder->findAll(Name("a.wild.example.org"), target,
  2542. ZoneFinder::FIND_DNSSEC);
  2543. EXPECT_EQ(ZoneFinder::SUCCESS, result->code);
  2544. EXPECT_TRUE(result->isWildcard());
  2545. EXPECT_TRUE(result->isNSECSigned());
  2546. EXPECT_FALSE(result->isNSEC3Signed());
  2547. ASSERT_EQ(2, target.size());
  2548. a_idx = target[1]->getType() == RRType::A();
  2549. EXPECT_EQ(RRType::A(), target[a_idx]->getType());
  2550. it = target[a_idx]->getRdataIterator();
  2551. ASSERT_FALSE(it->isLast());
  2552. EXPECT_EQ("192.0.2.5", it->getCurrent().toText());
  2553. it->next();
  2554. EXPECT_TRUE(it->isLast());
  2555. ConstRRsetPtr sig(target[a_idx]->getRRsig());
  2556. ASSERT_TRUE(sig);
  2557. EXPECT_EQ(RRType::RRSIG(), sig->getType());
  2558. EXPECT_EQ("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE",
  2559. sig->getRdataIterator()->getCurrent().toText());
  2560. EXPECT_EQ(RRType::NSEC(), target[1 - a_idx]->getType());
  2561. it = target[1 - a_idx]->getRdataIterator();
  2562. ASSERT_FALSE(it->isLast());
  2563. EXPECT_EQ("cancel.here.wild.example.org. A RRSIG NSEC",
  2564. it->getCurrent().toText());
  2565. it->next();
  2566. EXPECT_TRUE(it->isLast());
  2567. sig = target[1 - a_idx]->getRRsig();
  2568. ASSERT_TRUE(sig);
  2569. EXPECT_EQ(RRType::RRSIG(), sig->getType());
  2570. EXPECT_EQ("NSEC 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE",
  2571. sig->getRdataIterator()->getCurrent().toText());
  2572. }
  2573. TYPED_TEST(DatabaseClientTest, getOrigin) {
  2574. DataSourceClient::FindResult
  2575. zone(this->client_->findZone(Name("example.org")));
  2576. ASSERT_EQ(result::SUCCESS, zone.code);
  2577. boost::shared_ptr<DatabaseClient::Finder> finder(
  2578. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  2579. if (this->is_mock_) {
  2580. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  2581. }
  2582. EXPECT_EQ(this->zname_, finder->getOrigin());
  2583. }
  2584. TYPED_TEST(DatabaseClientTest, updaterFinder) {
  2585. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2586. ASSERT_TRUE(this->updater_);
  2587. // If this update isn't replacing the zone, the finder should work
  2588. // just like the normal find() case.
  2589. if (this->is_mock_) {
  2590. DatabaseClient::Finder& finder = dynamic_cast<DatabaseClient::Finder&>(
  2591. this->updater_->getFinder());
  2592. EXPECT_EQ(WRITABLE_ZONE_ID, finder.zone_id());
  2593. }
  2594. this->expected_rdatas_.clear();
  2595. this->expected_rdatas_.push_back("192.0.2.1");
  2596. doFindTest(this->updater_->getFinder(), this->qname_,
  2597. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2598. this->expected_rdatas_, this->empty_rdatas_);
  2599. // When replacing the zone, the updater's finder shouldn't see anything
  2600. // in the zone until something is added.
  2601. this->updater_.reset();
  2602. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2603. ASSERT_TRUE(this->updater_);
  2604. if (this->is_mock_) {
  2605. DatabaseClient::Finder& finder = dynamic_cast<DatabaseClient::Finder&>(
  2606. this->updater_->getFinder());
  2607. EXPECT_EQ(WRITABLE_ZONE_ID, finder.zone_id());
  2608. }
  2609. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2610. this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2611. this->empty_rdatas_, this->empty_rdatas_);
  2612. }
  2613. TYPED_TEST(DatabaseClientTest, flushZone) {
  2614. // A simple update case: flush the entire zone
  2615. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2616. // Before update, the name exists.
  2617. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  2618. this->qtype_)->code);
  2619. // start update in the replace mode. the normal finder should still
  2620. // be able to see the record, but the updater's finder shouldn't.
  2621. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2622. this->setUpdateAccessor();
  2623. EXPECT_EQ(ZoneFinder::SUCCESS,
  2624. finder->find(this->qname_, this->qtype_)->code);
  2625. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  2626. this->updater_->getFinder().find(this->qname_,
  2627. this->qtype_)->code);
  2628. // commit the update. now the normal finder shouldn't see it.
  2629. this->updater_->commit();
  2630. EXPECT_EQ(ZoneFinder::NXDOMAIN, finder->find(this->qname_,
  2631. this->qtype_)->code);
  2632. // Check rollback wasn't accidentally performed.
  2633. EXPECT_FALSE(this->isRollbacked());
  2634. }
  2635. TYPED_TEST(DatabaseClientTest, updateCancel) {
  2636. // similar to the previous test, but destruct the updater before commit.
  2637. ZoneFinderPtr finder = this->client_->findZone(this->zname_).zone_finder;
  2638. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  2639. this->qtype_)->code);
  2640. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2641. this->setUpdateAccessor();
  2642. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  2643. this->updater_->getFinder().find(this->qname_,
  2644. this->qtype_)->code);
  2645. // DB should not have been rolled back yet.
  2646. EXPECT_FALSE(this->isRollbacked());
  2647. this->updater_.reset(); // destruct without commit
  2648. // reset() should have triggered rollback (although it doesn't affect
  2649. // anything to the mock accessor implementation except for the result of
  2650. // isRollbacked())
  2651. EXPECT_TRUE(this->isRollbacked(true));
  2652. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  2653. this->qtype_)->code);
  2654. }
  2655. TYPED_TEST(DatabaseClientTest, exceptionFromRollback) {
  2656. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2657. this->rrset_.reset(new RRset(Name("throw.example.org"), this->qclass_,
  2658. this->qtype_, this->rrttl_));
  2659. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2660. this->rrset_->getClass(),
  2661. "192.0.2.1"));
  2662. this->updater_->addRRset(*this->rrset_);
  2663. // destruct without commit. The added name will result in an exception
  2664. // in the MockAccessor's rollback method. It shouldn't be propagated.
  2665. EXPECT_NO_THROW(this->updater_.reset());
  2666. }
  2667. TYPED_TEST(DatabaseClientTest, duplicateCommit) {
  2668. // duplicate commit. should result in exception.
  2669. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2670. this->updater_->commit();
  2671. EXPECT_THROW(this->updater_->commit(), DataSourceError);
  2672. }
  2673. TYPED_TEST(DatabaseClientTest, addRRsetToNewZone) {
  2674. // Add a single RRset to a fresh empty zone
  2675. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2676. this->updater_->addRRset(*this->rrset_);
  2677. this->expected_rdatas_.clear();
  2678. this->expected_rdatas_.push_back("192.0.2.2");
  2679. {
  2680. SCOPED_TRACE("add RRset");
  2681. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2682. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2683. this->expected_rdatas_, this->empty_rdatas_);
  2684. }
  2685. // Similar to the previous case, but with RRSIG
  2686. this->updater_.reset();
  2687. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2688. this->updater_->addRRset(*this->rrset_);
  2689. this->updater_->addRRset(*this->rrsigset_);
  2690. // confirm the expected columns were passed to the accessor (if checkable).
  2691. const char* const rrsig_added[] = {
  2692. "www.example.org.", "org.example.www.", "3600", "RRSIG", "A",
  2693. "A 5 3 0 20000101000000 20000201000000 0 example.org. FAKEFAKEFAKE"
  2694. };
  2695. this->checkLastAdded(rrsig_added);
  2696. this->expected_sig_rdatas_.clear();
  2697. this->expected_sig_rdatas_.push_back(
  2698. rrsig_added[DatabaseAccessor::ADD_RDATA]);
  2699. {
  2700. SCOPED_TRACE("add RRset with RRSIG");
  2701. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2702. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2703. this->expected_rdatas_, this->expected_sig_rdatas_);
  2704. }
  2705. // Add the non RRSIG RRset again, to see the attempt of adding RRSIG
  2706. // causes any unexpected effect, in particular, whether the SIGTYPE
  2707. // field might remain.
  2708. this->updater_->addRRset(*this->rrset_);
  2709. const char* const rrset_added[] = {
  2710. "www.example.org.", "org.example.www.", "3600", "A", "", "192.0.2.2"
  2711. };
  2712. this->checkLastAdded(rrset_added);
  2713. }
  2714. //
  2715. // Below we define a set of NSEC3 update tests.
  2716. //
  2717. // Commonly used data for NSEC3 update tests below.
  2718. const char* const nsec3_hash = "1BB7SO0452U1QHL98UISNDD9218GELR5";
  2719. const char* const nsec3_rdata = "1 1 12 AABBCCDD "
  2720. "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR NS SOA RRSIG NSEC3PARAM";
  2721. const char* const nsec3_rdata2 = "1 1 12 AABBCCDD "
  2722. "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR NS SOA RRSIG"; // differ in bitmaps
  2723. const char* const nsec3_sig_rdata = "NSEC3 5 3 3600 20000101000000 "
  2724. "20000201000000 12345 example.org. FAKEFAKEFAKE";
  2725. const char* const nsec3_sig_rdata2 = "NSEC3 5 3 3600 20000101000000 "
  2726. "20000201000000 12345 example.org. FAKEFAKE"; // differ in the signature
  2727. // Commonly used subroutine that checks if we can get the expected record.
  2728. // According to the API, implementations can skip filling in columns other
  2729. // than those explicitly checked below, so we don't check them.
  2730. void
  2731. nsec3Check(const vector<ConstRRsetPtr>& expected_rrsets,
  2732. const Name& zone_name, const string& expected_hash,
  2733. DatabaseAccessor& accessor)
  2734. {
  2735. const int zone_id = accessor.getZone(zone_name.toText()).second;
  2736. DatabaseAccessor::IteratorContextPtr itctx =
  2737. accessor.getNSEC3Records(expected_hash, zone_id);
  2738. ASSERT_TRUE(itctx);
  2739. // Build a list of matched RRsets and compare the both expected and built
  2740. // ones as sets.
  2741. string columns[DatabaseAccessor::COLUMN_COUNT];
  2742. vector<ConstRRsetPtr> actual_rrsets;
  2743. while (itctx->getNext(columns)) {
  2744. actual_rrsets.push_back(
  2745. textToRRset(expected_hash + "." + zone_name.toText() + " " +
  2746. columns[DatabaseAccessor::TTL_COLUMN] + " IN " +
  2747. columns[DatabaseAccessor::TYPE_COLUMN] + " " +
  2748. columns[DatabaseAccessor::RDATA_COLUMN]));
  2749. }
  2750. rrsetsCheck(expected_rrsets.begin(), expected_rrsets.end(),
  2751. actual_rrsets.begin(), actual_rrsets.end());
  2752. }
  2753. TYPED_TEST(DatabaseClientTest, addDeleteNSEC3InZone) {
  2754. // Add one NSEC3 RR to the zone, delete it, and add another one.
  2755. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2756. const ConstRRsetPtr nsec3_rrset =
  2757. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN NSEC3 " +
  2758. string(nsec3_rdata));
  2759. const ConstRRsetPtr nsec3_rrset2 =
  2760. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN NSEC3 " +
  2761. string(nsec3_rdata2));
  2762. this->updater_->addRRset(*nsec3_rrset);
  2763. this->updater_->deleteRRset(*nsec3_rrset);
  2764. this->updater_->addRRset(*nsec3_rrset2);
  2765. this->updater_->commit();
  2766. // Check if we can get the expected record.
  2767. vector<ConstRRsetPtr> expected_rrsets;
  2768. expected_rrsets.push_back(nsec3_rrset2);
  2769. nsec3Check(expected_rrsets, this->zname_, nsec3_hash,
  2770. *this->current_accessor_);
  2771. }
  2772. TYPED_TEST(DatabaseClientTest, addDeleteNSEC3AndRRSIGToZone) {
  2773. // Add one NSEC3 RR and its RRSIG to the zone, delete the RRSIG and add
  2774. // a new one.
  2775. this->updater_ = this->client_->getUpdater(this->zname_, true);
  2776. const ConstRRsetPtr nsec3_rrset =
  2777. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN NSEC3 " +
  2778. string(nsec3_rdata));
  2779. const ConstRRsetPtr nsec3_sig_rrset =
  2780. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN RRSIG " +
  2781. string(nsec3_sig_rdata));
  2782. const ConstRRsetPtr nsec3_sig_rrset2 =
  2783. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN RRSIG " +
  2784. string(nsec3_sig_rdata2));
  2785. this->updater_->addRRset(*nsec3_rrset);
  2786. this->updater_->addRRset(*nsec3_sig_rrset);
  2787. this->updater_->deleteRRset(*nsec3_sig_rrset);
  2788. this->updater_->addRRset(*nsec3_sig_rrset2);
  2789. this->updater_->commit();
  2790. // Check if we can get the expected record.
  2791. vector<ConstRRsetPtr> expected_rrsets;
  2792. expected_rrsets.push_back(nsec3_rrset);
  2793. expected_rrsets.push_back(nsec3_sig_rrset2);
  2794. nsec3Check(expected_rrsets, this->zname_, nsec3_hash,
  2795. *this->current_accessor_);
  2796. }
  2797. TYPED_TEST(DatabaseClientTest, addRRsetToCurrentZone) {
  2798. // Similar to the previous test, but not replacing the existing data.
  2799. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2800. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2801. this->updater_->addRRset(*this->rrset_);
  2802. // We should see both old and new data.
  2803. this->expected_rdatas_.clear();
  2804. this->expected_rdatas_.push_back("192.0.2.1");
  2805. this->expected_rdatas_.push_back("192.0.2.2");
  2806. {
  2807. SCOPED_TRACE("add RRset");
  2808. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2809. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2810. this->expected_rdatas_, this->empty_rdatas_);
  2811. }
  2812. this->updater_->commit();
  2813. {
  2814. SCOPED_TRACE("add RRset after commit");
  2815. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  2816. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  2817. this->empty_rdatas_);
  2818. }
  2819. }
  2820. TYPED_TEST(DatabaseClientTest, addMultipleRRs) {
  2821. // Similar to the previous case, but the added RRset contains multiple
  2822. // RRs.
  2823. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2824. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2825. this->rrset_->getClass(),
  2826. "192.0.2.3"));
  2827. this->updater_->addRRset(*this->rrset_);
  2828. this->expected_rdatas_.clear();
  2829. this->expected_rdatas_.push_back("192.0.2.1");
  2830. this->expected_rdatas_.push_back("192.0.2.2");
  2831. this->expected_rdatas_.push_back("192.0.2.3");
  2832. {
  2833. SCOPED_TRACE("add multiple RRs");
  2834. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2835. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2836. this->expected_rdatas_, this->empty_rdatas_);
  2837. }
  2838. }
  2839. TYPED_TEST(DatabaseClientTest, addRRsetOfLargerTTL) {
  2840. // Similar to the previous one, but the TTL of the added RRset is larger
  2841. // than that of the existing record. The finder should use the smaller
  2842. // one.
  2843. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2844. this->rrset_->setTTL(RRTTL(7200));
  2845. this->updater_->addRRset(*this->rrset_);
  2846. this->expected_rdatas_.clear();
  2847. this->expected_rdatas_.push_back("192.0.2.1");
  2848. this->expected_rdatas_.push_back("192.0.2.2");
  2849. {
  2850. SCOPED_TRACE("add RRset of larger TTL");
  2851. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2852. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2853. this->expected_rdatas_, this->empty_rdatas_);
  2854. }
  2855. }
  2856. TYPED_TEST(DatabaseClientTest, addRRsetOfSmallerTTL) {
  2857. // Similar to the previous one, but the added RRset has a smaller TTL.
  2858. // The added TTL should be used by the finder.
  2859. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2860. this->rrset_->setTTL(RRTTL(1800));
  2861. this->updater_->addRRset(*this->rrset_);
  2862. this->expected_rdatas_.clear();
  2863. this->expected_rdatas_.push_back("192.0.2.1");
  2864. this->expected_rdatas_.push_back("192.0.2.2");
  2865. {
  2866. SCOPED_TRACE("add RRset of smaller TTL");
  2867. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2868. this->qtype_, RRTTL(1800), ZoneFinder::SUCCESS,
  2869. this->expected_rdatas_, this->empty_rdatas_);
  2870. }
  2871. }
  2872. TYPED_TEST(DatabaseClientTest, addSameRR) {
  2873. // Add the same RR as that is already in the data source.
  2874. // Currently the add interface doesn't try to suppress the duplicate,
  2875. // neither does the finder. We may want to revisit it in future versions.
  2876. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2877. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2878. this->rrttl_));
  2879. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2880. this->rrset_->getClass(),
  2881. "192.0.2.1"));
  2882. this->updater_->addRRset(*this->rrset_);
  2883. this->expected_rdatas_.clear();
  2884. this->expected_rdatas_.push_back("192.0.2.1");
  2885. this->expected_rdatas_.push_back("192.0.2.1");
  2886. {
  2887. SCOPED_TRACE("add same RR");
  2888. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2889. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2890. this->expected_rdatas_, this->empty_rdatas_);
  2891. }
  2892. }
  2893. TYPED_TEST(DatabaseClientTest, addDeviantRR) {
  2894. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2895. // RR class mismatch. This should be detected and rejected.
  2896. this->rrset_.reset(new RRset(this->qname_, RRClass::CH(), RRType::TXT(),
  2897. this->rrttl_));
  2898. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2899. this->rrset_->getClass(),
  2900. "test text"));
  2901. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2902. // Out-of-zone owner name. At a higher level this should be rejected,
  2903. // but it doesn't happen in this interface.
  2904. this->rrset_.reset(new RRset(Name("example.com"), this->qclass_,
  2905. this->qtype_, this->rrttl_));
  2906. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2907. this->rrset_->getClass(),
  2908. "192.0.2.100"));
  2909. this->updater_->addRRset(*this->rrset_);
  2910. this->expected_rdatas_.clear();
  2911. this->expected_rdatas_.push_back("192.0.2.100");
  2912. {
  2913. // Note: find() rejects out-of-zone query name with an exception
  2914. // regardless of whether adding the RR succeeded, so this check
  2915. // actually doesn't confirm it.
  2916. SCOPED_TRACE("add out-of-zone RR");
  2917. EXPECT_THROW(this->updater_->getFinder().find(Name("example.com"),
  2918. this->qtype_),
  2919. OutOfZone);
  2920. }
  2921. }
  2922. TYPED_TEST(DatabaseClientTest, addEmptyRRset) {
  2923. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2924. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2925. this->rrttl_));
  2926. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2927. }
  2928. TYPED_TEST(DatabaseClientTest, addAfterCommit) {
  2929. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2930. this->updater_->commit();
  2931. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2932. }
  2933. TYPED_TEST(DatabaseClientTest, addRRsetWithRRSIG) {
  2934. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2935. this->rrset_->addRRsig(*this->rrsigset_);
  2936. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2937. }
  2938. TYPED_TEST(DatabaseClientTest, deleteRRset) {
  2939. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2940. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2941. this->rrttl_));
  2942. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2943. this->rrset_->getClass(),
  2944. "192.0.2.1"));
  2945. // Delete one RR from an RRset
  2946. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2947. this->updater_->deleteRRset(*this->rrset_);
  2948. // Delete the only RR of a name
  2949. this->rrset_.reset(new RRset(Name("cname.example.org"), this->qclass_,
  2950. RRType::CNAME(), this->rrttl_));
  2951. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2952. this->rrset_->getClass(),
  2953. "www.example.org"));
  2954. this->updater_->deleteRRset(*this->rrset_);
  2955. // The this->updater_ finder should immediately see the deleted results.
  2956. {
  2957. SCOPED_TRACE("delete RRset");
  2958. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2959. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2960. this->empty_rdatas_, this->empty_rdatas_);
  2961. doFindTest(this->updater_->getFinder(), Name("cname.example.org"),
  2962. this->qtype_, this->qtype_, this->rrttl_,
  2963. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2964. this->empty_rdatas_);
  2965. }
  2966. // before committing the change, the original finder should see the
  2967. // original record.
  2968. {
  2969. SCOPED_TRACE("delete RRset before commit");
  2970. this->expected_rdatas_.push_back("192.0.2.1");
  2971. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  2972. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  2973. this->empty_rdatas_);
  2974. this->expected_rdatas_.clear();
  2975. this->expected_rdatas_.push_back("www.example.org.");
  2976. doFindTest(*finder, Name("cname.example.org"), this->qtype_,
  2977. RRType::CNAME(), this->rrttl_, ZoneFinder::CNAME,
  2978. this->expected_rdatas_, this->empty_rdatas_);
  2979. }
  2980. // once committed, the record should be removed from the original finder's
  2981. // view, too.
  2982. this->updater_->commit();
  2983. {
  2984. SCOPED_TRACE("delete RRset after commit");
  2985. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  2986. this->rrttl_, ZoneFinder::NXRRSET, this->empty_rdatas_,
  2987. this->empty_rdatas_);
  2988. doFindTest(*finder, Name("cname.example.org"), this->qtype_,
  2989. this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2990. this->empty_rdatas_, this->empty_rdatas_);
  2991. }
  2992. }
  2993. TYPED_TEST(DatabaseClientTest, deleteRRsetToNXDOMAIN) {
  2994. // similar to the previous case, but it removes the only record of the
  2995. // given name. a subsequent find() should result in NXDOMAIN.
  2996. this->rrset_.reset(new RRset(Name("cname.example.org"), this->qclass_,
  2997. RRType::CNAME(), this->rrttl_));
  2998. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2999. this->rrset_->getClass(),
  3000. "www.example.org"));
  3001. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3002. this->updater_->deleteRRset(*this->rrset_);
  3003. {
  3004. SCOPED_TRACE("delete RRset to NXDOMAIN");
  3005. doFindTest(this->updater_->getFinder(), Name("cname.example.org"),
  3006. this->qtype_, this->qtype_, this->rrttl_,
  3007. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  3008. this->empty_rdatas_);
  3009. }
  3010. }
  3011. TYPED_TEST(DatabaseClientTest, deleteMultipleRRs) {
  3012. this->rrset_.reset(new RRset(this->qname_, this->qclass_, RRType::AAAA(),
  3013. this->rrttl_));
  3014. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3015. this->rrset_->getClass(),
  3016. "2001:db8::1"));
  3017. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3018. this->rrset_->getClass(),
  3019. "2001:db8::2"));
  3020. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3021. this->updater_->deleteRRset(*this->rrset_);
  3022. {
  3023. SCOPED_TRACE("delete multiple RRs");
  3024. doFindTest(this->updater_->getFinder(), this->qname_, RRType::AAAA(),
  3025. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  3026. this->empty_rdatas_, this->empty_rdatas_);
  3027. }
  3028. }
  3029. TYPED_TEST(DatabaseClientTest, partialDelete) {
  3030. this->rrset_.reset(new RRset(this->qname_, this->qclass_, RRType::AAAA(),
  3031. this->rrttl_));
  3032. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3033. this->rrset_->getClass(),
  3034. "2001:db8::1"));
  3035. // This does not exist in the test data source:
  3036. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3037. this->rrset_->getClass(),
  3038. "2001:db8::3"));
  3039. // deleteRRset should succeed "silently", and subsequent find() should
  3040. // find the remaining RR.
  3041. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3042. this->updater_->deleteRRset(*this->rrset_);
  3043. {
  3044. SCOPED_TRACE("partial delete");
  3045. this->expected_rdatas_.push_back("2001:db8::2");
  3046. doFindTest(this->updater_->getFinder(), this->qname_, RRType::AAAA(),
  3047. RRType::AAAA(), this->rrttl_, ZoneFinder::SUCCESS,
  3048. this->expected_rdatas_, this->empty_rdatas_);
  3049. }
  3050. }
  3051. TYPED_TEST(DatabaseClientTest, deleteNoMatch) {
  3052. // similar to the previous test, but there's not even a match in the
  3053. // specified RRset. Essentially there's no difference in the result.
  3054. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3055. this->updater_->deleteRRset(*this->rrset_);
  3056. {
  3057. SCOPED_TRACE("delete no match");
  3058. this->expected_rdatas_.push_back("192.0.2.1");
  3059. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  3060. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  3061. this->expected_rdatas_, this->empty_rdatas_);
  3062. }
  3063. }
  3064. TYPED_TEST(DatabaseClientTest, deleteWithDifferentTTL) {
  3065. // Our delete interface simply ignores TTL (may change in a future version)
  3066. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  3067. RRTTL(1800)));
  3068. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3069. this->rrset_->getClass(),
  3070. "192.0.2.1"));
  3071. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3072. this->updater_->deleteRRset(*this->rrset_);
  3073. {
  3074. SCOPED_TRACE("delete RRset with a different TTL");
  3075. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  3076. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  3077. this->empty_rdatas_, this->empty_rdatas_);
  3078. }
  3079. }
  3080. TYPED_TEST(DatabaseClientTest, deleteDeviantRR) {
  3081. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3082. // RR class mismatch. This should be detected and rejected.
  3083. this->rrset_.reset(new RRset(this->qname_, RRClass::CH(), RRType::TXT(),
  3084. this->rrttl_));
  3085. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3086. this->rrset_->getClass(),
  3087. "test text"));
  3088. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  3089. // Out-of-zone owner name. At a higher level this should be rejected,
  3090. // but it doesn't happen in this interface.
  3091. this->rrset_.reset(new RRset(Name("example.com"), this->qclass_,
  3092. this->qtype_, this->rrttl_));
  3093. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3094. this->rrset_->getClass(),
  3095. "192.0.2.100"));
  3096. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->rrset_));
  3097. }
  3098. TYPED_TEST(DatabaseClientTest, deleteAfterCommit) {
  3099. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3100. this->updater_->commit();
  3101. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  3102. }
  3103. TYPED_TEST(DatabaseClientTest, deleteEmptyRRset) {
  3104. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3105. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  3106. this->rrttl_));
  3107. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  3108. }
  3109. TYPED_TEST(DatabaseClientTest, deleteRRsetWithRRSIG) {
  3110. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3111. this->rrset_->addRRsig(*this->rrsigset_);
  3112. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  3113. }
  3114. TYPED_TEST(DatabaseClientTest, compoundUpdate) {
  3115. // This test case performs an arbitrary chosen add/delete operations
  3116. // in a single update transaction. Essentially there is nothing new to
  3117. // test here, but there may be some bugs that was overlooked and can
  3118. // only happen in the compound update scenario, so we test it.
  3119. this->updater_ = this->client_->getUpdater(this->zname_, false);
  3120. // add a new RR to an existing RRset
  3121. this->updater_->addRRset(*this->rrset_);
  3122. this->expected_rdatas_.clear();
  3123. this->expected_rdatas_.push_back("192.0.2.1");
  3124. this->expected_rdatas_.push_back("192.0.2.2");
  3125. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  3126. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  3127. this->expected_rdatas_, this->empty_rdatas_);
  3128. // delete an existing RR
  3129. this->rrset_.reset(new RRset(Name("www.example.org"), this->qclass_,
  3130. this->qtype_, this->rrttl_));
  3131. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3132. this->rrset_->getClass(),
  3133. "192.0.2.1"));
  3134. this->updater_->deleteRRset(*this->rrset_);
  3135. this->expected_rdatas_.clear();
  3136. this->expected_rdatas_.push_back("192.0.2.2");
  3137. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  3138. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  3139. this->expected_rdatas_, this->empty_rdatas_);
  3140. // re-add it
  3141. this->updater_->addRRset(*this->rrset_);
  3142. this->expected_rdatas_.push_back("192.0.2.1");
  3143. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  3144. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  3145. this->expected_rdatas_, this->empty_rdatas_);
  3146. // add a new RR with a new name
  3147. const Name newname("newname.example.org");
  3148. const RRType newtype(RRType::AAAA());
  3149. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  3150. this->rrttl_, ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  3151. this->empty_rdatas_);
  3152. this->rrset_.reset(new RRset(newname, this->qclass_, newtype,
  3153. this->rrttl_));
  3154. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3155. this->rrset_->getClass(),
  3156. "2001:db8::10"));
  3157. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3158. this->rrset_->getClass(),
  3159. "2001:db8::11"));
  3160. this->updater_->addRRset(*this->rrset_);
  3161. this->expected_rdatas_.clear();
  3162. this->expected_rdatas_.push_back("2001:db8::10");
  3163. this->expected_rdatas_.push_back("2001:db8::11");
  3164. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  3165. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  3166. this->empty_rdatas_);
  3167. // delete one RR from the previous set
  3168. this->rrset_.reset(new RRset(newname, this->qclass_, newtype,
  3169. this->rrttl_));
  3170. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  3171. this->rrset_->getClass(),
  3172. "2001:db8::11"));
  3173. this->updater_->deleteRRset(*this->rrset_);
  3174. this->expected_rdatas_.clear();
  3175. this->expected_rdatas_.push_back("2001:db8::10");
  3176. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  3177. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  3178. this->empty_rdatas_);
  3179. // Commit the changes, confirm the entire changes applied.
  3180. this->updater_->commit();
  3181. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  3182. this->expected_rdatas_.clear();
  3183. this->expected_rdatas_.push_back("192.0.2.2");
  3184. this->expected_rdatas_.push_back("192.0.2.1");
  3185. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_, this->rrttl_,
  3186. ZoneFinder::SUCCESS, this->expected_rdatas_,
  3187. this->empty_rdatas_);
  3188. this->expected_rdatas_.clear();
  3189. this->expected_rdatas_.push_back("2001:db8::10");
  3190. doFindTest(*finder, newname, newtype, newtype, this->rrttl_,
  3191. ZoneFinder::SUCCESS, this->expected_rdatas_,
  3192. this->empty_rdatas_);
  3193. }
  3194. TYPED_TEST(DatabaseClientTest, previous) {
  3195. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  3196. EXPECT_EQ(Name("www.example.org."),
  3197. finder->findPreviousName(Name("www2.example.org.")));
  3198. // Check a name that doesn't exist there
  3199. EXPECT_EQ(Name("www.example.org."),
  3200. finder->findPreviousName(Name("www1.example.org.")));
  3201. if (this->is_mock_) { // We can't really force the DB to throw
  3202. // Check it doesn't crash or anything if the underlying DB throws
  3203. DataSourceClient::FindResult
  3204. zone(this->client_->findZone(Name("bad.example.org")));
  3205. finder =
  3206. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder);
  3207. EXPECT_THROW(finder->findPreviousName(Name("bad.example.org")),
  3208. isc::NotImplemented);
  3209. } else {
  3210. // No need to test this on mock one, because we test only that
  3211. // the exception gets through
  3212. // A name before the origin
  3213. EXPECT_THROW(finder->findPreviousName(Name("example.com")),
  3214. isc::NotImplemented);
  3215. }
  3216. }
  3217. TYPED_TEST(DatabaseClientTest, invalidRdata) {
  3218. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  3219. EXPECT_THROW(finder->find(Name("invalidrdata.example.org."), RRType::A()),
  3220. DataSourceError);
  3221. EXPECT_THROW(finder->find(Name("invalidrdata2.example.org."), RRType::A()),
  3222. DataSourceError);
  3223. }
  3224. TEST_F(MockDatabaseClientTest, missingNSEC) {
  3225. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  3226. /*
  3227. * FIXME: For now, we can't really distinguish this bogus input
  3228. * from not-signed zone so we can't throw. But once we can,
  3229. * enable the original test.
  3230. */
  3231. #if 0
  3232. EXPECT_THROW(finder->find(Name("badnsec2.example.org."), RRType::A(), NULL,
  3233. ZoneFinder::FIND_DNSSEC),
  3234. DataSourceError);
  3235. #endif
  3236. doFindTest(*finder, Name("badnsec2.example.org."), RRType::A(),
  3237. RRType::A(), this->rrttl_, ZoneFinder::NXDOMAIN,
  3238. this->expected_rdatas_, this->expected_sig_rdatas_);
  3239. }
  3240. TEST_F(MockDatabaseClientTest, badName) {
  3241. boost::shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  3242. EXPECT_THROW(finder->findPreviousName(Name("brokenname.example.org.")),
  3243. DataSourceError);
  3244. }
  3245. /*
  3246. * Test correct use of the updater with a journal.
  3247. */
  3248. TYPED_TEST(DatabaseClientTest, journal) {
  3249. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3250. this->updater_->deleteRRset(*this->soa_);
  3251. this->updater_->deleteRRset(*this->rrset_);
  3252. this->soa_.reset(new RRset(this->zname_, this->qclass_, RRType::SOA(),
  3253. this->rrttl_));
  3254. this->soa_->addRdata(rdata::createRdata(this->soa_->getType(),
  3255. this->soa_->getClass(),
  3256. "ns1.example.org. "
  3257. "admin.example.org. "
  3258. "1235 3600 1800 2419200 7200"));
  3259. this->updater_->addRRset(*this->soa_);
  3260. this->updater_->addRRset(*this->rrset_);
  3261. ASSERT_NO_THROW(this->updater_->commit());
  3262. std::vector<JournalEntry> expected;
  3263. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3264. DatabaseAccessor::DIFF_DELETE,
  3265. "example.org.", "SOA", "3600",
  3266. "ns1.example.org. admin.example.org. "
  3267. "1234 3600 1800 2419200 7200"));
  3268. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3269. DatabaseAccessor::DIFF_DELETE,
  3270. "www.example.org.", "A", "3600",
  3271. "192.0.2.2"));
  3272. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1235,
  3273. DatabaseAccessor::DIFF_ADD,
  3274. "example.org.", "SOA", "3600",
  3275. "ns1.example.org. admin.example.org. "
  3276. "1235 3600 1800 2419200 7200"));
  3277. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1235,
  3278. DatabaseAccessor::DIFF_ADD,
  3279. "www.example.org.", "A", "3600",
  3280. "192.0.2.2"));
  3281. this->checkJournal(expected);
  3282. }
  3283. TYPED_TEST(DatabaseClientTest, journalForNSEC3) {
  3284. // Similar to the previous test, but adding/deleting NSEC3 RRs, just to
  3285. // confirm that NSEC3 is not special for managing diffs.
  3286. const ConstRRsetPtr nsec3_rrset =
  3287. textToRRset(string(nsec3_hash) + ".example.org. 3600 IN NSEC3 " +
  3288. string(nsec3_rdata));
  3289. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3290. this->updater_->deleteRRset(*this->soa_);
  3291. this->updater_->deleteRRset(*nsec3_rrset);
  3292. this->soa_.reset(new RRset(this->zname_, this->qclass_, RRType::SOA(),
  3293. this->rrttl_));
  3294. this->soa_->addRdata(rdata::createRdata(this->soa_->getType(),
  3295. this->soa_->getClass(),
  3296. "ns1.example.org. "
  3297. "admin.example.org. "
  3298. "1235 3600 1800 2419200 7200"));
  3299. this->updater_->addRRset(*this->soa_);
  3300. this->updater_->addRRset(*nsec3_rrset);
  3301. this->updater_->commit();
  3302. std::vector<JournalEntry> expected;
  3303. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3304. DatabaseAccessor::DIFF_DELETE,
  3305. "example.org.", "SOA", "3600",
  3306. "ns1.example.org. admin.example.org. "
  3307. "1234 3600 1800 2419200 7200"));
  3308. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3309. DatabaseAccessor::DIFF_DELETE,
  3310. string(nsec3_hash) + ".example.org.",
  3311. "NSEC3", "3600", nsec3_rdata));
  3312. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1235,
  3313. DatabaseAccessor::DIFF_ADD,
  3314. "example.org.", "SOA", "3600",
  3315. "ns1.example.org. admin.example.org. "
  3316. "1235 3600 1800 2419200 7200"));
  3317. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1235,
  3318. DatabaseAccessor::DIFF_ADD,
  3319. string(nsec3_hash) + ".example.org.",
  3320. "NSEC3", "3600", nsec3_rdata));
  3321. this->checkJournal(expected);
  3322. }
  3323. /*
  3324. * Push multiple delete-add sequences. Checks it is allowed and all is
  3325. * saved.
  3326. */
  3327. TYPED_TEST(DatabaseClientTest, journalMultiple) {
  3328. std::vector<JournalEntry> expected;
  3329. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3330. std::string soa_rdata = "ns1.example.org. admin.example.org. "
  3331. "1234 3600 1800 2419200 7200";
  3332. for (size_t i = 1; i < 100; ++ i) {
  3333. // Remove the old SOA
  3334. this->updater_->deleteRRset(*this->soa_);
  3335. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234 + i - 1,
  3336. DatabaseAccessor::DIFF_DELETE,
  3337. "example.org.", "SOA", "3600",
  3338. soa_rdata));
  3339. // Create a new SOA
  3340. soa_rdata = "ns1.example.org. admin.example.org. " +
  3341. lexical_cast<std::string>(1234 + i) + " 3600 1800 2419200 7200";
  3342. this->soa_.reset(new RRset(this->zname_, this->qclass_, RRType::SOA(),
  3343. this->rrttl_));
  3344. this->soa_->addRdata(rdata::createRdata(this->soa_->getType(),
  3345. this->soa_->getClass(),
  3346. soa_rdata));
  3347. // Add the new SOA
  3348. this->updater_->addRRset(*this->soa_);
  3349. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234 + i,
  3350. DatabaseAccessor::DIFF_ADD,
  3351. "example.org.", "SOA", "3600",
  3352. soa_rdata));
  3353. }
  3354. ASSERT_NO_THROW(this->updater_->commit());
  3355. // Check the journal contains everything.
  3356. this->checkJournal(expected);
  3357. }
  3358. /*
  3359. * Test passing a forbidden sequence to it and expect it to throw.
  3360. *
  3361. * Note that we implicitly test in different testcases (these for add and
  3362. * delete) that if the journaling is false, it doesn't expect the order.
  3363. *
  3364. * In this test we don't check with the real databases as this case shouldn't
  3365. * contain backend specific behavior.
  3366. */
  3367. TEST_F(MockDatabaseClientTest, journalBadSequence) {
  3368. std::vector<JournalEntry> expected;
  3369. {
  3370. SCOPED_TRACE("Delete A before SOA");
  3371. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3372. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_),
  3373. isc::BadValue);
  3374. // Make sure the journal is empty now
  3375. this->checkJournal(expected);
  3376. }
  3377. {
  3378. SCOPED_TRACE("Add before delete");
  3379. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3380. EXPECT_THROW(this->updater_->addRRset(*this->soa_), isc::BadValue);
  3381. // Make sure the journal is empty now
  3382. this->checkJournal(expected);
  3383. }
  3384. {
  3385. SCOPED_TRACE("Add A before SOA");
  3386. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3387. // So far OK
  3388. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->soa_));
  3389. // But we miss the add SOA here
  3390. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), isc::BadValue);
  3391. // Make sure the journal contains only the first one
  3392. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3393. DatabaseAccessor::DIFF_DELETE,
  3394. "example.org.", "SOA", "3600",
  3395. "ns1.example.org. admin.example.org. "
  3396. "1234 3600 1800 2419200 7200"));
  3397. this->checkJournal(expected);
  3398. }
  3399. {
  3400. SCOPED_TRACE("Commit before add");
  3401. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3402. // So far OK
  3403. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->soa_));
  3404. // Commit at the wrong time
  3405. EXPECT_THROW(updater_->commit(), isc::BadValue);
  3406. current_accessor_->checkJournal(expected);
  3407. }
  3408. {
  3409. SCOPED_TRACE("Delete two SOAs");
  3410. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3411. // So far OK
  3412. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->soa_));
  3413. // Delete the SOA again
  3414. EXPECT_THROW(this->updater_->deleteRRset(*this->soa_), isc::BadValue);
  3415. this->checkJournal(expected);
  3416. }
  3417. {
  3418. SCOPED_TRACE("Add two SOAs");
  3419. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3420. // So far OK
  3421. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->soa_));
  3422. // Still OK
  3423. EXPECT_NO_THROW(this->updater_->addRRset(*this->soa_));
  3424. // But this one is added again
  3425. EXPECT_THROW(this->updater_->addRRset(*this->soa_), isc::BadValue);
  3426. expected.push_back(JournalEntry(WRITABLE_ZONE_ID, 1234,
  3427. DatabaseAccessor::DIFF_ADD,
  3428. "example.org.", "SOA", "3600",
  3429. "ns1.example.org. admin.example.org. "
  3430. "1234 3600 1800 2419200 7200"));
  3431. this->checkJournal(expected);
  3432. }
  3433. }
  3434. /*
  3435. * Test it rejects to store journals when we request it together with
  3436. * erasing the whole zone.
  3437. */
  3438. TYPED_TEST(DatabaseClientTest, journalOnErase) {
  3439. EXPECT_THROW(this->client_->getUpdater(this->zname_, true, true),
  3440. isc::BadValue);
  3441. }
  3442. /*
  3443. * Check that exception is propagated when the journal is not implemented.
  3444. */
  3445. TEST_F(MockDatabaseClientTest, journalNotImplemented) {
  3446. updater_ = client_->getUpdater(Name("null.example.org"), false, true);
  3447. EXPECT_THROW(updater_->deleteRRset(*soa_), isc::NotImplemented);
  3448. soa_.reset(new RRset(zname_, qclass_, RRType::SOA(), rrttl_));
  3449. soa_->addRdata(rdata::createRdata(soa_->getType(), soa_->getClass(),
  3450. "ns1.example.org. admin.example.org. "
  3451. "1234 3600 1800 2419201 7200"));
  3452. EXPECT_THROW(updater_->addRRset(*soa_), isc::NotImplemented);
  3453. }
  3454. /*
  3455. * Test that different exceptions are propagated.
  3456. */
  3457. TEST_F(MockDatabaseClientTest, journalException) {
  3458. updater_ = client_->getUpdater(Name("bad.example.org"), false, true);
  3459. EXPECT_THROW(updater_->deleteRRset(*soa_), DataSourceError);
  3460. }
  3461. //
  3462. // Tests for the ZoneJournalReader
  3463. //
  3464. // Install a simple, commonly used diff sequence: making an update from one
  3465. // SOA to another. Return the end SOA RRset for the convenience of the caller.
  3466. ConstRRsetPtr
  3467. makeSimpleDiff(DataSourceClient& client, const Name& zname,
  3468. const RRClass& rrclass, ConstRRsetPtr begin_soa)
  3469. {
  3470. ZoneUpdaterPtr updater = client.getUpdater(zname, false, true);
  3471. updater->deleteRRset(*begin_soa);
  3472. RRsetPtr soa_end(new RRset(zname, rrclass, RRType::SOA(), RRTTL(3600)));
  3473. soa_end->addRdata(rdata::createRdata(RRType::SOA(), rrclass,
  3474. "ns1.example.org. admin.example.org. "
  3475. "1235 3600 1800 2419200 7200"));
  3476. updater->addRRset(*soa_end);
  3477. updater->commit();
  3478. return (soa_end);
  3479. }
  3480. TYPED_TEST(DatabaseClientTest, journalReader) {
  3481. // Check the simple case made by makeSimpleDiff.
  3482. ConstRRsetPtr soa_end = makeSimpleDiff(*this->client_, this->zname_,
  3483. this->qclass_, this->soa_);
  3484. pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> result =
  3485. this->client_->getJournalReader(this->zname_, 1234, 1235);
  3486. EXPECT_EQ(ZoneJournalReader::SUCCESS, result.first);
  3487. ZoneJournalReaderPtr jnl_reader = result.second;
  3488. ASSERT_TRUE(jnl_reader);
  3489. ConstRRsetPtr rrset = jnl_reader->getNextDiff();
  3490. ASSERT_TRUE(rrset);
  3491. rrsetCheck(this->soa_, rrset);
  3492. rrset = jnl_reader->getNextDiff();
  3493. ASSERT_TRUE(rrset);
  3494. rrsetCheck(soa_end, rrset);
  3495. rrset = jnl_reader->getNextDiff();
  3496. ASSERT_FALSE(rrset);
  3497. // Once it reaches the end of the sequence, further read attempt will
  3498. // result in exception.
  3499. EXPECT_THROW(jnl_reader->getNextDiff(), isc::InvalidOperation);
  3500. }
  3501. TYPED_TEST(DatabaseClientTest, readLargeJournal) {
  3502. // Similar to journalMultiple, but check that at a higher level.
  3503. this->updater_ = this->client_->getUpdater(this->zname_, false, true);
  3504. vector<ConstRRsetPtr> expected;
  3505. for (size_t i = 0; i < 100; ++i) {
  3506. // Create the old SOA and remove it, and record it in the expected list
  3507. RRsetPtr rrset1(new RRset(this->zname_, this->qclass_, RRType::SOA(),
  3508. this->rrttl_));
  3509. string soa_rdata = "ns1.example.org. admin.example.org. " +
  3510. lexical_cast<std::string>(1234 + i) + " 3600 1800 2419200 7200";
  3511. rrset1->addRdata(rdata::createRdata(RRType::SOA(), this->qclass_,
  3512. soa_rdata));
  3513. this->updater_->deleteRRset(*rrset1);
  3514. expected.push_back(rrset1);
  3515. // Create a new SOA, add it, and record it.
  3516. RRsetPtr rrset2(new RRset(this->zname_, this->qclass_, RRType::SOA(),
  3517. this->rrttl_));
  3518. soa_rdata = "ns1.example.org. admin.example.org. " +
  3519. lexical_cast<std::string>(1234 + i + 1) +
  3520. " 3600 1800 2419200 7200";
  3521. rrset2->addRdata(rdata::createRdata(RRType::SOA(), this->qclass_,
  3522. soa_rdata));
  3523. this->updater_->addRRset(*rrset2);
  3524. expected.push_back(rrset2);
  3525. }
  3526. this->updater_->commit();
  3527. ZoneJournalReaderPtr jnl_reader(this->client_->getJournalReader(
  3528. this->zname_, 1234, 1334).second);
  3529. ConstRRsetPtr actual;
  3530. int i = 0;
  3531. while ((actual = jnl_reader->getNextDiff()) != NULL) {
  3532. rrsetCheck(expected.at(i++), actual);
  3533. }
  3534. EXPECT_EQ(expected.size(), i); // we should have eaten all expected data
  3535. }
  3536. TYPED_TEST(DatabaseClientTest, readJournalForNoRange) {
  3537. makeSimpleDiff(*this->client_, this->zname_, this->qclass_, this->soa_);
  3538. // The specified range does not exist in the diff storage. The factory
  3539. // method should result in NO_SUCH_VERSION
  3540. pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> result =
  3541. this->client_->getJournalReader(this->zname_, 1200, 1235);
  3542. EXPECT_EQ(ZoneJournalReader::NO_SUCH_VERSION, result.first);
  3543. EXPECT_FALSE(result.second);
  3544. }
  3545. TYPED_TEST(DatabaseClientTest, journalReaderForNXZone) {
  3546. pair<ZoneJournalReader::Result, ZoneJournalReaderPtr> result =
  3547. this->client_->getJournalReader(Name("nosuchzone"), 0, 1);
  3548. EXPECT_EQ(ZoneJournalReader::NO_SUCH_ZONE, result.first);
  3549. EXPECT_FALSE(result.second);
  3550. }
  3551. // A helper function for journalWithBadData. It installs a simple diff
  3552. // from one serial (of 'begin') to another ('begin' + 1), tweaking a specified
  3553. // field of data with some invalid value.
  3554. void
  3555. installBadDiff(MockAccessor& accessor, uint32_t begin,
  3556. DatabaseAccessor::DiffRecordParams modify_param,
  3557. const char* const data)
  3558. {
  3559. string data1[] = {"example.org.", "SOA", "3600", "ns. root. 1 1 1 1 1"};
  3560. string data2[] = {"example.org.", "SOA", "3600", "ns. root. 2 1 1 1 1"};
  3561. data1[modify_param] = data;
  3562. accessor.addRecordDiff(READONLY_ZONE_ID, begin,
  3563. DatabaseAccessor::DIFF_DELETE, data1);
  3564. accessor.addRecordDiff(READONLY_ZONE_ID, begin + 1,
  3565. DatabaseAccessor::DIFF_ADD, data2);
  3566. }
  3567. TEST_F(MockDatabaseClientTest, journalWithBadData) {
  3568. MockAccessor& mock_accessor =
  3569. dynamic_cast<MockAccessor&>(*current_accessor_);
  3570. // One of the fields from the data source is broken as an RR parameter.
  3571. // The journal reader should still be constructed, but getNextDiff()
  3572. // should result in exception.
  3573. installBadDiff(mock_accessor, 1, DatabaseAccessor::DIFF_NAME,
  3574. "example..org");
  3575. installBadDiff(mock_accessor, 3, DatabaseAccessor::DIFF_TYPE,
  3576. "bad-rrtype");
  3577. installBadDiff(mock_accessor, 5, DatabaseAccessor::DIFF_TTL,
  3578. "bad-ttl");
  3579. installBadDiff(mock_accessor, 7, DatabaseAccessor::DIFF_RDATA,
  3580. "bad rdata");
  3581. EXPECT_THROW(this->client_->getJournalReader(this->zname_, 1, 2).
  3582. second->getNextDiff(), DataSourceError);
  3583. EXPECT_THROW(this->client_->getJournalReader(this->zname_, 3, 4).
  3584. second->getNextDiff(), DataSourceError);
  3585. EXPECT_THROW(this->client_->getJournalReader(this->zname_, 5, 6).
  3586. second->getNextDiff(), DataSourceError);
  3587. EXPECT_THROW(this->client_->getJournalReader(this->zname_, 7, 8).
  3588. second->getNextDiff(), DataSourceError);
  3589. }
  3590. /// Let us test a little bit of NSEC3.
  3591. TEST_F(MockDatabaseClientTest, findNSEC3) {
  3592. // Set up the faked hash calculator.
  3593. setNSEC3HashCreator(&test_nsec3_hash_creator_);
  3594. DataSourceClient::FindResult
  3595. zone(this->client_->findZone(Name("example.org")));
  3596. ASSERT_EQ(result::SUCCESS, zone.code);
  3597. boost::shared_ptr<DatabaseClient::Finder> finder(
  3598. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  3599. // It'll complain if there is no NSEC3PARAM yet
  3600. EXPECT_THROW(finder->findNSEC3(Name("example.org"), false),
  3601. DataSourceError);
  3602. // And enable NSEC3 in the zone.
  3603. this->current_accessor_->enableNSEC3();
  3604. // The rest is in the function, it is shared with in-memory tests
  3605. performNSEC3Test(*finder);
  3606. }
  3607. }