]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#641,!352] Addressed review comments.
authorMarcin Siodelski <marcin@isc.org>
Mon, 10 Jun 2019 11:17:39 +0000 (13:17 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 10 Jun 2019 12:39:17 +0000 (08:39 -0400)
src/lib/cc/server_tag.cc
src/lib/cc/server_tag.h
src/lib/cc/tests/server_tag_unittest.cc
src/lib/config_backend/base_config_backend_pool.h
src/lib/database/server.h
src/lib/database/tests/server_unittest.cc

index 931d2561d4722733f1a986a076599096e0fda1a4..e99d75bef43df17f2e06f8fc12d9f733e1acadc8 100644 (file)
@@ -7,6 +7,7 @@
 #include <cc/server_tag.h>
 #include <exceptions/exceptions.h>
 #include <util/strutil.h>
+#include <boost/algorithm/string.hpp>
 
 namespace isc {
 namespace data {
@@ -25,6 +26,8 @@ ServerTag::ServerTag(const std::string& tag)
     } else if (tag_.length() > 256) {
         isc_throw(BadValue, "server-tag must not be longer than 256 characters");
     }
+
+    boost::algorithm::to_lower(tag_);
 }
 
 bool
index 95502ae898cc5f09218a059c00a2e3ec5a57e468..c85fc1bd5c0d7e69ddfc6f9b2866dd6abb87f50d 100644 (file)
@@ -33,7 +33,8 @@ public:
 
     /// @brief Constructor.
     ///
-    /// @param tag server tag provided as string.
+    /// @param tag server tag provided as string. The tag is converted to
+    /// lower case.
     explicit ServerTag(const std::string& tag);
 
     /// @brief Checks if the server tag is set to "all servers".
@@ -41,7 +42,10 @@ public:
     /// @return true if the server tag is set to all servers, false
     /// otherwise.
     bool amAll() const;
+
     /// @brief Returns server tag as string.
+    ///
+    /// @return lower case server tag.
     std::string get() const {
         return (tag_);
     }
index 95cfd4f39397e140c65f3379a46177bb9da1550e..f782a065a0ef11b4c45959fdd010eedbe3391d6a 100644 (file)
@@ -62,6 +62,13 @@ TEST(ServerTagTest, constructors) {
         EXPECT_EQ("both left-right", tag->get());
         EXPECT_FALSE(tag->amAll());
     }
+
+    {
+        SCOPED_TRACE("upper to lower case");
+        ASSERT_NO_THROW(tag.reset(new ServerTag("UPPER CASE TAG")));
+        EXPECT_EQ("upper case tag", tag->get());
+        EXPECT_FALSE(tag->amAll());
+    }
 }
 
 // This test verifies that malformed server tags are rejected.
index 2fc67b51646c04e59647d558aacc9061776f39a0..337f332f653f51754981c6c1f62abee387aa86d9 100644 (file)
@@ -401,7 +401,6 @@ protected:
     ///
     /// @param MethodPointer Pointer to the backend method to be called.
     /// @param backend_selector Backend selector.
-    /// @param server_selector Server selector.
     /// @param [out] properties Reference to the collection of retrieved properties.
     ///
     /// @throw db::NoSuchDatabase if no database matching the given selector
index aa4e5b27c31c2319fc56c3fa5f0ba25b94c68488..fc1d84f4bf72442f618053aec9214766c81ff01f 100644 (file)
@@ -19,7 +19,7 @@ class Server;
 /// @brief Shared pointer to the @c Server class.
 typedef boost::shared_ptr<Server> ServerPtr;
 
-/// @brief Represents information about the Kea server in the database.
+/// @brief Represents information about a Kea server in the database.
 ///
 /// The configuration backend holds the information about the servers
 /// for which the backend holds the configuration information. The
@@ -33,14 +33,14 @@ public:
     /// @brief Constructor.
     ///
     /// @param tag server tag.
-    /// @param server description.
+    /// @param description server description.
     Server(const data::ServerTag& tag, const std::string& description);
 
     /// @brief Factory function to be used to create an instance of the
     /// @c Server object.
     ///
     /// @param tag server tag.
-    /// @param server description.
+    /// @param description server description.
     ///
     /// @return Pointer to the server instance.
     /// @throw BadValue if the server tag exceeds 256 characters or the
index 75e96b20b6644b97815f1b86cfd63d2e85c240f0..b9a4def5bd7a52eaa971d468ceebc178f5f30ed9 100644 (file)
@@ -37,9 +37,13 @@ TEST(ServerTest, tooLongDescription) {
 // Tests that it is possible to fetch server by tag fromn the collection.
 TEST(ServerFetcherTest, getByTag) {
     ServerCollection servers;
-    servers.insert(Server::create(ServerTag("alpha"), "alpha description"));
-    servers.insert(Server::create(ServerTag("beta"), "beta description"));
-    servers.insert(Server::create(ServerTag("gamma"), "gamma description"));
+
+    EXPECT_TRUE(servers.insert(Server::create(ServerTag("alpha"), "alpha description")).second);
+    EXPECT_TRUE(servers.insert(Server::create(ServerTag("beta"), "beta description")).second);
+    EXPECT_TRUE(servers.insert(Server::create(ServerTag("gamma"), "gamma description")).second);
+
+    // Inserting an element with duplicated server tag should be unsuccessful.
+    EXPECT_FALSE(servers.insert(Server::create(ServerTag("gamma"), "gamma 2 description")).second);
 
     auto alpha = ServerFetcher::get(servers, ServerTag("alpha"));
     ASSERT_TRUE(alpha);