Browse Source

[trac999] added parameter validation to setQueryACL()

JINMEI Tatuya 14 years ago
parent
commit
679d8390f4

+ 6 - 0
src/bin/resolver/resolver.cc

@@ -24,6 +24,8 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/foreach.hpp>
 
+#include <exceptions/exceptions.h>
+
 #include <acl/acl.h>
 #include <acl/loader.h>
 
@@ -784,6 +786,10 @@ Resolver::getQueryACL() const {
 
 void
 Resolver::setQueryACL(shared_ptr<const ClientACL> new_acl) {
+    if (!new_acl) {
+        isc_throw(InvalidParameter, "NULL pointer is passed to setQueryACL");
+    }
+
     LOG_INFO(resolver_logger, RESOLVER_SETQUERYACL);
     impl_->setQueryACL(new_acl);
 }

+ 15 - 0
src/bin/resolver/resolver.h

@@ -246,10 +246,25 @@ public:
      */
     int getRetries() const;
 
+    // Shortcut typedef used for query ACL.
     typedef isc::acl::ACL<isc::server_common::Client> ClientACL;
 
+    /// Get the query ACL.
+    ///
+    /// \exception None
     const ClientACL& getQueryACL() const;
 
+    /// Set the new query ACL.
+    ///
+    /// This method replaces the existing query ACL completely.
+    /// Normally this method will be called via the configuration handler,
+    /// but is publicly available for convenience of tests (and other
+    /// experimental purposes).
+    /// \c new_acl must not be a NULL pointer.
+    ///
+    /// \exception InvalidParameter The given pointer is NULL
+    ///
+    /// \param new_acl The new ACL to replace the existing one.
     void setQueryACL(boost::shared_ptr<const ClientACL> new_acl);
 
 private:

+ 10 - 0
src/bin/resolver/tests/resolver_unittest.cc

@@ -14,6 +14,8 @@
 
 #include <string>
 
+#include <exceptions/exceptions.h>
+
 #include <dns/name.h>
 
 #include <cc/data.h>
@@ -151,6 +153,14 @@ TEST_F(ResolverTest, notifyFail) {
                 Opcode::NOTIFY().getCode(), QR_FLAG, 0, 0, 0, 0);
 }
 
+TEST_F(ResolverTest, setQueryACL) {
+    // valid cases are tested through other tests.  We only explicitly check
+    // an invalid case: passing a NULL shared pointer.
+    EXPECT_THROW(server.setQueryACL(
+                     boost::shared_ptr<const Resolver::ClientACL>()),
+                 isc::InvalidParameter);
+}
+
 TEST_F(ResolverTest, queryACL) {
     // The "ACCEPT" cases are covered in other tests.  Here we explicitly
     // test "REJECT" and "DROP" cases.