BIND 10 trac2522, updated. 4daf58b65f126c84a0d68d102ad899e260ea5662 [2522] convert TSIG string constructor tests to checkFromText
BIND 10 source code commits
bind10-changes at lists.isc.org
Wed May 8 03:58:46 UTC 2013
The branch, trac2522 has been updated
via 4daf58b65f126c84a0d68d102ad899e260ea5662 (commit)
via 20a8d4adbdcc32b17fabc43ef1e6af4c4b7c67d2 (commit)
from fc2a9e9876510fd425d693aaa5b93230606d26ec (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 4daf58b65f126c84a0d68d102ad899e260ea5662
Author: Paul Selkirk <pselkirk at isc.org>
Date: Tue May 7 23:58:42 2013 -0400
[2522] convert TSIG string constructor tests to checkFromText
commit 20a8d4adbdcc32b17fabc43ef1e6af4c4b7c67d2
Author: Paul Selkirk <pselkirk at isc.org>
Date: Tue May 7 22:13:22 2013 -0400
[2522] more TSIG unit tests
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/rdata/any_255/tsig_250.cc | 8 +--
src/lib/dns/tests/rdata_tsig_unittest.cc | 91 ++++++++++++++++++++----------
2 files changed, 66 insertions(+), 33 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/rdata/any_255/tsig_250.cc b/src/lib/dns/rdata/any_255/tsig_250.cc
index 8253807..0a45f4f 100644
--- a/src/lib/dns/rdata/any_255/tsig_250.cc
+++ b/src/lib/dns/rdata/any_255/tsig_250.cc
@@ -88,15 +88,15 @@ TSIG::constructFromLexer(MasterLexer& lexer) {
} catch (const boost::bad_lexical_cast&) {
isc_throw(InvalidRdataText, "Invalid TSIG Time");
}
- if (time_signed > 0xffffffffffff) {
+ if ((time_signed >> 48) != 0) {
isc_throw(InvalidRdataText, "TSIG Time out of range");
}
- const int32_t fudge = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+ const uint32_t fudge = lexer.getNextToken(MasterToken::NUMBER).getNumber();
if (fudge > 0xffff) {
isc_throw(InvalidRdataText, "TSIG Fudge out of range");
}
- const int32_t macsize = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+ const uint32_t macsize = lexer.getNextToken(MasterToken::NUMBER).getNumber();
if (macsize > 0xffff) {
isc_throw(InvalidRdataText, "TSIG MAC Size out of range");
}
@@ -109,7 +109,7 @@ TSIG::constructFromLexer(MasterLexer& lexer) {
isc_throw(InvalidRdataText, "TSIG MAC Size and data are inconsistent");
}
- const int32_t orig_id = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+ const uint32_t orig_id = lexer.getNextToken(MasterToken::NUMBER).getNumber();
if (orig_id > 0xffff) {
isc_throw(InvalidRdataText, "TSIG Original ID out of range");
}
diff --git a/src/lib/dns/tests/rdata_tsig_unittest.cc b/src/lib/dns/tests/rdata_tsig_unittest.cc
index 0982624..b73c4dd 100644
--- a/src/lib/dns/tests/rdata_tsig_unittest.cc
+++ b/src/lib/dns/tests/rdata_tsig_unittest.cc
@@ -32,16 +32,11 @@
using isc::UnitTestUtil;
using namespace std;
+using namespace isc;
using namespace isc::dns;
using namespace isc::util;
using namespace isc::dns::rdata;
-namespace {
-class Rdata_TSIG_Test : public RdataTest {
-protected:
- vector<uint8_t> expect_data;
-};
-
const char* const valid_text1 = "hmac-md5.sig-alg.reg.int. 1286779327 300 "
"0 16020 BADKEY 0";
const char* const valid_text2 = "hmac-sha256. 1286779327 300 12 "
@@ -59,7 +54,39 @@ const char* const too_long_label = "012345678901234567890123456789"
// commonly used test RDATA
const any::TSIG rdata_tsig((string(valid_text1)));
-TEST_F(Rdata_TSIG_Test, createFromText) {
+namespace {
+class Rdata_TSIG_Test : public RdataTest {
+protected:
+ void checkFromText_InvalidText(const string& rdata_str) {
+ checkFromText<any::TSIG, InvalidRdataText, InvalidRdataText>(
+ rdata_str, rdata_tsig, true, true);
+ }
+
+ void checkFromText_BadValue(const string& rdata_str) {
+ checkFromText<any::TSIG, BadValue, BadValue>(
+ rdata_str, rdata_tsig, true, true);
+ }
+
+ void checkFromText_LexerError(const string& rdata_str) {
+ checkFromText
+ <any::TSIG, InvalidRdataText, MasterLexer::LexerError>(
+ rdata_str, rdata_tsig, true, true);
+ }
+
+ void checkFromText_TooLongLabel(const string& rdata_str) {
+ checkFromText<any::TSIG, TooLongLabel, TooLongLabel>(
+ rdata_str, rdata_tsig, true, true);
+ }
+
+ void checkFromText_EmptyLabel(const string& rdata_str) {
+ checkFromText<any::TSIG, EmptyLabel, EmptyLabel>(
+ rdata_str, rdata_tsig, true, true);
+ }
+
+ vector<uint8_t> expect_data;
+};
+
+TEST_F(Rdata_TSIG_Test, fromText) {
// normal case. it also tests getter methods.
EXPECT_EQ(Name("hmac-md5.sig-alg.reg.int"), rdata_tsig.getAlgorithm());
EXPECT_EQ(1286779327, rdata_tsig.getTimeSigned());
@@ -84,42 +111,48 @@ TEST_F(Rdata_TSIG_Test, createFromText) {
// numeric representation of TSIG error
any::TSIG tsig5((string(valid_text5)));
EXPECT_EQ(2845, tsig5.getError());
+}
- //
- // invalid cases
- //
- // there's a garbage parameter at the end
+TEST_F(Rdata_TSIG_Test, badText) {
+ // too many fields
EXPECT_THROW(any::TSIG("foo 0 0 0 0 BADKEY 0 0"), InvalidRdataText);
- // input is too short
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 BADKEY"), InvalidRdataText);
+ // not enough fields
+ checkFromText_LexerError("foo 0 0 0 0 BADKEY");
// bad domain name
- EXPECT_THROW(any::TSIG(string(too_long_label) + "0 0 0 0 BADKEY 0"),
- TooLongLabel);
+ checkFromText_TooLongLabel(string(too_long_label) + "0 0 0 0 BADKEY 0");
+ checkFromText_EmptyLabel("foo..bar 0 0 0 0 BADKEY");
// time is too large (2814...6 is 2^48)
- EXPECT_THROW(any::TSIG("foo 281474976710656 0 0 0 BADKEY 0"),
- InvalidRdataText);
+ checkFromText_InvalidText("foo 281474976710656 0 0 0 BADKEY 0");
// invalid time (negative)
- EXPECT_THROW(any::TSIG("foo -1 0 0 0 BADKEY 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo -1 0 0 0 BADKEY 0");
+ // invalid time (not a number)
+ checkFromText_InvalidText("foo TIME 0 0 0 BADKEY 0");
// fudge is too large
- EXPECT_THROW(any::TSIG("foo 0 65536 0 0 BADKEY 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 65536 0 0 BADKEY 0");
// invalid fudge (negative)
- EXPECT_THROW(any::TSIG("foo 0 -1 0 0 BADKEY 0"), InvalidRdataText);
+ checkFromText_LexerError("foo 0 -1 0 0 BADKEY 0");
+ // invalid fudge (not a number)
+ checkFromText_LexerError("foo 0 FUDGE 0 0 BADKEY 0");
// MAC size is too large
- EXPECT_THROW(any::TSIG("foo 0 0 65536 0 BADKEY 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 65536 0 BADKEY 0");
+ // invalide MAC size (negative)
+ checkFromText_LexerError("foo 0 0 -1 0 BADKEY 0");
+ // invalid MAC size (not a number)
+ checkFromText_LexerError("foo 0 0 MACSIZE 0 BADKEY 0");
// MAC size and MAC mismatch
- EXPECT_THROW(any::TSIG("foo 0 0 9 FAKE 0 BADKEY 0"), InvalidRdataText);
- EXPECT_THROW(any::TSIG("foo 0 0 0 FAKE 0 BADKEY 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 9 FAKE 0 BADKEY 0");
// MAC is bad base64
- EXPECT_THROW(any::TSIG("foo 0 0 3 FAK= 0 BADKEY 0"), isc::BadValue);
+ checkFromText_BadValue("foo 0 0 3 FAK= 0 BADKEY 0");
// Unknown error code
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 TEST 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 0 0 TEST 0");
// Numeric error code is too large
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 65536 0"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 0 0 65536 0");
// Other len is too large
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 NOERROR 65536 FAKE"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 0 0 NOERROR 65536 FAKE");
+ // invalid Other len
+ checkFromText_LexerError("foo 0 0 0 0 NOERROR LEN FAKE");
// Other len and data mismatch
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 NOERROR 9 FAKE"), InvalidRdataText);
- EXPECT_THROW(any::TSIG("foo 0 0 0 0 NOERROR 0 FAKE"), InvalidRdataText);
+ checkFromText_InvalidText("foo 0 0 0 0 NOERROR 9 FAKE");
}
void
More information about the bind10-changes
mailing list