diff options
author | Mukund Sivaraman <muks@isc.org> | 2013-04-02 07:46:21 +0200 |
---|---|---|
committer | Mukund Sivaraman <muks@isc.org> | 2013-04-02 07:48:18 +0200 |
commit | 7b2ee20fb35a475916a817c30668d31d15fc8907 (patch) | |
tree | 85ea4364bb2d9850eb7127bef46b5278e6c7cf61 | |
parent | [2387] Remove unused includes (diff) | |
download | kea-7b2ee20fb35a475916a817c30668d31d15fc8907.tar.xz kea-7b2ee20fb35a475916a817c30668d31d15fc8907.zip |
[2387] Add tests for trailing garbage in strings
-rw-r--r-- | src/lib/dns/tests/rdata_dnskey_unittest.cc | 12 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_nsec3_unittest.cc | 13 | ||||
-rw-r--r-- | src/lib/dns/tests/rdata_nsec3param_unittest.cc | 17 |
3 files changed, 40 insertions, 2 deletions
diff --git a/src/lib/dns/tests/rdata_dnskey_unittest.cc b/src/lib/dns/tests/rdata_dnskey_unittest.cc index 8da5f6f9e0..95075de3e8 100644 --- a/src/lib/dns/tests/rdata_dnskey_unittest.cc +++ b/src/lib/dns/tests/rdata_dnskey_unittest.cc @@ -78,6 +78,12 @@ protected: rdata_str, rdata_dnskey2, true, true); } + void checkFromText_BadString(const string& rdata_str) { + checkFromText + <generic::DNSKEY, InvalidRdataText, isc::Exception>( + rdata_str, rdata_dnskey2, true, false); + } + const string dnskey_txt; const string dnskey_txt2; const generic::DNSKEY rdata_dnskey; @@ -118,6 +124,12 @@ TEST_F(Rdata_DNSKEY_Test, fromText) { checkFromText_LexerError("foo 3 5 YmluZDEwLmlzYy5vcmc="); checkFromText_LexerError("257 foo 5 YmluZDEwLmlzYy5vcmc="); checkFromText_LexerError("257 3 foo YmluZDEwLmlzYy5vcmc="); + + // Trailing garbage. This should cause only the string constructor + // to fail, but the lexer constructor must be able to continue + // parsing from it. + checkFromText_BadString("257 3 5 YmluZDEwLmlzYy5vcmc= ; comment\n" + "257 3 4 YmluZDEwLmlzYy5vcmc="); } TEST_F(Rdata_DNSKEY_Test, assign) { diff --git a/src/lib/dns/tests/rdata_nsec3_unittest.cc b/src/lib/dns/tests/rdata_nsec3_unittest.cc index 4487e0aab6..8b6db0fb4e 100644 --- a/src/lib/dns/tests/rdata_nsec3_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec3_unittest.cc @@ -71,6 +71,12 @@ protected: rdata_str, rdata_nsec3, true, true); } + void checkFromText_BadString(const string& rdata_str) { + checkFromText + <generic::NSEC3, InvalidRdataText, isc::Exception>( + rdata_str, rdata_nsec3, true, false); + } + const string nsec3_txt; const string nsec3_nosalt_txt; const string nsec3_notype_txt; @@ -131,6 +137,13 @@ TEST_F(Rdata_NSEC3_Test, fromText) { "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA"); checkFromText_LexerError("1 1 foo D399EAAB " "H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA"); + + // Trailing garbage. This should cause only the string constructor + // to fail, but the lexer constructor must be able to continue + // parsing from it. + checkFromText_BadString( + "1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA ;comment\n" + "1 1 1 D399EAAB H9RSFB7FPF2L8HG35CMPC765TDK23RP6 A NS SOA"); } TEST_F(Rdata_NSEC3_Test, createFromWire) { diff --git a/src/lib/dns/tests/rdata_nsec3param_unittest.cc b/src/lib/dns/tests/rdata_nsec3param_unittest.cc index 9abbb2281a..4c1b2abc56 100644 --- a/src/lib/dns/tests/rdata_nsec3param_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec3param_unittest.cc @@ -65,6 +65,14 @@ protected: rdata_str, rdata_nsec3param, true, true); } + void checkFromText_BadString(const string& rdata_str, + const generic::NSEC3PARAM& rdata) + { + checkFromText + <generic::NSEC3PARAM, InvalidRdataText, isc::Exception>( + rdata_str, rdata, true, false); + } + const string nsec3param_txt; const string nsec3param_nosalt_txt; const generic::NSEC3PARAM rdata_nsec3param; @@ -81,8 +89,7 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) { // constructor, as the lexer constructor stops reading at the end of // its RDATA. const generic::NSEC3PARAM rdata_nsec3param2("1 1 1 D399"); - checkFromText<generic::NSEC3PARAM, InvalidRdataText, isc::Exception>( - "1 1 1 D399 EAAB", rdata_nsec3param2, true, false); + checkFromText_BadString("1 1 1 D399 EAAB", rdata_nsec3param2); // Hash algorithm out of range. checkFromText_InvalidText("256 1 1 D399EAAB"); @@ -100,6 +107,12 @@ TEST_F(Rdata_NSEC3PARAM_Test, fromText) { checkFromText_LexerError("foo 1 256 D399EAAB"); checkFromText_LexerError("1 foo 256 D399EAAB"); checkFromText_LexerError("1 1 foo D399EAAB"); + + // Trailing garbage. This should cause only the string constructor + // to fail, but the lexer constructor must be able to continue + // parsing from it. + checkFromText_BadString("1 1 1 D399EAAB ; comment\n" + "1 1 1 D399EAAB", rdata_nsec3param); } TEST_F(Rdata_NSEC3PARAM_Test, toText) { |