#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
#include <testutils/log_utils.h>
+#include <testutils/gtest_utils.h>
#include <util/chrono_time_utils.h>
#include <util/doubles.h>
EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError);
}
+// Verifies that simple list of valid classes parses and
+// is staged for commit.
+TEST_F(Dhcp4ParserTest, clientClassValidLifetime) {
+ string config = "{ " + genIfaceConfig() + "," +
+ "\"client-classes\" : [ \n"
+ " { \n"
+ " \"name\": \"one\", \n"
+ " \"min-valid-lifetime\": 1000, \n"
+ " \"valid-lifetime\": 2000, \n"
+ " \"max-valid-lifetime\": 3000 \n"
+ " }, \n"
+ " { \n"
+ " \"name\": \"two\" \n"
+ " } \n"
+ "], \n"
+ "\"subnet4\": [ { \n"
+ " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n"
+ " \"subnet\": \"192.0.2.0/24\" \n"
+ " } ] \n"
+ "} \n";
+
+ ConstElementPtr json;
+ ASSERT_NO_THROW_LOG(json = parseDHCP4(config));
+ extractConfig(config);
+
+ ConstElementPtr status;
+ ASSERT_NO_THROW_LOG(status = configureDhcp4Server(*srv_, json));
+ ASSERT_TRUE(status);
+ checkResult(status, 0);
+
+ // We check staging config because CfgMgr::commit hasn't been executed.
+ ClientClassDictionaryPtr dictionary;
+ dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary();
+ ASSERT_TRUE(dictionary);
+ EXPECT_EQ(2, dictionary->getClasses()->size());
+
+ // Execute the commit
+ ASSERT_NO_THROW(CfgMgr::instance().commit());
+
+ // Verify that after commit, the current config has the correct dictionary
+ dictionary = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary();
+ ASSERT_TRUE(dictionary);
+ EXPECT_EQ(2, dictionary->getClasses()->size());
+
+ ClientClassDefPtr class_def = dictionary->findClass("one");
+ ASSERT_TRUE(class_def);
+ EXPECT_EQ(class_def->getValid().getMin(), 1000);
+ EXPECT_EQ(class_def->getValid().get(), 2000);
+ EXPECT_EQ(class_def->getValid().getMax(), 3000);
+
+ class_def = dictionary->findClass("two");
+ ASSERT_TRUE(class_def);
+ EXPECT_TRUE(class_def->getValid().unspecified());
+
+}
+
+
// Test verifies that regular configuration does not provide any user context
// in the address pool.
TEST_F(Dhcp4ParserTest, poolUserContextMissing) {
ClientClassDefPtr class_def;
ASSERT_NO_THROW_LOG(class_def = parseClientClassDef(oss.str(), AF_INET));
ASSERT_TRUE(class_def);
- EXPECT_EQ(class_def->getValid(), scenario.exp_triplet_);
+ if (scenario.exp_triplet_.unspecified()) {
+ EXPECT_TRUE(class_def->getValid().unspecified());
+ } else {
+ EXPECT_EQ(class_def->getValid(), scenario.exp_triplet_);
+ EXPECT_EQ(class_def->getValid().getMin(), scenario.exp_triplet_.getMin());
+ EXPECT_EQ(class_def->getValid().get(), scenario.exp_triplet_.get());
+ EXPECT_EQ(class_def->getValid().getMax(), scenario.exp_triplet_.getMax());
+ }
}
}
}