2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[1627] Unify testcases for NameParserException checks

This commit is contained in:
Mukund Sivaraman
2012-03-27 13:06:18 +05:30
parent c80eae98a8
commit 1a46994e85

View File

@@ -130,6 +130,15 @@ TEST_F(NameTest, nonlocalObject) {
EXPECT_EQ("\\255.example.com.", downcased_global.toText()); EXPECT_EQ("\\255.example.com.", downcased_global.toText());
} }
template <typename ExceptionType>
void
checkBadTextName(const string& txt) {
// Check it results in the specified type of exception as well as
// NameParserException.
EXPECT_THROW(Name(txt, false), ExceptionType);
EXPECT_THROW(Name(txt, false), NameParserException);
}
TEST_F(NameTest, fromText) { TEST_F(NameTest, fromText) {
vector<string> strnames; vector<string> strnames;
strnames.push_back("www.example.com"); strnames.push_back("www.example.com");
@@ -154,42 +163,42 @@ TEST_F(NameTest, fromText) {
// Tests for bogus names. These should trigger exceptions. // Tests for bogus names. These should trigger exceptions.
// //
// empty label cannot be followed by another label // empty label cannot be followed by another label
EXPECT_THROW(Name(".a"), EmptyLabel); checkBadTextName<EmptyLabel>(".a");
// duplicate period // duplicate period
EXPECT_THROW(Name("a.."), EmptyLabel); checkBadTextName<EmptyLabel>("a..");
// label length must be < 64 // label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789" checkBadTextName<TooLongLabel>("012345678901234567890123456789"
"012345678901234567890123456789" "012345678901234567890123456789"
"0123"), TooLongLabel); "0123");
// now-unsupported bitstring labels // now-unsupported bitstring labels
EXPECT_THROW(Name("\\[b11010000011101]"), BadLabelType); checkBadTextName<BadLabelType>("\\[b11010000011101]");
// label length must be < 64 // label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789" checkBadTextName<TooLongLabel>("012345678901234567890123456789"
"012345678901234567890123456789" "012345678901234567890123456789"
"012\\x"), TooLongLabel); "012\\x");
// but okay as long as resulting len < 64 even if the original string is // but okay as long as resulting len < 64 even if the original string is
// "too long" // "too long"
EXPECT_NO_THROW(Name("012345678901234567890123456789" EXPECT_NO_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789" "012345678901234567890123456789"
"01\\x")); "01\\x"));
// incomplete \DDD pattern (exactly 3 D's must appear) // incomplete \DDD pattern (exactly 3 D's must appear)
EXPECT_THROW(Name("\\12abc"), BadEscape); checkBadTextName<BadEscape>("\\12abc");
// \DDD must not exceed 255 // \DDD must not exceed 255
EXPECT_THROW(Name("\\256"), BadEscape); checkBadTextName<BadEscape>("\\256");
// Same tests for \111 as for \\x above // Same tests for \111 as for \\x above
EXPECT_THROW(Name("012345678901234567890123456789" checkBadTextName<TooLongLabel>("012345678901234567890123456789"
"012345678901234567890123456789" "012345678901234567890123456789"
"012\\111"), TooLongLabel); "012\\111");
EXPECT_NO_THROW(Name("012345678901234567890123456789" EXPECT_NO_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789" "012345678901234567890123456789"
"01\\111")); "01\\111"));
// A domain name must be 255 octets or less // A domain name must be 255 octets or less
EXPECT_THROW(Name("123456789.123456789.123456789.123456789.123456789." checkBadTextName<TooLongName>("123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
"1234"), TooLongName); "1234");
// This is a possible longest name and should be accepted // This is a possible longest name and should be accepted
EXPECT_NO_THROW(Name("123456789.123456789.123456789.123456789.123456789." EXPECT_NO_THROW(Name("123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
@@ -198,7 +207,7 @@ TEST_F(NameTest, fromText) {
"123456789.123456789.123456789.123456789.123456789." "123456789.123456789.123456789.123456789.123456789."
"123")); "123"));
// \DDD must consist of 3 digits. // \DDD must consist of 3 digits.
EXPECT_THROW(Name("\\12"), IncompleteName); checkBadTextName<IncompleteName>("\\12");
// a name with the max number of labels. should be constructed without // a name with the max number of labels. should be constructed without
// an error, and its length should be the max value. // an error, and its length should be the max value.
@@ -212,43 +221,6 @@ TEST_F(NameTest, fromText) {
EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabelCount()); EXPECT_EQ(Name::MAX_LABELS, maxlabels.getLabelCount());
} }
TEST_F(NameTest, testNameParserExceptions) {
//
// Tests for bogus names. These should trigger exceptions.
//
// empty label cannot be followed by another label
EXPECT_THROW(Name(".a"), NameParserException);
// duplicate period
EXPECT_THROW(Name("a.."), NameParserException);
// label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"0123"), NameParserException);
// now-unsupported bitstring labels
EXPECT_THROW(Name("\\[b11010000011101]"), NameParserException);
// label length must be < 64
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"012\\x"), NameParserException);
// incomplete \DDD pattern (exactly 3 D's must appear)
EXPECT_THROW(Name("\\12abc"), NameParserException);
// \DDD must not exceed 255
EXPECT_THROW(Name("\\256"), NameParserException);
// Same tests for \111 as for \\x above
EXPECT_THROW(Name("012345678901234567890123456789"
"012345678901234567890123456789"
"012\\111"), NameParserException);
// A domain name must be 255 octets or less
EXPECT_THROW(Name("123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"1234"), NameParserException);
// \DDD must consist of 3 digits.
EXPECT_THROW(Name("\\12"), NameParserException);
}
TEST_F(NameTest, fromWire) { TEST_F(NameTest, fromWire) {
// //
// test cases derived from BIND9 tests. // test cases derived from BIND9 tests.