BIND 10 trac981, updated. ea2a4f906dc3b5bae939a0348a5f82fa690bbec5 [trac981] Register the creators

BIND 10 source code commits bind10-changes at lists.isc.org
Mon Jul 4 14:16:35 UTC 2011


The branch, trac981 has been updated
       via  ea2a4f906dc3b5bae939a0348a5f82fa690bbec5 (commit)
       via  376fd546007d1bf592e391f11b5fdf08993914c2 (commit)
       via  c0442d5d6e70643e10e639efe1162b64c44cce45 (commit)
      from  2ab154b25ceb6264f87ba6a3ca139ec44c7db275 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ea2a4f906dc3b5bae939a0348a5f82fa690bbec5
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jul 4 16:16:03 2011 +0200

    [trac981] Register the creators

commit 376fd546007d1bf592e391f11b5fdf08993914c2
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jul 4 16:03:58 2011 +0200

    [trac981] Implementation of the NOT creator

commit c0442d5d6e70643e10e639efe1162b64c44cce45
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date:   Mon Jul 4 15:55:21 2011 +0200

    [trac981] Tests for the not creator

-----------------------------------------------------------------------

Summary of changes:
 src/lib/acl/dns.cc                    |   17 +++++++++++-
 src/lib/acl/logic_check.h             |   44 +++++++++++++++++++++++++++++++++
 src/lib/acl/tests/dns_test.cc         |   20 +++++++++++++++
 src/lib/acl/tests/logic_check_test.cc |   26 +++++++++++++++++++
 4 files changed, 105 insertions(+), 2 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/acl/dns.cc b/src/lib/acl/dns.cc
index 16f1bf5..4dae297 100644
--- a/src/lib/acl/dns.cc
+++ b/src/lib/acl/dns.cc
@@ -13,6 +13,9 @@
 // PERFORMANCE OF THIS SOFTWARE.
 
 #include "dns.h"
+#include "logic_check.h"
+
+using boost::shared_ptr;
 
 namespace isc {
 namespace acl {
@@ -22,9 +25,19 @@ Loader&
 getLoader() {
     static Loader* loader(NULL);
     if (loader == NULL) {
+        // TODO:
+        // There's some trick with auto_ptr in the branch when IP check
+        // is added here. That one is better, bring it in on merge.
         loader = new Loader(REJECT);
-        // TODO: This is the place where we register default check creators
-        // like IP check, etc, once we have them.
+        loader->registerCreator(
+            shared_ptr<NotCreator<RequestContext> >(
+                new NotCreator<RequestContext>("NOT")));
+        loader->registerCreator(
+            shared_ptr<LogicCreator<AnyOfSpec, RequestContext> >(
+                new LogicCreator<AnyOfSpec, RequestContext>("ANY")));
+        loader->registerCreator(
+            shared_ptr<LogicCreator<AllOfSpec, RequestContext> >(
+                new LogicCreator<AllOfSpec, RequestContext>("ALL")));
     }
     return (*loader);
 }
diff --git a/src/lib/acl/logic_check.h b/src/lib/acl/logic_check.h
index cf511ba..fe16f7f 100644
--- a/src/lib/acl/logic_check.h
+++ b/src/lib/acl/logic_check.h
@@ -236,6 +236,50 @@ private:
     const boost::shared_ptr<Check<Context> > expr_;
 };
 
+template<typename Context, typename Action = BasicAction>
+class NotCreator : public Loader<Context, Action>::CheckCreator {
+public:
+    /**
+     * \brief Constructor
+     *
+     * \param name The name of the NOT operator to be loaded as.
+     */
+    NotCreator(const std::string& name) :
+        name_(name)
+    { }
+    /**
+     * \brief List of the names this loads
+     *
+     * \return Single-value vector containing the name passed to the
+     *     constructor.
+     */
+    virtual std::vector<std::string> names() const {
+        std::vector<std::string> result;
+        result.push_back(name_);
+        return (result);
+    }
+    /// \brief Create the check.
+    virtual boost::shared_ptr<Check<Context> > create(const std::string&,
+                                                      data::ConstElementPtr
+                                                      definition,
+                                                      const Loader<Context,
+                                                      Action>& loader)
+    {
+        return (boost::shared_ptr<Check<Context> >(new NotCheck<Context>(
+                    loader.loadCheck(definition))));
+    }
+    /**
+     * \brief Or-abbreviated form.
+     *
+     * This returns false. In theory, the NOT operator could be used with
+     * the abbreviated form, but it would be confusing. Such syntax is
+     * therefore explicitly forbidden.
+     */
+    virtual bool allowListAbbreviation() const { return (false); }
+public:
+    const std::string name_;
+};
+
 }
 }
 
diff --git a/src/lib/acl/tests/dns_test.cc b/src/lib/acl/tests/dns_test.cc
index e5e0f3a..b2f9678 100644
--- a/src/lib/acl/tests/dns_test.cc
+++ b/src/lib/acl/tests/dns_test.cc
@@ -32,4 +32,24 @@ TEST(DNSACL, getLoader) {
     // check, are loaded.
 }
 
+// The following tests test only the creators are registered, they are tested
+// elsewhere
+
+// TODO: Enable the tests when we merge the IP check branch here (is it called
+// "from" in the branch?)
+TEST(DNSACL, DISABLED_notLoad) {
+    EXPECT_NO_THROW(getLoader().loadCheck(isc::data::Element::fromJSON(
+        "{\"NOT\": {\"from\": \"192.0.2.1\"}}")));
+}
+
+TEST(DNSACL, DISABLED_allLoad) {
+    EXPECT_NO_THROW(getLoader().loadCheck(isc::data::Element::fromJSON(
+        "{\"ALL\": [{\"from\": \"192.0.2.1\"}]}")));
+}
+
+TEST(DNSACL, DISABLED_anyLoad) {
+    EXPECT_NO_THROW(getLoader().loadCheck(isc::data::Element::fromJSON(
+        "{\"ANY\": [{\"from\": \"192.0.2.1\"}]}")));
+}
+
 }
diff --git a/src/lib/acl/tests/logic_check_test.cc b/src/lib/acl/tests/logic_check_test.cc
index 2e5fa58..1d1979a 100644
--- a/src/lib/acl/tests/logic_check_test.cc
+++ b/src/lib/acl/tests/logic_check_test.cc
@@ -93,6 +93,7 @@ public:
             LogicCreator<AllOfSpec, Log>("ALL")));
         loader_.registerCreator(CreatorPtr(new ThrowCreator));
         loader_.registerCreator(CreatorPtr(new LogCreator));
+        loader_.registerCreator(CreatorPtr(new NotCreator<Log>("NOT")));
     }
     // To mark which parts of the check did run
     Log log_;
@@ -262,4 +263,29 @@ TEST(Not, falseValue) {
     notTest(false);
 }
 
+TEST_F(LogicCreatorTest, notInvalid) {
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": null}")),
+                 LoaderError);
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": \"hello\"}")),
+                 LoaderError);
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": true}")),
+                 LoaderError);
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": 42}")),
+                 LoaderError);
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": []}")),
+                 LoaderError);
+    EXPECT_THROW(loader_.loadCheck(Element::fromJSON("{\"NOT\": [{"
+                                                     "\"logcheck\": [0, true]"
+                                                     "}]}")),
+                 LoaderError);
+}
+
+TEST_F(LogicCreatorTest, notValid) {
+    shared_ptr<NotCheck<Log> > notOp(load<NotCheck<Log> >("{\"NOT\":"
+                                                          "  {\"logcheck\":"
+                                                          "     [0, true]}}"));
+    EXPECT_FALSE(notOp->matches(log_));
+    log_.checkFirst(1);
+}
+
 }




More information about the bind10-changes mailing list