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

test for requests with unknown opcodes


git-svn-id: svn://bind10.isc.org/svn/bind10/trunk@1340 e5f2f494-b856-4b98-b285-d166d9295462
parent e5d3cfc8
......@@ -35,7 +35,7 @@ namespace {
class AuthSrvTest : public ::testing::Test {
protected:
AuthSrvTest() : request_message(Message::RENDER),
parse_message(Message::PARSE),
parse_message(Message::PARSE), default_qid(0x1035),
qname("www.example.com"),
qclass(RRClass::IN()), qtype(RRType::A()),
request_obuffer(0), request_renderer(request_obuffer),
......@@ -44,6 +44,7 @@ protected:
AuthSrv server;
Message request_message;
Message parse_message;
qid_t default_qid;
Name qname;
RRClass qclass;
RRType qtype;
......@@ -54,16 +55,61 @@ protected:
vector<uint8_t> data;
};
static void
// These are flags to indicate whether the corresponding flag bit of the
// DNS header is to be set in the test cases. (Note that the flag values
// is irrelevant to their wire-format values)
const unsigned int QR_FLAG = 0x1;
const unsigned int AA_FLAG = 0x2;
const unsigned int TC_FLAG = 0x4;
const unsigned int RD_FLAG = 0x8;
const unsigned int RA_FLAG = 0x10;
const unsigned int AD_FLAG = 0x20;
const unsigned int CD_FLAG = 0x40;
void
createDataFromFile(const char* const datafile, vector<uint8_t>& data) {
UnitTestUtil::readWireData(datafile, data);
InputBuffer buffer(&data[0], data.size());
}
TEST_F(AuthSrvTest, ManyQuery) {
createDataFromFile("testdata/iquery_fromWire", data);
InputBuffer buffer(&data[0], data.size());
EXPECT_EQ(0, server.processMessage(buffer, parse_message, response_renderer,
true, false));
void
headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
const uint16_t opcodeval, const unsigned int flags,
const unsigned int qdcount,
const unsigned int ancount, const unsigned int nscount,
const unsigned int arcount)
{
EXPECT_EQ(qid, message.getQid());
EXPECT_EQ(rcode, message.getRcode());
EXPECT_EQ(opcodeval, message.getOpcode().getCode());
EXPECT_EQ((flags & QR_FLAG) == 1, message.getHeaderFlag(MessageFlag::QR()));
EXPECT_EQ((flags & AA_FLAG) == 1, message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ((flags & TC_FLAG) == 1, message.getHeaderFlag(MessageFlag::TC()));
EXPECT_EQ((flags & RA_FLAG) == 1, message.getHeaderFlag(MessageFlag::RA()));
EXPECT_EQ((flags & RD_FLAG) == 1, message.getHeaderFlag(MessageFlag::RD()));
EXPECT_EQ((flags & AD_FLAG) == 1, message.getHeaderFlag(MessageFlag::AD()));
EXPECT_EQ((flags & CD_FLAG) == 1, message.getHeaderFlag(MessageFlag::CD()));
EXPECT_EQ(qdcount, message.getRRCount(Section::QUESTION()));
EXPECT_EQ(ancount, message.getRRCount(Section::ANSWER()));
EXPECT_EQ(nscount, message.getRRCount(Section::AUTHORITY()));
EXPECT_EQ(arcount, message.getRRCount(Section::ADDITIONAL()));
}
// Unsupported requests. Should result in NOTIMP.
TEST_F(AuthSrvTest, unsupportedRequest) {
createDataFromFile("testdata/simplequery_fromWire", data);
for (unsigned int i = 1; i < 16; ++i) {
// set Opcode to 'i', which iterators over all possible codes except
// the standard query (0)
data[2] = ((i << 3) & 0xff);
InputBuffer buffer(&data[0], data.size());
parse_message.clear(Message::PARSE);
EXPECT_EQ(0, server.processMessage(buffer, parse_message,
response_renderer, true, false));
headerCheck(parse_message, default_qid, Rcode::NOTIMP(), i, QR_FLAG,
0, 0, 0, 0);
}
}
}
###
### This data file was auto-generated from iquery_fromWire.spec
### This data file was auto-generated from simplequery_fromWire.spec
###
# Header Section
# ID=4149 QR=Query Opcode=IQUERY(1) Rcode=NOERROR(0)
1035 4000
# ID=4149 QR=Query Opcode=QUERY(0) Rcode=NOERROR(0)
1035 0000
# QDCNT=1, ANCNT=0, NSCNT=0, ARCNT=0
0001 0000 0000 0000
......
#
# IQUERY message.
# A simple QUERY message.
#
[header]
opcode: iquery
# use default
[question]
# use default
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