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

more test cases

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jinmei-dnsmessageapi@363 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
JINMEI Tatuya 2009-12-14 20:04:54 +00:00
parent 9e6879509a
commit 3cf09942c9
6 changed files with 69 additions and 2 deletions

View File

@ -241,7 +241,7 @@ Name::Name(InputBuffer& buffer, bool downcase)
{
unsigned int new_current;
std::vector<unsigned char> offsets;
offsets.reserve(Name::MAX_WIRE / 2);
offsets.reserve(Name::MAX_LABELS);
/*
* Initialize things to make the compiler happy; they're not required.
@ -562,7 +562,6 @@ Name::concatenate(const Name& suffix) const
transform(suffix.offsets_.begin(), suffix.offsets_.end(),
back_inserter(retname.offsets_),
bind2nd(OffsetAdjuster(), this->length_ - 1));
assert(retname.offsets_.back() == retname.length_ - 1);
assert(retname.offsets_.size() == labels);
retname.labels_ = labels;

View File

@ -38,6 +38,7 @@ protected:
NameTest() : example_name("www.example.com") {}
Name example_name;
static const size_t MAX_WIRE = Name::MAX_WIRE;
static const size_t MAX_LABELS = Name::MAX_LABELS;
//
// helper methods
@ -176,6 +177,24 @@ TEST_F(NameTest, fromWire)
EXPECT_EQ(true, nameFactoryFromWire("testdata/name_fromWire8", 383) ==
Name("vix.com"));
//
// Additional test cases
//
// large names, a long but valid one, and invalid (too long) one.
EXPECT_EQ(MAX_WIRE,
nameFactoryFromWire("testdata/name_fromWire9", 0).getLength());
EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire10", 0).getLength(),
isc::dns::TooLongName);
// A name with possible maximum number of labels; awkward but valid
EXPECT_EQ(nameFactoryFromWire("testdata/name_fromWire11", 0).getLabels(),
MAX_LABELS);
// Wire format including an invalid label length
EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire12", 0),
isc::dns::BadLabelType);
// converting upper-case letters to down-case
EXPECT_EQ("vix.com.", nameFactoryFromWire("testdata/name_fromWire1",
25, true).toText());

View File

@ -0,0 +1,12 @@
#
# Too large name; should trigger an exception.
#
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 040102030400

View File

@ -0,0 +1,12 @@
#
# A name with possible maximum number of labels; should be accepted safely.
#
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 01000100010001000100 01000100010001000100
01000100010001000100 0100010000

View File

@ -0,0 +1,13 @@
#
# Wire format including an invalid label length
#
#(1) a (7) e x a m p l e
01 61 07 65 78 61 6d 70 6c 65
# invalid label length: 64
40
# a "label" of 64 characters: shouldn't be parsed
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f
20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f
30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f
00

12
src/lib/dns/cpp/testdata/name_fromWire9 vendored Normal file
View File

@ -0,0 +1,12 @@
#
# A possible longest name; should be accepted safely.
#
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 09010203040506070809 09010203040506070809
09010203040506070809 0301020300