12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586 |
- // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #include <sstream>
- #include <vector>
- #include <boost/bind.hpp>
- #include <boost/foreach.hpp>
- #include <exceptions/exceptions.h>
- #include <dns/masterload.h>
- #include <dns/name.h>
- #include <dns/rdata.h>
- #include <dns/rdataclass.h>
- #include <dns/rrclass.h>
- #include <dns/rrsetlist.h>
- #include <dns/rrttl.h>
- #include <dns/masterload.h>
- #include <datasrc/memory_datasrc.h>
- #include <datasrc/data_source.h>
- #include <datasrc/iterator.h>
- #include <testutils/dnsmessage_test.h>
- #include <gtest/gtest.h>
- using namespace std;
- using namespace isc::dns;
- using namespace isc::dns::rdata;
- using namespace isc::datasrc;
- using namespace isc::testutils;
- namespace {
- // Commonly used result codes (Who should write the prefix all the time)
- using result::SUCCESS;
- using result::EXIST;
- class InMemoryClientTest : public ::testing::Test {
- protected:
- InMemoryClientTest() : rrclass(RRClass::IN())
- {}
- RRClass rrclass;
- InMemoryClient memory_client;
- };
- TEST_F(InMemoryClientTest, add_find_Zone) {
- // test add zone
- // Bogus zone (NULL)
- EXPECT_THROW(memory_client.addZone(ZoneFinderPtr()),
- isc::InvalidParameter);
- // add zones with different names one by one
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("a")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("b")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("c")))));
- // add zones with the same name suffix
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("x.d.e.f")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("o.w.y.d.e.f")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("p.w.y.d.e.f")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("q.w.y.d.e.f")))));
- // add super zone and its subzone
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("g.h")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("i.g.h")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("z.d.e.f")))));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("j.z.d.e.f")))));
- // different zone class isn't allowed.
- EXPECT_EQ(result::EXIST, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::CH(),
- Name("q.w.y.d.e.f")))));
- // names are compared in a case insensitive manner.
- EXPECT_EQ(result::EXIST, memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(RRClass::IN(),
- Name("Q.W.Y.d.E.f")))));
- // test find zone
- EXPECT_EQ(result::SUCCESS, memory_client.findZone(Name("a")).code);
- EXPECT_EQ(Name("a"),
- memory_client.findZone(Name("a")).zone_finder->getOrigin());
- EXPECT_EQ(result::SUCCESS,
- memory_client.findZone(Name("j.z.d.e.f")).code);
- EXPECT_EQ(Name("j.z.d.e.f"),
- memory_client.findZone(Name("j.z.d.e.f")).zone_finder->
- getOrigin());
- // NOTFOUND
- EXPECT_EQ(result::NOTFOUND, memory_client.findZone(Name("d.e.f")).code);
- EXPECT_EQ(ConstZoneFinderPtr(),
- memory_client.findZone(Name("d.e.f")).zone_finder);
- EXPECT_EQ(result::NOTFOUND,
- memory_client.findZone(Name("w.y.d.e.f")).code);
- EXPECT_EQ(ConstZoneFinderPtr(),
- memory_client.findZone(Name("w.y.d.e.f")).zone_finder);
- // there's no exact match. the result should be the longest match,
- // and the code should be PARTIALMATCH.
- EXPECT_EQ(result::PARTIALMATCH,
- memory_client.findZone(Name("j.g.h")).code);
- EXPECT_EQ(Name("g.h"),
- memory_client.findZone(Name("g.h")).zone_finder->getOrigin());
- EXPECT_EQ(result::PARTIALMATCH,
- memory_client.findZone(Name("z.i.g.h")).code);
- EXPECT_EQ(Name("i.g.h"),
- memory_client.findZone(Name("z.i.g.h")).zone_finder->
- getOrigin());
- }
- TEST_F(InMemoryClientTest, iterator) {
- // Just some preparations of data
- boost::shared_ptr<InMemoryZoneFinder>
- zone(new InMemoryZoneFinder(RRClass::IN(), Name("a")));
- RRsetPtr aRRsetA(new RRset(Name("a"), RRClass::IN(), RRType::A(),
- RRTTL(300)));
- aRRsetA->addRdata(rdata::in::A("192.0.2.1"));
- RRsetPtr aRRsetAAAA(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
- RRTTL(300)));
- aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::1"));
- aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::2"));
- RRsetPtr subRRsetA(new RRset(Name("sub.x.a"), RRClass::IN(), RRType::A(),
- RRTTL(300)));
- subRRsetA->addRdata(rdata::in::A("192.0.2.2"));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(zone));
- // First, the zone is not there, so it should throw
- EXPECT_THROW(memory_client.getIterator(Name("b")), DataSourceError);
- // This zone is not there either, even when there's a zone containing this
- EXPECT_THROW(memory_client.getIterator(Name("x.a")), DataSourceError);
- // Now, an empty zone
- ZoneIteratorPtr iterator(memory_client.getIterator(Name("a")));
- EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
- // It throws Unexpected when we are past the end
- EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
- EXPECT_EQ(result::SUCCESS, zone->add(aRRsetA));
- EXPECT_EQ(result::SUCCESS, zone->add(aRRsetAAAA));
- EXPECT_EQ(result::SUCCESS, zone->add(subRRsetA));
- // Check it with full zone, one by one.
- // It should be in ascending order in case of InMemory data source
- // (isn't guaranteed in general)
- iterator = memory_client.getIterator(Name("a"));
- EXPECT_EQ(aRRsetA, iterator->getNextRRset());
- EXPECT_EQ(aRRsetAAAA, iterator->getNextRRset());
- EXPECT_EQ(subRRsetA, iterator->getNextRRset());
- EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
- }
- TEST_F(InMemoryClientTest, iterator_separate_rrs) {
- // Exactly the same tests as for iterator, but now with separate_rrs = true
- // For the one that returns actual data, the AAAA should now be split up
- boost::shared_ptr<InMemoryZoneFinder>
- zone(new InMemoryZoneFinder(RRClass::IN(), Name("a")));
- RRsetPtr aRRsetA(new RRset(Name("a"), RRClass::IN(), RRType::A(),
- RRTTL(300)));
- aRRsetA->addRdata(rdata::in::A("192.0.2.1"));
- RRsetPtr aRRsetAAAA(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
- RRTTL(300)));
- aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::1"));
- aRRsetAAAA->addRdata(rdata::in::AAAA("2001:db8::2"));
- RRsetPtr aRRsetAAAA_r1(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
- RRTTL(300)));
- aRRsetAAAA_r1->addRdata(rdata::in::AAAA("2001:db8::1"));
- RRsetPtr aRRsetAAAA_r2(new RRset(Name("a"), RRClass::IN(), RRType::AAAA(),
- RRTTL(300)));
- aRRsetAAAA_r2->addRdata(rdata::in::AAAA("2001:db8::2"));
- RRsetPtr subRRsetA(new RRset(Name("sub.x.a"), RRClass::IN(), RRType::A(),
- RRTTL(300)));
- subRRsetA->addRdata(rdata::in::A("192.0.2.2"));
- EXPECT_EQ(result::SUCCESS, memory_client.addZone(zone));
- // First, the zone is not there, so it should throw
- EXPECT_THROW(memory_client.getIterator(Name("b"), true), DataSourceError);
- // This zone is not there either, even when there's a zone containing this
- EXPECT_THROW(memory_client.getIterator(Name("x.a")), DataSourceError);
- // Now, an empty zone
- ZoneIteratorPtr iterator(memory_client.getIterator(Name("a"), true));
- EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
- // It throws Unexpected when we are past the end
- EXPECT_THROW(iterator->getNextRRset(), isc::Unexpected);
- ASSERT_EQ(result::SUCCESS, zone->add(aRRsetA));
- ASSERT_EQ(result::SUCCESS, zone->add(aRRsetAAAA));
- ASSERT_EQ(result::SUCCESS, zone->add(subRRsetA));
- // Check it with full zone, one by one.
- // It should be in ascending order in case of InMemory data source
- // (isn't guaranteed in general)
- iterator = memory_client.getIterator(Name("a"), true);
- EXPECT_EQ(aRRsetA->toText(), iterator->getNextRRset()->toText());
- EXPECT_EQ(aRRsetAAAA_r1->toText(), iterator->getNextRRset()->toText());
- EXPECT_EQ(aRRsetAAAA_r2->toText(), iterator->getNextRRset()->toText());
- EXPECT_EQ(subRRsetA->toText(), iterator->getNextRRset()->toText());
- EXPECT_EQ(ConstRRsetPtr(), iterator->getNextRRset());
- }
- TEST_F(InMemoryClientTest, getZoneCount) {
- EXPECT_EQ(0, memory_client.getZoneCount());
- memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(rrclass,
- Name("example.com"))));
- EXPECT_EQ(1, memory_client.getZoneCount());
- // duplicate add. counter shouldn't change
- memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(rrclass,
- Name("example.com"))));
- EXPECT_EQ(1, memory_client.getZoneCount());
- // add one more
- memory_client.addZone(
- ZoneFinderPtr(new InMemoryZoneFinder(rrclass,
- Name("example.org"))));
- EXPECT_EQ(2, memory_client.getZoneCount());
- }
- TEST_F(InMemoryClientTest, startUpdateZone) {
- EXPECT_THROW(memory_client.getUpdater(Name("example.org"), false),
- isc::NotImplemented);
- }
- // Commonly used RRSIG data
- const char* const rrsig_a_txt =
- "example.org. 300 IN RRSIG A 5 3 3600 20000101000000 20000201000000 12345 "
- "example.org. FAKEFAKEFAKE\n";
- const char* const rrsig_ns_txt =
- "example.org. 300 IN RRSIG NS 5 3 3600 20000101000000 20000201000000 "
- "54321 example.org. FAKEFAKEFAKEFAKE\n";
- // This RRset has two RRSIGs
- const char* const rrsig_aaaa_txt =
- "ns.example.org. 300 IN RRSIG AAAA 5 3 3600 20000101000000 20000201000000 "
- "12345 example.org. FAKEFAKEFAKE\n"
- "ns.example.org. 300 IN RRSIG AAAA 5 3 3600 20000101000000 20000201000000 "
- "54321 example.org. FAKEFAKEFAKEFAKE\n";
- // A helper callback of masterLoad() used in InMemoryZoneFinderTest.
- void
- setRRset(RRsetPtr rrset, vector<RRsetPtr*>::iterator& it) {
- *(*it) = rrset;
- ++it;
- }
- /// \brief Test fixture for the InMemoryZoneFinder class
- class InMemoryZoneFinderTest : public ::testing::Test {
- // A straightforward pair of textual RR(set) and a RRsetPtr variable
- // to store the RRset. Used to build test data below.
- struct RRsetData {
- const char* const text; // textual representation of an RRset
- RRsetPtr* rrset;
- };
- public:
- InMemoryZoneFinderTest() :
- class_(RRClass::IN()),
- origin_("example.org"),
- zone_finder_(class_, origin_)
- {
- // Build test RRsets. Below, we construct an RRset for
- // each textual RR(s) of zone_data, and assign it to the corresponding
- // rr_xxx.
- const RRsetData zone_data[] = {
- {"example.org. 300 IN NS ns.example.org.", &rr_ns_},
- {"example.org. 300 IN A 192.0.2.1", &rr_a_},
- {"ns.example.org. 300 IN A 192.0.2.2", &rr_ns_a_},
- {"ns.example.org. 300 IN AAAA 2001:db8::2", &rr_ns_aaaa_},
- {"cname.example.org. 300 IN CNAME canonical.example.org",
- &rr_cname_},
- {"cname.example.org. 300 IN A 192.0.2.3", &rr_cname_a_},
- {"dname.example.org. 300 IN DNAME target.example.org.",
- &rr_dname_},
- {"dname.example.org. 300 IN A 192.0.2.39", &rr_dname_a_},
- {"dname.example.org. 300 IN NS ns.dname.example.org.",
- &rr_dname_ns_},
- {"example.org. 300 IN DNAME example.com.", &rr_dname_apex_},
- {"child.example.org. 300 IN NS ns.child.example.org.",
- &rr_child_ns_},
- {"child.example.org. 300 IN DS 12345 5 1 DEADBEEF",
- &rr_child_ds_},
- {"ns.child.example.org. 300 IN A 192.0.2.153",
- &rr_child_glue_},
- {"grand.child.example.org. 300 IN NS ns.grand.child.example.org.",
- &rr_grandchild_ns_},
- {"ns.grand.child.example.org. 300 IN AAAA 2001:db8::253",
- &rr_grandchild_glue_},
- {"dname.child.example.org. 300 IN DNAME example.com.",
- &rr_child_dname_},
- {"example.com. 300 IN A 192.0.2.10", &rr_out_},
- {"*.wild.example.org. 300 IN A 192.0.2.1", &rr_wild_},
- {"foo.wild.example.org. 300 IN A 192.0.2.3", &rr_under_wild_},
- {"wild.*.foo.example.org. 300 IN A 192.0.2.1", &rr_emptywild_},
- {"wild.*.foo.*.bar.example.org. 300 IN A 192.0.2.1",
- &rr_nested_emptywild_},
- {"*.nswild.example.org. 300 IN NS nswild.example.", &rr_nswild_},
- {"*.dnamewild.example.org. 300 IN DNAME dnamewild.example.",
- &rr_dnamewild_},
- {"*.child.example.org. 300 IN A 192.0.2.1", &rr_child_wild_},
- {"bar.foo.wild.example.org. 300 IN A 192.0.2.2", &rr_not_wild_},
- {"baz.foo.wild.example.org. 300 IN A 192.0.2.3",
- &rr_not_wild_another_},
- {NULL, NULL}
- };
- stringstream zone_data_stream;
- vector<RRsetPtr*> rrsets;
- for (unsigned int i = 0; zone_data[i].text != NULL; ++i) {
- zone_data_stream << zone_data[i].text << "\n";
- rrsets.push_back(zone_data[i].rrset);
- }
- masterLoad(zone_data_stream, Name::ROOT_NAME(), class_,
- boost::bind(setRRset, _1, rrsets.begin()));
- }
- // Some data to test with
- const RRClass class_;
- const Name origin_;
- // The zone finder to torture by tests
- InMemoryZoneFinder zone_finder_;
- // Placeholder for storing RRsets to be checked with rrsetsCheck()
- vector<ConstRRsetPtr> actual_rrsets_;
- /*
- * Some RRsets to put inside the zone.
- */
- RRsetPtr
- // Out of zone RRset
- rr_out_,
- // NS of example.org
- rr_ns_,
- // A of ns.example.org
- rr_ns_a_,
- // AAAA of ns.example.org
- rr_ns_aaaa_,
- // A of example.org
- rr_a_;
- RRsetPtr rr_cname_; // CNAME in example.org (RDATA will be added)
- RRsetPtr rr_cname_a_; // for mixed CNAME + A case
- RRsetPtr rr_dname_; // DNAME in example.org (RDATA will be added)
- RRsetPtr rr_dname_a_; // for mixed DNAME + A case
- RRsetPtr rr_dname_ns_; // for mixed DNAME + NS case
- RRsetPtr rr_dname_apex_; // for mixed DNAME + NS case in the apex
- RRsetPtr rr_child_ns_; // NS of a child domain (for delegation)
- RRsetPtr rr_child_ds_; // DS of a child domain (for delegation, auth data)
- RRsetPtr rr_child_glue_; // glue RR of the child domain
- RRsetPtr rr_grandchild_ns_; // NS below a zone cut (unusual)
- RRsetPtr rr_grandchild_glue_; // glue RR below a deeper zone cut
- RRsetPtr rr_child_dname_; // A DNAME under NS
- RRsetPtr rr_wild_;
- RRsetPtr rr_emptywild_;
- RRsetPtr rr_nested_emptywild_;
- RRsetPtr rr_nswild_, rr_dnamewild_;
- RRsetPtr rr_child_wild_;
- RRsetPtr rr_under_wild_;
- RRsetPtr rr_not_wild_;
- RRsetPtr rr_not_wild_another_;
- /**
- * \brief Test one find query to the zone finder.
- *
- * Asks a query to the zone finder and checks it does not throw and returns
- * expected results. It returns nothing, it just signals failures
- * to GTEST.
- *
- * \param name The name to ask for.
- * \param rrtype The RRType to ask of.
- * \param result The expected code of the result.
- * \param check_answer Should a check against equality of the answer be
- * done?
- * \param answer The expected rrset, if any should be returned.
- * \param zone_finder Check different InMemoryZoneFinder object than
- * zone_finder_ (if NULL, uses zone_finder_)
- * \param check_wild_answer Checks that the answer has the same RRs, type
- * class and TTL as the eqxpected answer and that the name corresponds
- * to the one searched. It is meant for checking answers for wildcard
- * queries.
- */
- void findTest(const Name& name, const RRType& rrtype,
- ZoneFinder::Result result,
- bool check_answer = true,
- const ConstRRsetPtr& answer = ConstRRsetPtr(),
- InMemoryZoneFinder* zone_finder = NULL,
- ZoneFinder::FindOptions options = ZoneFinder::FIND_DEFAULT,
- bool check_wild_answer = false)
- {
- if (zone_finder == NULL) {
- zone_finder = &zone_finder_;
- }
- // The whole block is inside, because we need to check the result and
- // we can't assign to FindResult
- EXPECT_NO_THROW({
- ZoneFinder::FindResult find_result(zone_finder->find(
- name, rrtype,
- options));
- // Check it returns correct answers
- EXPECT_EQ(result, find_result.code);
- if (check_answer) {
- EXPECT_EQ(answer, find_result.rrset);
- } else if (check_wild_answer) {
- ASSERT_NE(ConstRRsetPtr(), answer) <<
- "Wrong test, don't check for wild names if you expect "
- "empty answer";
- ASSERT_NE(ConstRRsetPtr(), find_result.rrset) <<
- "No answer found";
- RdataIteratorPtr expectedIt(answer->getRdataIterator());
- RdataIteratorPtr actualIt(
- find_result.rrset->getRdataIterator());
- while (!expectedIt->isLast() && !actualIt->isLast()) {
- EXPECT_EQ(0, expectedIt->getCurrent().compare(
- actualIt->getCurrent())) << "The RRs differ ('" <<
- expectedIt->getCurrent().toText() << "', '" <<
- actualIt->getCurrent().toText() << "')";
- expectedIt->next();
- actualIt->next();
- }
- EXPECT_TRUE(expectedIt->isLast()) <<
- "Result has less RRs than expected";
- EXPECT_TRUE(actualIt->isLast()) <<
- "Result has more RRs than expected";
- EXPECT_EQ(answer->getClass(),
- find_result.rrset->getClass());
- EXPECT_EQ(answer->getType(),
- find_result.rrset->getType());
- EXPECT_EQ(answer->getTTL(),
- find_result.rrset->getTTL());
- EXPECT_EQ(name, find_result.rrset->getName());
- }
- });
- }
- /**
- * \brief Calls the findAll on the finder and checks the result.
- */
- std::vector<ConstRRsetPtr> findAllTest(const Name& name,
- ZoneFinder::Result result,
- size_t expected_size,
- InMemoryZoneFinder* finder = NULL,
- const ConstRRsetPtr &rrset_result =
- ConstRRsetPtr(),
- ZoneFinder::FindOptions options =
- ZoneFinder::FIND_DEFAULT)
- {
- if (finder == NULL) {
- finder = &zone_finder_;
- }
- std::vector<ConstRRsetPtr> target;
- ZoneFinder::FindResult findResult(finder->findAll(name, target,
- options));
- EXPECT_EQ(result, findResult.code);
- EXPECT_EQ(rrset_result, findResult.rrset);
- BOOST_FOREACH(const ConstRRsetPtr& rrset, target) {
- EXPECT_EQ(name, rrset->getName());
- }
- EXPECT_EQ(expected_size, target.size());
- return (target);
- }
- // Internal part of the cancelWildcard test that is multiple times
- void doCancelWildcardTest();
- ConstRRsetPtr textToRRset(const string& text_rrset,
- const RRClass& rrclass = RRClass::IN()) const
- {
- stringstream ss(text_rrset);
- RRsetPtr rrset;
- vector<RRsetPtr*> rrsets;
- rrsets.push_back(&rrset);
- masterLoad(ss, Name::ROOT_NAME(), rrclass,
- boost::bind(setRRset, _1, rrsets.begin()));
- return (rrset);
- }
- };
- /**
- * \brief Check that findPreviousName throws as it should now.
- */
- TEST_F(InMemoryZoneFinderTest, findPreviousName) {
- EXPECT_THROW(zone_finder_.findPreviousName(Name("www.example.org")),
- isc::NotImplemented);
- }
- /**
- * \brief Test InMemoryZoneFinder::InMemoryZoneFinder constructor.
- *
- * Takes the created zone finder and checks its properties they are the same
- * as passed parameters.
- */
- TEST_F(InMemoryZoneFinderTest, constructor) {
- ASSERT_EQ(class_, zone_finder_.getClass());
- ASSERT_EQ(origin_, zone_finder_.getOrigin());
- }
- /**
- * \brief Test adding.
- *
- * We test that it throws at the correct moments and the correct exceptions.
- * And we test the return value.
- */
- TEST_F(InMemoryZoneFinderTest, add) {
- // This one does not belong to this zone
- EXPECT_THROW(zone_finder_.add(rr_out_), InMemoryZoneFinder::OutOfZone);
- // Test null pointer
- EXPECT_THROW(zone_finder_.add(ConstRRsetPtr()),
- InMemoryZoneFinder::NullRRset);
- // Now put all the data we have there. It should throw nothing
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_a_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_aaaa_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_a_)));
- // Try putting there something twice, it should be rejected
- EXPECT_NO_THROW(EXPECT_EQ(EXIST, zone_finder_.add(rr_ns_)));
- EXPECT_NO_THROW(EXPECT_EQ(EXIST, zone_finder_.add(rr_ns_a_)));
- }
- TEST_F(InMemoryZoneFinderTest, addMultipleCNAMEs) {
- rr_cname_->addRdata(generic::CNAME("canonical2.example.org."));
- EXPECT_THROW(zone_finder_.add(rr_cname_), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addCNAMEThenOther) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_cname_));
- EXPECT_THROW(zone_finder_.add(rr_cname_a_), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addOtherThenCNAME) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_cname_a_));
- EXPECT_THROW(zone_finder_.add(rr_cname_), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addCNAMEAndDNSSECRecords) {
- // CNAME and RRSIG can coexist
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_cname_));
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname.example.org. 300 IN RRSIG CNAME 5 3 "
- "3600 20000101000000 20000201000000 12345 "
- "example.org. FAKEFAKEFAKE")));
- // Same for NSEC
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname.example.org. 300 IN NSEC "
- "dname.example.org. CNAME RRSIG NSEC")));
- // Same as above, but adding NSEC first.
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname2.example.org. 300 IN NSEC "
- "dname.example.org. CNAME RRSIG NSEC")));
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname2.example.org. 300 IN CNAME c.example.")));
- // If there's another type of RRset with NSEC, it should still fail.
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname3.example.org. 300 IN A 192.0.2.1")));
- EXPECT_EQ(SUCCESS, zone_finder_.add(
- textToRRset("cname3.example.org. 300 IN NSEC "
- "dname.example.org. CNAME RRSIG NSEC")));
- EXPECT_THROW(zone_finder_.add(textToRRset("cname3.example.org. 300 "
- "IN CNAME c.example.")),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, findCNAME) {
- // install CNAME RR
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_cname_));
- // Find A RR of the same. Should match the CNAME
- findTest(rr_cname_->getName(), RRType::NS(), ZoneFinder::CNAME, true,
- rr_cname_);
- // Find the CNAME itself. Should result in normal SUCCESS
- findTest(rr_cname_->getName(), RRType::CNAME(), ZoneFinder::SUCCESS, true,
- rr_cname_);
- }
- TEST_F(InMemoryZoneFinderTest, findCNAMEUnderZoneCut) {
- // There's nothing special when we find a CNAME under a zone cut
- // (with FIND_GLUE_OK). The behavior is different from BIND 9,
- // so we test this case explicitly.
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_));
- ConstRRsetPtr rr_cname_under_cut_ = textToRRset(
- "cname.child.example.org. 300 IN CNAME target.child.example.org.");
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_cname_under_cut_));
- findTest(Name("cname.child.example.org"), RRType::AAAA(),
- ZoneFinder::CNAME, true, rr_cname_under_cut_, NULL,
- ZoneFinder::FIND_GLUE_OK);
- }
- // Two DNAMEs at single domain are disallowed by RFC 2672, section 3)
- // Having a CNAME there is disallowed too, but it is tested by
- // addOtherThenCNAME and addCNAMEThenOther.
- TEST_F(InMemoryZoneFinderTest, addMultipleDNAMEs) {
- rr_dname_->addRdata(generic::DNAME("target2.example.org."));
- EXPECT_THROW(zone_finder_.add(rr_dname_), InMemoryZoneFinder::AddError);
- }
- /*
- * These two tests ensure that we can't have DNAME and NS at the same
- * node with the exception of the apex of zone (forbidden by RFC 2672)
- */
- TEST_F(InMemoryZoneFinderTest, addDNAMEThenNS) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_)));
- EXPECT_THROW(zone_finder_.add(rr_dname_ns_), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addNSThenDNAME) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_ns_)));
- EXPECT_THROW(zone_finder_.add(rr_dname_), InMemoryZoneFinder::AddError);
- }
- // It is allowed to have NS and DNAME at apex
- TEST_F(InMemoryZoneFinderTest, DNAMEAndNSAtApex) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_apex_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- // The NS should be possible to be found, below should be DNAME, not
- // delegation
- findTest(origin_, RRType::NS(), ZoneFinder::SUCCESS, true, rr_ns_);
- findTest(rr_child_ns_->getName(), RRType::A(), ZoneFinder::DNAME, true,
- rr_dname_apex_);
- }
- TEST_F(InMemoryZoneFinderTest, NSAndDNAMEAtApex) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_apex_)));
- }
- // TODO: Test (and implement) adding data under DNAME. That is forbidden by
- // 2672 as well.
- // Search under a DNAME record. It should return the DNAME
- TEST_F(InMemoryZoneFinderTest, findBelowDNAME) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_)));
- findTest(Name("below.dname.example.org"), RRType::A(), ZoneFinder::DNAME,
- true, rr_dname_);
- }
- // Search at the domain with DNAME. It should act as DNAME isn't there, DNAME
- // influences only the data below (see RFC 2672, section 3)
- TEST_F(InMemoryZoneFinderTest, findAtDNAME) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_dname_a_)));
- const Name dname_name(rr_dname_->getName());
- findTest(dname_name, RRType::A(), ZoneFinder::SUCCESS, true, rr_dname_a_);
- findTest(dname_name, RRType::DNAME(), ZoneFinder::SUCCESS, true,
- rr_dname_);
- findTest(dname_name, RRType::TXT(), ZoneFinder::NXRRSET, true);
- }
- // Try searching something that is both under NS and DNAME, without and with
- // GLUE_OK mode (it should stop at the NS and DNAME respectively).
- TEST_F(InMemoryZoneFinderTest, DNAMEUnderNS) {
- zone_finder_.add(rr_child_ns_);
- zone_finder_.add(rr_child_dname_);
- Name lowName("below.dname.child.example.org.");
- findTest(lowName, RRType::A(), ZoneFinder::DELEGATION, true, rr_child_ns_);
- findTest(lowName, RRType::A(), ZoneFinder::DNAME, true, rr_child_dname_,
- NULL, ZoneFinder::FIND_GLUE_OK);
- }
- // Test adding child zones and zone cut handling
- TEST_F(InMemoryZoneFinderTest, delegationNS) {
- // add in-zone data
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- // install a zone cut
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_)));
- // below the zone cut
- findTest(Name("www.child.example.org"), RRType::A(),
- ZoneFinder::DELEGATION, true, rr_child_ns_);
- // at the zone cut
- findTest(Name("child.example.org"), RRType::A(), ZoneFinder::DELEGATION,
- true, rr_child_ns_);
- findTest(Name("child.example.org"), RRType::NS(), ZoneFinder::DELEGATION,
- true, rr_child_ns_);
- // finding NS for the apex (origin) node. This must not be confused
- // with delegation due to the existence of an NS RR.
- findTest(origin_, RRType::NS(), ZoneFinder::SUCCESS, true, rr_ns_);
- // unusual case of "nested delegation": the highest cut should be used.
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_grandchild_ns_)));
- findTest(Name("www.grand.child.example.org"), RRType::A(),
- // note: !rr_grandchild_ns_
- ZoneFinder::DELEGATION, true, rr_child_ns_);
- }
- TEST_F(InMemoryZoneFinderTest, delegationWithDS) {
- // Similar setup to the previous one, but with DS RR at the delegation
- // point.
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_));
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_));
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ds_));
- // Normal types of query should result in delegation, but DS query
- // should be considered in-zone.
- findTest(Name("child.example.org"), RRType::A(), ZoneFinder::DELEGATION,
- true, rr_child_ns_);
- findTest(Name("child.example.org"), RRType::DS(), ZoneFinder::SUCCESS,
- true, rr_child_ds_);
- // There's nothing special for DS query at the zone apex. It would
- // normally result in NXRRSET.
- findTest(Name("example.org"), RRType::DS(), ZoneFinder::NXRRSET,
- true, ConstRRsetPtr());
- }
- TEST_F(InMemoryZoneFinderTest, findAny) {
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_a_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_glue_)));
- // origin
- std::vector<ConstRRsetPtr> rrsets(findAllTest(origin_, ZoneFinder::SUCCESS,
- 2));
- EXPECT_FALSE(rrsets.end() == std::find(rrsets.begin(), rrsets.end(),
- rr_a_));
- EXPECT_FALSE(rrsets.end() == std::find(rrsets.begin(), rrsets.end(),
- rr_ns_));
- // out zone name
- findAllTest(Name("example.com"), ZoneFinder::NXDOMAIN, 0);
- rrsets = findAllTest(rr_child_glue_->getName(), ZoneFinder::SUCCESS, 1);
- EXPECT_FALSE(rrsets.end() == std::find(rrsets.begin(), rrsets.end(),
- rr_child_glue_));
- // TODO: test NXRRSET case after rbtree non-terminal logic has
- // been implemented
- // add zone cut
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_)));
- // zone cut
- findAllTest(rr_child_ns_->getName(), ZoneFinder::DELEGATION, 0, NULL,
- rr_child_ns_);
- // glue for this zone cut
- findAllTest(rr_child_glue_->getName(),ZoneFinder::DELEGATION, 0, NULL,
- rr_child_ns_);
- }
- TEST_F(InMemoryZoneFinderTest, glue) {
- // install zone data:
- // a zone cut
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_)));
- // glue for this cut
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_glue_)));
- // a nested zone cut (unusual)
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_grandchild_ns_)));
- // glue under the deeper zone cut
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_grandchild_glue_)));
- // by default glue is hidden due to the zone cut
- findTest(rr_child_glue_->getName(), RRType::A(), ZoneFinder::DELEGATION,
- true, rr_child_ns_);
- // If we do it in the "glue OK" mode, we should find the exact match.
- findTest(rr_child_glue_->getName(), RRType::A(), ZoneFinder::SUCCESS, true,
- rr_child_glue_, NULL, ZoneFinder::FIND_GLUE_OK);
- // glue OK + NXRRSET case
- findTest(rr_child_glue_->getName(), RRType::AAAA(), ZoneFinder::NXRRSET,
- true, ConstRRsetPtr(), NULL, ZoneFinder::FIND_GLUE_OK);
- // glue OK + NXDOMAIN case
- findTest(Name("www.child.example.org"), RRType::A(),
- ZoneFinder::DELEGATION, true, rr_child_ns_, NULL,
- ZoneFinder::FIND_GLUE_OK);
- // nested cut case. The glue should be found.
- findTest(rr_grandchild_glue_->getName(), RRType::AAAA(),
- ZoneFinder::SUCCESS,
- true, rr_grandchild_glue_, NULL, ZoneFinder::FIND_GLUE_OK);
- // A non-existent name in nested cut. This should result in delegation
- // at the highest zone cut.
- findTest(Name("www.grand.child.example.org"), RRType::TXT(),
- ZoneFinder::DELEGATION, true, rr_child_ns_, NULL,
- ZoneFinder::FIND_GLUE_OK);
- }
- /**
- * \brief Test searching.
- *
- * Check it finds or does not find correctly and does not throw exceptions.
- * \todo This doesn't do any kind of CNAME and so on. If it isn't
- * directly there, it just tells it doesn't exist.
- */
- TEST_F(InMemoryZoneFinderTest, find) {
- // Fill some data inside
- // Now put all the data we have there. It should throw nothing
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_a_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_ns_aaaa_)));
- EXPECT_NO_THROW(EXPECT_EQ(SUCCESS, zone_finder_.add(rr_a_)));
- // These two should be successful
- findTest(origin_, RRType::NS(), ZoneFinder::SUCCESS, true, rr_ns_);
- findTest(rr_ns_a_->getName(), RRType::A(), ZoneFinder::SUCCESS, true,
- rr_ns_a_);
- // These domain exist but don't have the provided RRType
- findTest(origin_, RRType::AAAA(), ZoneFinder::NXRRSET);
- findTest(rr_ns_a_->getName(), RRType::NS(), ZoneFinder::NXRRSET);
- // These domains don't exist (and one is out of the zone)
- findTest(Name("nothere.example.org"), RRType::A(), ZoneFinder::NXDOMAIN);
- findTest(Name("example.net"), RRType::A(), ZoneFinder::NXDOMAIN);
- }
- TEST_F(InMemoryZoneFinderTest, emptyNode) {
- /*
- * The backend RBTree for this test should look like as follows:
- * example.org
- * |
- * baz (empty; easy case)
- * / | \
- * bar | x.foo ('foo' part is empty; a bit trickier)
- * bbb
- * /
- * aaa
- */
- // Construct the test zone
- const char* const names[] = {
- "bar.example.org.", "x.foo.example.org.", "aaa.baz.example.org.",
- "bbb.baz.example.org.", NULL};
- for (int i = 0; names[i] != NULL; ++i) {
- ConstRRsetPtr rrset = textToRRset(string(names[i]) +
- " 300 IN A 192.0.2.1");
- EXPECT_EQ(SUCCESS, zone_finder_.add(rrset));
- }
- // empty node matching, easy case: the node for 'baz' exists with
- // no data.
- findTest(Name("baz.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- // empty node matching, a trickier case: the node for 'foo' is part of
- // "x.foo", which should be considered an empty node.
- findTest(Name("foo.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- // "org" is contained in "example.org", but it shouldn't be treated as
- // NXRRSET because it's out of zone.
- // Note: basically we don't expect such a query to be performed (the common
- // operation is to identify the best matching zone first then perform
- // search it), but we shouldn't be confused even in the unexpected case.
- findTest(Name("org"), RRType::A(), ZoneFinder::NXDOMAIN);
- }
- TEST_F(InMemoryZoneFinderTest, load) {
- // Put some data inside the zone
- EXPECT_NO_THROW(EXPECT_EQ(result::SUCCESS, zone_finder_.add(rr_ns_)));
- // Loading with different origin should fail
- EXPECT_THROW(zone_finder_.load(TEST_DATA_DIR "/root.zone"),
- MasterLoadError);
- // See the original data is still there, survived the exception
- findTest(origin_, RRType::NS(), ZoneFinder::SUCCESS, true, rr_ns_);
- // Create correct zone
- InMemoryZoneFinder rootzone(class_, Name("."));
- // Try putting something inside
- EXPECT_NO_THROW(EXPECT_EQ(result::SUCCESS, rootzone.add(rr_ns_aaaa_)));
- // Load the zone. It should overwrite/remove the above RRset
- EXPECT_NO_THROW(rootzone.load(TEST_DATA_DIR "/root.zone"));
- // Now see there are some rrsets (we don't look inside, though)
- findTest(Name("."), RRType::SOA(), ZoneFinder::SUCCESS, false,
- ConstRRsetPtr(), &rootzone);
- findTest(Name("."), RRType::NS(), ZoneFinder::SUCCESS, false,
- ConstRRsetPtr(), &rootzone);
- findTest(Name("a.root-servers.net."), RRType::A(), ZoneFinder::SUCCESS,
- false, ConstRRsetPtr(), &rootzone);
- // But this should no longer be here
- findTest(rr_ns_a_->getName(), RRType::AAAA(), ZoneFinder::NXDOMAIN, true,
- ConstRRsetPtr(), &rootzone);
- // Try loading zone that is wrong in a different way
- EXPECT_THROW(zone_finder_.load(TEST_DATA_DIR "/duplicate_rrset.zone"),
- MasterLoadError);
- }
- /*
- * Test that puts a (simple) wildcard into the zone and checks we can
- * correctly find the data.
- */
- TEST_F(InMemoryZoneFinderTest, wildcard) {
- /*
- * example.org.
- * |
- * wild (not *.wild, should have wild mark)
- * |
- * *
- */
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_wild_));
- // Search at the parent. The parent will not have the A, but it will
- // be in the wildcard (so check the wildcard isn't matched at the parent)
- {
- SCOPED_TRACE("Search at parrent");
- findTest(Name("wild.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- }
- // Search the original name of wildcard
- {
- SCOPED_TRACE("Search directly at *");
- findTest(Name("*.wild.example.org"), RRType::A(), ZoneFinder::SUCCESS,
- true, rr_wild_);
- }
- // Search "created" name.
- {
- SCOPED_TRACE("Search at created child");
- findTest(Name("a.wild.example.org"), RRType::A(), ZoneFinder::SUCCESS,
- false, rr_wild_, NULL, ZoneFinder::FIND_DEFAULT, true);
- }
- // Search another created name, this time little bit lower
- {
- SCOPED_TRACE("Search at created grand-child");
- findTest(Name("a.b.wild.example.org"), RRType::A(),
- ZoneFinder::SUCCESS, false, rr_wild_, NULL,
- ZoneFinder::FIND_DEFAULT, true);
- }
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_under_wild_));
- {
- SCOPED_TRACE("Search under non-wildcard");
- findTest(Name("bar.foo.wild.example.org"), RRType::A(),
- ZoneFinder::NXDOMAIN);
- }
- }
- /*
- * Test that we don't match a wildcard if we get under delegation.
- * By 4.3.3 of RFC1034:
- * "Wildcard RRs do not apply:
- * - When the query is in another zone. That is, delegation cancels
- * the wildcard defaults."
- */
- TEST_F(InMemoryZoneFinderTest, delegatedWildcard) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_wild_));
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_child_ns_));
- {
- SCOPED_TRACE("Looking under delegation point");
- findTest(Name("a.child.example.org"), RRType::A(),
- ZoneFinder::DELEGATION, true, rr_child_ns_);
- }
- {
- SCOPED_TRACE("Looking under delegation point in GLUE_OK mode");
- findTest(Name("a.child.example.org"), RRType::A(),
- ZoneFinder::DELEGATION, true, rr_child_ns_, NULL,
- ZoneFinder::FIND_GLUE_OK);
- }
- }
- // Tests combination of wildcard and ANY.
- TEST_F(InMemoryZoneFinderTest, anyWildcard) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_wild_));
- // First try directly the name (normal match)
- {
- SCOPED_TRACE("Asking direcly for *");
- const std::vector<ConstRRsetPtr>
- target(findAllTest(Name("*.wild.example.org"), ZoneFinder::SUCCESS,
- 1));
- ASSERT_EQ(1, target.size());
- EXPECT_EQ(RRType::A(), (*target.begin())->getType());
- EXPECT_EQ(Name("*.wild.example.org"), (*target.begin())->getName());
- }
- // Then a wildcard match
- {
- SCOPED_TRACE("Asking in the wild way");
- const std::vector<ConstRRsetPtr>
- target(findAllTest(Name("a.wild.example.org"), ZoneFinder::SUCCESS,
- 1));
- EXPECT_EQ(RRType::A(), (*target.begin())->getType());
- EXPECT_EQ(Name("a.wild.example.org"), (*target.begin())->getName());
- }
- }
- // Test there's nothing in the wildcard in the middle if we load
- // wild.*.foo.example.org.
- TEST_F(InMemoryZoneFinderTest, emptyWildcard) {
- /*
- * example.org.
- * foo
- * *
- * wild
- */
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_emptywild_));
- {
- SCOPED_TRACE("Asking for the original record under wildcard");
- findTest(Name("wild.*.foo.example.org"), RRType::A(),
- ZoneFinder::SUCCESS, true, rr_emptywild_);
- }
- {
- SCOPED_TRACE("Asking for A record");
- findTest(Name("a.foo.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- findTest(Name("*.foo.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- findTest(Name("foo.example.org"), RRType::A(), ZoneFinder::NXRRSET);
- }
- {
- SCOPED_TRACE("Asking for ANY record");
- findAllTest(Name("*.foo.example.org"), ZoneFinder::NXRRSET, 0);
- findAllTest(Name("a.foo.example.org"), ZoneFinder::NXRRSET, 0);
- }
- {
- SCOPED_TRACE("Asking on the non-terminal");
- findTest(Name("wild.bar.foo.example.org"), RRType::A(),
- ZoneFinder::NXRRSET);
- }
- }
- // Same as emptyWildcard, but with multiple * in the path.
- TEST_F(InMemoryZoneFinderTest, nestedEmptyWildcard) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_nested_emptywild_));
- {
- SCOPED_TRACE("Asking for the original record under wildcards");
- findTest(Name("wild.*.foo.*.bar.example.org"), RRType::A(),
- ZoneFinder::SUCCESS, true, rr_nested_emptywild_);
- }
- {
- SCOPED_TRACE("Matching wildcard against empty nonterminal");
- const char* names[] = {
- "baz.foo.*.bar.example.org",
- "baz.foo.baz.bar.example.org",
- "*.foo.baz.bar.example.org",
- NULL
- };
- for (const char** name = names; *name != NULL; ++ name) {
- SCOPED_TRACE(string("Node ") + *name);
- findTest(Name(*name), RRType::A(), ZoneFinder::NXRRSET);
- }
- }
- // Domains to test
- const char* names[] = {
- "*.foo.*.bar.example.org",
- "foo.*.bar.example.org",
- "*.bar.example.org",
- "bar.example.org",
- NULL
- };
- {
- SCOPED_TRACE("Asking directly for A on parent nodes");
- for (const char** name = names; *name != NULL; ++ name) {
- SCOPED_TRACE(string("Node ") + *name);
- findTest(Name(*name), RRType::A(), ZoneFinder::NXRRSET);
- }
- }
- {
- SCOPED_TRACE("Asking for ANY on parent nodes");
- for (const char** name = names; *name != NULL; ++ name) {
- SCOPED_TRACE(string("Node ") + *name);
- findAllTest(Name(*name), ZoneFinder::NXRRSET, 0);
- }
- }
- }
- // We run this part twice from the below test, in two slightly different
- // situations
- void
- InMemoryZoneFinderTest::doCancelWildcardTest() {
- // These should be canceled
- {
- SCOPED_TRACE("Canceled under foo.wild.example.org");
- findTest(Name("aaa.foo.wild.example.org"), RRType::A(),
- ZoneFinder::NXDOMAIN);
- findTest(Name("zzz.foo.wild.example.org"), RRType::A(),
- ZoneFinder::NXDOMAIN);
- }
- // This is existing, non-wildcard domain, shouldn't wildcard at all
- {
- SCOPED_TRACE("Existing domain under foo.wild.example.org");
- findTest(Name("bar.foo.wild.example.org"), RRType::A(),
- ZoneFinder::SUCCESS, true, rr_not_wild_);
- }
- // These should be caught by the wildcard
- {
- SCOPED_TRACE("Neighbor wildcards to foo.wild.example.org");
- const char* names[] = {
- "aaa.bbb.wild.example.org",
- "aaa.zzz.wild.example.org",
- "zzz.wild.example.org",
- NULL
- };
- for (const char** name = names; *name != NULL; ++ name) {
- SCOPED_TRACE(string("Node ") + *name);
- findTest(Name(*name), RRType::A(), ZoneFinder::SUCCESS, false,
- rr_wild_, NULL, ZoneFinder::FIND_DEFAULT, true);
- }
- }
- // This shouldn't be wildcarded, it's an existing domain
- {
- SCOPED_TRACE("The foo.wild.example.org itself");
- findTest(Name("foo.wild.example.org"), RRType::A(),
- ZoneFinder::NXRRSET);
- }
- }
- /*
- * This tests that if there's a name between the wildcard domain and the
- * searched one, it will not trigger wildcard, for example, if we have
- * *.wild.example.org and bar.foo.wild.example.org, then we know
- * foo.wild.example.org exists and is not wildcard. Therefore, search for
- * aaa.foo.wild.example.org should return NXDOMAIN.
- *
- * Tests few cases "around" the canceled wildcard match, to see something that
- * shouldn't be canceled isn't.
- */
- TEST_F(InMemoryZoneFinderTest, cancelWildcard) {
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_wild_));
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_not_wild_));
- {
- SCOPED_TRACE("Runnig with single entry under foo.wild.example.org");
- doCancelWildcardTest();
- }
- // Try putting another one under foo.wild....
- // The result should be the same but it will be done in another way in the
- // code, because the foo.wild.example.org will exist in the tree.
- EXPECT_EQ(SUCCESS, zone_finder_.add(rr_not_wild_another_));
- {
- SCOPED_TRACE("Runnig with two entries under foo.wild.example.org");
- doCancelWildcardTest();
- }
- }
- TEST_F(InMemoryZoneFinderTest, loadBadWildcard) {
- // We reject loading the zone if it contains a wildcard name for
- // NS or DNAME.
- EXPECT_THROW(zone_finder_.add(rr_nswild_), InMemoryZoneFinder::AddError);
- EXPECT_THROW(zone_finder_.add(rr_dnamewild_),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, swap) {
- // build one zone finder with some data
- InMemoryZoneFinder finder1(class_, origin_);
- EXPECT_EQ(result::SUCCESS, finder1.add(rr_ns_));
- EXPECT_EQ(result::SUCCESS, finder1.add(rr_ns_aaaa_));
- // build another zone finder of a different RR class with some other data
- const Name other_origin("version.bind");
- ASSERT_NE(origin_, other_origin); // make sure these two are different
- InMemoryZoneFinder finder2(RRClass::CH(), other_origin);
- EXPECT_EQ(result::SUCCESS,
- finder2.add(textToRRset("version.bind. 0 CH TXT \"test\"",
- RRClass::CH())));
- finder1.swap(finder2);
- EXPECT_EQ(other_origin, finder1.getOrigin());
- EXPECT_EQ(origin_, finder2.getOrigin());
- EXPECT_EQ(RRClass::CH(), finder1.getClass());
- EXPECT_EQ(RRClass::IN(), finder2.getClass());
- // make sure the zone data is swapped, too
- findTest(origin_, RRType::NS(), ZoneFinder::NXDOMAIN, false,
- ConstRRsetPtr(), &finder1);
- findTest(other_origin, RRType::TXT(), ZoneFinder::SUCCESS, false,
- ConstRRsetPtr(), &finder1);
- findTest(origin_, RRType::NS(), ZoneFinder::SUCCESS, false,
- ConstRRsetPtr(), &finder2);
- findTest(other_origin, RRType::TXT(), ZoneFinder::NXDOMAIN, false,
- ConstRRsetPtr(), &finder2);
- }
- TEST_F(InMemoryZoneFinderTest, getFileName) {
- // for an empty zone the file name should also be empty.
- EXPECT_TRUE(zone_finder_.getFileName().empty());
- // if loading a zone fails the file name shouldn't be set.
- EXPECT_THROW(zone_finder_.load(TEST_DATA_DIR "/root.zone"),
- MasterLoadError);
- EXPECT_TRUE(zone_finder_.getFileName().empty());
- // after a successful load, the specified file name should be set
- InMemoryZoneFinder rootzone(class_, Name("."));
- EXPECT_NO_THROW(rootzone.load(TEST_DATA_DIR "/root.zone"));
- EXPECT_EQ(TEST_DATA_DIR "/root.zone", rootzone.getFileName());
- // overriding load, which will fail
- EXPECT_THROW(rootzone.load(TEST_DATA_DIR "/duplicate_rrset.zone"),
- MasterLoadError);
- // the file name should be intact.
- EXPECT_EQ(TEST_DATA_DIR "/root.zone", rootzone.getFileName());
- // After swap, file names should also be swapped.
- zone_finder_.swap(rootzone);
- EXPECT_EQ(TEST_DATA_DIR "/root.zone", zone_finder_.getFileName());
- EXPECT_TRUE(rootzone.getFileName().empty());
- }
- TEST_F(InMemoryZoneFinderTest, addRRsig) {
- // A simple valid case: adding an RRset to be signed followed by an RRSIG
- // that covers the first RRset
- zone_finder_.add(rr_a_);
- zone_finder_.add(textToRRset(rrsig_a_txt));
- ZoneFinder::FindResult result = zone_finder_.find(origin_, RRType::A(),
- ZoneFinder::FIND_DNSSEC);
- EXPECT_EQ(ZoneFinder::SUCCESS, result.code);
- ASSERT_TRUE(result.rrset);
- ASSERT_TRUE(result.rrset->getRRsig());
- actual_rrsets_.push_back(result.rrset->getRRsig());
- rrsetsCheck(rrsig_a_txt, actual_rrsets_.begin(), actual_rrsets_.end());
- // Confirm a separate RRISG for a different type can be added
- actual_rrsets_.clear();
- zone_finder_.add(rr_ns_);
- zone_finder_.add(textToRRset(rrsig_ns_txt));
- ZoneFinder::FindResult result2 =
- zone_finder_.find(origin_, RRType::NS(), ZoneFinder::FIND_DNSSEC);
- EXPECT_EQ(ZoneFinder::SUCCESS, result2.code);
- ASSERT_TRUE(result2.rrset);
- ASSERT_TRUE(result2.rrset->getRRsig());
- actual_rrsets_.push_back(result2.rrset->getRRsig());
- rrsetsCheck(rrsig_ns_txt, actual_rrsets_.begin(), actual_rrsets_.end());
- // Check a case with multiple RRSIGs
- actual_rrsets_.clear();
- zone_finder_.add(rr_ns_aaaa_);
- zone_finder_.add(textToRRset(rrsig_aaaa_txt));
- ZoneFinder::FindResult result3 =
- zone_finder_.find(Name("ns.example.org"), RRType::AAAA(),
- ZoneFinder::FIND_DNSSEC);
- EXPECT_EQ(ZoneFinder::SUCCESS, result3.code);
- ASSERT_TRUE(result3.rrset);
- ASSERT_TRUE(result3.rrset->getRRsig());
- actual_rrsets_.push_back(result3.rrset->getRRsig());
- rrsetsCheck(rrsig_aaaa_txt, actual_rrsets_.begin(), actual_rrsets_.end());
- }
- TEST_F(InMemoryZoneFinderTest, addRRsigWithoutCovered) {
- // The current implementation rejects attempts of adding RRSIG without
- // covered RRsets already in the zone.
- // Name doesn't exist
- EXPECT_THROW(zone_finder_.add(
- textToRRset("notexist.example.org. 300 IN RRSIG A 5 3 "
- "3600 20000101000000 20000201000000 12345 "
- "example.org. FAKEFAKEFAKE\n")),
- InMemoryZoneFinder::AddError);
- // Name exists, but is empty.
- zone_finder_.add(rr_emptywild_);
- EXPECT_THROW(zone_finder_.add(
- textToRRset("foo.example.org. 300 IN RRSIG A 5 3 "
- "3600 20000101000000 20000201000000 12345 "
- "example.org. FAKEFAKEFAKE\n")),
- InMemoryZoneFinder::AddError);
- // Add RRSIG RRset without covered RR
- zone_finder_.add(rr_a_);
- EXPECT_THROW(zone_finder_.add(textToRRset(rrsig_ns_txt)),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addbadRRsig) {
- // Tests with other types of bogus input
- // Empty RRSIG RRset.
- EXPECT_THROW(zone_finder_.add(RRsetPtr(new RRset(origin_, class_,
- RRType::RRSIG(),
- RRTTL(300)))),
- InMemoryZoneFinder::AddError);
- // RRSIG with mixed covered types
- zone_finder_.add(rr_a_); // make sure the covered name exists
- // textToRRset() doesn't work as intended for this pathological case,
- // so we need to construct the RRset by hand.
- RRsetPtr rrset(new RRset(origin_, class_, RRType::RRSIG(), RRTTL(300)));
- rrset->addRdata(generic::RRSIG("A 5 3 3600 20000101000000 20000201000000 "
- "12345 example.org. FAKEFAKEFAKE"));
- rrset->addRdata(generic::RRSIG("NS 5 3 3600 20000101000000 20000201000000 "
- "54321 example.org. FAKEFAKEFAKEFAKE"));
- EXPECT_THROW(zone_finder_.add(rrset), InMemoryZoneFinder::AddError);
- // An attempt of overriding an existing RRSIG. The current implementation
- // prohibits that.
- zone_finder_.add(textToRRset(rrsig_a_txt));
- EXPECT_THROW(zone_finder_.add(textToRRset(rrsig_a_txt)),
- InMemoryZoneFinder::AddError);
- }
- //
- // (Faked) NSEC3 hash data. Arbitrarily borrowed from RFC515 examples.
- //
- // Commonly used NSEC3 suffix. It's incorrect to use it for all NSEC3s, but
- // doesn't matter for the purpose of our tests.
- const char* const nsec3_common = " 300 IN NSEC3 1 1 12 aabbccdd "
- "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG";
- // Likewise, common RRSIG suffix for NSEC3s.
- const char* const nsec3_rrsig_common = " 300 IN RRSIG NSEC3 5 3 3600 "
- "20000101000000 20000201000000 12345 example.org. FAKEFAKEFAKE";
- // For apex (example.org)
- const char* const apex_hash = "0P9MHAVEQVM6T7VBL5LOP2U3T2RP3TOM";
- const char* const apex_hash_lower = "0p9mhaveqvm6t7vbl5lop2u3t2rp3tom";
- // For ns1.example.org
- const char* const ns1_hash = "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR";
- // For x.y.w.example.org (lower-cased)
- const char* const xrw_hash = "2vptu5timamqttgl4luu9kg21e0aor3s";
- void
- nsec3Check(bool expected_matched, const string& expected_rrsets_txt,
- const ZoneFinder::FindNSEC3Result& result,
- bool expected_sig = false)
- {
- vector<ConstRRsetPtr> actual_rrsets;
- EXPECT_EQ(expected_matched, result.matched);
- ASSERT_TRUE(result.closest_proof);
- if (expected_sig) {
- ASSERT_TRUE(result.closest_proof->getRRsig());
- }
- actual_rrsets.push_back(result.closest_proof);
- if (expected_sig) {
- actual_rrsets.push_back(result.closest_proof->getRRsig());
- }
- rrsetsCheck(expected_rrsets_txt, actual_rrsets.begin(),
- actual_rrsets.end());
- }
- // In the following tests we use a temporary faked version of findNSEC3
- // as the real version isn't implemented yet (it's a task for #1577).
- // When #1577 is done the tests should be updated using the real version.
- // If we can use fake hash calculator (see #1575), we should be able to
- // just replace findNSEC3Tmp with findNSEC3.
- TEST_F(InMemoryZoneFinderTest, addNSEC3) {
- const string nsec3_text = string(apex_hash) + ".example.org." +
- string(nsec3_common);
- // This name shouldn't be found in the normal domain tree.
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nsec3_text)));
- EXPECT_EQ(ZoneFinder::NXDOMAIN,
- zone_finder_.find(Name(string(apex_hash) + ".example.org"),
- RRType::NSEC3()).code);
- // Dedicated NSEC3 find should be able to find it.
- nsec3Check(true, nsec3_text,
- zone_finder_.findNSEC3Tmp(Name("example.org"), false));
- // This implementation rejects duplicate/update add of the same hash name
- EXPECT_EQ(result::EXIST,
- zone_finder_.add(textToRRset(
- string(apex_hash) + ".example.org." +
- string(nsec3_common) + " AAAA")));
- // The original NSEC3 should be intact
- nsec3Check(true, nsec3_text,
- zone_finder_.findNSEC3Tmp(Name("example.org"), false));
- // NSEC3-like name but of ordinary RR type should go to normal tree.
- const string nonsec3_text = string(apex_hash) + ".example.org. " +
- "300 IN A 192.0.2.1";
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nonsec3_text)));
- EXPECT_EQ(ZoneFinder::SUCCESS,
- zone_finder_.find(Name(string(apex_hash) + ".example.org"),
- RRType::A()).code);
- }
- TEST_F(InMemoryZoneFinderTest, addNSEC3Lower) {
- // Similar to the previous case, but NSEC3 owner name is lower-cased.
- const string nsec3_text = string(apex_hash_lower) + ".example.org." +
- string(nsec3_common);
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nsec3_text)));
- nsec3Check(true, nsec3_text,
- zone_finder_.findNSEC3Tmp(Name("example.org"), false));
- }
- TEST_F(InMemoryZoneFinderTest, addNSEC3Ordering) {
- // Check that the internal storage ensures comparison based on the NSEC3
- // semantics, regardless of the add order or the letter-case of hash.
- // Adding "0P..", "2v..", then "2T..".
- const string smallest = string(apex_hash) + ".example.org." +
- string(nsec3_common);
- const string middle = string(ns1_hash) + ".example.org." +
- string(nsec3_common);
- const string largest = string(xrw_hash) + ".example.org." +
- string(nsec3_common);
- zone_finder_.add(textToRRset(smallest));
- zone_finder_.add(textToRRset(largest));
- zone_finder_.add(textToRRset(middle));
- // Then look for NSEC3 that covers a name whose hash is "2S.."
- // The covering NSEC3 should be "0P.."
- nsec3Check(false, smallest,
- zone_finder_.findNSEC3Tmp(Name("www.example.org"), false));
- // Look for NSEC3 that covers names whose hash are "Q0.." and "0A.."
- // The covering NSEC3 should be "2v.." in both cases
- nsec3Check(false, largest,
- zone_finder_.findNSEC3Tmp(Name("xxx.example.org"), false));
- nsec3Check(false, largest,
- zone_finder_.findNSEC3Tmp(Name("yyy.example.org"), false));
- }
- TEST_F(InMemoryZoneFinderTest, badNSEC3Name) {
- // Our implementation refuses to load NSEC3 at a wildcard name
- EXPECT_THROW(zone_finder_.add(textToRRset("*.example.org." +
- string(nsec3_common))),
- InMemoryZoneFinder::AddError);
- // Likewise, if the owner name of NSEC3 has too many labels, it's refused.
- EXPECT_THROW(zone_finder_.add(textToRRset("a." + string(apex_hash) +
- ".example.org." +
- string(nsec3_common))),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addMultiNSEC3) {
- // In this current implementation multiple NSEC3 RDATA isn't supported.
- RRsetPtr nsec3(new RRset(Name(string(apex_hash) + ".example.org"),
- RRClass::IN(), RRType::NSEC3(), RRTTL(300)));
- nsec3->addRdata(
- generic::NSEC3("1 0 12 aabbccdd 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A"));
- nsec3->addRdata(
- generic::NSEC3("1 1 1 ddccbbaa 2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A"));
- EXPECT_THROW(zone_finder_.add(nsec3), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, addNSEC3WithRRSIG) {
- // Adding NSEC3 and its RRSIG
- const string nsec3_text = string(apex_hash) + ".example.org." +
- string(nsec3_common);
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nsec3_text)));
- const string nsec3_rrsig_text = string(apex_hash) + ".example.org." +
- string(nsec3_rrsig_common);
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(textToRRset(nsec3_rrsig_text)));
- // Then look for it. The NSEC3 should have the RRSIG that was just added.
- nsec3Check(true, nsec3_text + "\n" + nsec3_rrsig_text,
- zone_finder_.findNSEC3Tmp(Name("example.org"), false), true);
- // Duplicate add of RRSIG for the same NSEC3 is prohibited.
- EXPECT_THROW(zone_finder_.add(textToRRset(nsec3_rrsig_text)),
- InMemoryZoneFinder::AddError);
- // Same check using the lower-cased name. This also confirms matching
- // is case-insensitive.
- EXPECT_THROW(zone_finder_.add(textToRRset(string(apex_hash_lower) +
- ".example.org."
- + string(nsec3_rrsig_common))),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, badRRsigForNSEC3) {
- // adding RRSIG for NSEC3 even before adding any NSEC3 (internally,
- // a space for NSEC3 namespace isn't yet allocated)
- EXPECT_THROW(zone_finder_.add(textToRRset(string(apex_hash) +
- ".example.org." +
- string(nsec3_rrsig_common))),
- InMemoryZoneFinder::AddError);
- // Add an NSEC3
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(
- textToRRset(string(apex_hash) + ".example.org." +
- string(nsec3_common))));
- // Then add an NSEC3 for a non existent NSEC3. It should fail in the
- // current implementation.
- EXPECT_THROW(zone_finder_.add(textToRRset(string(ns1_hash) +
- ".example.org." +
- string(nsec3_rrsig_common))),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, paramConsistencyWithNSEC3PARAM) {
- // First, add an NSEC3PARAM RR
- EXPECT_EQ(result::SUCCESS,
- zone_finder_.add(textToRRset("example.org. 300 IN NSEC3PARAM "
- "1 0 12 aabbccdd")));
- // Adding an NSEC3 that has matching parameters is okay.
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(
- textToRRset(string(apex_hash) + ".example.org." +
- string(nsec3_common))));
- // NSEC3 with inconsistent parameter will be rejected
- EXPECT_THROW(zone_finder_.add(
- textToRRset("a.example.org. 300 IN NSEC3 1 0 1 aabbccdd "
- "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG")),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, paramConsistencyWithNSEC3) {
- // Add an NSEC3 without adding NSEC3PARAM
- EXPECT_EQ(result::SUCCESS, zone_finder_.add(
- textToRRset(string(apex_hash) + ".example.org." +
- string(nsec3_common))));
- // Adding an NSEC3 with inconsistent parameter will be rejected at this pt.
- EXPECT_THROW(zone_finder_.add(
- textToRRset("a.example.org. 300 IN NSEC3 1 0 1 aabbccdd "
- "2T7B4G4VSA5SMI47K61MV5BV1A22BOJR A RRSIG")),
- InMemoryZoneFinder::AddError);
- // Likewise, NSEC3PARAM with inconsistent parameter will be rejected.
- EXPECT_THROW(zone_finder_.add(textToRRset("example.org. 300 IN NSEC3PARAM "
- "1 0 1 aabbccdd")),
- InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, multiNSEC3PARAM) {
- // In this current implementation multiple NSEC3PARAM isn't supported.
- RRsetPtr nsec3param(new RRset(Name("example.org"), RRClass::IN(),
- RRType::NSEC3PARAM(), RRTTL(300)));
- nsec3param->addRdata(generic::NSEC3PARAM("1 0 12 aabbccdd"));
- nsec3param->addRdata(generic::NSEC3PARAM("1 1 1 ddccbbaa"));
- EXPECT_THROW(zone_finder_.add(nsec3param), InMemoryZoneFinder::AddError);
- }
- TEST_F(InMemoryZoneFinderTest, nonOriginNSEC3PARAM) {
- // This is a normal NSEC3PARAM at the zone origin
- EXPECT_EQ(result::SUCCESS,
- zone_finder_.add(textToRRset("example.org. 300 IN NSEC3PARAM "
- "1 0 12 aabbccdd")));
- // Add another (with different param) at a non origin node. This is
- // awkward, but the implementation accepts it as an ordinary RR.
- EXPECT_EQ(result::SUCCESS,
- zone_finder_.add(textToRRset("a.example.org. 300 IN NSEC3PARAM "
- "1 1 1 aabbccdd")));
- }
- TEST_F(InMemoryZoneFinderTest, loadNSEC3Zone) {
- // Check if it can load validly NSEC3-signed zone. At this moment
- // it's sufficient to see it doesn't crash
- zone_finder_.load(TEST_DATA_DIR "/example.org.nsec3-signed");
- // Reload the zone with a version that doesn't have NSEC3PARAM.
- // This is an abnormal case, but the implementation accepts it.
- zone_finder_.load(TEST_DATA_DIR "/example.org.nsec3-signed-noparam");
- }
- }
|