From: Tomek Mrugalski Date: Tue, 10 Sep 2013 09:50:21 +0000 (+0200) Subject: [3145] Added negative test case for IAADDR option X-Git-Tag: bind10-1.2.0beta1-release~224^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f3591204bb394d7b2aa00508e99ec71a5720a8b;p=thirdparty%2Fkea.git [3145] Added negative test case for IAADDR option --- diff --git a/src/lib/dhcp/option6_iaaddr.cc b/src/lib/dhcp/option6_iaaddr.cc index d0ba0874c8..c45243011b 100644 --- a/src/lib/dhcp/option6_iaaddr.cc +++ b/src/lib/dhcp/option6_iaaddr.cc @@ -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, diff --git a/src/lib/dhcp/option6_iaaddr.h b/src/lib/dhcp/option6_iaaddr.h index cb85bed4d4..c188f8829e 100644 --- a/src/lib/dhcp/option6_iaaddr.h +++ b/src/lib/dhcp/option6_iaaddr.h @@ -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 diff --git a/src/lib/dhcp/tests/option6_iaaddr_unittest.cc b/src/lib/dhcp/tests/option6_iaaddr_unittest.cc index e28e2e0ed3..d2e6a156db 100644 --- a/src/lib/dhcp/tests/option6_iaaddr_unittest.cc +++ b/src/lib/dhcp/tests/option6_iaaddr_unittest.cc @@ -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); +} + }