Parcourir la source

[1063] Ignore NS at origin

It was written, but the zone didn't know it's own origin. This is now
fixed and tested.
Michal 'vorner' Vaner il y a 13 ans
Parent
commit
ce3bc8504d

+ 10 - 7
src/lib/datasrc/database.cc

@@ -49,16 +49,18 @@ DatabaseClient::findZone(const Name& name) const {
     if (zone.first) {
         return (FindResult(result::SUCCESS,
                            ZoneFinderPtr(new Finder(database_,
-                                                    zone.second))));
+                                                    zone.second, name))));
     }
     // Than super domains
     // Start from 1, as 0 is covered above
     for (size_t i(1); i < name.getLabelCount(); ++i) {
-        zone = database_->getZone(name.split(i));
+        isc::dns::Name superdomain(name.split(i));
+        zone = database_->getZone(superdomain);
         if (zone.first) {
             return (FindResult(result::PARTIALMATCH,
                                ZoneFinderPtr(new Finder(database_,
-                                                        zone.second))));
+                                                        zone.second,
+                                                        superdomain))));
         }
     }
     // No, really nothing
@@ -66,9 +68,11 @@ DatabaseClient::findZone(const Name& name) const {
 }
 
 DatabaseClient::Finder::Finder(boost::shared_ptr<DatabaseAccessor>
-                               database, int zone_id) :
+                               database, int zone_id,
+                               const isc::dns::Name& origin) :
     database_(database),
-    zone_id_(zone_id)
+    zone_id_(zone_id),
+    origin_(origin)
 { }
 
 namespace {
@@ -372,8 +376,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
 
 Name
 DatabaseClient::Finder::getOrigin() const {
-    // TODO Implement
-    return (Name("."));
+    return (origin_);
 }
 
 isc::dns::RRClass

+ 8 - 1
src/lib/datasrc/database.h

@@ -17,6 +17,8 @@
 
 #include <datasrc/client.h>
 
+#include <dns/name.h>
+
 namespace isc {
 namespace datasrc {
 
@@ -218,8 +220,12 @@ public:
          * \param zone_id The zone ID which was returned from
          *     DatabaseAccessor::getZone and which will be passed to further
          *     calls to the database.
+         * \param origin The name of the origin of this zone. It could query
+         *     it from database, but as the DatabaseClient just searched for
+         *     the zone using the name, it should have it.
          */
-        Finder(boost::shared_ptr<DatabaseAccessor> database, int zone_id);
+        Finder(boost::shared_ptr<DatabaseAccessor> database, int zone_id,
+               const isc::dns::Name& origin);
         // The following three methods are just implementations of inherited
         // ZoneFinder's pure virtual methods.
         virtual isc::dns::Name getOrigin() const;
@@ -290,6 +296,7 @@ public:
     private:
         boost::shared_ptr<DatabaseAccessor> database_;
         const int zone_id_;
+        const isc::dns::Name origin_;
         /**
          * \brief Searches database for an RRset
          *

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

@@ -265,7 +265,6 @@ private:
         addCurName("badsigtype.example.org.");
 
         // Data for testing delegation (with NS and DNAME)
-        addRecord("A", "3600", "", "192.0.2.1");
         addRecord("NS", "3600", "", "ns.example.com.");
         addRecord("NS", "3600", "", "ns.delegation.example.org.");
         addCurName("delegation.example.org.");
@@ -282,6 +281,12 @@ private:
         addRecord("DNAME", "3600", "", "dname1.example.com.");
         addRecord("DNAME", "3600", "", "dname2.example.com.");
         addCurName("baddname.example.org.");
+
+        // Put some data into apex (including NS) so we can check our NS
+        // doesn't break anything
+        addRecord("NS", "3600", "", "ns.example.com.");
+        addRecord("A", "3600", "", "192.0.2.1");
+        addCurName("example.org.");
     }
 };
 
@@ -703,6 +708,17 @@ TEST_F(DatabaseClientTest, find) {
                expected_rdatas, expected_sig_rdatas);
     EXPECT_FALSE(current_database_->searchRunning());
 
+    // The apex should not be considered delegation point and we can access
+    // data
+    expected_rdatas.clear();
+    expected_sig_rdatas.clear();
+    expected_rdatas.push_back("192.0.2.1");
+    doFindTest(finder, isc::dns::Name("example.org."),
+               isc::dns::RRType::A(), isc::dns::RRType::A(),
+               isc::dns::RRTTL(3600), ZoneFinder::SUCCESS, expected_rdatas,
+               expected_sig_rdatas);
+    EXPECT_FALSE(current_database_->searchRunning());
+
     // Check when we ask for something below delegation point, we get the NS
     // (Both when the RRset there exists and doesn't)
     expected_rdatas.clear();
@@ -769,6 +785,16 @@ TEST_F(DatabaseClientTest, find) {
                               isc::dns::RRType::A(), NULL,
                               ZoneFinder::FIND_DEFAULT),
                  DataSourceError);
+    EXPECT_FALSE(current_database_->searchRunning());
+}
+
+TEST_F(DatabaseClientTest, getOrigin) {
+    DataSourceClient::FindResult zone(client_->findZone(Name("example.org")));
+    ASSERT_EQ(result::SUCCESS, zone.code);
+    shared_ptr<DatabaseClient::Finder> finder(
+        dynamic_pointer_cast<DatabaseClient::Finder>(zone.zone_finder));
+    EXPECT_EQ(42, finder->zone_id());
+    EXPECT_EQ(isc::dns::Name("example.org"), finder->getOrigin());
 }
 
 }