From: Francis Dupont Date: Sun, 31 Dec 2017 09:28:48 +0000 (+0100) Subject: [5351] Finished merge of trac5452 (unparse subnets) X-Git-Tag: trac5494_base~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c24d057bed2692eaf3cdb6af889122eb582ffede;p=thirdparty%2Fkea.git [5351] Finished merge of trac5452 (unparse subnets) --- c24d057bed2692eaf3cdb6af889122eb582ffede diff --cc src/lib/dhcpsrv/tests/host_unittest.cc index bc17bb13f4,df9501da3e..d3603fbae7 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@@ -1031,164 -1010,9 +1031,164 @@@ TEST_F(HostTest, toText) host->toText()); } +// This test checks that Host object is correctly unparsed, +TEST_F(HostTest, unparse) { + boost::scoped_ptr host; + ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address", + SubnetID(1), SubnetID(2), + IOAddress("192.0.2.3"), + "myhost.example.com"))); + + // Add 4 reservations: 2 for NAs, 2 for PDs. + ASSERT_NO_THROW( + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, + IOAddress("2001:db8:1::cafe"))); + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, + IOAddress("2001:db8:1:1::"), 64)); + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_PD, + IOAddress("2001:db8:1:2::"), 64)); + host->addReservation(IPv6Resrv(IPv6Resrv::TYPE_NA, + IOAddress("2001:db8:1::1"))); + ); + + // Add user context + std::string user_context = "{ \"comment\": \"a host reservation\" }"; + host->setContext(Element::fromJSON(user_context)); + + // Make sure that the output is correct, + EXPECT_EQ("{ " + "\"boot-file-name\": \"\", " + "\"client-classes\": [ ], " + "\"comment\": \"a host reservation\", " + "\"hostname\": \"myhost.example.com\", " + "\"hw-address\": \"01:02:03:04:05:06\", " + "\"ip-address\": \"192.0.2.3\", " + "\"next-server\": \"0.0.0.0\", " + "\"option-data\": [ ], " + "\"server-hostname\": \"\" " + "}", + host->toElement4()->str()); + + EXPECT_EQ("{ " + "\"client-classes\": [ ], " + "\"comment\": \"a host reservation\", " + "\"hostname\": \"myhost.example.com\", " + "\"hw-address\": \"01:02:03:04:05:06\", " + "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], " + "\"option-data\": [ ], " + "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] " + "}", + host->toElement6()->str()); + + // Reset some of the data and make sure that the output is affected. + host->setHostname(""); + host->removeIPv4Reservation(); + host->setIPv4SubnetID(0); + + EXPECT_EQ("{ " + "\"boot-file-name\": \"\", " + "\"client-classes\": [ ], " + "\"comment\": \"a host reservation\", " + "\"hostname\": \"\", " + "\"hw-address\": \"01:02:03:04:05:06\", " + "\"next-server\": \"0.0.0.0\", " + "\"option-data\": [ ], " + "\"server-hostname\": \"\" " + "}", + host->toElement4()->str()); + + EXPECT_EQ("{ " + "\"client-classes\": [ ], " + "\"comment\": \"a host reservation\", " + "\"hostname\": \"\", " + "\"hw-address\": \"01:02:03:04:05:06\", " + "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], " + "\"option-data\": [ ], " + "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] " + "}", + host->toElement6()->str()); + + // Create host identified by DUID, instead of HWADDR, with a very + // basic configuration. + ASSERT_NO_THROW(host.reset(new Host("11:12:13:14:15", "duid", + SubnetID(0), SubnetID(0), + IOAddress::IPV4_ZERO_ADDRESS(), + "myhost"))); + + EXPECT_EQ("{ " + "\"boot-file-name\": \"\", " + "\"client-classes\": [ ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"next-server\": \"0.0.0.0\", " + "\"option-data\": [ ], " + "\"server-hostname\": \"\" " + "}", + host->toElement4()->str()); + + EXPECT_EQ("{ " + "\"client-classes\": [ ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"ip-addresses\": [ ], " + "\"option-data\": [ ], " + "\"prefixes\": [ ] " + "}", + host->toElement6()->str()); + + // Add some classes. + host->addClientClass4("modem"); + host->addClientClass4("router"); + + EXPECT_EQ("{ " + "\"boot-file-name\": \"\", " + "\"client-classes\": [ \"modem\", \"router\" ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"next-server\": \"0.0.0.0\", " + "\"option-data\": [ ], " + "\"server-hostname\": \"\" " + "}", + host->toElement4()->str()); + + EXPECT_EQ("{ " + "\"client-classes\": [ ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"ip-addresses\": [ ], " + "\"option-data\": [ ], " + "\"prefixes\": [ ] " + "}", + host->toElement6()->str()); + + host->addClientClass6("hub"); + host->addClientClass6("device"); + + EXPECT_EQ("{ " + "\"boot-file-name\": \"\", " + "\"client-classes\": [ \"modem\", \"router\" ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"next-server\": \"0.0.0.0\", " + "\"option-data\": [ ], " + "\"server-hostname\": \"\" " + "}", + host->toElement4()->str()); + + EXPECT_EQ("{ " + "\"client-classes\": [ \"device\", \"hub\" ], " + "\"duid\": \"11:12:13:14:15\", " + "\"hostname\": \"myhost\", " + "\"ip-addresses\": [ ], " + "\"option-data\": [ ], " + "\"prefixes\": [ ] " + "}", + host->toElement6()->str()); +} + // Test verifies if the host can store HostId properly. TEST_F(HostTest, hostId) { - boost::scoped_ptr host; + HostPtr host; ASSERT_NO_THROW(host.reset(new Host("01:02:03:04:05:06", "hw-address", SubnetID(1), SubnetID(2), IOAddress("192.0.2.3"),