[svn] commit: r1356 - in /trunk/src/bin/auth: auth_srv.cc tests/auth_srv_unittest.cc tests/testdata/shortanswer_fromWire tests/testdata/shortanswer_fromWire.spec tests/testdata/shortquestion_fromWire
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Mar 12 08:20:08 UTC 2010
Author: jinmei
Date: Fri Mar 12 08:20:08 2010
New Revision: 1356
Log:
added test cases for short message with a complete header.
this should result in FORMERR.
Added:
trunk/src/bin/auth/tests/testdata/shortanswer_fromWire
trunk/src/bin/auth/tests/testdata/shortanswer_fromWire.spec
trunk/src/bin/auth/tests/testdata/shortquestion_fromWire
Modified:
trunk/src/bin/auth/auth_srv.cc
trunk/src/bin/auth/tests/auth_srv_unittest.cc
Modified: trunk/src/bin/auth/auth_srv.cc
==============================================================================
--- trunk/src/bin/auth/auth_srv.cc (original)
+++ trunk/src/bin/auth/auth_srv.cc Fri Mar 12 08:20:08 2010
@@ -157,11 +157,16 @@
try {
message.fromWire(request_buffer);
} catch (const DNSProtocolError& error) {
- cerr << "returning protocol error" << endl;
+ if (verbose_mode) {
+ cerr << "returning " << error.getRcode().toText() << ": "
+ << error.what() << endl;
+ }
makeErrorMessage(message, response_renderer, error.getRcode());
return (true);
} catch (const Exception& ex) {
- cerr << "returning servfail" << endl;
+ if (verbose_mode) {
+ cerr << "returning SERVFAIL: " << ex.what() << endl;
+ }
makeErrorMessage(message, response_renderer, Rcode::SERVFAIL());
return (true);
} // other exceptions will be handled at a higher layer.
Modified: trunk/src/bin/auth/tests/auth_srv_unittest.cc
==============================================================================
--- trunk/src/bin/auth/tests/auth_srv_unittest.cc (original)
+++ trunk/src/bin/auth/tests/auth_srv_unittest.cc Fri Mar 12 08:20:08 2010
@@ -44,11 +44,11 @@
AuthSrv server;
Message request_message;
Message parse_message;
- qid_t default_qid;
- Opcode opcode;
- Name qname;
- RRClass qclass;
- RRType qtype;
+ const qid_t default_qid;
+ const Opcode opcode;
+ const Name qname;
+ const RRClass qclass;
+ const RRType qtype;
InputBuffer* ibuffer;
OutputBuffer request_obuffer;
MessageRenderer request_renderer;
@@ -165,7 +165,35 @@
createDataFromFile("testdata/iqueryresponse_fromWire");
EXPECT_EQ(false, server.processMessage(*ibuffer, parse_message,
response_renderer, true, false));
+}
+// Query with a broken question
+TEST_F(AuthSrvTest, shortQuestion) {
+ createDataFromFile("testdata/shortquestion_fromWire");
+ EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
+ response_renderer, true, false));
+ // Since the query's question is broken, the question section of the
+ // response should be empty.
+ headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
+ QR_FLAG, 0, 0, 0, 0);
+}
+
+// Query with a broken answer section
+TEST_F(AuthSrvTest, shortAnswer) {
+ createDataFromFile("testdata/shortanswer_fromWire");
+ EXPECT_EQ(true, server.processMessage(*ibuffer, parse_message,
+ response_renderer, true, true));
+ headerCheck(parse_message, default_qid, Rcode::FORMERR(), opcode.getCode(),
+ QR_FLAG, 1, 0, 0, 0);
+
+ // This is a bogus query, but question section is valid. So the response
+ // should copy the question section.
+ QuestionIterator qit = parse_message.beginQuestion();
+ EXPECT_EQ(Name("example.com"), (*qit)->getName());
+ EXPECT_EQ(RRClass::IN(), (*qit)->getClass());
+ EXPECT_EQ(RRType::A(), (*qit)->getType());
+ ++qit;
+ EXPECT_TRUE(qit == parse_message.endQuestion());
}
}
More information about the bind10-changes
mailing list