]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5058] Added unit test to check loading declined leases from CSV file
authorThomas Markwalder <tmark@isc.org>
Fri, 28 Oct 2016 15:46:43 +0000 (11:46 -0400)
committerThomas Markwalder <tmark@isc.org>
Fri, 28 Oct 2016 15:46:43 +0000 (11:46 -0400)
src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc
    TEST_F(CSVLeaseFile4Test, declinedLeaseTest) - new test

src/lib/dhcpsrv/tests/csv_lease_file4_unittest.cc

index dfd294b07459e4584845c4debce5e2b89f02d41a..7b575a5784fe766ec18ccc3bf5ce99cb75f9ccb4 100644 (file)
@@ -385,6 +385,36 @@ TEST_F(CSVLeaseFile4Test, downGrade) {
     }
 }
 
+// Verifies that leases with no hardware address or only permitted
+// if they are in the declined state.
+TEST_F(CSVLeaseFile4Test, declinedLeaseTest) {
+    io_.writeFile("address,hwaddr,client_id,valid_lifetime,expire,subnet_id,"
+                  "fqdn_fwd,fqdn_rev,hostname,state\n"
+                  "192.0.2.1,,,200,200,8,1,1,host.example.com,0\n"
+                  "192.0.2.1,,,200,200,8,1,1,host.example.com,1\n");
+
+    // Lease file should open and report as needing downgrade.
+    CSVLeaseFile4 lf(filename_);
+    ASSERT_NO_THROW(lf.open());
+    EXPECT_FALSE(lf.needsConversion());
+    EXPECT_EQ(util::VersionedCSVFile::CURRENT,
+              lf.getInputSchemaState());
+    Lease4Ptr lease;
+
+    {
+    SCOPED_TRACE("No hardware and not declined, invalid");
+    EXPECT_FALSE(lf.next(lease));
+    ASSERT_FALSE(lease);
+    EXPECT_EQ(lf.getReadErrs(),1);
+    }
+
+    {
+    SCOPED_TRACE("No hardware and declined, valid");
+    EXPECT_TRUE(lf.next(lease));
+    ASSERT_TRUE(lease);
+    EXPECT_EQ(lf.getReadErrs(),1);
+    }
+}
 
 /// @todo Currently we don't check invalid lease attributes, such as invalid
 /// lease type, invalid preferred lifetime vs valid lifetime etc. The Lease6