|
@@ -9,6 +9,7 @@
|
|
|
#include <dhcp/duid.h>
|
|
|
#include <dhcpsrv/lease.h>
|
|
|
#include <util/pointer_util.h>
|
|
|
+#include <cc/data.h>
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <vector>
|
|
|
#include <sstream>
|
|
@@ -16,6 +17,7 @@
|
|
|
using namespace isc;
|
|
|
using namespace isc::asiolink;
|
|
|
using namespace isc::dhcp;
|
|
|
+using namespace isc::data;
|
|
|
|
|
|
namespace {
|
|
|
|
|
@@ -423,6 +425,56 @@ TEST_F(Lease4Test, toText) {
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
}
|
|
|
|
|
|
+// Verify that Lease4 structure can be converted to JSON properly.
|
|
|
+TEST_F(Lease4Test, toElement) {
|
|
|
+
|
|
|
+ const time_t current_time = 12345678;
|
|
|
+ Lease4 lease(IOAddress("192.0.2.3"), hwaddr_, clientid_, 3600, 123,
|
|
|
+ 456, current_time, 789, true, true, "urania.example.org");
|
|
|
+
|
|
|
+ ElementPtr l = lease.toElement();
|
|
|
+
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("ip-address"));
|
|
|
+ EXPECT_EQ("192.0.2.3", l->get("ip-address")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("valid-lft"));
|
|
|
+ EXPECT_EQ(3600, l->get("valid-lft")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("cltt"));
|
|
|
+ EXPECT_EQ(current_time, l->get("cltt")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("hw-address"));
|
|
|
+ EXPECT_EQ(hwaddr_->toText(false), l->get("hw-address")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("client-id"));
|
|
|
+ EXPECT_EQ(clientid_->toText(), l->get("client-id")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("subnet-id"));
|
|
|
+ EXPECT_EQ(789, l->get("subnet-id")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("state"));
|
|
|
+ EXPECT_EQ(static_cast<int>(Lease::STATE_DEFAULT), l->get("state")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("fqdn-fwd"));
|
|
|
+ EXPECT_TRUE(l->get("fqdn-fwd")->boolValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("fqdn-rev"));
|
|
|
+ EXPECT_TRUE(l->get("fqdn-rev")->boolValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("hostname"));
|
|
|
+ EXPECT_EQ("urania.example.org", l->get("hostname")->stringValue());
|
|
|
+
|
|
|
+ // Now let's try with a lease without client-id.
|
|
|
+ lease.client_id_.reset();
|
|
|
+
|
|
|
+ l = lease.toElement();
|
|
|
+
|
|
|
+ EXPECT_FALSE(l->contains("client-id"));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// Verify that decline() method properly clears up specific fields.
|
|
|
TEST_F(Lease4Test, decline) {
|
|
|
|
|
@@ -803,7 +855,7 @@ TEST(Lease6Test, hasIdenticalFqdn) {
|
|
|
false, false)));
|
|
|
}
|
|
|
|
|
|
-// Verify that toText() method reports Lease4 structure properly.
|
|
|
+// Verify that toText() method reports Lease6 structure properly.
|
|
|
TEST(Lease6Test, toText) {
|
|
|
|
|
|
HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
@@ -848,6 +900,71 @@ TEST(Lease6Test, toText) {
|
|
|
EXPECT_EQ(expected.str(), lease.toText());
|
|
|
}
|
|
|
|
|
|
+// Verify that Lease6 structure can be converted to JSON properly.
|
|
|
+TEST(Lease6Test, toElement) {
|
|
|
+
|
|
|
+ HWAddrPtr hwaddr(new HWAddr(HWADDR, sizeof(HWADDR), HTYPE_ETHER));
|
|
|
+
|
|
|
+ uint8_t llt[] = {0, 1, 2, 3, 4, 5, 6, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
|
|
|
+ DuidPtr duid(new DUID(llt, sizeof(llt)));
|
|
|
+
|
|
|
+ Lease6 lease(Lease::TYPE_NA, IOAddress("2001:db8::1"), duid, 123456,
|
|
|
+ 400, 800, 100, 200, 5678, hwaddr, 128);
|
|
|
+ lease.cltt_ = 12345678;
|
|
|
+ lease.state_ = Lease::STATE_DECLINED;
|
|
|
+ lease.hostname_ = "urania.example.org";
|
|
|
+
|
|
|
+ ElementPtr l = lease.toElement();
|
|
|
+
|
|
|
+ ASSERT_TRUE(l);
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("ip-address"));
|
|
|
+ EXPECT_EQ("2001:db8::1", l->get("ip-address")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("type"));
|
|
|
+ EXPECT_EQ("IA_NA", l->get("type")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("prefix-len"));
|
|
|
+ EXPECT_EQ(128, l->get("prefix-len")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("iaid"));
|
|
|
+ EXPECT_EQ(123456, l->get("iaid")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("preferred-lft"));
|
|
|
+ EXPECT_EQ(400, l->get("preferred-lft")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("valid-lft"));
|
|
|
+ EXPECT_EQ(800, l->get("valid-lft")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("duid"));
|
|
|
+ EXPECT_EQ("00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f",
|
|
|
+ l->get("duid")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("hw-address"));
|
|
|
+ EXPECT_EQ(hwaddr->toText(false), l->get("hw-address")->stringValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("subnet-id"));
|
|
|
+ EXPECT_EQ(5678, l->get("subnet-id")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("state"));
|
|
|
+ EXPECT_EQ(static_cast<int>(Lease::STATE_DECLINED),
|
|
|
+ l->get("state")->intValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("fqdn-fwd"));
|
|
|
+ EXPECT_FALSE(l->get("fqdn-fwd")->boolValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("fqdn-rev"));
|
|
|
+ EXPECT_FALSE(l->get("fqdn-rev")->boolValue());
|
|
|
+
|
|
|
+ ASSERT_TRUE(l->contains("hostname"));
|
|
|
+ EXPECT_EQ("urania.example.org", l->get("hostname")->stringValue());
|
|
|
+
|
|
|
+ // Now let's try with a lease without hardware address.
|
|
|
+ lease.hwaddr_.reset();
|
|
|
+ l = lease.toElement();
|
|
|
+ EXPECT_FALSE(l->contains("hw-address"));
|
|
|
+}
|
|
|
+
|
|
|
// Verify that the lease states are correctly returned in the textual format.
|
|
|
TEST(Lease6Test, stateToText) {
|
|
|
EXPECT_EQ("default", Lease6::statesToText(Lease::STATE_DEFAULT));
|