|
@@ -24,15 +24,250 @@ namespace {
|
|
using namespace isc;
|
|
using namespace isc;
|
|
using namespace isc::dhcp;
|
|
using namespace isc::dhcp;
|
|
|
|
|
|
-class Option6ClientFqdnTest : public ::testing::Test {
|
|
|
|
-public:
|
|
|
|
|
|
+// Redefine option flags here as uint8_t. They will be used to initialize
|
|
|
|
+// elements of the arrays that are used in tests below. Note that use of
|
|
|
|
+// enum values defined in Option6ClientFqdn class may cause compilation issues
|
|
|
|
+// during uint8_t arrays initialization. That is because the underlying
|
|
|
|
+// integral type used to represent enums is larger than one byte.
|
|
|
|
+const uint8_t FLAG_S = 0x01;
|
|
|
|
+const uint8_t FLAG_O = 0x02;
|
|
|
|
+const uint8_t FLAG_N = 0x04;
|
|
|
|
+
|
|
|
|
+// This test verifies that constructor accepts empty partial domain-name but
|
|
|
|
+// does not accept empty fully qualified domain name.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructEmptyName) {
|
|
|
|
+ // Create an instance of the source option.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_S, "",
|
|
|
|
+ Option6ClientFqdn::PARTIAL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_TRUE(option->getDomainName().empty());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Constructor should not accept empty fully qualified domain name.
|
|
|
|
+ EXPECT_THROW(Option6ClientFqdn(Option6ClientFqdn::FLAG_S, "",
|
|
|
|
+ Option6ClientFqdn::FULL),
|
|
|
|
+ InvalidFqdnOptionDomainName);
|
|
|
|
+ // This check is similar to previous one, but using domain-name comprising
|
|
|
|
+ // a single space character. This should be treated as empty domain-name.
|
|
|
|
+ EXPECT_THROW(Option6ClientFqdn(Option6ClientFqdn::FLAG_S, " ",
|
|
|
|
+ Option6ClientFqdn::FULL),
|
|
|
|
+ InvalidFqdnOptionDomainName);
|
|
|
|
+
|
|
|
|
+ // Try different constructor.
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_O))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_TRUE(option->getDomainName().empty());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that copy constructor makes a copy of the option and
|
|
|
|
+// the source option instance can be deleted (both instances don't share
|
|
|
|
+// any resources).
|
|
|
|
+TEST(Option6ClientFqdnTest, copyConstruct) {
|
|
|
|
+ // Create an instance of the source option.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "myhost.example.com",
|
|
|
|
+ Option6ClientFqdn::FULL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ // Use copy constructor to create a second instance of the option.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option_copy;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option_copy.reset(new Option6ClientFqdn(*option))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option_copy);
|
|
|
|
+
|
|
|
|
+ // Copy construction should result in no shared resources between
|
|
|
|
+ // two objects. In particular, pointer to implementation should not
|
|
|
|
+ // be shared. Thus, we can release the source object now.
|
|
|
|
+ option.reset();
|
|
|
|
+
|
|
|
|
+ // Verify that all parameters have been copied to the target object.
|
|
|
|
+ EXPECT_TRUE(option_copy->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option_copy->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option_copy->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_EQ("myhost.example.com.", option_copy->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::FULL, option_copy->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Do another test with different parameters to verify that parameters
|
|
|
|
+ // change when copied object is changed.
|
|
|
|
+
|
|
|
|
+ // Create an option with different parameters.
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_O,
|
|
|
|
+ "example",
|
|
|
|
+ Option6ClientFqdn::PARTIAL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ // Call copy-constructor to copy the option.
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option_copy.reset(new Option6ClientFqdn(*option))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option_copy);
|
|
|
|
+
|
|
|
|
+ option.reset();
|
|
|
|
+
|
|
|
|
+ EXPECT_FALSE(option_copy->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_TRUE(option_copy->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option_copy->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_EQ("example", option_copy->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option_copy->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that the option in the on-wire format is parsed correctly.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructFromWire) {
|
|
|
|
+ const uint8_t in_data[] = {
|
|
|
|
+ FLAG_S, // flags
|
|
|
|
+ 6, 109, 121, 104, 111, 115, 116, // myhost.
|
|
|
|
+ 7, 101, 120, 97, 109, 112, 108, 101, // example.
|
|
|
|
+ 3, 99, 111, 109, 0 // com.
|
|
|
|
+ };
|
|
|
|
+ size_t in_data_size = sizeof(in_data) / sizeof(in_data[0]);
|
|
|
|
+ OptionBuffer in_buf(in_data, in_data + in_data_size);
|
|
|
|
+
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(in_buf.begin(), in_buf.end()))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_EQ("myhost.example.com.", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that truncated option is rejected.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructFromWireTruncated) {
|
|
|
|
+ // Empty buffer is invalid. It should be at least one octet long.
|
|
|
|
+ OptionBuffer in_buf;
|
|
|
|
+ ASSERT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
|
|
|
|
+ OutOfRange);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that the option in the on-wire format with partial
|
|
|
|
+// domain-name is parsed correctly.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructFromWirePartial) {
|
|
|
|
+ const uint8_t in_data[] = {
|
|
|
|
+ FLAG_N, // flags
|
|
|
|
+ 6, 109, 121, 104, 111, 115, 116 // myhost
|
|
|
|
+ };
|
|
|
|
+ size_t in_data_size = sizeof(in_data) / sizeof(in_data[0]);
|
|
|
|
+ OptionBuffer in_buf(in_data, in_data + in_data_size);
|
|
|
|
+
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(in_buf.begin(), in_buf.end()))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_EQ("myhost", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that the option in the on-wire format with empty
|
|
|
|
+// domain-name is parsed correctly.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructFromWireEmpty) {
|
|
|
|
+ OptionBuffer in_buf(FLAG_S);
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(in_buf.begin(), in_buf.end()))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
|
|
- Option6ClientFqdnTest() { }
|
|
|
|
|
|
+ // domain-name field should be empty because on-wire data comprised
|
|
|
|
+ // flags field only.
|
|
|
|
+ EXPECT_TRUE(option->getDomainName().empty());
|
|
|
|
+}
|
|
|
|
|
|
- virtual ~Option6ClientFqdnTest() { }
|
|
|
|
-};
|
|
|
|
|
|
+// This test verifies that assignment operator can be used to assign one
|
|
|
|
+// instance of the option to another.
|
|
|
|
+TEST(Option6ClientFqdnTest, assignment) {
|
|
|
|
+ // Usually the smart pointer is used to declare options and call
|
|
|
|
+ // constructor within assert. Thanks to this approach, the option instance
|
|
|
|
+ // is in the function scope and only initialization is done within assert.
|
|
|
|
+ // In this particular test we can't use smart pointers because we are
|
|
|
|
+ // testing assignment operator like this:
|
|
|
|
+ //
|
|
|
|
+ // option2 = option;
|
|
|
|
+ //
|
|
|
|
+ // The two asserts below do not create the instances that we will used to
|
|
|
|
+ // test assignment. They just attempt to create instances of the options
|
|
|
|
+ // with the same parameters as those that will be created for the actual
|
|
|
|
+ // assignment test. If these asserts do not fail, we can create options
|
|
|
|
+ // for the assignment test, do not surround them with asserts and be sure
|
|
|
|
+ // they will not throw.
|
|
|
|
+ ASSERT_NO_THROW(Option6ClientFqdn(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "myhost.example.com",
|
|
|
|
+ Option6ClientFqdn::FULL));
|
|
|
|
+
|
|
|
|
+ ASSERT_NO_THROW(Option6ClientFqdn(Option6ClientFqdn::FLAG_N,
|
|
|
|
+ "myhost",
|
|
|
|
+ Option6ClientFqdn::PARTIAL));
|
|
|
|
+
|
|
|
|
+ // Create options with the same parameters as tested above.
|
|
|
|
+
|
|
|
|
+ // Create first option.
|
|
|
|
+ Option6ClientFqdn option(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "myhost.example.com",
|
|
|
|
+ Option6ClientFqdn::FULL);
|
|
|
|
+
|
|
|
|
+ // Verify that the values have been set correctly.
|
|
|
|
+ ASSERT_TRUE(option.getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ ASSERT_FALSE(option.getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ ASSERT_FALSE(option.getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ ASSERT_EQ("myhost.example.com.", option.getDomainName());
|
|
|
|
+ ASSERT_EQ(Option6ClientFqdn::FULL, option.getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Create a second option.
|
|
|
|
+ Option6ClientFqdn option2(Option6ClientFqdn::FLAG_N,
|
|
|
|
+ "myhost",
|
|
|
|
+ Option6ClientFqdn::PARTIAL);
|
|
|
|
+
|
|
|
|
+ // Verify tha the values have been set correctly.
|
|
|
|
+ ASSERT_FALSE(option2.getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ ASSERT_FALSE(option2.getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ ASSERT_TRUE(option2.getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ ASSERT_EQ("myhost", option2.getDomainName());
|
|
|
|
+ ASSERT_EQ(Option6ClientFqdn::PARTIAL, option2.getDomainNameType());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // Make the assignment.
|
|
|
|
+ ASSERT_NO_THROW(option2 = option);
|
|
|
|
+
|
|
|
|
+ // Both options should now have the same values.
|
|
|
|
+ EXPECT_TRUE(option2.getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option2.getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_FALSE(option2.getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_EQ(option.getDomainName(), option2.getDomainName());
|
|
|
|
+ EXPECT_EQ(option.getDomainNameType(), option2.getDomainNameType());
|
|
|
|
+}
|
|
|
|
|
|
-TEST_F(Option6ClientFqdnTest, ctorInvalidFlags) {
|
|
|
|
|
|
+// This test verifies that constructor will throw an exception if invalid
|
|
|
|
+// DHCPv6 Client FQDN Option flags are specified.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructInvalidFlags) {
|
|
// First, check that constructor does not throw an exception when
|
|
// First, check that constructor does not throw an exception when
|
|
// valid flags values are provided. That way we eliminate the issue
|
|
// valid flags values are provided. That way we eliminate the issue
|
|
// that constructor always throws exception.
|
|
// that constructor always throws exception.
|
|
@@ -53,9 +288,24 @@ TEST_F(Option6ClientFqdnTest, ctorInvalidFlags) {
|
|
InvalidFqdnOptionFlags);
|
|
InvalidFqdnOptionFlags);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// This test verifies that constructor which parses option from on-wire format
|
|
|
|
+// will throw exception if parsed flags field is invalid.
|
|
|
|
+TEST(Option6ClientFqdnTest, constructFromWireInvalidFlags) {
|
|
|
|
+ // Create a buffer which holds flags field only. Set valid flag field at
|
|
|
|
+ // at first to make sure that constructor doesn't always throw an exception.
|
|
|
|
+ OptionBuffer in_buf(FLAG_N);
|
|
|
|
+ ASSERT_NO_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()));
|
|
|
|
+
|
|
|
|
+ // Replace the flags with invalid value and verify that constructor throws
|
|
|
|
+ // appropriate exception.
|
|
|
|
+ in_buf[0] = FLAG_N | FLAG_S;
|
|
|
|
+ EXPECT_THROW(Option6ClientFqdn(in_buf.begin(), in_buf.end()),
|
|
|
|
+ InvalidFqdnOptionFlags);
|
|
|
|
+}
|
|
|
|
+
|
|
// This test verifies that if invalid domain name is used the constructor
|
|
// This test verifies that if invalid domain name is used the constructor
|
|
// will throw appropriate exception.
|
|
// will throw appropriate exception.
|
|
-TEST_F(Option6ClientFqdnTest, ctorInvalidName) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, constructInvalidName) {
|
|
// First, check that constructor does not throw when valid domain name
|
|
// First, check that constructor does not throw when valid domain name
|
|
// is specified. That way we eliminate the possibility that constructor
|
|
// is specified. That way we eliminate the possibility that constructor
|
|
// always throws exception.
|
|
// always throws exception.
|
|
@@ -67,11 +317,11 @@ TEST_F(Option6ClientFqdnTest, ctorInvalidName) {
|
|
}
|
|
}
|
|
|
|
|
|
// This test verifies that getFlag throws an exception if flag value of 0x3
|
|
// This test verifies that getFlag throws an exception if flag value of 0x3
|
|
-// is specified.TThis test does not verify other invalid values, e.g. 0x5,
|
|
|
|
|
|
+// is specified.This test does not verify other invalid values, e.g. 0x5,
|
|
// 0x6 etc. because conversion of int values which do not belong to the range
|
|
// 0x6 etc. because conversion of int values which do not belong to the range
|
|
// between the lowest and highest enumerator will give an undefined
|
|
// between the lowest and highest enumerator will give an undefined
|
|
// result.
|
|
// result.
|
|
-TEST_F(Option6ClientFqdnTest, getFlag) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, getFlag) {
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
ASSERT_NO_THROW(
|
|
ASSERT_NO_THROW(
|
|
option.reset(new Option6ClientFqdn(0, "myhost.example.com"))
|
|
option.reset(new Option6ClientFqdn(0, "myhost.example.com"))
|
|
@@ -87,7 +337,7 @@ TEST_F(Option6ClientFqdnTest, getFlag) {
|
|
|
|
|
|
// This test verifies that flags can be modified and that incorrect flags
|
|
// This test verifies that flags can be modified and that incorrect flags
|
|
// are rejected.
|
|
// are rejected.
|
|
-TEST_F(Option6ClientFqdnTest, setFlag) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, setFlag) {
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
ASSERT_NO_THROW(
|
|
ASSERT_NO_THROW(
|
|
@@ -142,8 +392,61 @@ TEST_F(Option6ClientFqdnTest, setFlag) {
|
|
InvalidFqdnOptionFlags);
|
|
InvalidFqdnOptionFlags);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// This test verifies that current domain-name can be replaced with a new
|
|
|
|
+// domain-name.
|
|
|
|
+TEST(Option6ClientFqdnTest, setDomainName) {
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "myhost.example.com",
|
|
|
|
+ Option6ClientFqdn::FULL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ ASSERT_EQ("myhost.example.com.", option->getDomainName());
|
|
|
|
+ ASSERT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Partial domain-name.
|
|
|
|
+ ASSERT_NO_THROW(option->setDomainName("myhost",
|
|
|
|
+ Option6ClientFqdn::PARTIAL));
|
|
|
|
+ EXPECT_EQ("myhost", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Fully qualified domain-name.
|
|
|
|
+ ASSERT_NO_THROW(option->setDomainName("example.com",
|
|
|
|
+ Option6ClientFqdn::FULL));
|
|
|
|
+ EXPECT_EQ("example.com.", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Empty domain name (partial). This should be successful.
|
|
|
|
+ ASSERT_NO_THROW(option->setDomainName("", Option6ClientFqdn::PARTIAL));
|
|
|
|
+ EXPECT_TRUE(option->getDomainName().empty());
|
|
|
|
+
|
|
|
|
+ // Fully qualified domain-names must not be empty.
|
|
|
|
+ EXPECT_THROW(option->setDomainName("", Option6ClientFqdn::FULL),
|
|
|
|
+ InvalidFqdnOptionDomainName);
|
|
|
|
+ EXPECT_THROW(option->setDomainName(" ", Option6ClientFqdn::FULL),
|
|
|
|
+ InvalidFqdnOptionDomainName);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that current domain-name can be reset to empty one.
|
|
|
|
+TEST(Option6ClientFqdnTest, resetDomainName) {
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_S,
|
|
|
|
+ "myhost.example.com",
|
|
|
|
+ Option6ClientFqdn::FULL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ ASSERT_EQ("myhost.example.com.", option->getDomainName());
|
|
|
|
+ ASSERT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ // Set the domain-name to empty one.
|
|
|
|
+ ASSERT_NO_THROW(option->resetDomainName());
|
|
|
|
+ EXPECT_TRUE(option->getDomainName().empty());
|
|
|
|
+}
|
|
|
|
+
|
|
// This test verifies on-wire format of the option is correctly created.
|
|
// This test verifies on-wire format of the option is correctly created.
|
|
-TEST_F(Option6ClientFqdnTest, pack) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, pack) {
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
const uint8_t flags = Option6ClientFqdn::FLAG_S;
|
|
const uint8_t flags = Option6ClientFqdn::FLAG_S;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
@@ -159,7 +462,7 @@ TEST_F(Option6ClientFqdnTest, pack) {
|
|
// Prepare reference data.
|
|
// Prepare reference data.
|
|
const uint8_t ref_data[] = {
|
|
const uint8_t ref_data[] = {
|
|
0, 39, 0, 21, // header
|
|
0, 39, 0, 21, // header
|
|
- Option6ClientFqdn::FLAG_S, // flags
|
|
|
|
|
|
+ FLAG_S, // flags
|
|
6, 109, 121, 104, 111, 115, 116, // myhost.
|
|
6, 109, 121, 104, 111, 115, 116, // myhost.
|
|
7, 101, 120, 97, 109, 112, 108, 101, // example.
|
|
7, 101, 120, 97, 109, 112, 108, 101, // example.
|
|
3, 99, 111, 109, 0 // com.
|
|
3, 99, 111, 109, 0 // com.
|
|
@@ -174,7 +477,7 @@ TEST_F(Option6ClientFqdnTest, pack) {
|
|
|
|
|
|
// This test verifies on-wire format of the option with partial domain name
|
|
// This test verifies on-wire format of the option with partial domain name
|
|
// is correctly created.
|
|
// is correctly created.
|
|
-TEST_F(Option6ClientFqdnTest, packPartial) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, packPartial) {
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
const uint8_t flags = Option6ClientFqdn::FLAG_S;
|
|
const uint8_t flags = Option6ClientFqdn::FLAG_S;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
@@ -191,7 +494,7 @@ TEST_F(Option6ClientFqdnTest, packPartial) {
|
|
// Prepare reference data.
|
|
// Prepare reference data.
|
|
const uint8_t ref_data[] = {
|
|
const uint8_t ref_data[] = {
|
|
0, 39, 0, 8, // header
|
|
0, 39, 0, 8, // header
|
|
- Option6ClientFqdn::FLAG_S, // flags
|
|
|
|
|
|
+ FLAG_S, // flags
|
|
6, 109, 121, 104, 111, 115, 116 // myhost
|
|
6, 109, 121, 104, 111, 115, 116 // myhost
|
|
};
|
|
};
|
|
size_t ref_data_size = sizeof(ref_data) / sizeof(ref_data[0]);
|
|
size_t ref_data_size = sizeof(ref_data) / sizeof(ref_data[0]);
|
|
@@ -202,9 +505,143 @@ TEST_F(Option6ClientFqdnTest, packPartial) {
|
|
EXPECT_EQ(0, memcmp(ref_data, buf.getData(), buf.getLength()));
|
|
EXPECT_EQ(0, memcmp(ref_data, buf.getData(), buf.getLength()));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// This test verifies that on-wire option data holding fully qualified domain
|
|
|
|
+// name is parsed correctly.
|
|
|
|
+TEST(Option6ClientFqdnTest, unpack) {
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_O,
|
|
|
|
+ "myhost",
|
|
|
|
+ Option6ClientFqdn::PARTIAL))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ // Make sure that the parameters have been set correctly. Later in this
|
|
|
|
+ // test we will check that they will be replaced with new values when
|
|
|
|
+ // unpack is called.
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_EQ("myhost", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ const uint8_t in_data[] = {
|
|
|
|
+ FLAG_S, // flags
|
|
|
|
+ 6, 109, 121, 104, 111, 115, 116, // myhost.
|
|
|
|
+ 7, 101, 120, 97, 109, 112, 108, 101, // example.
|
|
|
|
+ 3, 99, 111, 109, 0 // com.
|
|
|
|
+ };
|
|
|
|
+ size_t in_data_size = sizeof(in_data) / sizeof(in_data[0]);
|
|
|
|
+ OptionBuffer in_buf(in_data, in_data + in_data_size);
|
|
|
|
+
|
|
|
|
+ // Initialize new values from the on-wire format.
|
|
|
|
+ ASSERT_NO_THROW(option->unpack(in_buf.begin(), in_buf.end()));
|
|
|
|
+
|
|
|
|
+ // Check that new values are correct.
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_EQ("myhost.example.com.", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that on-wire option data holding partial domain name
|
|
|
|
+// is parsed correctly.
|
|
|
|
+TEST(Option6ClientFqdnTest, unpackPartial) {
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_O,
|
|
|
|
+ "myhost.example.com"))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+ // Make sure that the parameters have been set correctly. Later in this
|
|
|
|
+ // test we will check that they will be replaced with new values when
|
|
|
|
+ // unpack is called.
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_EQ("myhost.example.com.", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::FULL, option->getDomainNameType());
|
|
|
|
+
|
|
|
|
+ const uint8_t in_data[] = {
|
|
|
|
+ FLAG_S, // flags
|
|
|
|
+ 6, 109, 121, 104, 111, 115, 116 // myhost
|
|
|
|
+ };
|
|
|
|
+ size_t in_data_size = sizeof(in_data) / sizeof(in_data[0]);
|
|
|
|
+ OptionBuffer in_buf(in_data, in_data + in_data_size);
|
|
|
|
+
|
|
|
|
+ // Initialize new values from the on-wire format.
|
|
|
|
+ ASSERT_NO_THROW(option->unpack(in_buf.begin(), in_buf.end()));
|
|
|
|
+
|
|
|
|
+ // Check that new values are correct.
|
|
|
|
+ EXPECT_TRUE(option->getFlag(Option6ClientFqdn::FLAG_S));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_N));
|
|
|
|
+ EXPECT_FALSE(option->getFlag(Option6ClientFqdn::FLAG_O));
|
|
|
|
+ EXPECT_EQ("myhost", option->getDomainName());
|
|
|
|
+ EXPECT_EQ(Option6ClientFqdn::PARTIAL, option->getDomainNameType());
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that the empty buffer is rejected when decoding an option
|
|
|
|
+// from on-wire format.
|
|
|
|
+TEST(Option6ClientFqdnTest, unpackTruncated) {
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(Option6ClientFqdn::FLAG_O))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ // Empty buffer is invalid. It should be at least 1 octet long.
|
|
|
|
+ OptionBuffer in_buf;
|
|
|
|
+ EXPECT_THROW(option->unpack(in_buf.begin(), in_buf.end()), OutOfRange);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// This test verifies that string representation of the option returned by
|
|
|
|
+// toText method is correctly formatted.
|
|
|
|
+TEST(Option6ClientFqdnTest, toText) {
|
|
|
|
+ // Create option instance. Check that constructor doesn't throw.
|
|
|
|
+ uint8_t flags = Option6ClientFqdn::FLAG_N | Option6ClientFqdn::FLAG_O;
|
|
|
|
+ boost::scoped_ptr<Option6ClientFqdn> option;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(flags,
|
|
|
|
+ "myhost.example.com"))
|
|
|
|
+ );
|
|
|
|
+ ASSERT_TRUE(option);
|
|
|
|
+
|
|
|
|
+ // The base indentation of the option will be set to 2. It should appear
|
|
|
|
+ // as follows.
|
|
|
|
+ std::string ref_string =
|
|
|
|
+ " type=39(CLIENT_FQDN)\n"
|
|
|
|
+ " flags:\n"
|
|
|
|
+ " N=1\n"
|
|
|
|
+ " O=1\n"
|
|
|
|
+ " S=0\n"
|
|
|
|
+ " domain-name='myhost.example.com.' (full)\n";
|
|
|
|
+ const int indent = 2;
|
|
|
|
+ EXPECT_EQ(ref_string, option->toText(indent));
|
|
|
|
+
|
|
|
|
+ // Create another option with different parameters:
|
|
|
|
+ // - flags set to 0
|
|
|
|
+ // - domain-name is now partial, not fully qualified
|
|
|
|
+ // Also, remove base indentation.
|
|
|
|
+ flags = 0;
|
|
|
|
+ ASSERT_NO_THROW(
|
|
|
|
+ option.reset(new Option6ClientFqdn(flags, "myhost",
|
|
|
|
+ Option6ClientFqdn::PARTIAL))
|
|
|
|
+ );
|
|
|
|
+ ref_string =
|
|
|
|
+ "type=39(CLIENT_FQDN)\n"
|
|
|
|
+ "flags:\n"
|
|
|
|
+ " N=0\n"
|
|
|
|
+ " O=0\n"
|
|
|
|
+ " S=0\n"
|
|
|
|
+ "domain-name='myhost' (partial)\n";
|
|
|
|
+ EXPECT_EQ(ref_string, option->toText());
|
|
|
|
+}
|
|
|
|
+
|
|
// This test verifies that the correct length of the option in on-wire
|
|
// This test verifies that the correct length of the option in on-wire
|
|
// format is returned.
|
|
// format is returned.
|
|
-TEST_F(Option6ClientFqdnTest, len) {
|
|
|
|
|
|
+TEST(Option6ClientFqdnTest, len) {
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
// Create option instance. Check that constructor doesn't throw.
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
boost::scoped_ptr<Option6ClientFqdn> option;
|
|
ASSERT_NO_THROW(
|
|
ASSERT_NO_THROW(
|