diff options
author | Thomas Markwalder <tmark@isc.org> | 2023-02-09 22:21:37 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2023-02-09 22:26:45 +0100 |
commit | 9f1374d4a04166c9cf4ab55acc07860724a81796 (patch) | |
tree | 0f12375663a6f4601cf19ed65af6f9748558e382 /src | |
parent | [#2538] Addressed more comments (diff) | |
download | kea-9f1374d4a04166c9cf4ab55acc07860724a81796.tar.xz kea-9f1374d4a04166c9cf4ab55acc07860724a81796.zip |
[#2538] Fix UTs
Restored detection in encapsulateInternal() to avoid
throws in UTs
modified:
src/lib/dhcpsrv/cfg_option.cc
src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/dhcpsrv/cfg_option.cc | 5 | ||||
-rw-r--r-- | src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc | 27 |
2 files changed, 19 insertions, 13 deletions
diff --git a/src/lib/dhcpsrv/cfg_option.cc b/src/lib/dhcpsrv/cfg_option.cc index de1378586e..ba88b0081a 100644 --- a/src/lib/dhcpsrv/cfg_option.cc +++ b/src/lib/dhcpsrv/cfg_option.cc @@ -270,6 +270,11 @@ CfgOption::encapsulateInternal(const OptionPtr& option) { // Retrieve all options from the encapsulated option space. OptionContainerPtr encap_options = getAll(encap_space); for (auto const& encap_opt : *encap_options) { + if (option.get() == encap_opt.option_.get()) { + // Avoid recursion by not adding options to themselves. + continue; + } + // Add sub-option if there isn't one added already. if (!option->getOption(encap_opt.option_->getType())) { option->addOption(encap_opt.option_); diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index ab377da597..409dbd0dc7 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -3401,19 +3401,20 @@ TEST_F(ParseConfigTest, selfEncapsulationTest) { // Verify that the configuration string parses. family_ = AF_INET6; - ElementPtr json = Element::fromJSON(config); - EXPECT_TRUE(json); - ConstElementPtr status = parseElementSet(json, false); - int rcode = 0; - ConstElementPtr comment = parseAnswer(rcode, status); - ASSERT_TRUE(comment); - ASSERT_EQ(comment->getType(), Element::string); - EXPECT_EQ(1, rcode); - std::string expected = - "Configuration parsing failed: " - "option cannot be added to itself: type=00045, len=00015:" - ",\noptions:\n type=00001, len=00011: 01:02:02:02:02:03:03:03:03:03:03"; - EXPECT_EQ(expected, comment->stringValue()); + int rcode = parseConfiguration(config, true, true); + ASSERT_EQ(0, rcode); + + // Verify that the option can be retrieved. + OptionCustomPtr opt = boost::dynamic_pointer_cast<OptionCustom> + (getOptionPtr(DHCP6_OPTION_SPACE, D6O_CLIENT_DATA)); + ASSERT_TRUE(opt); + + // Verify length is correct and doesn't infinitely recurse. + EXPECT_EQ(19, opt->len()); + + // Check if it can be unparsed. + CfgOptionsTest cfg(CfgMgr::instance().getStagingCfg()); + cfg.runCfgOptionsTest(family_, config); } } // Anonymous namespace |