database_unittest.cc 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711
  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 <boost/shared_ptr.hpp>
  15. #include <gtest/gtest.h>
  16. #include <dns/name.h>
  17. #include <dns/rrttl.h>
  18. #include <dns/rrset.h>
  19. #include <exceptions/exceptions.h>
  20. #include <datasrc/database.h>
  21. #include <datasrc/zone.h>
  22. #include <datasrc/data_source.h>
  23. #include <datasrc/iterator.h>
  24. #include <datasrc/sqlite3_accessor.h>
  25. #include <testutils/dnsmessage_test.h>
  26. #include <map>
  27. using namespace isc::datasrc;
  28. using namespace std;
  29. // don't import the entire boost namespace. It will unexpectedly hide uint32_t
  30. // for some systems.
  31. using boost::shared_ptr;
  32. using boost::dynamic_pointer_cast;
  33. using namespace isc::dns;
  34. namespace {
  35. // Imaginary zone IDs used in the mock accessor below.
  36. const int READONLY_ZONE_ID = 42;
  37. const int WRITABLE_ZONE_ID = 4200;
  38. // Commonly used test data
  39. const char* const TEST_RECORDS[][5] = {
  40. // some plain data
  41. {"www.example.org.", "A", "3600", "", "192.0.2.1"},
  42. {"www.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  43. {"www.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  44. {"www.example.org.", "NSEC", "3600", "", "www2.example.org. A AAAA NSEC RRSIG"},
  45. {"www.example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  46. {"www2.example.org.", "A", "3600", "", "192.0.2.1"},
  47. {"www2.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  48. {"www2.example.org.", "A", "3600", "", "192.0.2.2"},
  49. {"cname.example.org.", "CNAME", "3600", "", "www.example.org."},
  50. // some DNSSEC-'signed' data
  51. {"signed1.example.org.", "A", "3600", "", "192.0.2.1"},
  52. {"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  53. {"signed1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
  54. {"signed1.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  55. {"signed1.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  56. {"signed1.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  57. {"signedcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
  58. {"signedcname1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  59. // special case might fail; sig is for cname, which isn't there (should be ignored)
  60. // (ignoring of 'normal' other type is done above by www.)
  61. {"acnamesig1.example.org.", "A", "3600", "", "192.0.2.1"},
  62. {"acnamesig1.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  63. {"acnamesig1.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  64. // let's pretend we have a database that is not careful
  65. // about the order in which it returns data
  66. {"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  67. {"signed2.example.org.", "AAAA", "3600", "", "2001:db8::2"},
  68. {"signed2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE"},
  69. {"signed2.example.org.", "A", "3600", "", "192.0.2.1"},
  70. {"signed2.example.org.", "RRSIG", "3600", "", "AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  71. {"signed2.example.org.", "AAAA", "3600", "", "2001:db8::1"},
  72. {"signedcname2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  73. {"signedcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
  74. {"acnamesig2.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  75. {"acnamesig2.example.org.", "A", "3600", "", "192.0.2.1"},
  76. {"acnamesig2.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  77. {"acnamesig3.example.org.", "RRSIG", "3600", "", "CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  78. {"acnamesig3.example.org.", "RRSIG", "3600", "", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  79. {"acnamesig3.example.org.", "A", "3600", "", "192.0.2.1"},
  80. {"ttldiff1.example.org.", "A", "3600", "", "192.0.2.1"},
  81. {"ttldiff1.example.org.", "A", "360", "", "192.0.2.2"},
  82. {"ttldiff2.example.org.", "A", "360", "", "192.0.2.1"},
  83. {"ttldiff2.example.org.", "A", "3600", "", "192.0.2.2"},
  84. // also add some intentionally bad data
  85. {"badcname1.example.org.", "A", "3600", "", "192.0.2.1"},
  86. {"badcname1.example.org.", "CNAME", "3600", "", "www.example.org."},
  87. {"badcname2.example.org.", "CNAME", "3600", "", "www.example.org."},
  88. {"badcname2.example.org.", "A", "3600", "", "192.0.2.1"},
  89. {"badcname3.example.org.", "CNAME", "3600", "", "www.example.org."},
  90. {"badcname3.example.org.", "CNAME", "3600", "", "www.example2.org."},
  91. {"badrdata.example.org.", "A", "3600", "", "bad"},
  92. {"badtype.example.org.", "BAD_TYPE", "3600", "", "192.0.2.1"},
  93. {"badttl.example.org.", "A", "badttl", "", "192.0.2.1"},
  94. {"badsig.example.org.", "A", "badttl", "", "192.0.2.1"},
  95. {"badsig.example.org.", "RRSIG", "3600", "", "A 5 3 3600 somebaddata 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  96. {"badsigtype.example.org.", "A", "3600", "", "192.0.2.1"},
  97. {"badsigtype.example.org.", "RRSIG", "3600", "TXT", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  98. // Data for testing delegation (with NS and DNAME)
  99. {"delegation.example.org.", "NS", "3600", "", "ns.example.com."},
  100. {"delegation.example.org.", "NS", "3600", "",
  101. "ns.delegation.example.org."},
  102. {"delegation.example.org.", "DS", "3600", "", "1 RSAMD5 2 abcd"},
  103. {"delegation.example.org.", "RRSIG", "3600", "", "NS 5 3 3600 "
  104. "20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  105. {"ns.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
  106. {"deep.below.delegation.example.org.", "A", "3600", "", "192.0.2.1"},
  107. {"dname.example.org.", "A", "3600", "", "192.0.2.1"},
  108. {"dname.example.org.", "DNAME", "3600", "", "dname.example.com."},
  109. {"dname.example.org.", "RRSIG", "3600", "",
  110. "DNAME 5 3 3600 20000101000000 20000201000000 12345 "
  111. "example.org. FAKEFAKEFAKE"},
  112. {"below.dname.example.org.", "A", "3600", "", "192.0.2.1"},
  113. // Broken NS
  114. {"brokenns1.example.org.", "A", "3600", "", "192.0.2.1"},
  115. {"brokenns1.example.org.", "NS", "3600", "", "ns.example.com."},
  116. {"brokenns2.example.org.", "NS", "3600", "", "ns.example.com."},
  117. {"brokenns2.example.org.", "A", "3600", "", "192.0.2.1"},
  118. // Now double DNAME, to test failure mode
  119. {"baddname.example.org.", "DNAME", "3600", "", "dname1.example.com."},
  120. {"baddname.example.org.", "DNAME", "3600", "", "dname2.example.com."},
  121. // Put some data into apex (including NS) so we can check our NS
  122. // doesn't break anything
  123. {"example.org.", "SOA", "3600", "", "ns1.example.org. admin.example.org. "
  124. "1234 3600 1800 2419200 7200" },
  125. {"example.org.", "NS", "3600", "", "ns.example.com."},
  126. {"example.org.", "A", "3600", "", "192.0.2.1"},
  127. {"example.org.", "NSEC", "3600", "", "acnamesig1.example.org. NS A NSEC RRSIG"},
  128. {"example.org.", "RRSIG", "3600", "", "SOA 5 3 3600 20000101000000 "
  129. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  130. {"example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 "
  131. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  132. {"example.org.", "RRSIG", "3600", "", "NS 5 3 3600 20000101000000 "
  133. "20000201000000 12345 example.org. FAKEFAKEFAKE"},
  134. // This is because of empty domain test
  135. {"a.b.example.org.", "A", "3600", "", "192.0.2.1"},
  136. // Something for wildcards
  137. {"*.wild.example.org.", "A", "3600", "", "192.0.2.5"},
  138. {"*.wild.example.org.", "RRSIG", "3600", "A", "A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  139. {"*.wild.example.org.", "NSEC", "3600", "", "cancel.here.wild.example.org. A NSEC RRSIG"},
  140. {"*.wild.example.org.", "RRSIG", "3600", "", "NSEC 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE"},
  141. {"cancel.here.wild.example.org.", "AAAA", "3600", "", "2001:db8::5"},
  142. {"delegatedwild.example.org.", "NS", "3600", "", "ns.example.com."},
  143. {"*.delegatedwild.example.org.", "A", "3600", "", "192.0.2.5"},
  144. {"wild.*.foo.example.org.", "A", "3600", "", "192.0.2.5"},
  145. {"wild.*.foo.*.bar.example.org.", "A", "3600", "", "192.0.2.5"},
  146. {"wild.*.foo.*.bar.example.org.", "NSEC", "3600", "",
  147. "brokenns1.example.org. A NSEC"},
  148. {"bao.example.org.", "NSEC", "3600", "", "wild.*.foo.*.bar.example.org. NSEC"},
  149. {"*.cnamewild.example.org.", "CNAME", "3600", "", "www.example.org."},
  150. {"*.dnamewild.example.org.", "DNAME", "3600", "", "dname.example.com."},
  151. {"*.nswild.example.org.", "NS", "3600", "", "ns.example.com."},
  152. // For NSEC empty non-terminal
  153. {"l.example.org.", "NSEC", "3600", "", "empty.nonterminal.example.org. NSEC"},
  154. {"empty.nonterminal.example.org.", "A", "3600", "", "192.0.2.1"},
  155. // Invalid rdata
  156. {"invalidrdata.example.org.", "A", "3600", "", "Bunch of nonsense"},
  157. {"invalidrdata2.example.org.", "A", "3600", "", "192.0.2.1"},
  158. {"invalidrdata2.example.org.", "RRSIG", "3600", "", "Nonsense"},
  159. {NULL, NULL, NULL, NULL, NULL},
  160. };
  161. /*
  162. * An accessor with minimum implementation, keeping the original
  163. * "NotImplemented" methods.
  164. */
  165. class NopAccessor : public DatabaseAccessor {
  166. public:
  167. NopAccessor() : database_name_("mock_database")
  168. { }
  169. virtual std::pair<bool, int> getZone(const std::string& name) const {
  170. if (name == "example.org.") {
  171. return (std::pair<bool, int>(true, READONLY_ZONE_ID));
  172. } else if (name == "null.example.org.") {
  173. return (std::pair<bool, int>(true, 13));
  174. } else if (name == "empty.example.org.") {
  175. return (std::pair<bool, int>(true, 0));
  176. } else if (name == "bad.example.org.") {
  177. return (std::pair<bool, int>(true, -1));
  178. } else {
  179. return (std::pair<bool, int>(false, 0));
  180. }
  181. }
  182. virtual shared_ptr<DatabaseAccessor> clone() {
  183. // This accessor is stateless, so we can simply return a new instance.
  184. return (shared_ptr<DatabaseAccessor>(new NopAccessor));
  185. }
  186. virtual std::pair<bool, int> startUpdateZone(const std::string&, bool) {
  187. // return dummy value. unused anyway.
  188. return (pair<bool, int>(true, 0));
  189. }
  190. virtual void startTransaction() {}
  191. virtual void commit() {}
  192. virtual void rollback() {}
  193. virtual void addRecordToZone(const string (&)[ADD_COLUMN_COUNT]) {}
  194. virtual void deleteRecordInZone(const string (&)[DEL_PARAM_COUNT]) {}
  195. virtual void addRecordDiff(int, uint32_t, DiffOperation,
  196. const std::string (&)[DIFF_PARAM_COUNT]) {}
  197. virtual const std::string& getDBName() const {
  198. return (database_name_);
  199. }
  200. virtual IteratorContextPtr getRecords(const std::string&, int, bool)
  201. const
  202. {
  203. isc_throw(isc::NotImplemented,
  204. "This database datasource can't be iterated");
  205. }
  206. virtual IteratorContextPtr getAllRecords(int) const {
  207. isc_throw(isc::NotImplemented,
  208. "This database datasource can't be iterated");
  209. }
  210. virtual IteratorContextPtr getDiffs(int, uint32_t, uint32_t) const {
  211. isc_throw(isc::NotImplemented,
  212. "This database datasource can't be iterated");
  213. }
  214. virtual std::string findPreviousName(int, const std::string&) const {
  215. isc_throw(isc::NotImplemented,
  216. "This data source doesn't support DNSSEC");
  217. }
  218. private:
  219. const std::string database_name_;
  220. };
  221. /*
  222. * A virtual database accessor that pretends it contains single zone --
  223. * example.org.
  224. *
  225. * It has the same getZone method as NopConnection, but it provides
  226. * implementation of the optional functionality.
  227. */
  228. class MockAccessor : public NopAccessor {
  229. // Type of mock database "row"s. This is a map whose keys are the
  230. // own names. We internally sort them by the name comparison order.
  231. struct NameCompare : public binary_function<string, string, bool> {
  232. bool operator()(const string& n1, const string& n2) const {
  233. return (Name(n1).compare(Name(n2)).getOrder() < 0);
  234. }
  235. };
  236. typedef std::map<std::string,
  237. std::vector< std::vector<std::string> >,
  238. NameCompare > Domains;
  239. public:
  240. MockAccessor() : rollbacked_(false), did_transaction_(false) {
  241. readonly_records_ = &readonly_records_master_;
  242. update_records_ = &update_records_master_;
  243. empty_records_ = &empty_records_master_;
  244. fillData();
  245. }
  246. virtual shared_ptr<DatabaseAccessor> clone() {
  247. shared_ptr<MockAccessor> cloned_accessor(new MockAccessor());
  248. cloned_accessor->readonly_records_ = &readonly_records_master_;
  249. cloned_accessor->update_records_ = &update_records_master_;
  250. cloned_accessor->empty_records_ = &empty_records_master_;
  251. latest_clone_ = cloned_accessor;
  252. return (cloned_accessor);
  253. }
  254. virtual void startTransaction() {
  255. // Currently we only use this transaction for simple read-only
  256. // operations. So we just make a local copy of the data (we don't
  257. // care about what happens after commit() or rollback()).
  258. // Obviously as a consequence, if a test case tries to make multiple
  259. // transactions on a single mock accessor it will fail.
  260. // Check any attempt of multiple transactions
  261. if (did_transaction_) {
  262. isc_throw(isc::Unexpected, "MockAccessor::startTransaction() "
  263. "called multiple times - likely a bug in the test");
  264. }
  265. readonly_records_copy_ = *readonly_records_;
  266. readonly_records_ = &readonly_records_copy_;
  267. did_transaction_ = true;
  268. }
  269. private:
  270. class MockNameIteratorContext : public IteratorContext {
  271. public:
  272. MockNameIteratorContext(const MockAccessor& mock_accessor, int zone_id,
  273. const std::string& name, bool subdomains) :
  274. searched_name_(name), cur_record_(0)
  275. {
  276. // 'hardcoded' names to trigger exceptions
  277. // On these names some exceptions are thrown, to test the robustness
  278. // of the find() method.
  279. if (searched_name_ == "dsexception.in.search.") {
  280. isc_throw(DataSourceError, "datasource exception on search");
  281. } else if (searched_name_ == "iscexception.in.search.") {
  282. isc_throw(isc::Exception, "isc exception on search");
  283. } else if (searched_name_ == "basicexception.in.search.") {
  284. throw std::exception();
  285. }
  286. cur_record_ = 0;
  287. const Domains& cur_records = mock_accessor.getMockRecords(zone_id);
  288. if (cur_records.count(name) > 0) {
  289. // we're not aiming for efficiency in this test, simply
  290. // copy the relevant vector from records
  291. cur_name = cur_records.find(name)->second;
  292. } else if (subdomains) {
  293. cur_name.clear();
  294. // Just walk everything and check if it is a subdomain.
  295. // If it is, just copy all data from there.
  296. for (Domains::const_iterator i(cur_records.begin());
  297. i != cur_records.end(); ++i) {
  298. const Name local(i->first);
  299. if (local.compare(Name(name)).getRelation() ==
  300. isc::dns::NameComparisonResult::SUBDOMAIN) {
  301. cur_name.insert(cur_name.end(), i->second.begin(),
  302. i->second.end());
  303. }
  304. }
  305. } else {
  306. cur_name.clear();
  307. }
  308. }
  309. virtual bool getNext(std::string (&columns)[COLUMN_COUNT]) {
  310. if (searched_name_ == "dsexception.in.getnext.") {
  311. isc_throw(DataSourceError, "datasource exception on getnextrecord");
  312. } else if (searched_name_ == "iscexception.in.getnext.") {
  313. isc_throw(isc::Exception, "isc exception on getnextrecord");
  314. } else if (searched_name_ == "basicexception.in.getnext.") {
  315. throw std::exception();
  316. }
  317. if (cur_record_ < cur_name.size()) {
  318. for (size_t i = 0; i < COLUMN_COUNT; ++i) {
  319. columns[i] = cur_name[cur_record_][i];
  320. }
  321. cur_record_++;
  322. return (true);
  323. } else {
  324. return (false);
  325. }
  326. }
  327. private:
  328. const std::string searched_name_;
  329. int cur_record_;
  330. std::vector< std::vector<std::string> > cur_name;
  331. };
  332. class MockIteratorContext : public IteratorContext {
  333. private:
  334. int step;
  335. const Domains& domains_;
  336. public:
  337. MockIteratorContext(const Domains& domains) :
  338. step(0), domains_(domains)
  339. { }
  340. virtual bool getNext(string (&data)[COLUMN_COUNT]) {
  341. // A special case: if the given set of domains is already empty,
  342. // we always return false.
  343. if (domains_.empty()) {
  344. return (false);
  345. }
  346. // Return faked data for tests
  347. switch (step ++) {
  348. case 0:
  349. data[DatabaseAccessor::NAME_COLUMN] = "example.org";
  350. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  351. data[DatabaseAccessor::TTL_COLUMN] = "3600";
  352. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
  353. return (true);
  354. case 1:
  355. data[DatabaseAccessor::NAME_COLUMN] = "example.org";
  356. data[DatabaseAccessor::TYPE_COLUMN] = "SOA";
  357. data[DatabaseAccessor::TTL_COLUMN] = "3600";
  358. data[DatabaseAccessor::RDATA_COLUMN] = "ns1.example.org. admin.example.org. "
  359. "1234 3600 1800 2419200 7200";
  360. return (true);
  361. case 2:
  362. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  363. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  364. data[DatabaseAccessor::TTL_COLUMN] = "300";
  365. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
  366. return (true);
  367. case 3:
  368. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  369. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  370. data[DatabaseAccessor::TTL_COLUMN] = "300";
  371. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
  372. return (true);
  373. case 4:
  374. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  375. data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
  376. data[DatabaseAccessor::TTL_COLUMN] = "300";
  377. data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::1";
  378. return (true);
  379. case 5:
  380. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  381. data[DatabaseAccessor::TYPE_COLUMN] = "AAAA";
  382. data[DatabaseAccessor::TTL_COLUMN] = "300";
  383. data[DatabaseAccessor::RDATA_COLUMN] = "2001:db8::2";
  384. return (true);
  385. case 6:
  386. data[DatabaseAccessor::NAME_COLUMN] = "ttldiff.example.org";
  387. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  388. data[DatabaseAccessor::TTL_COLUMN] = "300";
  389. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
  390. return (true);
  391. case 7:
  392. data[DatabaseAccessor::NAME_COLUMN] = "ttldiff.example.org";
  393. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  394. data[DatabaseAccessor::TTL_COLUMN] = "600";
  395. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
  396. return (true);
  397. default:
  398. ADD_FAILURE() <<
  399. "Request past the end of iterator context";
  400. case 8:
  401. return (false);
  402. }
  403. }
  404. };
  405. class EmptyIteratorContext : public IteratorContext {
  406. public:
  407. virtual bool getNext(string(&)[COLUMN_COUNT]) {
  408. return (false);
  409. }
  410. };
  411. class BadIteratorContext : public IteratorContext {
  412. private:
  413. int step;
  414. public:
  415. BadIteratorContext() :
  416. step(0)
  417. { }
  418. virtual bool getNext(string (&data)[COLUMN_COUNT]) {
  419. switch (step ++) {
  420. case 0:
  421. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  422. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  423. data[DatabaseAccessor::TTL_COLUMN] = "300";
  424. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.1";
  425. return (true);
  426. case 1:
  427. data[DatabaseAccessor::NAME_COLUMN] = "x.example.org";
  428. data[DatabaseAccessor::TYPE_COLUMN] = "A";
  429. data[DatabaseAccessor::TTL_COLUMN] = "301";
  430. data[DatabaseAccessor::RDATA_COLUMN] = "192.0.2.2";
  431. return (true);
  432. default:
  433. ADD_FAILURE() <<
  434. "Request past the end of iterator context";
  435. case 2:
  436. return (false);
  437. }
  438. }
  439. };
  440. public:
  441. virtual IteratorContextPtr getAllRecords(int id) const {
  442. if (id == READONLY_ZONE_ID) {
  443. return (IteratorContextPtr(new MockIteratorContext(
  444. *readonly_records_)));
  445. } else if (id == 13) {
  446. return (IteratorContextPtr());
  447. } else if (id == 0) {
  448. return (IteratorContextPtr(new EmptyIteratorContext()));
  449. } else if (id == -1) {
  450. return (IteratorContextPtr(new BadIteratorContext()));
  451. } else {
  452. isc_throw(isc::Unexpected, "Unknown zone ID");
  453. }
  454. }
  455. virtual IteratorContextPtr getRecords(const std::string& name, int id,
  456. bool subdomains) const
  457. {
  458. if (id == READONLY_ZONE_ID || id == WRITABLE_ZONE_ID) {
  459. return (IteratorContextPtr(
  460. new MockNameIteratorContext(*this, id, name,
  461. subdomains)));
  462. } else {
  463. // This iterator is bogus, but for the cases tested below that's
  464. // sufficient.
  465. return (IteratorContextPtr(
  466. new MockNameIteratorContext(*this, READONLY_ZONE_ID,
  467. name, subdomains)));
  468. }
  469. }
  470. virtual pair<bool, int> startUpdateZone(const std::string& zone_name,
  471. bool replace)
  472. {
  473. const pair<bool, int> zone_info = getZone(zone_name);
  474. if (!zone_info.first) {
  475. return (pair<bool, int>(false, 0));
  476. }
  477. // Prepare the record set for update. If replacing the existing one,
  478. // we use an empty set; otherwise we use a writable copy of the
  479. // original.
  480. if (replace) {
  481. update_records_->clear();
  482. } else {
  483. *update_records_ = *readonly_records_;
  484. }
  485. return (pair<bool, int>(true, WRITABLE_ZONE_ID));
  486. }
  487. virtual void commit() {
  488. *readonly_records_ = *update_records_;
  489. }
  490. virtual void rollback() {
  491. // Special hook: if something with a name of "throw.example.org"
  492. // has been added, trigger an imaginary unexpected event with an
  493. // exception.
  494. if (update_records_->count("throw.example.org.") > 0) {
  495. isc_throw(DataSourceError, "unexpected failure in rollback");
  496. }
  497. rollbacked_ = true;
  498. }
  499. virtual void addRecordToZone(const string (&columns)[ADD_COLUMN_COUNT]) {
  500. // Copy the current value to cur_name. If it doesn't exist,
  501. // operator[] will create a new one.
  502. cur_name_ = (*update_records_)[columns[DatabaseAccessor::ADD_NAME]];
  503. vector<string> record_columns;
  504. record_columns.push_back(columns[DatabaseAccessor::ADD_TYPE]);
  505. record_columns.push_back(columns[DatabaseAccessor::ADD_TTL]);
  506. record_columns.push_back(columns[DatabaseAccessor::ADD_SIGTYPE]);
  507. record_columns.push_back(columns[DatabaseAccessor::ADD_RDATA]);
  508. record_columns.push_back(columns[DatabaseAccessor::ADD_NAME]);
  509. // copy back the added entry
  510. cur_name_.push_back(record_columns);
  511. (*update_records_)[columns[DatabaseAccessor::ADD_NAME]] = cur_name_;
  512. // remember this one so that test cases can check it.
  513. copy(columns, columns + DatabaseAccessor::ADD_COLUMN_COUNT,
  514. columns_lastadded_);
  515. }
  516. // Helper predicate class used in deleteRecordInZone().
  517. struct deleteMatch {
  518. deleteMatch(const string& type, const string& rdata) :
  519. type_(type), rdata_(rdata)
  520. {}
  521. bool operator()(const vector<string>& row) const {
  522. return (row[0] == type_ && row[3] == rdata_);
  523. }
  524. const string& type_;
  525. const string& rdata_;
  526. };
  527. virtual void deleteRecordInZone(const string (&params)[DEL_PARAM_COUNT]) {
  528. vector<vector<string> >& records =
  529. (*update_records_)[params[DatabaseAccessor::DEL_NAME]];
  530. records.erase(remove_if(records.begin(), records.end(),
  531. deleteMatch(
  532. params[DatabaseAccessor::DEL_TYPE],
  533. params[DatabaseAccessor::DEL_RDATA])),
  534. records.end());
  535. if (records.empty()) {
  536. (*update_records_).erase(params[DatabaseAccessor::DEL_NAME]);
  537. }
  538. }
  539. //
  540. // Helper methods to keep track of some update related activities
  541. //
  542. bool isRollbacked() const {
  543. return (rollbacked_);
  544. }
  545. const string* getLastAdded() const {
  546. return (columns_lastadded_);
  547. }
  548. // This allows the test code to get the accessor used in an update context
  549. shared_ptr<const MockAccessor> getLatestClone() const {
  550. return (latest_clone_);
  551. }
  552. virtual std::string findPreviousName(int id, const std::string& rname)
  553. const
  554. {
  555. if (id == -1) {
  556. isc_throw(isc::NotImplemented, "Test not implemented behaviour");
  557. } else if (id == READONLY_ZONE_ID) {
  558. // For some specific names we intentionally return broken or
  559. // unexpected result.
  560. if (rname == "org.example.badnsec2.") {
  561. return ("badnsec1.example.org.");
  562. } else if (rname == "org.example.brokenname.") {
  563. return ("brokenname...example.org.");
  564. } else if (rname == "org.example.notimplnsec." ||
  565. rname == "org.example.wild.here.") {
  566. isc_throw(isc::NotImplemented, "Not implemented in this test");
  567. }
  568. // For the general case, we search for the first name N in the
  569. // domains that meets N >= reverse(rname) using lower_bound.
  570. // The "previous name" is the name of the previous entry of N.
  571. // Note that Domains are internally sorted by the Name comparison
  572. // order. Due to the API requirement we are given a reversed
  573. // name (rname), so we need to reverse it again to convert it
  574. // to the original name.
  575. Domains::const_iterator it(readonly_records_->lower_bound(
  576. Name(rname).reverse().toText()));
  577. if (it == readonly_records_->begin()) {
  578. isc_throw(isc::Unexpected, "Unexpected name");
  579. }
  580. if (it == readonly_records_->end()) {
  581. return ((*readonly_records_->rbegin()).first);
  582. }
  583. return ((*(--it)).first);
  584. } else {
  585. isc_throw(isc::Unexpected, "Unknown zone ID");
  586. }
  587. }
  588. private:
  589. // The following member variables are storage and/or update work space
  590. // of the test zone. The "master"s are the real objects that contain
  591. // the data, and they are shared among all accessors cloned from
  592. // an initially created one. The "copy" data will be used for read-only
  593. // transaction. The pointer members allow the sharing.
  594. // "readonly" is for normal lookups. "update" is the workspace for
  595. // updates. When update starts it will be initialized either as an
  596. // empty set (when replacing the entire zone) or as a copy of the
  597. // "readonly" one. "empty" is a sentinel to produce negative results.
  598. Domains readonly_records_master_;
  599. Domains readonly_records_copy_;
  600. Domains* readonly_records_;
  601. Domains update_records_master_;
  602. Domains* update_records_;
  603. const Domains empty_records_master_;
  604. const Domains* empty_records_;
  605. // used as temporary storage after searchForRecord() and during
  606. // getNextRecord() calls, as well as during the building of the
  607. // fake data
  608. std::vector< std::vector<std::string> > cur_name_;
  609. // The columns that were most recently added via addRecordToZone()
  610. string columns_lastadded_[ADD_COLUMN_COUNT];
  611. // Whether rollback operation has been performed for the database.
  612. // Not useful except for purely testing purpose.
  613. bool rollbacked_;
  614. // Remember the mock accessor that was last cloned
  615. boost::shared_ptr<MockAccessor> latest_clone_;
  616. // Internal flag for duplicate check
  617. bool did_transaction_;
  618. const Domains& getMockRecords(int zone_id) const {
  619. if (zone_id == READONLY_ZONE_ID) {
  620. return (*readonly_records_);
  621. } else if (zone_id == WRITABLE_ZONE_ID) {
  622. return (*update_records_);
  623. }
  624. return (*empty_records_);
  625. }
  626. // Adds one record to the current name in the database
  627. // The actual data will not be added to 'records' until
  628. // addCurName() is called
  629. void addRecord(const std::string& type,
  630. const std::string& ttl,
  631. const std::string& sigtype,
  632. const std::string& rdata) {
  633. std::vector<std::string> columns;
  634. columns.push_back(type);
  635. columns.push_back(ttl);
  636. columns.push_back(sigtype);
  637. columns.push_back(rdata);
  638. cur_name_.push_back(columns);
  639. }
  640. // Adds all records we just built with calls to addRecords
  641. // to the actual fake database. This will clear cur_name_,
  642. // so we can immediately start adding new records.
  643. void addCurName(const std::string& name) {
  644. ASSERT_EQ(0, readonly_records_->count(name));
  645. // Append the name to all of them
  646. for (std::vector<std::vector<std::string> >::iterator
  647. i(cur_name_.begin()); i != cur_name_.end(); ++ i) {
  648. i->push_back(name);
  649. }
  650. (*readonly_records_)[name] = cur_name_;
  651. cur_name_.clear();
  652. }
  653. // Fills the database with zone data.
  654. // This method constructs a number of resource records (with addRecord),
  655. // which will all be added for one domain name to the fake database
  656. // (with addCurName). So for instance the first set of calls create
  657. // data for the name 'www.example.org', which will consist of one A RRset
  658. // of one record, and one AAAA RRset of two records.
  659. // The order in which they are added is the order in which getNextRecord()
  660. // will return them (so we can test whether find() etc. support data that
  661. // might not come in 'normal' order)
  662. // It shall immediately fail if you try to add the same name twice.
  663. void fillData() {
  664. const char* prev_name = NULL;
  665. for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
  666. if (prev_name != NULL &&
  667. strcmp(prev_name, TEST_RECORDS[i][0]) != 0) {
  668. addCurName(prev_name);
  669. }
  670. prev_name = TEST_RECORDS[i][0];
  671. addRecord(TEST_RECORDS[i][1], TEST_RECORDS[i][2],
  672. TEST_RECORDS[i][3], TEST_RECORDS[i][4]);
  673. }
  674. addCurName(prev_name);
  675. }
  676. };
  677. // This tests the default getRecords behaviour, throwing NotImplemented
  678. TEST(DatabaseConnectionTest, getRecords) {
  679. EXPECT_THROW(NopAccessor().getRecords(".", 1, false),
  680. isc::NotImplemented);
  681. }
  682. // This tests the default getAllRecords behaviour, throwing NotImplemented
  683. TEST(DatabaseConnectionTest, getAllRecords) {
  684. // The parameters don't matter
  685. EXPECT_THROW(NopAccessor().getAllRecords(1),
  686. isc::NotImplemented);
  687. }
  688. // This test fixture is templated so that we can share (most of) the test
  689. // cases with different types of data sources. Note that in test cases
  690. // we need to use 'this' to refer to member variables of the test class.
  691. template <typename ACCESSOR_TYPE>
  692. class DatabaseClientTest : public ::testing::Test {
  693. public:
  694. DatabaseClientTest() : zname_("example.org"), qname_("www.example.org"),
  695. qclass_(RRClass::IN()), qtype_(RRType::A()),
  696. rrttl_(3600)
  697. {
  698. createClient();
  699. // set up the commonly used finder.
  700. DataSourceClient::FindResult zone(client_->findZone(zname_));
  701. assert(zone.code == result::SUCCESS);
  702. finder_ = dynamic_pointer_cast<DatabaseClient::Finder>(
  703. zone.zone_finder);
  704. // Test IN/A RDATA to be added in update tests. Intentionally using
  705. // different data than the initial data configured in the MockAccessor.
  706. rrset_.reset(new RRset(qname_, qclass_, qtype_, rrttl_));
  707. rrset_->addRdata(rdata::createRdata(rrset_->getType(),
  708. rrset_->getClass(), "192.0.2.2"));
  709. // And its RRSIG. Also different from the configured one.
  710. rrsigset_.reset(new RRset(qname_, qclass_, RRType::RRSIG(),
  711. rrttl_));
  712. rrsigset_->addRdata(rdata::createRdata(rrsigset_->getType(),
  713. rrsigset_->getClass(),
  714. "A 5 3 0 20000101000000 "
  715. "20000201000000 0 example.org. "
  716. "FAKEFAKEFAKE"));
  717. }
  718. /*
  719. * We initialize the client from a function, so we can call it multiple
  720. * times per test.
  721. */
  722. void createClient() {
  723. current_accessor_ = new ACCESSOR_TYPE();
  724. is_mock_ = (dynamic_cast<MockAccessor*>(current_accessor_) != NULL);
  725. client_.reset(new DatabaseClient(qclass_,
  726. shared_ptr<ACCESSOR_TYPE>(
  727. current_accessor_)));
  728. }
  729. /**
  730. * Check the zone finder is a valid one and references the zone ID and
  731. * database available here.
  732. */
  733. void checkZoneFinder(const DataSourceClient::FindResult& zone) {
  734. ASSERT_NE(ZoneFinderPtr(), zone.zone_finder) << "No zone finder";
  735. shared_ptr<DatabaseClient::Finder> finder(
  736. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  737. ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
  738. "Wrong type of finder";
  739. if (is_mock_) {
  740. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  741. }
  742. EXPECT_EQ(current_accessor_, &finder->getAccessor());
  743. }
  744. shared_ptr<DatabaseClient::Finder> getFinder() {
  745. DataSourceClient::FindResult zone(client_->findZone(zname_));
  746. EXPECT_EQ(result::SUCCESS, zone.code);
  747. shared_ptr<DatabaseClient::Finder> finder(
  748. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  749. if (is_mock_) {
  750. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  751. }
  752. return (finder);
  753. }
  754. // Helper methods for update tests
  755. bool isRollbacked(bool expected = false) const {
  756. if (is_mock_) {
  757. const MockAccessor& mock_accessor =
  758. dynamic_cast<const MockAccessor&>(*update_accessor_);
  759. return (mock_accessor.isRollbacked());
  760. } else {
  761. return (expected);
  762. }
  763. }
  764. void checkLastAdded(const char* const expected[]) const {
  765. if (is_mock_) {
  766. const MockAccessor* mock_accessor =
  767. dynamic_cast<const MockAccessor*>(current_accessor_);
  768. for (int i = 0; i < DatabaseAccessor::ADD_COLUMN_COUNT; ++i) {
  769. EXPECT_EQ(expected[i],
  770. mock_accessor->getLatestClone()->getLastAdded()[i]);
  771. }
  772. }
  773. }
  774. void setUpdateAccessor() {
  775. if (is_mock_) {
  776. const MockAccessor* mock_accessor =
  777. dynamic_cast<const MockAccessor*>(current_accessor_);
  778. update_accessor_ = mock_accessor->getLatestClone();
  779. }
  780. }
  781. // Some tests only work for MockAccessor. We remember whether our accessor
  782. // is of that type.
  783. bool is_mock_;
  784. // Will be deleted by client_, just keep the current value for comparison.
  785. ACCESSOR_TYPE* current_accessor_;
  786. shared_ptr<DatabaseClient> client_;
  787. const std::string database_name_;
  788. // The zone finder of the test zone commonly used in various tests.
  789. shared_ptr<DatabaseClient::Finder> finder_;
  790. // Some shortcut variables for commonly used test parameters
  791. const Name zname_; // the zone name stored in the test data source
  792. const Name qname_; // commonly used name to be found
  793. const RRClass qclass_; // commonly used RR class used with qname
  794. const RRType qtype_; // commonly used RR type used with qname
  795. const RRTTL rrttl_; // commonly used RR TTL
  796. RRsetPtr rrset_; // for adding/deleting an RRset
  797. RRsetPtr rrsigset_; // for adding/deleting an RRset
  798. // update related objects to be tested
  799. ZoneUpdaterPtr updater_;
  800. shared_ptr<const DatabaseAccessor> update_accessor_;
  801. // placeholders
  802. const std::vector<std::string> empty_rdatas_; // for NXRRSET/NXDOMAIN
  803. std::vector<std::string> expected_rdatas_;
  804. std::vector<std::string> expected_sig_rdatas_;
  805. };
  806. class TestSQLite3Accessor : public SQLite3Accessor {
  807. public:
  808. TestSQLite3Accessor() : SQLite3Accessor(
  809. TEST_DATA_BUILDDIR "/rwtest.sqlite3.copied", "IN")
  810. {
  811. startUpdateZone("example.org.", true);
  812. string columns[ADD_COLUMN_COUNT];
  813. for (int i = 0; TEST_RECORDS[i][0] != NULL; ++i) {
  814. columns[ADD_NAME] = TEST_RECORDS[i][0];
  815. columns[ADD_REV_NAME] = Name(columns[ADD_NAME]).reverse().toText();
  816. columns[ADD_TYPE] = TEST_RECORDS[i][1];
  817. columns[ADD_TTL] = TEST_RECORDS[i][2];
  818. columns[ADD_SIGTYPE] = TEST_RECORDS[i][3];
  819. columns[ADD_RDATA] = TEST_RECORDS[i][4];
  820. addRecordToZone(columns);
  821. }
  822. commit();
  823. }
  824. };
  825. // The following two lines instantiate test cases with concrete accessor
  826. // classes to be tested.
  827. // XXX: clang++ installed on our FreeBSD buildbot cannot complete compiling
  828. // this file, seemingly due to the size of the code. We'll consider more
  829. // complete workaround, but for a short term workaround we'll reduce the
  830. // number of tested accessor classes (thus reducing the amount of code
  831. // to be compiled) for this particular environment.
  832. #if defined(__clang__) && defined(__FreeBSD__)
  833. typedef ::testing::Types<MockAccessor> TestAccessorTypes;
  834. #else
  835. typedef ::testing::Types<MockAccessor, TestSQLite3Accessor> TestAccessorTypes;
  836. #endif
  837. TYPED_TEST_CASE(DatabaseClientTest, TestAccessorTypes);
  838. // In some cases the entire test fixture is for the mock accessor only.
  839. // We use the usual TEST_F for them with the corresponding specialized class
  840. // to make the code simpler.
  841. typedef DatabaseClientTest<MockAccessor> MockDatabaseClientTest;
  842. TYPED_TEST(DatabaseClientTest, zoneNotFound) {
  843. DataSourceClient::FindResult zone(
  844. this->client_->findZone(Name("example.com")));
  845. EXPECT_EQ(result::NOTFOUND, zone.code);
  846. }
  847. TYPED_TEST(DatabaseClientTest, exactZone) {
  848. DataSourceClient::FindResult zone(
  849. this->client_->findZone(Name("example.org")));
  850. EXPECT_EQ(result::SUCCESS, zone.code);
  851. this->checkZoneFinder(zone);
  852. }
  853. TYPED_TEST(DatabaseClientTest, superZone) {
  854. DataSourceClient::FindResult zone(this->client_->findZone(Name(
  855. "sub.example.org")));
  856. EXPECT_EQ(result::PARTIALMATCH, zone.code);
  857. this->checkZoneFinder(zone);
  858. }
  859. // This test doesn't depend on derived accessor class, so we use TEST().
  860. TEST(GenericDatabaseClientTest, noAccessorException) {
  861. // We need a dummy variable here; some compiler would regard it a mere
  862. // declaration instead of an instantiation and make the test fail.
  863. EXPECT_THROW(DatabaseClient dummy(RRClass::IN(),
  864. shared_ptr<DatabaseAccessor>()),
  865. isc::InvalidParameter);
  866. }
  867. // If the zone doesn't exist, exception is thrown
  868. TYPED_TEST(DatabaseClientTest, noZoneIterator) {
  869. EXPECT_THROW(this->client_->getIterator(Name("example.com")),
  870. DataSourceError);
  871. }
  872. // If the zone doesn't exist and iteration is not implemented, it still throws
  873. // the exception it doesn't exist
  874. TEST(GenericDatabaseClientTest, noZoneNotImplementedIterator) {
  875. EXPECT_THROW(DatabaseClient(RRClass::IN(),
  876. boost::shared_ptr<DatabaseAccessor>(
  877. new NopAccessor())).getIterator(
  878. Name("example.com")),
  879. DataSourceError);
  880. }
  881. TEST(GenericDatabaseClientTest, notImplementedIterator) {
  882. EXPECT_THROW(DatabaseClient(RRClass::IN(), shared_ptr<DatabaseAccessor>(
  883. new NopAccessor())).getIterator(Name("example.org")),
  884. isc::NotImplemented);
  885. }
  886. // Pretend a bug in the connection and pass NULL as the context
  887. // Should not crash, but gracefully throw. Works for the mock accessor only.
  888. TEST_F(MockDatabaseClientTest, nullIteratorContext) {
  889. EXPECT_THROW(this->client_->getIterator(Name("null.example.org")),
  890. isc::Unexpected);
  891. }
  892. // It doesn't crash or anything if the zone is completely empty.
  893. // Works for the mock accessor only.
  894. TEST_F(MockDatabaseClientTest, emptyIterator) {
  895. ZoneIteratorPtr it(this->client_->getIterator(Name("empty.example.org")));
  896. EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
  897. // This is past the end, it should throw
  898. EXPECT_THROW(it->getNextRRset(), isc::Unexpected);
  899. }
  900. // checks if the given rrset matches the
  901. // given name, class, type and rdatas
  902. void
  903. checkRRset(isc::dns::ConstRRsetPtr rrset,
  904. const isc::dns::Name& name,
  905. const isc::dns::RRClass& rrclass,
  906. const isc::dns::RRType& rrtype,
  907. const isc::dns::RRTTL& rrttl,
  908. const std::vector<std::string>& rdatas) {
  909. isc::dns::RRsetPtr expected_rrset(
  910. new isc::dns::RRset(name, rrclass, rrtype, rrttl));
  911. for (unsigned int i = 0; i < rdatas.size(); ++i) {
  912. expected_rrset->addRdata(
  913. isc::dns::rdata::createRdata(rrtype, rrclass,
  914. rdatas[i]));
  915. }
  916. isc::testutils::rrsetCheck(expected_rrset, rrset);
  917. }
  918. // Iterate through a zone
  919. TYPED_TEST(DatabaseClientTest, iterator) {
  920. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
  921. ConstRRsetPtr rrset(it->getNextRRset());
  922. ASSERT_NE(ConstRRsetPtr(), rrset);
  923. // The first name should be the zone origin.
  924. EXPECT_EQ(this->zname_, rrset->getName());
  925. // The rest of the checks work only for the mock accessor.
  926. if (!this->is_mock_) {
  927. return;
  928. }
  929. this->expected_rdatas_.clear();
  930. this->expected_rdatas_.push_back("192.0.2.1");
  931. checkRRset(rrset, Name("example.org"), this->qclass_, RRType::A(),
  932. this->rrttl_, this->expected_rdatas_);
  933. rrset = it->getNextRRset();
  934. this->expected_rdatas_.clear();
  935. this->expected_rdatas_.push_back("ns1.example.org. admin.example.org. "
  936. "1234 3600 1800 2419200 7200");
  937. checkRRset(rrset, Name("example.org"), this->qclass_, RRType::SOA(),
  938. this->rrttl_, this->expected_rdatas_);
  939. rrset = it->getNextRRset();
  940. this->expected_rdatas_.clear();
  941. this->expected_rdatas_.push_back("192.0.2.1");
  942. this->expected_rdatas_.push_back("192.0.2.2");
  943. checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::A(),
  944. RRTTL(300), this->expected_rdatas_);
  945. rrset = it->getNextRRset();
  946. this->expected_rdatas_.clear();
  947. this->expected_rdatas_.push_back("2001:db8::1");
  948. this->expected_rdatas_.push_back("2001:db8::2");
  949. checkRRset(rrset, Name("x.example.org"), this->qclass_, RRType::AAAA(),
  950. RRTTL(300), this->expected_rdatas_);
  951. rrset = it->getNextRRset();
  952. ASSERT_NE(ConstRRsetPtr(), rrset);
  953. this->expected_rdatas_.clear();
  954. this->expected_rdatas_.push_back("192.0.2.1");
  955. this->expected_rdatas_.push_back("192.0.2.2");
  956. checkRRset(rrset, Name("ttldiff.example.org"), this->qclass_, RRType::A(),
  957. RRTTL(300), this->expected_rdatas_);
  958. EXPECT_EQ(ConstRRsetPtr(), it->getNextRRset());
  959. }
  960. // This has inconsistent TTL in the set (the rest, like nonsense in
  961. // the data is handled in rdata itself). Works for the mock accessor only.
  962. TEST_F(MockDatabaseClientTest, badIterator) {
  963. // It should not throw, but get the lowest one of them
  964. ZoneIteratorPtr it(this->client_->getIterator(Name("bad.example.org")));
  965. EXPECT_EQ(it->getNextRRset()->getTTL(), isc::dns::RRTTL(300));
  966. }
  967. TYPED_TEST(DatabaseClientTest, getSOAFromIterator) {
  968. vector<string> soa_data;
  969. soa_data.push_back("ns1.example.org. admin.example.org. "
  970. "1234 3600 1800 2419200 7200");
  971. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  972. ASSERT_TRUE(it);
  973. checkRRset(it->getSOA(), this->zname_, this->qclass_, RRType::SOA(),
  974. this->rrttl_, soa_data);
  975. // Iterate over the zone until we find an SOA. Although there's a broken
  976. // RDATA that would trigger an exception in getNextRRset(), we should
  977. // reach the SOA as the sequence should be sorted and the SOA is at
  978. // the origin name (which has no bogus data).
  979. ConstRRsetPtr rrset;
  980. while ((rrset = it->getNextRRset()) != ConstRRsetPtr() &&
  981. rrset->getType() != RRType::SOA()) {
  982. ;
  983. }
  984. ASSERT_TRUE(rrset);
  985. // It should be identical to the result of getSOA().
  986. isc::testutils::rrsetCheck(it->getSOA(), rrset);
  987. }
  988. TYPED_TEST(DatabaseClientTest, noSOAFromIterator) {
  989. // First, empty the zone.
  990. this->updater_ = this->client_->getUpdater(this->zname_, true);
  991. this->updater_->commit();
  992. // Then getSOA() should return NULL.
  993. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  994. ASSERT_TRUE(it);
  995. EXPECT_FALSE(it->getSOA());
  996. }
  997. TYPED_TEST(DatabaseClientTest, iterateThenUpdate) {
  998. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  999. ASSERT_TRUE(it);
  1000. // Try to empty the zone after getting the iterator. Depending on the
  1001. // underlying data source, it may result in an exception due to the
  1002. // transaction for the iterator. In either case the integrity of the
  1003. // iterator result should be reserved.
  1004. try {
  1005. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1006. this->updater_->commit();
  1007. // Confirm at least it doesn't contain any SOA
  1008. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  1009. this->getFinder()->find(this->zname_, RRType::SOA()).code);
  1010. } catch (const DataSourceError&) {}
  1011. ConstRRsetPtr rrset;
  1012. while ((rrset = it->getNextRRset()) != ConstRRsetPtr() &&
  1013. rrset->getType() != RRType::SOA()) {
  1014. ;
  1015. }
  1016. ASSERT_TRUE(rrset);
  1017. // It should be identical to the result of getSOA().
  1018. isc::testutils::rrsetCheck(it->getSOA(), rrset);
  1019. }
  1020. TYPED_TEST(DatabaseClientTest, updateThenIterateThenUpdate) {
  1021. // First clear the zone.
  1022. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1023. this->updater_->commit();
  1024. // Then iterate over it. It should immediately reach the end, at which
  1025. // point the transaction should be committed.
  1026. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1027. ASSERT_TRUE(it);
  1028. EXPECT_FALSE(it->getNextRRset());
  1029. // So another update attempt should succeed, too.
  1030. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1031. this->updater_->commit();
  1032. }
  1033. TYPED_TEST(DatabaseClientTest, updateAfterDeleteIterator) {
  1034. // Similar to the previous case, but we delete the iterator in the
  1035. // middle of zone. The transaction should be canceled (actually no
  1036. // different from commit though) at that point.
  1037. ZoneIteratorPtr it(this->client_->getIterator(this->zname_));
  1038. ASSERT_TRUE(it);
  1039. EXPECT_TRUE(it->getNextRRset());
  1040. it.reset();
  1041. // So another update attempt should succeed.
  1042. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1043. this->updater_->commit();
  1044. }
  1045. void
  1046. doFindTest(ZoneFinder& finder,
  1047. const isc::dns::Name& name,
  1048. const isc::dns::RRType& type,
  1049. const isc::dns::RRType& expected_type,
  1050. const isc::dns::RRTTL expected_ttl,
  1051. ZoneFinder::Result expected_result,
  1052. const std::vector<std::string>& expected_rdatas,
  1053. const std::vector<std::string>& expected_sig_rdatas,
  1054. const isc::dns::Name& expected_name = isc::dns::Name::ROOT_NAME(),
  1055. const ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT)
  1056. {
  1057. SCOPED_TRACE("doFindTest " + name.toText() + " " + type.toText());
  1058. const ZoneFinder::FindResult result = finder.find(name, type, NULL,
  1059. options);
  1060. ASSERT_EQ(expected_result, result.code) << name << " " << type;
  1061. if (!expected_rdatas.empty() && result.rrset) {
  1062. checkRRset(result.rrset, expected_name != Name(".") ? expected_name :
  1063. name, finder.getClass(), expected_type, expected_ttl,
  1064. expected_rdatas);
  1065. if (!expected_sig_rdatas.empty() && result.rrset->getRRsig()) {
  1066. checkRRset(result.rrset->getRRsig(), expected_name != Name(".") ?
  1067. expected_name : name, finder.getClass(),
  1068. isc::dns::RRType::RRSIG(), expected_ttl,
  1069. expected_sig_rdatas);
  1070. } else if (expected_sig_rdatas.empty()) {
  1071. EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset->getRRsig());
  1072. } else {
  1073. ADD_FAILURE() << "Missing RRSIG";
  1074. }
  1075. } else if (expected_rdatas.empty()) {
  1076. EXPECT_EQ(isc::dns::RRsetPtr(), result.rrset);
  1077. } else {
  1078. ADD_FAILURE() << "Missing result";
  1079. }
  1080. }
  1081. // When asking for an RRset where RRs somehow have different TTLs, it should
  1082. // convert to the lowest one.
  1083. TEST_F(MockDatabaseClientTest, ttldiff) {
  1084. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
  1085. // Walk through the full iterator, we should see 1 rrset with name
  1086. // ttldiff1.example.org., and two rdatas. Same for ttldiff2
  1087. Name name("ttldiff.example.org.");
  1088. bool found = false;
  1089. //bool found2 = false;
  1090. ConstRRsetPtr rrset = it->getNextRRset();
  1091. while(rrset != ConstRRsetPtr()) {
  1092. if (rrset->getName() == name) {
  1093. ASSERT_FALSE(found);
  1094. ASSERT_EQ(2, rrset->getRdataCount());
  1095. ASSERT_EQ(RRTTL(300), rrset->getTTL());
  1096. found = true;
  1097. }
  1098. rrset = it->getNextRRset();
  1099. }
  1100. ASSERT_TRUE(found);
  1101. }
  1102. // Unless we ask for individual RRs in our iterator request. In that case
  1103. // every RR should go into its own 'rrset'
  1104. TEST_F(MockDatabaseClientTest, ttldiff_no_adjust_ttl) {
  1105. ZoneIteratorPtr it(this->client_->getIterator(Name("example.org"), false));
  1106. // Walk through the full iterator, we should see 1 rrset with name
  1107. // ttldiff1.example.org., and two rdatas. Same for ttldiff2
  1108. Name name("ttldiff.example.org.");
  1109. int found1 = false;
  1110. int found2 = false;
  1111. ConstRRsetPtr rrset = it->getNextRRset();
  1112. while(rrset != ConstRRsetPtr()) {
  1113. if (rrset->getName() == name) {
  1114. ASSERT_EQ(1, rrset->getRdataCount());
  1115. // We should find 1 'rrset' with TTL 300 and one with TTL 600
  1116. if (rrset->getTTL() == RRTTL(300)) {
  1117. ASSERT_FALSE(found1);
  1118. found1 = true;
  1119. } else if (rrset->getTTL() == RRTTL(600)) {
  1120. ASSERT_FALSE(found2);
  1121. found2 = true;
  1122. } else {
  1123. FAIL() << "Found unexpected TTL: " <<
  1124. rrset->getTTL().toText();
  1125. }
  1126. }
  1127. rrset = it->getNextRRset();
  1128. }
  1129. ASSERT_TRUE(found1);
  1130. ASSERT_TRUE(found2);
  1131. }
  1132. TYPED_TEST(DatabaseClientTest, find) {
  1133. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1134. this->expected_rdatas_.clear();
  1135. this->expected_sig_rdatas_.clear();
  1136. this->expected_rdatas_.push_back("192.0.2.1");
  1137. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1138. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1139. this->expected_rdatas_, this->expected_sig_rdatas_);
  1140. this->expected_rdatas_.clear();
  1141. this->expected_sig_rdatas_.clear();
  1142. this->expected_rdatas_.push_back("192.0.2.1");
  1143. this->expected_rdatas_.push_back("192.0.2.2");
  1144. doFindTest(*finder, isc::dns::Name("www2.example.org."),
  1145. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1146. this->expected_rdatas_, this->expected_sig_rdatas_);
  1147. this->expected_rdatas_.clear();
  1148. this->expected_sig_rdatas_.clear();
  1149. this->expected_rdatas_.push_back("2001:db8::1");
  1150. this->expected_rdatas_.push_back("2001:db8::2");
  1151. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1152. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1153. this->rrttl_,
  1154. ZoneFinder::SUCCESS,
  1155. this->expected_rdatas_, this->expected_sig_rdatas_);
  1156. this->expected_rdatas_.clear();
  1157. this->expected_sig_rdatas_.clear();
  1158. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1159. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(),
  1160. this->rrttl_,
  1161. ZoneFinder::NXRRSET,
  1162. this->expected_rdatas_, this->expected_sig_rdatas_);
  1163. this->expected_rdatas_.clear();
  1164. this->expected_sig_rdatas_.clear();
  1165. this->expected_rdatas_.push_back("www.example.org.");
  1166. doFindTest(*finder, isc::dns::Name("cname.example.org."),
  1167. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1168. ZoneFinder::CNAME, this->expected_rdatas_,
  1169. this->expected_sig_rdatas_);
  1170. this->expected_rdatas_.clear();
  1171. this->expected_sig_rdatas_.clear();
  1172. this->expected_rdatas_.push_back("www.example.org.");
  1173. doFindTest(*finder, isc::dns::Name("cname.example.org."),
  1174. isc::dns::RRType::CNAME(), isc::dns::RRType::CNAME(),
  1175. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1176. this->expected_sig_rdatas_);
  1177. this->expected_rdatas_.clear();
  1178. this->expected_sig_rdatas_.clear();
  1179. doFindTest(*finder, isc::dns::Name("doesnotexist.example.org."),
  1180. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1181. this->expected_rdatas_, this->expected_sig_rdatas_);
  1182. this->expected_rdatas_.clear();
  1183. this->expected_sig_rdatas_.clear();
  1184. this->expected_rdatas_.push_back("192.0.2.1");
  1185. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1186. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  1187. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1188. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1189. this->expected_rdatas_, this->expected_sig_rdatas_);
  1190. this->expected_rdatas_.clear();
  1191. this->expected_sig_rdatas_.clear();
  1192. this->expected_rdatas_.push_back("2001:db8::1");
  1193. this->expected_rdatas_.push_back("2001:db8::2");
  1194. this->expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1195. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1196. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1197. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1198. this->expected_sig_rdatas_);
  1199. this->expected_rdatas_.clear();
  1200. this->expected_sig_rdatas_.clear();
  1201. doFindTest(*finder, isc::dns::Name("signed1.example.org."),
  1202. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(), this->rrttl_,
  1203. ZoneFinder::NXRRSET, this->expected_rdatas_,
  1204. this->expected_sig_rdatas_);
  1205. this->expected_rdatas_.clear();
  1206. this->expected_sig_rdatas_.clear();
  1207. this->expected_rdatas_.push_back("www.example.org.");
  1208. this->expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1209. doFindTest(*finder, isc::dns::Name("signedcname1.example.org."),
  1210. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1211. ZoneFinder::CNAME, this->expected_rdatas_,
  1212. this->expected_sig_rdatas_);
  1213. this->expected_rdatas_.clear();
  1214. this->expected_sig_rdatas_.clear();
  1215. this->expected_rdatas_.push_back("192.0.2.1");
  1216. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1217. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12346 example.org. FAKEFAKEFAKE");
  1218. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1219. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1220. this->expected_rdatas_, this->expected_sig_rdatas_);
  1221. this->expected_rdatas_.clear();
  1222. this->expected_sig_rdatas_.clear();
  1223. this->expected_rdatas_.push_back("2001:db8::2");
  1224. this->expected_rdatas_.push_back("2001:db8::1");
  1225. this->expected_sig_rdatas_.push_back("AAAA 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1226. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1227. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1228. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1229. this->expected_sig_rdatas_);
  1230. this->expected_rdatas_.clear();
  1231. this->expected_sig_rdatas_.clear();
  1232. doFindTest(*finder, isc::dns::Name("signed2.example.org."),
  1233. isc::dns::RRType::TXT(), isc::dns::RRType::TXT(), this->rrttl_,
  1234. ZoneFinder::NXRRSET, this->expected_rdatas_,
  1235. this->expected_sig_rdatas_);
  1236. this->expected_rdatas_.clear();
  1237. this->expected_sig_rdatas_.clear();
  1238. this->expected_rdatas_.push_back("www.example.org.");
  1239. this->expected_sig_rdatas_.push_back("CNAME 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1240. doFindTest(*finder, isc::dns::Name("signedcname2.example.org."),
  1241. this->qtype_, isc::dns::RRType::CNAME(), this->rrttl_,
  1242. ZoneFinder::CNAME, this->expected_rdatas_,
  1243. this->expected_sig_rdatas_);
  1244. this->expected_rdatas_.clear();
  1245. this->expected_sig_rdatas_.clear();
  1246. this->expected_rdatas_.push_back("192.0.2.1");
  1247. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1248. doFindTest(*finder, isc::dns::Name("acnamesig1.example.org."),
  1249. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1250. this->expected_rdatas_, this->expected_sig_rdatas_);
  1251. this->expected_rdatas_.clear();
  1252. this->expected_sig_rdatas_.clear();
  1253. this->expected_rdatas_.push_back("192.0.2.1");
  1254. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1255. doFindTest(*finder, isc::dns::Name("acnamesig2.example.org."),
  1256. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1257. this->expected_rdatas_, this->expected_sig_rdatas_);
  1258. this->expected_rdatas_.clear();
  1259. this->expected_sig_rdatas_.clear();
  1260. this->expected_rdatas_.push_back("192.0.2.1");
  1261. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1262. doFindTest(*finder, isc::dns::Name("acnamesig3.example.org."),
  1263. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1264. this->expected_rdatas_, this->expected_sig_rdatas_);
  1265. this->expected_rdatas_.clear();
  1266. this->expected_sig_rdatas_.clear();
  1267. this->expected_rdatas_.push_back("192.0.2.1");
  1268. this->expected_rdatas_.push_back("192.0.2.2");
  1269. doFindTest(*finder, isc::dns::Name("ttldiff1.example.org."),
  1270. this->qtype_, this->qtype_, isc::dns::RRTTL(360),
  1271. ZoneFinder::SUCCESS, this->expected_rdatas_,
  1272. this->expected_sig_rdatas_);
  1273. this->expected_rdatas_.clear();
  1274. this->expected_sig_rdatas_.clear();
  1275. this->expected_rdatas_.push_back("192.0.2.1");
  1276. this->expected_rdatas_.push_back("192.0.2.2");
  1277. doFindTest(*finder, isc::dns::Name("ttldiff2.example.org."),
  1278. this->qtype_, this->qtype_, isc::dns::RRTTL(360),
  1279. ZoneFinder::SUCCESS, this->expected_rdatas_,
  1280. this->expected_sig_rdatas_);
  1281. EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
  1282. this->qtype_,
  1283. NULL, ZoneFinder::FIND_DEFAULT),
  1284. DataSourceError);
  1285. EXPECT_THROW(finder->find(isc::dns::Name("badcname2.example.org."),
  1286. this->qtype_,
  1287. NULL, ZoneFinder::FIND_DEFAULT),
  1288. DataSourceError);
  1289. EXPECT_THROW(finder->find(isc::dns::Name("badcname3.example.org."),
  1290. this->qtype_,
  1291. NULL, ZoneFinder::FIND_DEFAULT),
  1292. DataSourceError);
  1293. EXPECT_THROW(finder->find(isc::dns::Name("badrdata.example.org."),
  1294. this->qtype_,
  1295. NULL, ZoneFinder::FIND_DEFAULT),
  1296. DataSourceError);
  1297. EXPECT_THROW(finder->find(isc::dns::Name("badtype.example.org."),
  1298. this->qtype_,
  1299. NULL, ZoneFinder::FIND_DEFAULT),
  1300. DataSourceError);
  1301. EXPECT_THROW(finder->find(isc::dns::Name("badttl.example.org."),
  1302. this->qtype_,
  1303. NULL, ZoneFinder::FIND_DEFAULT),
  1304. DataSourceError);
  1305. EXPECT_THROW(finder->find(isc::dns::Name("badsig.example.org."),
  1306. this->qtype_,
  1307. NULL, ZoneFinder::FIND_DEFAULT),
  1308. DataSourceError);
  1309. // Trigger the hardcoded exceptions and see if find() has cleaned up
  1310. if (this->is_mock_) {
  1311. EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.search."),
  1312. this->qtype_,
  1313. NULL, ZoneFinder::FIND_DEFAULT),
  1314. DataSourceError);
  1315. EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.search."),
  1316. this->qtype_,
  1317. NULL, ZoneFinder::FIND_DEFAULT),
  1318. isc::Exception);
  1319. EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.search."),
  1320. this->qtype_,
  1321. NULL, ZoneFinder::FIND_DEFAULT),
  1322. std::exception);
  1323. EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
  1324. this->qtype_,
  1325. NULL, ZoneFinder::FIND_DEFAULT),
  1326. DataSourceError);
  1327. EXPECT_THROW(finder->find(isc::dns::Name("iscexception.in.getnext."),
  1328. this->qtype_,
  1329. NULL, ZoneFinder::FIND_DEFAULT),
  1330. isc::Exception);
  1331. EXPECT_THROW(finder->find(isc::dns::Name("basicexception.in.getnext."),
  1332. this->qtype_,
  1333. NULL, ZoneFinder::FIND_DEFAULT),
  1334. std::exception);
  1335. }
  1336. // This RRSIG has the wrong sigtype field, which should be
  1337. // an error if we decide to keep using that field
  1338. // Right now the field is ignored, so it does not error
  1339. this->expected_rdatas_.clear();
  1340. this->expected_sig_rdatas_.clear();
  1341. this->expected_rdatas_.push_back("192.0.2.1");
  1342. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE");
  1343. doFindTest(*finder, isc::dns::Name("badsigtype.example.org."),
  1344. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1345. this->expected_rdatas_, this->expected_sig_rdatas_);
  1346. }
  1347. TYPED_TEST(DatabaseClientTest, findDelegation) {
  1348. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1349. // The apex should not be considered delegation point and we can access
  1350. // data
  1351. this->expected_rdatas_.clear();
  1352. this->expected_sig_rdatas_.clear();
  1353. this->expected_rdatas_.push_back("192.0.2.1");
  1354. doFindTest(*finder, isc::dns::Name("example.org."),
  1355. this->qtype_, this->qtype_,
  1356. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1357. this->expected_sig_rdatas_);
  1358. this->expected_rdatas_.clear();
  1359. this->expected_rdatas_.push_back("ns.example.com.");
  1360. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
  1361. "12345 example.org. FAKEFAKEFAKE");
  1362. doFindTest(*finder, isc::dns::Name("example.org."),
  1363. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1364. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1365. this->expected_sig_rdatas_);
  1366. // Check when we ask for something below delegation point, we get the NS
  1367. // (Both when the RRset there exists and doesn't)
  1368. this->expected_rdatas_.clear();
  1369. this->expected_sig_rdatas_.clear();
  1370. this->expected_rdatas_.push_back("ns.example.com.");
  1371. this->expected_rdatas_.push_back("ns.delegation.example.org.");
  1372. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 20000201000000 "
  1373. "12345 example.org. FAKEFAKEFAKE");
  1374. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1375. this->qtype_, isc::dns::RRType::NS(),
  1376. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1377. this->expected_sig_rdatas_,
  1378. isc::dns::Name("delegation.example.org."));
  1379. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1380. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1381. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1382. this->expected_sig_rdatas_,
  1383. isc::dns::Name("delegation.example.org."));
  1384. doFindTest(*finder, isc::dns::Name("deep.below.delegation.example.org."),
  1385. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1386. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1387. this->expected_sig_rdatas_,
  1388. isc::dns::Name("delegation.example.org."));
  1389. // Even when we check directly at the delegation point, we should get
  1390. // the NS
  1391. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1392. isc::dns::RRType::AAAA(), isc::dns::RRType::NS(),
  1393. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1394. this->expected_sig_rdatas_);
  1395. // And when we ask direcly for the NS, we should still get delegation
  1396. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1397. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1398. this->rrttl_, ZoneFinder::DELEGATION, this->expected_rdatas_,
  1399. this->expected_sig_rdatas_);
  1400. // Now test delegation. If it is below the delegation point, we should get
  1401. // the DNAME (the one with data under DNAME is invalid zone, but we test
  1402. // the behaviour anyway just to make sure)
  1403. this->expected_rdatas_.clear();
  1404. this->expected_rdatas_.push_back("dname.example.com.");
  1405. this->expected_sig_rdatas_.clear();
  1406. this->expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
  1407. "20000201000000 12345 example.org. "
  1408. "FAKEFAKEFAKE");
  1409. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1410. this->qtype_, isc::dns::RRType::DNAME(),
  1411. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1412. this->expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
  1413. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1414. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  1415. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1416. this->expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
  1417. doFindTest(*finder, isc::dns::Name("really.deep.below.dname.example.org."),
  1418. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  1419. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1420. this->expected_sig_rdatas_, isc::dns::Name("dname.example.org."));
  1421. // Asking direcly for DNAME should give SUCCESS
  1422. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1423. isc::dns::RRType::DNAME(), isc::dns::RRType::DNAME(),
  1424. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1425. this->expected_sig_rdatas_);
  1426. // But we don't delegate at DNAME point
  1427. this->expected_rdatas_.clear();
  1428. this->expected_rdatas_.push_back("192.0.2.1");
  1429. this->expected_sig_rdatas_.clear();
  1430. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1431. this->qtype_, this->qtype_,
  1432. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1433. this->expected_sig_rdatas_);
  1434. this->expected_rdatas_.clear();
  1435. doFindTest(*finder, isc::dns::Name("dname.example.org."),
  1436. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1437. this->rrttl_, ZoneFinder::NXRRSET, this->expected_rdatas_,
  1438. this->expected_sig_rdatas_);
  1439. // This is broken dname, it contains two targets
  1440. EXPECT_THROW(finder->find(isc::dns::Name("below.baddname.example.org."),
  1441. this->qtype_, NULL,
  1442. ZoneFinder::FIND_DEFAULT),
  1443. DataSourceError);
  1444. // Broken NS - it lives together with something else
  1445. EXPECT_THROW(finder->find(isc::dns::Name("brokenns1.example.org."),
  1446. this->qtype_, NULL,
  1447. ZoneFinder::FIND_DEFAULT),
  1448. DataSourceError);
  1449. EXPECT_THROW(finder->find(isc::dns::Name("brokenns2.example.org."),
  1450. this->qtype_, NULL,
  1451. ZoneFinder::FIND_DEFAULT),
  1452. DataSourceError);
  1453. }
  1454. TYPED_TEST(DatabaseClientTest, emptyDomain) {
  1455. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1456. // This domain doesn't exist, but a subdomain of it does.
  1457. // Therefore we should pretend the domain is there, but contains no RRsets
  1458. doFindTest(*finder, isc::dns::Name("b.example.org."), this->qtype_,
  1459. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  1460. this->expected_rdatas_, this->expected_sig_rdatas_);
  1461. }
  1462. // Glue-OK mode. Just go through NS delegations down (but not through
  1463. // DNAME) and pretend it is not there.
  1464. TYPED_TEST(DatabaseClientTest, glueOK) {
  1465. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1466. this->expected_rdatas_.clear();
  1467. this->expected_sig_rdatas_.clear();
  1468. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1469. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1470. this->rrttl_, ZoneFinder::NXRRSET,
  1471. this->expected_rdatas_, this->expected_sig_rdatas_,
  1472. isc::dns::Name("ns.delegation.example.org."),
  1473. ZoneFinder::FIND_GLUE_OK);
  1474. doFindTest(*finder, isc::dns::Name("nothere.delegation.example.org."),
  1475. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1476. this->rrttl_, ZoneFinder::NXDOMAIN,
  1477. this->expected_rdatas_, this->expected_sig_rdatas_,
  1478. isc::dns::Name("nothere.delegation.example.org."),
  1479. ZoneFinder::FIND_GLUE_OK);
  1480. this->expected_rdatas_.push_back("192.0.2.1");
  1481. doFindTest(*finder, isc::dns::Name("ns.delegation.example.org."),
  1482. this->qtype_, this->qtype_,
  1483. this->rrttl_, ZoneFinder::SUCCESS,
  1484. this->expected_rdatas_, this->expected_sig_rdatas_,
  1485. isc::dns::Name("ns.delegation.example.org."),
  1486. ZoneFinder::FIND_GLUE_OK);
  1487. this->expected_rdatas_.clear();
  1488. this->expected_rdatas_.push_back("ns.example.com.");
  1489. this->expected_rdatas_.push_back("ns.delegation.example.org.");
  1490. this->expected_sig_rdatas_.clear();
  1491. this->expected_sig_rdatas_.push_back("NS 5 3 3600 20000101000000 "
  1492. "20000201000000 12345 example.org. "
  1493. "FAKEFAKEFAKE");
  1494. // When we request the NS, it should be SUCCESS, not DELEGATION
  1495. // (different in GLUE_OK)
  1496. doFindTest(*finder, isc::dns::Name("delegation.example.org."),
  1497. isc::dns::RRType::NS(), isc::dns::RRType::NS(),
  1498. this->rrttl_, ZoneFinder::SUCCESS,
  1499. this->expected_rdatas_, this->expected_sig_rdatas_,
  1500. isc::dns::Name("delegation.example.org."),
  1501. ZoneFinder::FIND_GLUE_OK);
  1502. this->expected_rdatas_.clear();
  1503. this->expected_rdatas_.push_back("dname.example.com.");
  1504. this->expected_sig_rdatas_.clear();
  1505. this->expected_sig_rdatas_.push_back("DNAME 5 3 3600 20000101000000 "
  1506. "20000201000000 12345 example.org. "
  1507. "FAKEFAKEFAKE");
  1508. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1509. this->qtype_, isc::dns::RRType::DNAME(),
  1510. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1511. this->expected_sig_rdatas_,
  1512. isc::dns::Name("dname.example.org."), ZoneFinder::FIND_GLUE_OK);
  1513. doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
  1514. isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
  1515. this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
  1516. this->expected_sig_rdatas_,
  1517. isc::dns::Name("dname.example.org."), ZoneFinder::FIND_GLUE_OK);
  1518. }
  1519. TYPED_TEST(DatabaseClientTest, wildcard) {
  1520. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1521. // First, simple wildcard match
  1522. // Check also that the RRSIG is added from the wildcard (not modified)
  1523. this->expected_rdatas_.push_back("192.0.2.5");
  1524. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  1525. "20000201000000 12345 example.org. "
  1526. "FAKEFAKEFAKE");
  1527. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  1528. this->qtype_, this->qtype_, this->rrttl_,
  1529. ZoneFinder::WILDCARD, this->expected_rdatas_,
  1530. this->expected_sig_rdatas_);
  1531. doFindTest(*finder, isc::dns::Name("b.a.wild.example.org"),
  1532. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::WILDCARD,
  1533. this->expected_rdatas_, this->expected_sig_rdatas_);
  1534. this->expected_rdatas_.clear();
  1535. this->expected_sig_rdatas_.clear();
  1536. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  1537. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1538. this->rrttl_, ZoneFinder::WILDCARD_NXRRSET,
  1539. this->expected_rdatas_, this->expected_sig_rdatas_);
  1540. doFindTest(*finder, isc::dns::Name("b.a.wild.example.org"),
  1541. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1542. this->rrttl_, ZoneFinder::WILDCARD_NXRRSET,
  1543. this->expected_rdatas_, this->expected_sig_rdatas_);
  1544. // Direct request for this wildcard
  1545. this->expected_rdatas_.push_back("192.0.2.5");
  1546. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  1547. "20000201000000 12345 example.org. "
  1548. "FAKEFAKEFAKE");
  1549. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  1550. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1551. this->expected_rdatas_, this->expected_sig_rdatas_);
  1552. this->expected_rdatas_.clear();
  1553. this->expected_sig_rdatas_.clear();
  1554. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  1555. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1556. this->rrttl_, ZoneFinder::NXRRSET, this->expected_rdatas_,
  1557. this->expected_sig_rdatas_);
  1558. // This is nonsense, but check it doesn't match by some stupid accident
  1559. doFindTest(*finder, isc::dns::Name("a.*.wild.example.org"),
  1560. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1561. this->expected_rdatas_, this->expected_sig_rdatas_);
  1562. // These should be canceled, since it is below a domain which exitsts
  1563. doFindTest(*finder, isc::dns::Name("nothing.here.wild.example.org"),
  1564. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1565. this->expected_rdatas_, this->expected_sig_rdatas_);
  1566. doFindTest(*finder, isc::dns::Name("cancel.here.wild.example.org"),
  1567. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  1568. this->expected_rdatas_, this->expected_sig_rdatas_);
  1569. doFindTest(*finder,
  1570. isc::dns::Name("below.cancel.here.wild.example.org"),
  1571. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1572. this->expected_rdatas_, this->expected_sig_rdatas_);
  1573. // And this should be just plain empty non-terminal domain, check
  1574. // the wildcard doesn't hurt it
  1575. doFindTest(*finder, isc::dns::Name("here.wild.example.org"),
  1576. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  1577. this->expected_rdatas_, this->expected_sig_rdatas_);
  1578. // Also make sure that the wildcard doesn't hurt the original data
  1579. // below the wildcard
  1580. this->expected_rdatas_.push_back("2001:db8::5");
  1581. doFindTest(*finder, isc::dns::Name("cancel.here.wild.example.org"),
  1582. isc::dns::RRType::AAAA(), isc::dns::RRType::AAAA(),
  1583. this->rrttl_, ZoneFinder::SUCCESS,
  1584. this->expected_rdatas_, this->expected_sig_rdatas_);
  1585. this->expected_rdatas_.clear();
  1586. // How wildcard go together with delegation
  1587. this->expected_rdatas_.push_back("ns.example.com.");
  1588. doFindTest(*finder, isc::dns::Name("below.delegatedwild.example.org"),
  1589. this->qtype_, isc::dns::RRType::NS(), this->rrttl_,
  1590. ZoneFinder::DELEGATION, this->expected_rdatas_,
  1591. this->expected_sig_rdatas_,
  1592. isc::dns::Name("delegatedwild.example.org"));
  1593. // FIXME: This doesn't look logically OK, GLUE_OK should make it transparent,
  1594. // so the match should either work or be canceled, but return NXDOMAIN
  1595. doFindTest(*finder, isc::dns::Name("below.delegatedwild.example.org"),
  1596. this->qtype_, isc::dns::RRType::NS(), this->rrttl_,
  1597. ZoneFinder::DELEGATION, this->expected_rdatas_,
  1598. this->expected_sig_rdatas_,
  1599. isc::dns::Name("delegatedwild.example.org"),
  1600. ZoneFinder::FIND_GLUE_OK);
  1601. this->expected_rdatas_.clear();
  1602. this->expected_rdatas_.push_back("192.0.2.5");
  1603. // These are direct matches
  1604. const char* positive_names[] = {
  1605. "wild.*.foo.example.org.",
  1606. "wild.*.foo.*.bar.example.org.",
  1607. NULL
  1608. };
  1609. for (const char** name(positive_names); *name != NULL; ++ name) {
  1610. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  1611. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1612. this->expected_rdatas_,
  1613. this->expected_sig_rdatas_);
  1614. }
  1615. // These are wildcard matches against empty nonterminal asterisk
  1616. this->expected_rdatas_.clear();
  1617. const char* negative_names[] = {
  1618. "a.foo.example.org.",
  1619. "*.foo.example.org.",
  1620. "foo.example.org.",
  1621. "wild.bar.foo.example.org.",
  1622. "baz.foo.*.bar.example.org",
  1623. "baz.foo.baz.bar.example.org",
  1624. "*.foo.baz.bar.example.org",
  1625. "*.foo.*.bar.example.org",
  1626. "foo.*.bar.example.org",
  1627. "*.bar.example.org",
  1628. "bar.example.org",
  1629. NULL
  1630. };
  1631. // Unless FIND_DNSSEC is specified, this is no different from other
  1632. // NXRRSET case.
  1633. for (const char** name(negative_names); *name != NULL; ++ name) {
  1634. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  1635. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  1636. this->expected_rdatas_, this->expected_sig_rdatas_);
  1637. }
  1638. // With FIND_DNSSEC, it should result in WILDCARD_NXRRSET.
  1639. const char* negative_dnssec_names[] = {
  1640. "a.bar.example.org.",
  1641. "foo.baz.bar.example.org.",
  1642. "a.foo.bar.example.org.",
  1643. NULL
  1644. };
  1645. this->expected_rdatas_.clear();
  1646. this->expected_rdatas_.push_back("wild.*.foo.*.bar.example.org. NSEC");
  1647. this->expected_sig_rdatas_.clear();
  1648. for (const char** name(negative_dnssec_names); *name != NULL; ++ name) {
  1649. doFindTest(*finder, isc::dns::Name(*name), this->qtype_,
  1650. RRType::NSEC(), this->rrttl_, ZoneFinder::WILDCARD_NXRRSET,
  1651. this->expected_rdatas_, this->expected_sig_rdatas_,
  1652. Name("bao.example.org."), ZoneFinder::FIND_DNSSEC);
  1653. }
  1654. // CNAME on a wildcard. Maybe not so common, but not disallowed.
  1655. this->expected_rdatas_.clear();
  1656. this->expected_rdatas_.push_back("www.example.org.");
  1657. this->expected_sig_rdatas_.clear();
  1658. doFindTest(*finder, isc::dns::Name("a.cnamewild.example.org."),
  1659. isc::dns::RRType::TXT(), isc::dns::RRType::CNAME(),
  1660. this->rrttl_, ZoneFinder::WILDCARD_CNAME,
  1661. this->expected_rdatas_, this->expected_sig_rdatas_);
  1662. // DNAME on a wildcard. In our implementation we ignore DNAMEs on a
  1663. // wildcard, but at a higher level we say the behavior is "unspecified".
  1664. // rfc2672bis strongly discourages the mixture of DNAME and wildcard
  1665. // (with SHOULD NOT).
  1666. this->expected_rdatas_.clear();
  1667. this->expected_sig_rdatas_.clear();
  1668. doFindTest(*finder, Name("a.dnamewild.example.org."),
  1669. this->qtype_, this->qtype_, this->rrttl_,
  1670. ZoneFinder::WILDCARD_NXRRSET, this->expected_rdatas_,
  1671. this->expected_sig_rdatas_);
  1672. // Some strange things in the wild node
  1673. this->expected_rdatas_.clear();
  1674. this->expected_rdatas_.push_back("ns.example.com.");
  1675. doFindTest(*finder, isc::dns::Name("a.nswild.example.org."),
  1676. isc::dns::RRType::TXT(), isc::dns::RRType::NS(),
  1677. this->rrttl_, ZoneFinder::DELEGATION,
  1678. this->expected_rdatas_, this->expected_sig_rdatas_);
  1679. }
  1680. TYPED_TEST(DatabaseClientTest, noWildcard) {
  1681. // Tests with the NO_WILDCARD flag.
  1682. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1683. // This would match *.wild.example.org, but with NO_WILDCARD should
  1684. // result in NXDOMAIN.
  1685. this->expected_rdatas_.push_back("cancel.here.wild.example.org. A "
  1686. "NSEC RRSIG");
  1687. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  1688. "20000201000000 12345 example.org. "
  1689. "FAKEFAKEFAKE");
  1690. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  1691. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  1692. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  1693. this->expected_sig_rdatas_, Name("*.wild.example.org."),
  1694. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  1695. // Should be the same without FIND_DNSSEC (but in this case no RRsets
  1696. // will be returned)
  1697. doFindTest(*finder, isc::dns::Name("a.wild.example.org"),
  1698. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  1699. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  1700. this->empty_rdatas_, Name::ROOT_NAME(), // name is dummy
  1701. ZoneFinder::NO_WILDCARD);
  1702. // Same for wildcard empty non terminal.
  1703. this->expected_rdatas_.clear();
  1704. this->expected_rdatas_.push_back("brokenns1.example.org. A NSEC");
  1705. doFindTest(*finder, isc::dns::Name("a.bar.example.org"),
  1706. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  1707. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  1708. this->empty_rdatas_, Name("wild.*.foo.*.bar.example.org"),
  1709. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  1710. // Search for a wildcard name with NO_WILDCARD. There should be no
  1711. // difference. This is, for example, necessary to provide non existence
  1712. // of matching wildcard for isnx.nonterminal.example.org.
  1713. this->expected_rdatas_.clear();
  1714. this->expected_rdatas_.push_back("empty.nonterminal.example.org. NSEC");
  1715. doFindTest(*finder, isc::dns::Name("*.nonterminal.example.org"),
  1716. RRType::NSEC(), RRType::NSEC(), this->rrttl_,
  1717. ZoneFinder::NXDOMAIN, this->expected_rdatas_,
  1718. this->empty_rdatas_, Name("l.example.org"),
  1719. ZoneFinder::FIND_DNSSEC | ZoneFinder::NO_WILDCARD);
  1720. // On the other hand, if there's exact match for the wildcard name
  1721. // it should be found regardless of NO_WILDCARD.
  1722. this->expected_rdatas_.clear();
  1723. this->expected_rdatas_.push_back("192.0.2.5");
  1724. this->expected_sig_rdatas_.clear();
  1725. this->expected_sig_rdatas_.push_back("A 5 3 3600 20000101000000 "
  1726. "20000201000000 12345 example.org. "
  1727. "FAKEFAKEFAKE");
  1728. doFindTest(*finder, isc::dns::Name("*.wild.example.org"),
  1729. this->qtype_, this->qtype_, this->rrttl_,
  1730. ZoneFinder::SUCCESS, this->expected_rdatas_,
  1731. this->expected_sig_rdatas_, Name("*.wild.example.org"),
  1732. ZoneFinder::NO_WILDCARD);
  1733. }
  1734. TYPED_TEST(DatabaseClientTest, NXRRSET_NSEC) {
  1735. // The domain exists, but doesn't have this RRType
  1736. // So we should get its NSEC
  1737. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1738. this->expected_rdatas_.push_back("www2.example.org. A AAAA NSEC RRSIG");
  1739. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  1740. "20000201000000 12345 example.org. "
  1741. "FAKEFAKEFAKE");
  1742. doFindTest(*finder, isc::dns::Name("www.example.org."),
  1743. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  1744. this->rrttl_, ZoneFinder::NXRRSET,
  1745. this->expected_rdatas_, this->expected_sig_rdatas_,
  1746. Name::ROOT_NAME(), ZoneFinder::FIND_DNSSEC);
  1747. }
  1748. TYPED_TEST(DatabaseClientTest, wildcardNXRRSET_NSEC) {
  1749. // The domain exists, but doesn't have this RRType
  1750. // So we should get its NSEC
  1751. //
  1752. // The user will have to query us again to get the correct
  1753. // answer (eg. prove there's not an exact match)
  1754. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1755. this->expected_rdatas_.push_back("cancel.here.wild.example.org. A NSEC "
  1756. "RRSIG");
  1757. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  1758. "20000201000000 12345 example.org. "
  1759. "FAKEFAKEFAKE");
  1760. // Note that the NSEC name should NOT be synthesized.
  1761. doFindTest(*finder, isc::dns::Name("a.wild.example.org."),
  1762. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  1763. this->rrttl_, ZoneFinder::WILDCARD_NXRRSET,
  1764. this->expected_rdatas_, this->expected_sig_rdatas_,
  1765. Name("*.wild.example.org"), ZoneFinder::FIND_DNSSEC);
  1766. }
  1767. TYPED_TEST(DatabaseClientTest, NXDOMAIN_NSEC) {
  1768. // The domain doesn't exist, so we must get the right NSEC
  1769. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1770. this->expected_rdatas_.push_back("www2.example.org. A AAAA NSEC RRSIG");
  1771. this->expected_sig_rdatas_.push_back("NSEC 5 3 3600 20000101000000 "
  1772. "20000201000000 12345 example.org. "
  1773. "FAKEFAKEFAKE");
  1774. doFindTest(*finder, isc::dns::Name("www1.example.org."),
  1775. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  1776. this->rrttl_, ZoneFinder::NXDOMAIN,
  1777. this->expected_rdatas_, this->expected_sig_rdatas_,
  1778. Name("www.example.org."), ZoneFinder::FIND_DNSSEC);
  1779. this->expected_rdatas_.clear();
  1780. this->expected_rdatas_.push_back("acnamesig1.example.org. NS A NSEC RRSIG");
  1781. // This tests it works correctly in apex (there was a bug, where a check
  1782. // for NS-alone was there and it would throw).
  1783. doFindTest(*finder, isc::dns::Name("aa.example.org."),
  1784. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(),
  1785. this->rrttl_, ZoneFinder::NXDOMAIN,
  1786. this->expected_rdatas_, this->expected_sig_rdatas_,
  1787. Name("example.org."), ZoneFinder::FIND_DNSSEC);
  1788. // Check that if the DB doesn't support it, the exception from there
  1789. // is not propagated and it only does not include the NSEC
  1790. if (!this->is_mock_) {
  1791. return; // We don't make the real DB to throw
  1792. }
  1793. EXPECT_NO_THROW(doFindTest(*finder,
  1794. isc::dns::Name("notimplnsec.example.org."),
  1795. isc::dns::RRType::TXT(),
  1796. isc::dns::RRType::NSEC(), this->rrttl_,
  1797. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  1798. this->empty_rdatas_, Name::ROOT_NAME(),
  1799. ZoneFinder::FIND_DNSSEC));
  1800. }
  1801. TYPED_TEST(DatabaseClientTest, emptyNonterminalNSEC) {
  1802. // Same as NXDOMAIN_NSEC, but with empty non-terminal
  1803. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1804. this->expected_rdatas_.push_back("empty.nonterminal.example.org. NSEC");
  1805. doFindTest(*finder, isc::dns::Name("nonterminal.example.org."),
  1806. isc::dns::RRType::TXT(), isc::dns::RRType::NSEC(), this->rrttl_,
  1807. ZoneFinder::NXRRSET,
  1808. this->expected_rdatas_, this->expected_sig_rdatas_,
  1809. Name("l.example.org."), ZoneFinder::FIND_DNSSEC);
  1810. // Check that if the DB doesn't support it, the exception from there
  1811. // is not propagated and it only does not include the NSEC
  1812. if (!this->is_mock_) {
  1813. return; // We don't make the real DB to throw
  1814. }
  1815. EXPECT_NO_THROW(doFindTest(*finder,
  1816. isc::dns::Name("here.wild.example.org."),
  1817. isc::dns::RRType::TXT(),
  1818. isc::dns::RRType::NSEC(),
  1819. this->rrttl_, ZoneFinder::NXRRSET,
  1820. this->empty_rdatas_, this->empty_rdatas_,
  1821. Name::ROOT_NAME(), ZoneFinder::FIND_DNSSEC));
  1822. }
  1823. TYPED_TEST(DatabaseClientTest, getOrigin) {
  1824. DataSourceClient::FindResult
  1825. zone(this->client_->findZone(Name("example.org")));
  1826. ASSERT_EQ(result::SUCCESS, zone.code);
  1827. shared_ptr<DatabaseClient::Finder> finder(
  1828. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
  1829. if (this->is_mock_) {
  1830. EXPECT_EQ(READONLY_ZONE_ID, finder->zone_id());
  1831. }
  1832. EXPECT_EQ(this->zname_, finder->getOrigin());
  1833. }
  1834. TYPED_TEST(DatabaseClientTest, updaterFinder) {
  1835. this->updater_ = this->client_->getUpdater(this->zname_, false);
  1836. ASSERT_TRUE(this->updater_);
  1837. // If this update isn't replacing the zone, the finder should work
  1838. // just like the normal find() case.
  1839. if (this->is_mock_) {
  1840. DatabaseClient::Finder& finder = dynamic_cast<DatabaseClient::Finder&>(
  1841. this->updater_->getFinder());
  1842. EXPECT_EQ(WRITABLE_ZONE_ID, finder.zone_id());
  1843. }
  1844. this->expected_rdatas_.clear();
  1845. this->expected_rdatas_.push_back("192.0.2.1");
  1846. doFindTest(this->updater_->getFinder(), this->qname_,
  1847. this->qtype_, this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1848. this->expected_rdatas_, this->empty_rdatas_);
  1849. // When replacing the zone, the updater's finder shouldn't see anything
  1850. // in the zone until something is added.
  1851. this->updater_.reset();
  1852. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1853. ASSERT_TRUE(this->updater_);
  1854. if (this->is_mock_) {
  1855. DatabaseClient::Finder& finder = dynamic_cast<DatabaseClient::Finder&>(
  1856. this->updater_->getFinder());
  1857. EXPECT_EQ(WRITABLE_ZONE_ID, finder.zone_id());
  1858. }
  1859. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  1860. this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  1861. this->empty_rdatas_, this->empty_rdatas_);
  1862. }
  1863. TYPED_TEST(DatabaseClientTest, flushZone) {
  1864. // A simple update case: flush the entire zone
  1865. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1866. // Before update, the name exists.
  1867. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  1868. this->qtype_).code);
  1869. // start update in the replace mode. the normal finder should still
  1870. // be able to see the record, but the updater's finder shouldn't.
  1871. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1872. this->setUpdateAccessor();
  1873. EXPECT_EQ(ZoneFinder::SUCCESS,
  1874. finder->find(this->qname_, this->qtype_).code);
  1875. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  1876. this->updater_->getFinder().find(this->qname_,
  1877. this->qtype_).code);
  1878. // commit the update. now the normal finder shouldn't see it.
  1879. this->updater_->commit();
  1880. EXPECT_EQ(ZoneFinder::NXDOMAIN, finder->find(this->qname_,
  1881. this->qtype_).code);
  1882. // Check rollback wasn't accidentally performed.
  1883. EXPECT_FALSE(this->isRollbacked());
  1884. }
  1885. TYPED_TEST(DatabaseClientTest, updateCancel) {
  1886. // similar to the previous test, but destruct the updater before commit.
  1887. ZoneFinderPtr finder = this->client_->findZone(this->zname_).zone_finder;
  1888. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  1889. this->qtype_).code);
  1890. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1891. this->setUpdateAccessor();
  1892. EXPECT_EQ(ZoneFinder::NXDOMAIN,
  1893. this->updater_->getFinder().find(this->qname_,
  1894. this->qtype_).code);
  1895. // DB should not have been rolled back yet.
  1896. EXPECT_FALSE(this->isRollbacked());
  1897. this->updater_.reset(); // destruct without commit
  1898. // reset() should have triggered rollback (although it doesn't affect
  1899. // anything to the mock accessor implementation except for the result of
  1900. // isRollbacked())
  1901. EXPECT_TRUE(this->isRollbacked(true));
  1902. EXPECT_EQ(ZoneFinder::SUCCESS, finder->find(this->qname_,
  1903. this->qtype_).code);
  1904. }
  1905. TYPED_TEST(DatabaseClientTest, exceptionFromRollback) {
  1906. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1907. this->rrset_.reset(new RRset(Name("throw.example.org"), this->qclass_,
  1908. this->qtype_, this->rrttl_));
  1909. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  1910. this->rrset_->getClass(),
  1911. "192.0.2.1"));
  1912. this->updater_->addRRset(*this->rrset_);
  1913. // destruct without commit. The added name will result in an exception
  1914. // in the MockAccessor's rollback method. It shouldn't be propagated.
  1915. EXPECT_NO_THROW(this->updater_.reset());
  1916. }
  1917. TYPED_TEST(DatabaseClientTest, duplicateCommit) {
  1918. // duplicate commit. should result in exception.
  1919. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1920. this->updater_->commit();
  1921. EXPECT_THROW(this->updater_->commit(), DataSourceError);
  1922. }
  1923. TYPED_TEST(DatabaseClientTest, addRRsetToNewZone) {
  1924. // Add a single RRset to a fresh empty zone
  1925. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1926. this->updater_->addRRset(*this->rrset_);
  1927. this->expected_rdatas_.clear();
  1928. this->expected_rdatas_.push_back("192.0.2.2");
  1929. {
  1930. SCOPED_TRACE("add RRset");
  1931. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  1932. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1933. this->expected_rdatas_, this->empty_rdatas_);
  1934. }
  1935. // Similar to the previous case, but with RRSIG
  1936. this->updater_.reset();
  1937. this->updater_ = this->client_->getUpdater(this->zname_, true);
  1938. this->updater_->addRRset(*this->rrset_);
  1939. this->updater_->addRRset(*this->rrsigset_);
  1940. // confirm the expected columns were passed to the accessor (if checkable).
  1941. const char* const rrsig_added[] = {
  1942. "www.example.org.", "org.example.www.", "3600", "RRSIG", "A",
  1943. "A 5 3 0 20000101000000 20000201000000 0 example.org. FAKEFAKEFAKE"
  1944. };
  1945. this->checkLastAdded(rrsig_added);
  1946. this->expected_sig_rdatas_.clear();
  1947. this->expected_sig_rdatas_.push_back(
  1948. rrsig_added[DatabaseAccessor::ADD_RDATA]);
  1949. {
  1950. SCOPED_TRACE("add RRset with RRSIG");
  1951. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  1952. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1953. this->expected_rdatas_, this->expected_sig_rdatas_);
  1954. }
  1955. // Add the non RRSIG RRset again, to see the attempt of adding RRSIG
  1956. // causes any unexpected effect, in particular, whether the SIGTYPE
  1957. // field might remain.
  1958. this->updater_->addRRset(*this->rrset_);
  1959. const char* const rrset_added[] = {
  1960. "www.example.org.", "org.example.www.", "3600", "A", "", "192.0.2.2"
  1961. };
  1962. this->checkLastAdded(rrset_added);
  1963. }
  1964. TYPED_TEST(DatabaseClientTest, addRRsetToCurrentZone) {
  1965. // Similar to the previous test, but not replacing the existing data.
  1966. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  1967. this->updater_ = this->client_->getUpdater(this->zname_, false);
  1968. this->updater_->addRRset(*this->rrset_);
  1969. // We should see both old and new data.
  1970. this->expected_rdatas_.clear();
  1971. this->expected_rdatas_.push_back("192.0.2.1");
  1972. this->expected_rdatas_.push_back("192.0.2.2");
  1973. {
  1974. SCOPED_TRACE("add RRset");
  1975. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  1976. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  1977. this->expected_rdatas_, this->empty_rdatas_);
  1978. }
  1979. this->updater_->commit();
  1980. {
  1981. SCOPED_TRACE("add RRset after commit");
  1982. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  1983. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  1984. this->empty_rdatas_);
  1985. }
  1986. }
  1987. TYPED_TEST(DatabaseClientTest, addMultipleRRs) {
  1988. // Similar to the previous case, but the added RRset contains multiple
  1989. // RRs.
  1990. this->updater_ = this->client_->getUpdater(this->zname_, false);
  1991. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  1992. this->rrset_->getClass(),
  1993. "192.0.2.3"));
  1994. this->updater_->addRRset(*this->rrset_);
  1995. this->expected_rdatas_.clear();
  1996. this->expected_rdatas_.push_back("192.0.2.1");
  1997. this->expected_rdatas_.push_back("192.0.2.2");
  1998. this->expected_rdatas_.push_back("192.0.2.3");
  1999. {
  2000. SCOPED_TRACE("add multiple RRs");
  2001. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2002. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2003. this->expected_rdatas_, this->empty_rdatas_);
  2004. }
  2005. }
  2006. TYPED_TEST(DatabaseClientTest, addRRsetOfLargerTTL) {
  2007. // Similar to the previous one, but the TTL of the added RRset is larger
  2008. // than that of the existing record. The finder should use the smaller
  2009. // one.
  2010. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2011. this->rrset_->setTTL(RRTTL(7200));
  2012. this->updater_->addRRset(*this->rrset_);
  2013. this->expected_rdatas_.clear();
  2014. this->expected_rdatas_.push_back("192.0.2.1");
  2015. this->expected_rdatas_.push_back("192.0.2.2");
  2016. {
  2017. SCOPED_TRACE("add RRset of larger TTL");
  2018. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2019. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2020. this->expected_rdatas_, this->empty_rdatas_);
  2021. }
  2022. }
  2023. TYPED_TEST(DatabaseClientTest, addRRsetOfSmallerTTL) {
  2024. // Similar to the previous one, but the added RRset has a smaller TTL.
  2025. // The added TTL should be used by the finder.
  2026. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2027. this->rrset_->setTTL(RRTTL(1800));
  2028. this->updater_->addRRset(*this->rrset_);
  2029. this->expected_rdatas_.clear();
  2030. this->expected_rdatas_.push_back("192.0.2.1");
  2031. this->expected_rdatas_.push_back("192.0.2.2");
  2032. {
  2033. SCOPED_TRACE("add RRset of smaller TTL");
  2034. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2035. this->qtype_, RRTTL(1800), ZoneFinder::SUCCESS,
  2036. this->expected_rdatas_, this->empty_rdatas_);
  2037. }
  2038. }
  2039. TYPED_TEST(DatabaseClientTest, addSameRR) {
  2040. // Add the same RR as that is already in the data source.
  2041. // Currently the add interface doesn't try to suppress the duplicate,
  2042. // neither does the finder. We may want to revisit it in future versions.
  2043. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2044. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2045. this->rrttl_));
  2046. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2047. this->rrset_->getClass(),
  2048. "192.0.2.1"));
  2049. this->updater_->addRRset(*this->rrset_);
  2050. this->expected_rdatas_.clear();
  2051. this->expected_rdatas_.push_back("192.0.2.1");
  2052. this->expected_rdatas_.push_back("192.0.2.1");
  2053. {
  2054. SCOPED_TRACE("add same RR");
  2055. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2056. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2057. this->expected_rdatas_, this->empty_rdatas_);
  2058. }
  2059. }
  2060. TYPED_TEST(DatabaseClientTest, addDeviantRR) {
  2061. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2062. // RR class mismatch. This should be detected and rejected.
  2063. this->rrset_.reset(new RRset(this->qname_, RRClass::CH(), RRType::TXT(),
  2064. this->rrttl_));
  2065. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2066. this->rrset_->getClass(),
  2067. "test text"));
  2068. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2069. // Out-of-zone owner name. At a higher level this should be rejected,
  2070. // but it doesn't happen in this interface.
  2071. this->rrset_.reset(new RRset(Name("example.com"), this->qclass_,
  2072. this->qtype_, this->rrttl_));
  2073. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2074. this->rrset_->getClass(),
  2075. "192.0.2.100"));
  2076. this->updater_->addRRset(*this->rrset_);
  2077. this->expected_rdatas_.clear();
  2078. this->expected_rdatas_.push_back("192.0.2.100");
  2079. {
  2080. // Note: with the find() implementation being more strict about
  2081. // zone cuts, this test may fail. Then the test should be updated.
  2082. SCOPED_TRACE("add out-of-zone RR");
  2083. doFindTest(this->updater_->getFinder(), Name("example.com"),
  2084. this->qtype_, this->qtype_, this->rrttl_,
  2085. ZoneFinder::SUCCESS, this->expected_rdatas_,
  2086. this->empty_rdatas_);
  2087. }
  2088. }
  2089. TYPED_TEST(DatabaseClientTest, addEmptyRRset) {
  2090. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2091. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2092. this->rrttl_));
  2093. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2094. }
  2095. TYPED_TEST(DatabaseClientTest, addAfterCommit) {
  2096. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2097. this->updater_->commit();
  2098. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2099. }
  2100. TYPED_TEST(DatabaseClientTest, addRRsetWithRRSIG) {
  2101. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2102. this->rrset_->addRRsig(*this->rrsigset_);
  2103. EXPECT_THROW(this->updater_->addRRset(*this->rrset_), DataSourceError);
  2104. }
  2105. TYPED_TEST(DatabaseClientTest, deleteRRset) {
  2106. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2107. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2108. this->rrttl_));
  2109. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2110. this->rrset_->getClass(),
  2111. "192.0.2.1"));
  2112. // Delete one RR from an RRset
  2113. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2114. this->updater_->deleteRRset(*this->rrset_);
  2115. // Delete the only RR of a name
  2116. this->rrset_.reset(new RRset(Name("cname.example.org"), this->qclass_,
  2117. RRType::CNAME(), this->rrttl_));
  2118. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2119. this->rrset_->getClass(),
  2120. "www.example.org"));
  2121. this->updater_->deleteRRset(*this->rrset_);
  2122. // The this->updater_ finder should immediately see the deleted results.
  2123. {
  2124. SCOPED_TRACE("delete RRset");
  2125. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2126. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2127. this->empty_rdatas_, this->empty_rdatas_);
  2128. doFindTest(this->updater_->getFinder(), Name("cname.example.org"),
  2129. this->qtype_, this->qtype_, this->rrttl_,
  2130. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2131. this->empty_rdatas_);
  2132. }
  2133. // before committing the change, the original finder should see the
  2134. // original record.
  2135. {
  2136. SCOPED_TRACE("delete RRset before commit");
  2137. this->expected_rdatas_.push_back("192.0.2.1");
  2138. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  2139. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  2140. this->empty_rdatas_);
  2141. this->expected_rdatas_.clear();
  2142. this->expected_rdatas_.push_back("www.example.org.");
  2143. doFindTest(*finder, Name("cname.example.org"), this->qtype_,
  2144. RRType::CNAME(), this->rrttl_, ZoneFinder::CNAME,
  2145. this->expected_rdatas_, this->empty_rdatas_);
  2146. }
  2147. // once committed, the record should be removed from the original finder's
  2148. // view, too.
  2149. this->updater_->commit();
  2150. {
  2151. SCOPED_TRACE("delete RRset after commit");
  2152. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_,
  2153. this->rrttl_, ZoneFinder::NXRRSET, this->empty_rdatas_,
  2154. this->empty_rdatas_);
  2155. doFindTest(*finder, Name("cname.example.org"), this->qtype_,
  2156. this->qtype_, this->rrttl_, ZoneFinder::NXDOMAIN,
  2157. this->empty_rdatas_, this->empty_rdatas_);
  2158. }
  2159. }
  2160. TYPED_TEST(DatabaseClientTest, deleteRRsetToNXDOMAIN) {
  2161. // similar to the previous case, but it removes the only record of the
  2162. // given name. a subsequent find() should result in NXDOMAIN.
  2163. this->rrset_.reset(new RRset(Name("cname.example.org"), this->qclass_,
  2164. RRType::CNAME(), this->rrttl_));
  2165. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2166. this->rrset_->getClass(),
  2167. "www.example.org"));
  2168. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2169. this->updater_->deleteRRset(*this->rrset_);
  2170. {
  2171. SCOPED_TRACE("delete RRset to NXDOMAIN");
  2172. doFindTest(this->updater_->getFinder(), Name("cname.example.org"),
  2173. this->qtype_, this->qtype_, this->rrttl_,
  2174. ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2175. this->empty_rdatas_);
  2176. }
  2177. }
  2178. TYPED_TEST(DatabaseClientTest, deleteMultipleRRs) {
  2179. this->rrset_.reset(new RRset(this->qname_, this->qclass_, RRType::AAAA(),
  2180. this->rrttl_));
  2181. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2182. this->rrset_->getClass(),
  2183. "2001:db8::1"));
  2184. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2185. this->rrset_->getClass(),
  2186. "2001:db8::2"));
  2187. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2188. this->updater_->deleteRRset(*this->rrset_);
  2189. {
  2190. SCOPED_TRACE("delete multiple RRs");
  2191. doFindTest(this->updater_->getFinder(), this->qname_, RRType::AAAA(),
  2192. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2193. this->empty_rdatas_, this->empty_rdatas_);
  2194. }
  2195. }
  2196. TYPED_TEST(DatabaseClientTest, partialDelete) {
  2197. this->rrset_.reset(new RRset(this->qname_, this->qclass_, RRType::AAAA(),
  2198. this->rrttl_));
  2199. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2200. this->rrset_->getClass(),
  2201. "2001:db8::1"));
  2202. // This does not exist in the test data source:
  2203. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2204. this->rrset_->getClass(),
  2205. "2001:db8::3"));
  2206. // deleteRRset should succeed "silently", and subsequent find() should
  2207. // find the remaining RR.
  2208. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2209. this->updater_->deleteRRset(*this->rrset_);
  2210. {
  2211. SCOPED_TRACE("partial delete");
  2212. this->expected_rdatas_.push_back("2001:db8::2");
  2213. doFindTest(this->updater_->getFinder(), this->qname_, RRType::AAAA(),
  2214. RRType::AAAA(), this->rrttl_, ZoneFinder::SUCCESS,
  2215. this->expected_rdatas_, this->empty_rdatas_);
  2216. }
  2217. }
  2218. TYPED_TEST(DatabaseClientTest, deleteNoMatch) {
  2219. // similar to the previous test, but there's not even a match in the
  2220. // specified RRset. Essentially there's no difference in the result.
  2221. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2222. this->updater_->deleteRRset(*this->rrset_);
  2223. {
  2224. SCOPED_TRACE("delete no match");
  2225. this->expected_rdatas_.push_back("192.0.2.1");
  2226. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2227. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2228. this->expected_rdatas_, this->empty_rdatas_);
  2229. }
  2230. }
  2231. TYPED_TEST(DatabaseClientTest, deleteWithDifferentTTL) {
  2232. // Our delete interface simply ignores TTL (may change in a future version)
  2233. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2234. RRTTL(1800)));
  2235. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2236. this->rrset_->getClass(),
  2237. "192.0.2.1"));
  2238. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2239. this->updater_->deleteRRset(*this->rrset_);
  2240. {
  2241. SCOPED_TRACE("delete RRset with a different TTL");
  2242. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2243. this->qtype_, this->rrttl_, ZoneFinder::NXRRSET,
  2244. this->empty_rdatas_, this->empty_rdatas_);
  2245. }
  2246. }
  2247. TYPED_TEST(DatabaseClientTest, deleteDeviantRR) {
  2248. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2249. // RR class mismatch. This should be detected and rejected.
  2250. this->rrset_.reset(new RRset(this->qname_, RRClass::CH(), RRType::TXT(),
  2251. this->rrttl_));
  2252. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2253. this->rrset_->getClass(),
  2254. "test text"));
  2255. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  2256. // Out-of-zone owner name. At a higher level this should be rejected,
  2257. // but it doesn't happen in this interface.
  2258. this->rrset_.reset(new RRset(Name("example.com"), this->qclass_,
  2259. this->qtype_, this->rrttl_));
  2260. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2261. this->rrset_->getClass(),
  2262. "192.0.2.100"));
  2263. EXPECT_NO_THROW(this->updater_->deleteRRset(*this->rrset_));
  2264. }
  2265. TYPED_TEST(DatabaseClientTest, deleteAfterCommit) {
  2266. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2267. this->updater_->commit();
  2268. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  2269. }
  2270. TYPED_TEST(DatabaseClientTest, deleteEmptyRRset) {
  2271. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2272. this->rrset_.reset(new RRset(this->qname_, this->qclass_, this->qtype_,
  2273. this->rrttl_));
  2274. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  2275. }
  2276. TYPED_TEST(DatabaseClientTest, deleteRRsetWithRRSIG) {
  2277. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2278. this->rrset_->addRRsig(*this->rrsigset_);
  2279. EXPECT_THROW(this->updater_->deleteRRset(*this->rrset_), DataSourceError);
  2280. }
  2281. TYPED_TEST(DatabaseClientTest, compoundUpdate) {
  2282. // This test case performs an arbitrary chosen add/delete operations
  2283. // in a single update transaction. Essentially there is nothing new to
  2284. // test here, but there may be some bugs that was overlooked and can
  2285. // only happen in the compound update scenario, so we test it.
  2286. this->updater_ = this->client_->getUpdater(this->zname_, false);
  2287. // add a new RR to an existing RRset
  2288. this->updater_->addRRset(*this->rrset_);
  2289. this->expected_rdatas_.clear();
  2290. this->expected_rdatas_.push_back("192.0.2.1");
  2291. this->expected_rdatas_.push_back("192.0.2.2");
  2292. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2293. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2294. this->expected_rdatas_, this->empty_rdatas_);
  2295. // delete an existing RR
  2296. this->rrset_.reset(new RRset(Name("www.example.org"), this->qclass_,
  2297. this->qtype_, this->rrttl_));
  2298. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2299. this->rrset_->getClass(),
  2300. "192.0.2.1"));
  2301. this->updater_->deleteRRset(*this->rrset_);
  2302. this->expected_rdatas_.clear();
  2303. this->expected_rdatas_.push_back("192.0.2.2");
  2304. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2305. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2306. this->expected_rdatas_, this->empty_rdatas_);
  2307. // re-add it
  2308. this->updater_->addRRset(*this->rrset_);
  2309. this->expected_rdatas_.push_back("192.0.2.1");
  2310. doFindTest(this->updater_->getFinder(), this->qname_, this->qtype_,
  2311. this->qtype_, this->rrttl_, ZoneFinder::SUCCESS,
  2312. this->expected_rdatas_, this->empty_rdatas_);
  2313. // add a new RR with a new name
  2314. const Name newname("newname.example.org");
  2315. const RRType newtype(RRType::AAAA());
  2316. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  2317. this->rrttl_, ZoneFinder::NXDOMAIN, this->empty_rdatas_,
  2318. this->empty_rdatas_);
  2319. this->rrset_.reset(new RRset(newname, this->qclass_, newtype,
  2320. this->rrttl_));
  2321. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2322. this->rrset_->getClass(),
  2323. "2001:db8::10"));
  2324. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2325. this->rrset_->getClass(),
  2326. "2001:db8::11"));
  2327. this->updater_->addRRset(*this->rrset_);
  2328. this->expected_rdatas_.clear();
  2329. this->expected_rdatas_.push_back("2001:db8::10");
  2330. this->expected_rdatas_.push_back("2001:db8::11");
  2331. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  2332. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  2333. this->empty_rdatas_);
  2334. // delete one RR from the previous set
  2335. this->rrset_.reset(new RRset(newname, this->qclass_, newtype,
  2336. this->rrttl_));
  2337. this->rrset_->addRdata(rdata::createRdata(this->rrset_->getType(),
  2338. this->rrset_->getClass(),
  2339. "2001:db8::11"));
  2340. this->updater_->deleteRRset(*this->rrset_);
  2341. this->expected_rdatas_.clear();
  2342. this->expected_rdatas_.push_back("2001:db8::10");
  2343. doFindTest(this->updater_->getFinder(), newname, newtype, newtype,
  2344. this->rrttl_, ZoneFinder::SUCCESS, this->expected_rdatas_,
  2345. this->empty_rdatas_);
  2346. // Commit the changes, confirm the entire changes applied.
  2347. this->updater_->commit();
  2348. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2349. this->expected_rdatas_.clear();
  2350. this->expected_rdatas_.push_back("192.0.2.2");
  2351. this->expected_rdatas_.push_back("192.0.2.1");
  2352. doFindTest(*finder, this->qname_, this->qtype_, this->qtype_, this->rrttl_,
  2353. ZoneFinder::SUCCESS, this->expected_rdatas_,
  2354. this->empty_rdatas_);
  2355. this->expected_rdatas_.clear();
  2356. this->expected_rdatas_.push_back("2001:db8::10");
  2357. doFindTest(*finder, newname, newtype, newtype, this->rrttl_,
  2358. ZoneFinder::SUCCESS, this->expected_rdatas_,
  2359. this->empty_rdatas_);
  2360. }
  2361. TYPED_TEST(DatabaseClientTest, previous) {
  2362. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2363. EXPECT_EQ(Name("www.example.org."),
  2364. finder->findPreviousName(Name("www2.example.org.")));
  2365. // Check a name that doesn't exist there
  2366. EXPECT_EQ(Name("www.example.org."),
  2367. finder->findPreviousName(Name("www1.example.org.")));
  2368. if (this->is_mock_) { // We can't really force the DB to throw
  2369. // Check it doesn't crash or anything if the underlying DB throws
  2370. DataSourceClient::FindResult
  2371. zone(this->client_->findZone(Name("bad.example.org")));
  2372. finder =
  2373. dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder);
  2374. EXPECT_THROW(finder->findPreviousName(Name("bad.example.org")),
  2375. isc::NotImplemented);
  2376. } else {
  2377. // No need to test this on mock one, because we test only that
  2378. // the exception gets through
  2379. // A name before the origin
  2380. EXPECT_THROW(finder->findPreviousName(Name("example.com")),
  2381. isc::NotImplemented);
  2382. }
  2383. }
  2384. TYPED_TEST(DatabaseClientTest, invalidRdata) {
  2385. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2386. EXPECT_THROW(finder->find(Name("invalidrdata.example.org."), RRType::A()),
  2387. DataSourceError);
  2388. EXPECT_THROW(finder->find(Name("invalidrdata2.example.org."), RRType::A()),
  2389. DataSourceError);
  2390. }
  2391. TEST_F(MockDatabaseClientTest, missingNSEC) {
  2392. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2393. /*
  2394. * FIXME: For now, we can't really distinguish this bogus input
  2395. * from not-signed zone so we can't throw. But once we can,
  2396. * enable the original test.
  2397. */
  2398. #if 0
  2399. EXPECT_THROW(finder->find(Name("badnsec2.example.org."), RRType::A(), NULL,
  2400. ZoneFinder::FIND_DNSSEC),
  2401. DataSourceError);
  2402. #endif
  2403. doFindTest(*finder, Name("badnsec2.example.org."), RRType::A(),
  2404. RRType::A(), this->rrttl_, ZoneFinder::NXDOMAIN,
  2405. this->expected_rdatas_, this->expected_sig_rdatas_);
  2406. }
  2407. TEST_F(MockDatabaseClientTest, badName) {
  2408. shared_ptr<DatabaseClient::Finder> finder(this->getFinder());
  2409. EXPECT_THROW(finder->findPreviousName(Name("brokenname.example.org.")),
  2410. DataSourceError);
  2411. }
  2412. }