Browse Source

[2981] Added validation checks for DHCP6 configuration tests

Stephen Morris 11 years ago
parent
commit
be68664ae1

+ 1 - 1
src/bin/dhcp6/tests/config_parser_unittest.cc

@@ -2057,7 +2057,7 @@ TEST_F(Dhcp6ParserTest, InvalidLibrary) {
     ASSERT_NO_THROW(status = configureDhcp6Server(srv_, json));
 
     // The status object must not be NULL
-    ASSERT_FALSE(status);
+    ASSERT_TRUE(status);
 
     // Returned value should not be 0
     comment_ = parseAnswer(rcode_, status);

+ 9 - 5
src/lib/dhcpsrv/dhcp_parsers.cc

@@ -23,7 +23,6 @@
 #include <boost/algorithm/string.hpp>
 #include <boost/foreach.hpp>
 #include <boost/lexical_cast.hpp>
-#include <boost/lexical_cast.hpp>
 
 #include <map>
 #include <string>
@@ -247,19 +246,24 @@ HooksLibrariesParser::build(ConstElementPtr value) {
     // - the command "DhcpN libreload" is required to reload the same
     // libraries (this prevents needless reloads when anything else in the
     // configuration is changed).
-/*
     vector<string> current_libraries = HooksManager::getLibraryNames();
     if (current_libraries == libraries_) {
         return;
     }
 
     // Library list has changed, validate each of the libraries specified.
-    string error_libs = HooksManager::validateLibraries(libraries_);
+    vector<string> error_libs = HooksManager::validateLibraries(libraries_);
     if (!error_libs.empty()) {
+
+        // Construct the list of libraries in error for the message.
+        string error_list = error_libs[0];
+        for (int i = 1; i < error_libs.size(); ++i) {
+            error_list += (string(", ") + error_libs[i]);
+        }
         isc_throw(DhcpConfigError, "hooks libraries failed to validate - "
-                  "library or libraries in error are: " + error_libs);
+                  "library or libraries in error are: " + error_list);
     }
-*/
+
     // The library list has changed and the libraries are valid, so flag for
     // update when commit() is called.
     changed_ = true;

+ 12 - 0
src/lib/dhcpsrv/tests/Makefile.am

@@ -24,6 +24,18 @@ TESTS_ENVIRONMENT = \
 
 TESTS =
 if HAVE_GTEST
+# Build shared libraries for testing.
+lib_LTLIBRARIES = libco1.la libco2.la
+
+libco1_la_SOURCES  = callout_library.cc
+libco1_la_CXXFLAGS = $(AM_CXXFLAGS)
+libco1_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
+
+libco2_la_SOURCES  = callout_library.cc
+libco2_la_CXXFLAGS = $(AM_CXXFLAGS)
+libco2_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
+
+
 TESTS += libdhcpsrv_unittests
 
 libdhcpsrv_unittests_SOURCES  = run_unittests.cc

+ 0 - 115
src/lib/dhcpsrv/tests/basic_callout_library.cc

@@ -1,115 +0,0 @@
-// Copyright (C) 2013  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.
-
-/// @file
-/// @brief Basic callout library
-///
-/// This is source of a test library for various test (LibraryManager and
-/// HooksManager).  The characteristics of the library produced from this
-/// file are:
-///
-/// - Only the "version" framework function is supplied.
-///
-/// - A context_create callout is supplied.
-///
-/// - Three "standard" callouts are supplied corresponding to the hooks
-///   "lm_one", "lm_two", "lm_three".  All do some trivial calculations
-///   on the arguments supplied to it and the context variables, returning
-///   intermediate results through the "result" argument. The result of
-///   executing all four callouts in order is:
-///
-///   @f[ (10 + data_1) * data_2 - data_3 @f]
-///
-///   ...where data_1, data_2 and data_3 are the values passed in arguments of
-///   the same name to the three callouts (data_1 passed to lm_one, data_2 to
-///   lm_two etc.) and the result is returned in the argument "result".
-
-#include <hooks/hooks.h>
-#include <fstream>
-
-using namespace isc::hooks;
-using namespace std;
-
-extern "C" {
-
-// Callouts.  All return their result through the "result" argument.
-
-int
-context_create(CalloutHandle& handle) {
-    handle.setContext("result", static_cast<int>(10));
-    handle.setArgument("result", static_cast<int>(10));
-    return (0);
-}
-
-// First callout adds the passed "data_1" argument to the initialized context
-// value of 10. (Note that the value set by context_create is accessed through
-// context and not the argument, so checking that context is correctly passed
-// between callouts in the same library.)
-
-int
-lm_one(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_1", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result += data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Second callout multiplies the current context value by the "data_2"
-// argument.
-
-int
-lm_two(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_2", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result *= data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Final callout subtracts the result in "data_3".
-
-int
-lm_three(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_3", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result -= data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Framework functions.  Only version() is supplied here.
-
-int
-version() {
-    return (BIND10_HOOKS_VERSION);
-}
-
-};
-

+ 31 - 0
src/lib/dhcpsrv/tests/callout_library.cc

@@ -0,0 +1,31 @@
+// Copyright (C) 2013  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.
+
+/// @file
+/// @brief Callout Library
+///
+/// This is the source of a test library for the basic DHCP parser 
+/// tests.  It just has to load - nothing else.
+
+#include <hooks/hooks.h>
+
+extern "C" {
+
+// Framework functions
+int
+version() {
+    return (BIND10_HOOKS_VERSION);
+}
+
+};

+ 7 - 7
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc

@@ -600,7 +600,7 @@ TEST_F(ParseConfigTest, noHooksLibrariesTest) {
 
     // Load a single library and repeat the parse.
     vector<string> basic_library;
-    basic_library.push_back(string(BASIC_CALLOUT_LIBRARY));
+    basic_library.push_back(string(CALLOUT_LIBRARY_1));
     HooksManager::loadLibraries(basic_library);
 
     rcode = parseConfiguration(config);
@@ -630,8 +630,8 @@ TEST_F(ParseConfigTest, validHooksLibrariesTest) {
     const std::string config =
         std::string("{ ") +
             std::string("\"hooks-libraries\": [") +
-                quote + std::string(BASIC_CALLOUT_LIBRARY) + quote + comma +
-                quote + std::string(FULL_CALLOUT_LIBRARY)  + quote +
+                quote + std::string(CALLOUT_LIBRARY_1) + quote + comma +
+                quote + std::string(CALLOUT_LIBRARY_2)  + quote +
             std::string("]") +
         std::string("}");
 
@@ -650,8 +650,8 @@ TEST_F(ParseConfigTest, validHooksLibrariesTest) {
     // The expected libraries should be the list of libraries specified
     // in the given order.
     std::vector<std::string> expected;
-    expected.push_back(BASIC_CALLOUT_LIBRARY);
-    expected.push_back(FULL_CALLOUT_LIBRARY);
+    expected.push_back(CALLOUT_LIBRARY_1);
+    expected.push_back(CALLOUT_LIBRARY_2);
     EXPECT_TRUE(expected == libraries);
 
     // Parse the string again.
@@ -677,9 +677,9 @@ TEST_F(ParseConfigTest, invalidHooksLibrariesTest) {
     const std::string config =
         std::string("{ ") +
             std::string("\"hooks-libraries\": [") +
-                quote + std::string(BASIC_CALLOUT_LIBRARY) + quote + comma +
+                quote + std::string(CALLOUT_LIBRARY_1) + quote + comma +
                 quote + std::string(NOT_PRESENT_LIBRARY) + quote + comma +
-                quote + std::string(FULL_CALLOUT_LIBRARY)  + quote +
+                quote + std::string(CALLOUT_LIBRARY_2)  + quote +
             std::string("]") +
         std::string("}");
 

+ 0 - 137
src/lib/dhcpsrv/tests/full_callout_library.cc

@@ -1,137 +0,0 @@
-// Copyright (C) 2013  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.
-
-/// @file
-/// @brief Full callout library
-///
-/// This is source of a test library for various test (LibraryManager and
-/// HooksManager).  The characteristics of the library produced from this
-/// file are:
-///
-/// The characteristics of this library are:
-///
-/// - All three framework functions are supplied (version(), load() and
-///   unload()), with unload() creating a marker file.  The test code checks
-///   for the presence of this file, so verifying that unload() has been run.
-///
-/// - One standard and two non-standard callouts are supplied, with the latter
-///   being registered by the load() function.
-///
-///   All callouts do trivial calculations, the result of all being called in
-///   sequence being
-///
-///   @f[ ((7 * data_1) - data_2) * data_3 @f]
-///
-///   ...where data_1, data_2 and data_3 are the values passed in arguments of
-///   the same name to the three callouts (data_1 passed to lm_one, data_2 to
-///   lm_two etc.) and the result is returned in the argument "result".
-
-#include <hooks/hooks.h>
-#include <hooks/tests/marker_file.h>
-
-#include <fstream>
-
-using namespace isc::hooks;
-
-extern "C" {
-
-// Callouts
-
-int
-context_create(CalloutHandle& handle) {
-    handle.setContext("result", static_cast<int>(7));
-    handle.setArgument("result", static_cast<int>(7));
-    return (0);
-}
-
-// First callout adds the passed "data_1" argument to the initialized context
-// value of 7. (Note that the value set by context_create is accessed through
-// context and not the argument, so checking that context is correctly passed
-// between callouts in the same library.)
-
-int
-lm_one(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_1", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result *= data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Second callout subtracts the passed value of data_2 from the current
-// running total.
-
-static int
-lm_nonstandard_two(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_2", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result -= data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Final callout multplies the current running total by data_3.
-
-static int
-lm_nonstandard_three(CalloutHandle& handle) {
-    int data;
-    handle.getArgument("data_3", data);
-
-    int result;
-    handle.getArgument("result", result);
-
-    result *= data;
-    handle.setArgument("result", result);
-
-    return (0);
-}
-
-// Framework functions
-
-int
-version() {
-    return (BIND10_HOOKS_VERSION);
-}
-
-int
-load(LibraryHandle& handle) {
-    // Register the non-standard functions
-    handle.registerCallout("lm_two", lm_nonstandard_two);
-    handle.registerCallout("lm_three", lm_nonstandard_three);
-
-    return (0);
-}
-
-int
-unload() {
-    // Create the marker file.
-    std::fstream marker;
-    marker.open(MARKER_FILE, std::fstream::out);
-    marker.close();
-
-    return (0);
-}
-
-};
-

+ 8 - 12
src/lib/dhcpsrv/tests/test_libraries.h.in

@@ -20,9 +20,9 @@
 namespace {
 
 
-// Take carse of differences in DLL naming between operating systems.
+// Take care of differences in DLL naming between operating systems.
 
-#ifdef OS_BSD
+#ifdef OS_OSX
 #define DLL_SUFFIX ".dylib"
 
 #else
@@ -33,22 +33,18 @@ namespace {
 
 // Names of the libraries used in these tests.  These libraries are built using
 // libtool, so we need to look in the hidden ".libs" directory to locate the
-// .so file.  Note that we access the .so file - libtool creates this as a
-// like to the real shared library.
+// shared library.
 
-// Basic library with context_create and three "standard" callouts.
-static const char* BASIC_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libbcl"
+// Library with load/unload functions creating marker files to check their
+// operation.
+static const char* CALLOUT_LIBRARY_1 = "@abs_builddir@/.libs/libco1"
+                                           DLL_SUFFIX;
+static const char* CALLOUT_LIBRARY_2 = "@abs_builddir@/.libs/libco2"
                                            DLL_SUFFIX;
-
-// Library with context_create and three "standard" callouts, as well as
-// load() and unload() functions.
-static const char* FULL_CALLOUT_LIBRARY = "@abs_builddir@/.libs/libfcl"
-                                          DLL_SUFFIX;
 
 // Name of a library which is not present.
 static const char* NOT_PRESENT_LIBRARY = "@abs_builddir@/.libs/libnothere"
                                          DLL_SUFFIX;
-
 } // anonymous namespace