Browse Source

[2435] Check ZoneFinder find() result and return accordingly

Mukund Sivaraman 12 years ago
parent
commit
5200f31617
2 changed files with 50 additions and 2 deletions
  1. 11 1
      src/lib/datasrc/database.cc
  2. 39 1
      src/lib/datasrc/tests/database_unittest.cc

+ 11 - 1
src/lib/datasrc/database.cc

@@ -1418,7 +1418,17 @@ public:
             ZoneFinderContextPtr result =
             ZoneFinderContextPtr result =
                 finder.find(name, rrtype,
                 finder.find(name, rrtype,
                             ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
                             ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
-            return (result->rrset);
+            // We return the result rrset only if the result code is
+            // SUCCESS. We return empty if CNAME, DNAME, DELEGATION,
+            // etc. are returned by the ZoneFinder.
+            //
+            // Note that in the case that the queried type itself is
+            // CNAME, then the finder will return SUCCESS.
+            if (result->code == ZoneFinder::SUCCESS) {
+                return (result->rrset);
+            } else {
+                return (ConstRRsetPtr());
+            }
         } catch (const OutOfZone&) {
         } catch (const OutOfZone&) {
             // As RRsetCollection is an arbitrary set of RRsets, in case
             // As RRsetCollection is an arbitrary set of RRsets, in case
             // the searched name is out of zone, we return nothing
             // the searched name is out of zone, we return nothing

+ 39 - 1
src/lib/datasrc/tests/database_unittest.cc

@@ -2184,6 +2184,12 @@ TYPED_TEST(DatabaseClientTest, findDelegation) {
                this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
                this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
                this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
                this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
                isc::dns::Name("dname.example.org."));
                isc::dns::Name("dname.example.org."));
+    // below.dname.example.org. has an A record
+    doFindTest(*finder, isc::dns::Name("below.dname.example.org."),
+               isc::dns::RRType::A(), isc::dns::RRType::DNAME(),
+               this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
+               this->expected_sig_rdatas_, ZoneFinder::RESULT_DEFAULT,
+               isc::dns::Name("dname.example.org."));
     doFindTest(*finder, isc::dns::Name("really.deep.below.dname.example.org."),
     doFindTest(*finder, isc::dns::Name("really.deep.below.dname.example.org."),
                isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
                isc::dns::RRType::AAAA(), isc::dns::RRType::DNAME(),
                this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
                this->rrttl_, ZoneFinder::DNAME, this->expected_rdatas_,
@@ -4199,10 +4205,42 @@ TYPED_TEST(RRsetCollectionTest, find) {
                                    RRType::AAAA());
                                    RRType::AAAA());
     EXPECT_FALSE(rrset);
     EXPECT_FALSE(rrset);
 
 
-    // Out of zone find()s must not throw.
+    // Out-of-zone find()s must not throw.
     rrset = this->collection->find(Name("www.example.com"), this->qclass_,
     rrset = this->collection->find(Name("www.example.com"), this->qclass_,
                                    RRType::A());
                                    RRType::A());
     EXPECT_FALSE(rrset);
     EXPECT_FALSE(rrset);
+
+    // "cname.example.org." with type CNAME should return the CNAME RRset
+    rrset = this->collection->find(Name("cname.example.org"), this->qclass_,
+                                   RRType::CNAME());
+    ASSERT_TRUE(rrset);
+    EXPECT_EQ(RRType::CNAME(), rrset->getType());
+    EXPECT_EQ(Name("cname.example.org"), rrset->getName());
+
+    // "cname.example.org." with type A should return nothing
+    rrset = this->collection->find(Name("cname.example.org"), this->qclass_,
+                                   RRType::A());
+    EXPECT_FALSE(rrset);
+
+    // "dname.example.org." with type DNAME should return the DNAME RRset
+    rrset = this->collection->find(Name("dname.example.org"), this->qclass_,
+                                   RRType::DNAME());
+    ASSERT_TRUE(rrset);
+    EXPECT_EQ(RRType::DNAME(), rrset->getType());
+    EXPECT_EQ(Name("dname.example.org"), rrset->getName());
+
+    // "below.dname.example.org." with type AAAA should return nothing
+    rrset = this->collection->find(Name("below.dname.example.org"),
+                                   this->qclass_, RRType::AAAA());
+    EXPECT_FALSE(rrset);
+
+    // TODO: "below.dname.example.org." with type A does not return the
+    // record (see top of file). It needs to be checked if this is what
+    // we want.
+    rrset = this->collection->find(Name("below.dname.example.org"),
+                                   this->qclass_, RRType::A());
+    // Is this correct behavior?
+    EXPECT_FALSE(rrset);
 }
 }
 
 
 TYPED_TEST(RRsetCollectionTest, iteratorTest) {
 TYPED_TEST(RRsetCollectionTest, iteratorTest) {