Commit b28e7102 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

added test cases for short message with a complete header.

this should result in FORMERR.


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1356 e5f2f494-b856-4b98-b285-d166d9295462
parent dbcf762d
......@@ -157,11 +157,16 @@ AuthSrv::processMessage(InputBuffer& request_buffer, Message& message,
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.
......
......@@ -44,11 +44,11 @@ protected:
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 @@ TEST_F(AuthSrvTest, response) {
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());
}
}
###
### This data file was auto-generated from shortanswer_fromWire.spec
###
# Header Section
# ID=4149 QR=Query Opcode=QUERY(0) Rcode=NOERROR(0)
1035 0000
# QDCNT=1, ANCNT=1, NSCNT=0, ARCNT=0
0001 0001 0000 0000
# Question Section
# QNAME=example.com. QTYPE=A(1) QCLASS=IN(1)
076578616d706c6503636f6d00 0001 0001
#
# A QUERY message with a broken answer section (ancount > 0 but the section
# is empty)
#
[header]
# use default
ancount: 1
[question]
# use default
###
### A query-like data, but missing QCLASS field in the Question section.
###
# Header Section
# ID=4149 QR=Query Opcode=QUERY(0) Rcode=NOERROR(0)
1035 0000
# QDCNT=1, ANCNT=0, NSCNT=0, ARCNT=0
0001 0000 0000 0000
# Question Section
# QNAME=example.com. QTYPE=A(1) (QCLASS missing)
076578616d706c6503636f6d00 0001
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment