Browse Source

[3382] A few more review changes.

Added unit tests for null DUIDs.
Minor nit fixes.
Thomas Markwalder 11 years ago
parent
commit
b7da638fdf

+ 1 - 1
src/lib/dhcpsrv/lease_mgr.h

@@ -122,7 +122,7 @@ public:
 /// see the documentation of those classes for details.
 class LeaseMgr {
 public:
-    /// @brief Defines maxiumum value for time that can be reliably stored.
+    /// @brief Defines maximum value for time that can be reliably stored.
     // If I'm still alive I'll be too old to care. You fix it.
     static const time_t MAX_DB_TIME;
 

+ 1 - 1
src/lib/dhcpsrv/pgsql_lease_mgr.h

@@ -99,7 +99,7 @@ struct PsqlBindArray {
     /// Converts the given boolean value to its corresponding to PostgreSQL
     /// string value and adds it as a TEXT_FMT value to the bind array.
     ///
-    /// @param value std::string containing the value to add.
+    /// @param value bool value to add.
     void add(const bool& value);
 
     /// @brief Dumps the contents of the array to a string.

+ 12 - 0
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc

@@ -1552,6 +1552,18 @@ GenericLeaseMgrTest::testRecreateLease6() {
     detailCompareLease(lease, l_returned);
 }
 
+void
+GenericLeaseMgrTest::testNullDuid() {
+    // Create leases, although we need only one.
+    vector<Lease6Ptr> leases = createLeases6();
+
+    // Set DUID to empty pointer.
+    leases[1]->duid_.reset();
+
+    // Insert should throw.
+    ASSERT_THROW(lmptr_->addLease(leases[1]), DbOperationError);
+}
+
 
 }; // namespace test
 }; // namespace dhcp

+ 3 - 0
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h

@@ -252,6 +252,9 @@ public:
     /// persistent storage has been updated as expected.
     void testRecreateLease6();
 
+    /// @brief Verifies that a null DUID is not allowed.
+    void testNullDuid();
+
     /// @brief String forms of IPv4 addresses
     std::vector<std::string>  straddress4_;
 

+ 10 - 0
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc

@@ -411,4 +411,14 @@ TEST_F(MemfileLeaseMgrTest, testRecreateLease6) {
 // testGetLease4HWAddrSubnetIdSize() - memfile just keeps Lease structure
 //     and does not do any checks of HWAddr content
 
+/// @brief Checks that null DUID is not allowed.
+/// Test is disabled as Memfile does not currently defend against a null DUID.
+TEST_F(MemfileLeaseMgrTest, DISABLED_nullDuid) {
+    // Create leases, although we need only one.
+    vector<Lease6Ptr> leases = createLeases6();
+
+    leases[1]->duid_.reset();
+    ASSERT_THROW(lmptr_->addLease(leases[1]), DbOperationError);
+}
+
 }; // end of anonymous namespace

+ 6 - 0
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc

@@ -516,4 +516,10 @@ TEST_F(MySqlLeaseMgrTest, testRecreateLease6) {
     testRecreateLease6();
 }
 
+/// @brief Checks that null DUID is not allowed.
+/// Test is disabled as MySqlLeaseMgr does not currently defend against a null DUID.
+TEST_F(MySqlLeaseMgrTest, DISABLED_nullDuid) {
+    testNullDuid();
+}
+
 }; // Of anonymous namespace

+ 4 - 0
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc

@@ -464,4 +464,8 @@ TEST_F(PgSqlLeaseMgrTest, updateLease6) {
     testUpdateLease6();
 }
 
+TEST_F(PgSqlLeaseMgrTest, nullDuid) {
+    testNullDuid();
+}
+
 };