]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3145] Added negative test case for IAADDR option
authorTomek Mrugalski <tomasz@isc.org>
Tue, 10 Sep 2013 09:50:21 +0000 (11:50 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 10 Sep 2013 09:50:21 +0000 (11:50 +0200)
src/lib/dhcp/option6_iaaddr.cc
src/lib/dhcp/option6_iaaddr.h
src/lib/dhcp/tests/option6_iaaddr_unittest.cc

index d0ba0874c8daae6f3f85916b20a09ed49a252055..c45243011bf1c241bec5283c019e0a8731811e05 100644 (file)
@@ -35,6 +35,9 @@ Option6IAAddr::Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr
                              uint32_t pref, uint32_t valid)
     :Option(V6, type), addr_(addr), preferred_(pref),
      valid_(valid) {
+    if (!addr.isV6()) {
+        isc_throw(isc::BadValue, addr_.toText() << " is not an IPv6 address");
+    }
 }
 
 Option6IAAddr::Option6IAAddr(uint32_t type, OptionBuffer::const_iterator begin,
index cb85bed4d4e057f9974230c58c574499be85ab68..c188f8829e6ffa6b2eaacb316d141e913bd27400 100644 (file)
@@ -33,7 +33,9 @@ public:
     /// length of the fixed part of the IAADDR option
     static const size_t OPTION6_IAADDR_LEN = 24;
 
-    /// @brief Ctor, used for options constructed (during transmission).
+    /// @brief Constructor, used for options constructed (during transmission).
+    ///
+    /// @throw BadValue if specified addr is not IPv6
     ///
     /// @param type option type
     /// @param addr reference to an address
@@ -42,7 +44,9 @@ public:
     Option6IAAddr(uint16_t type, const isc::asiolink::IOAddress& addr,
                   uint32_t preferred, uint32_t valid);
 
-    /// @brief ctor, used for received options.
+    /// @brief Constructor, used for received options.
+    ///
+    /// @throw OutOfRange if specified option is truncated
     ///
     /// @param type option type
     /// @param begin iterator to first byte of option data
index e28e2e0ed346cd85a6514e7063f1793a247694da..d2e6a156db334a551326c85babf10c4874cad742 100644 (file)
@@ -106,4 +106,19 @@ TEST_F(Option6IAAddrTest, basic) {
     EXPECT_NO_THROW(opt.reset());
 }
 
+/// @todo: Write test for (type, addr, pref, valid) constructor
+/// See option6_iaprefix_unittest.cc for similar test
+
+// Tests if broken usage causes exception to be thrown
+TEST_F(Option6IAAddrTest, negative) {
+
+    // Too short. Minimum length is 24
+    EXPECT_THROW(Option6IAAddr(D6O_IAADDR, buf_.begin(), buf_.begin() + 23),
+                 OutOfRange);
+
+    // This option is for IPv6 addresses only
+    EXPECT_THROW(Option6IAAddr(D6O_IAADDR, isc::asiolink::IOAddress("192.0.2.1"),
+                               1000, 2000), BadValue);
+}
+
 }