Commit 7a8a7f35 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

sync with trunk


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac399@3589 e5f2f494-b856-4b98-b285-d166d9295462
parents 1d36ea0c 37306241
116. [bug] jerry
src/bin/xfrout: Xfrout and Auth will communicate by long tcp
connection, Auth needs to make a new connection only on the first
time or if an error occurred.
(Trac #299, svn r3482)
115. [func]* jinmei
src/lib/dns: Changed DNS message flags and section names from
separate classes to simpler enums, considering the balance between
type safety and usability. API has been changed accordingly.
More documentation and tests were provided with these changes.
(Trac #358, r3439)
114. [build] jinmei
Supported clang++. Note: Boost >= 1.44 is required.
(Trac #365, svn r3383)
113. [func]* zhanglikun
Folder name 'utils'(the folder in /src/lib/python/isc/) has been
Folder name 'utils'(the folder in /src/lib/python/isc/) has been
renamed to 'util'. Programs that used 'import isc.utils.process'
now need to use 'import isc.util.process'. The folder
/src/lib/python/isc/Util is removed since it isn't used by any
program. (Trac #364, rTBD)
program. (Trac #364, r3382)
112. [func] zhang likun
Add one mixin class to override the naive serve_forever() provided
......
......@@ -206,7 +206,6 @@ fi
# gcc specific settings:
if test "X$GXX" = "Xyes"; then
B10_CXXFLAGS="-Wall -Wextra -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare"
UNUSED_PARAM_ATTRIBUTE='__attribute__((unused))'
# Certain versions of gcc (g++) have a bug that incorrectly warns about
# the use of anonymous name spaces even if they're closed in a single
......@@ -225,7 +224,6 @@ CXXFLAGS="$CXXFLAGS_SAVED"
fi dnl GXX = yes
AM_CONDITIONAL(GCC_WERROR_OK, test $werror_ok = 1)
AC_DEFINE_UNQUOTED(UNUSED_PARAM, $UNUSED_PARAM_ATTRIBUTE, Define to compiler keyword indicating a function argument is intentionally unused)
# produce PIC unless we disable shared libraries. need this for python bindings.
if test $enable_shared != "no" -a "X$GXX" = "Xyes"; then
......
......@@ -505,9 +505,7 @@ public:
}
}
void sendCompleted(const asio::error_code& error UNUSED_PARAM,
size_t bytes_sent UNUSED_PARAM)
{
void sendCompleted(const asio::error_code&, size_t) {
// Even if error occurred there's nothing to do. Simply handle
// the next request.
startReceive();
......
......@@ -132,7 +132,7 @@ public:
/// This constructor never throws an exception.
///
/// \param asio_address The ASIO \c ip::address to be converted.
IOAddress(const asio::ip::address& asio_adress);
IOAddress(const asio::ip::address& asio_address);
//@}
/// \brief Convert the address to a string.
......
......@@ -77,7 +77,7 @@ public:
MessageRenderer& response_renderer);
bool processAxfrQuery(const IOMessage& io_message, Message& message,
MessageRenderer& response_renderer);
bool processNotify(const IOMessage& io_message, Message& message,
bool processNotify(const IOMessage& io_message, Message& message,
MessageRenderer& response_renderer);
std::string db_file_;
ModuleCCSession* config_session_;
......@@ -152,8 +152,8 @@ makeErrorMessage(Message& message, MessageRenderer& renderer,
// XXX: with the current implementation, it's not easy to set EDNS0
// depending on whether the query had it. So we'll simply omit it.
const qid_t qid = message.getQid();
const bool rd = message.getHeaderFlag(MessageFlag::RD());
const bool cd = message.getHeaderFlag(MessageFlag::CD());
const bool rd = message.getHeaderFlag(Message::HEADERFLAG_RD);
const bool cd = message.getHeaderFlag(Message::HEADERFLAG_CD);
const Opcode& opcode = message.getOpcode();
vector<QuestionPtr> questions;
......@@ -166,12 +166,12 @@ makeErrorMessage(Message& message, MessageRenderer& renderer,
message.clear(Message::RENDER);
message.setQid(qid);
message.setOpcode(opcode);
message.setHeaderFlag(MessageFlag::QR());
message.setHeaderFlag(Message::HEADERFLAG_QR);
if (rd) {
message.setHeaderFlag(MessageFlag::RD());
message.setHeaderFlag(Message::HEADERFLAG_RD);
}
if (cd) {
message.setHeaderFlag(MessageFlag::CD());
message.setHeaderFlag(Message::HEADERFLAG_CD);
}
for_each(questions.begin(), questions.end(), QuestionInserter(&message));
message.setRcode(rcode);
......@@ -231,7 +231,7 @@ AuthSrv::processMessage(const IOMessage& io_message, Message& message,
message.parseHeader(request_buffer);
// Ignore all responses.
if (message.getHeaderFlag(MessageFlag::QR())) {
if (message.getHeaderFlag(Message::HEADERFLAG_QR)) {
if (impl_->verbose_mode_) {
cerr << "[b10-auth] received unexpected response, ignoring"
<< endl;
......@@ -279,7 +279,7 @@ AuthSrv::processMessage(const IOMessage& io_message, Message& message,
return (true);
}
if (message.getRRCount(Section::QUESTION()) != 1) {
if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
impl_->verbose_mode_);
return (true);
......@@ -307,10 +307,10 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, Message& message,
ConstEDNSPtr remote_edns = message.getEDNS();
const bool dnssec_ok = remote_edns && remote_edns->getDNSSECAwareness();
const uint16_t remote_bufsize = remote_edns ? remote_edns->getUDPSize() :
Message::DEFAULT_MAX_UDPSIZE;
Message::DEFAULT_MAX_UDPSIZE;
message.makeResponse();
message.setHeaderFlag(MessageFlag::AA());
message.setHeaderFlag(Message::HEADERFLAG_AA);
message.setRcode(Rcode::NOERROR());
if (remote_edns) {
......@@ -360,8 +360,10 @@ AuthSrvImpl::processAxfrQuery(const IOMessage& io_message, Message& message,
}
try {
xfrout_client_.connect();
xfrout_connected_ = true;
if (!xfrout_connected_) {
xfrout_client_.connect();
xfrout_connected_ = true;
}
xfrout_client_.sendXfroutRequestInfo(
io_message.getSocket().getNative(),
io_message.getData(),
......@@ -375,7 +377,7 @@ AuthSrvImpl::processAxfrQuery(const IOMessage& io_message, Message& message,
xfrout_client_.disconnect();
xfrout_connected_ = false;
}
if (verbose_mode_) {
cerr << "[b10-auth] Error in handling XFR request: " << err.what()
<< endl;
......@@ -385,22 +387,19 @@ AuthSrvImpl::processAxfrQuery(const IOMessage& io_message, Message& message,
return (true);
}
xfrout_client_.disconnect();
xfrout_connected_ = false;
return (false);
}
bool
AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
MessageRenderer& response_renderer)
AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
MessageRenderer& response_renderer)
{
// The incoming notify must contain exactly one question for SOA of the
// zone name.
if (message.getRRCount(Section::QUESTION()) != 1) {
if (message.getRRCount(Message::SECTION_QUESTION) != 1) {
if (verbose_mode_) {
cerr << "[b10-auth] invalid number of questions in notify: "
<< message.getRRCount(Section::QUESTION()) << endl;
<< message.getRRCount(Message::SECTION_QUESTION) << endl;
}
makeErrorMessage(message, response_renderer, Rcode::FORMERR(),
verbose_mode_);
......@@ -435,7 +434,7 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
}
return (false);
}
const string remote_ip_address =
io_message.getRemoteEndpoint().getAddress().toText();
static const string command_template_start =
......@@ -446,7 +445,7 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
try {
ConstElementPtr notify_command = Element::fromJSON(
command_template_start + question->getName().toText() +
command_template_start + question->getName().toText() +
command_template_master + remote_ip_address +
command_template_rrclass + question->getClass().toText() +
command_template_end);
......@@ -460,7 +459,7 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
if (rcode != 0) {
if (verbose_mode_) {
cerr << "[b10-auth] failed to notify Zonemgr: "
<< parsed_answer->str() << endl;
<< parsed_answer->str() << endl;
}
return (false);
}
......@@ -472,7 +471,7 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, Message& message,
}
message.makeResponse();
message.setHeaderFlag(MessageFlag::AA());
message.setHeaderFlag(Message::HEADERFLAG_AA);
message.setRcode(Rcode::NOERROR());
message.toWire(response_renderer);
return (true);
......
......@@ -84,7 +84,7 @@ public:
isc::xfr::AbstractXfroutClient& xfrout_client);
~AuthSrv();
//@}
/// \return \c true if the \message contains a response to be returned;
/// \return \c true if the \a message contains a response to be returned;
/// otherwise \c false.
bool processMessage(const asio_link::IOMessage& io_message,
isc::dns::Message& message,
......@@ -138,7 +138,7 @@ public:
/// containing the result of the update operation.
isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr config);
/// \param Returns the command and configuration session for the
/// \brief Returns the command and configuration session for the
/// \c AuthSrv.
///
/// This method never throws an exception.
......
......@@ -97,7 +97,7 @@ private:
virtual void startRead(boost::function<void()> read_callback);
virtual int reply(ConstElementPtr envelope, ConstElementPtr newmsg);
virtual bool hasQueuedMsgs() const;
virtual void setTimeout(size_t timeout UNUSED_PARAM) {};
virtual void setTimeout(size_t) {}
virtual size_t getTimeout() const { return 0; };
void setMessage(ConstElementPtr msg) { msg_ = msg; }
......@@ -156,30 +156,25 @@ protected:
};
void
AuthSrvTest::MockSession::establish(const char* socket_file UNUSED_PARAM) {}
AuthSrvTest::MockSession::establish(const char*) {}
void
AuthSrvTest::MockSession::disconnect() {}
void
AuthSrvTest::MockSession::subscribe(string group UNUSED_PARAM,
string instance UNUSED_PARAM)
AuthSrvTest::MockSession::subscribe(string, string)
{}
void
AuthSrvTest::MockSession::unsubscribe(string group UNUSED_PARAM,
string instance UNUSED_PARAM)
AuthSrvTest::MockSession::unsubscribe(string, string)
{}
void
AuthSrvTest::MockSession::startRead(
boost::function<void()> read_callback UNUSED_PARAM)
AuthSrvTest::MockSession::startRead(boost::function<void()>)
{}
int
AuthSrvTest::MockSession::reply(ConstElementPtr envelope UNUSED_PARAM,
ConstElementPtr newmsg UNUSED_PARAM)
{
AuthSrvTest::MockSession::reply(ConstElementPtr, ConstElementPtr) {
return (-1);
}
......@@ -190,8 +185,7 @@ AuthSrvTest::MockSession::hasQueuedMsgs() const {
int
AuthSrvTest::MockSession::group_sendmsg(ConstElementPtr msg, string group,
string instance UNUSED_PARAM,
string to UNUSED_PARAM)
string, string)
{
if (!send_ok_) {
isc_throw(XfroutError, "mock session send is disabled for test");
......@@ -203,10 +197,8 @@ AuthSrvTest::MockSession::group_sendmsg(ConstElementPtr msg, string group,
}
bool
AuthSrvTest::MockSession::group_recvmsg(ConstElementPtr& envelope UNUSED_PARAM,
ConstElementPtr& msg,
bool nonblock UNUSED_PARAM,
int seq UNUSED_PARAM)
AuthSrvTest::MockSession::group_recvmsg(ConstElementPtr&,
ConstElementPtr& msg, bool, int)
{
if (!receive_ok_) {
isc_throw(XfroutError, "mock session receive is disabled for test");
......@@ -234,10 +226,9 @@ AuthSrvTest::MockXfroutClient::disconnect() {
}
int
AuthSrvTest::MockXfroutClient::sendXfroutRequestInfo(
const int tcp_sock UNUSED_PARAM,
const void* msg_data UNUSED_PARAM,
const uint16_t msg_len UNUSED_PARAM)
AuthSrvTest::MockXfroutClient::sendXfroutRequestInfo(const int,
const void*,
const uint16_t)
{
if (!send_ok_) {
isc_throw(XfroutError, "xfrout connection send is disabled for test");
......@@ -321,18 +312,25 @@ headerCheck(const Message& message, const qid_t qid, const Rcode& rcode,
EXPECT_EQ(qid, message.getQid());
EXPECT_EQ(rcode, message.getRcode());
EXPECT_EQ(opcodeval, message.getOpcode().getCode());
EXPECT_EQ((flags & QR_FLAG) != 0, message.getHeaderFlag(MessageFlag::QR()));
EXPECT_EQ((flags & AA_FLAG) != 0, message.getHeaderFlag(MessageFlag::AA()));
EXPECT_EQ((flags & TC_FLAG) != 0, message.getHeaderFlag(MessageFlag::TC()));
EXPECT_EQ((flags & RA_FLAG) != 0, message.getHeaderFlag(MessageFlag::RA()));
EXPECT_EQ((flags & RD_FLAG) != 0, message.getHeaderFlag(MessageFlag::RD()));
EXPECT_EQ((flags & AD_FLAG) != 0, message.getHeaderFlag(MessageFlag::AD()));
EXPECT_EQ((flags & CD_FLAG) != 0, 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()));
EXPECT_EQ((flags & QR_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_QR));
EXPECT_EQ((flags & AA_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_AA));
EXPECT_EQ((flags & TC_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_TC));
EXPECT_EQ((flags & RA_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_RA));
EXPECT_EQ((flags & RD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_RD));
EXPECT_EQ((flags & AD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_AD));
EXPECT_EQ((flags & CD_FLAG) != 0,
message.getHeaderFlag(Message::HEADERFLAG_CD));
EXPECT_EQ(qdcount, message.getRRCount(Message::SECTION_QUESTION));
EXPECT_EQ(ancount, message.getRRCount(Message::SECTION_ANSWER));
EXPECT_EQ(nscount, message.getRRCount(Message::SECTION_AUTHORITY));
EXPECT_EQ(arcount, message.getRRCount(Message::SECTION_ADDITIONAL));
}
// Unsupported requests. Should result in NOTIMP.
......@@ -482,7 +480,7 @@ TEST_F(AuthSrvTest, AXFRSuccess) {
// so we shouldn't have to respond.
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
EXPECT_FALSE(xfrout.isConnected());
EXPECT_TRUE(xfrout.isConnected());
}
TEST_F(AuthSrvTest, AXFRConnectFail) {
......@@ -494,8 +492,6 @@ TEST_F(AuthSrvTest, AXFRConnectFail) {
response_renderer));
headerCheck(parse_message, default_qid, Rcode::SERVFAIL(),
opcode.getCode(), QR_FLAG, 1, 0, 0, 0);
// For a shot term workaround with xfrout we currently close the connection
// for each AXFR attempt
EXPECT_FALSE(xfrout.isConnected());
}
......@@ -505,7 +501,7 @@ TEST_F(AuthSrvTest, AXFRSendFail) {
createRequestPacket(opcode, Name("example.com"), RRClass::IN(),
RRType::AXFR(), IPPROTO_TCP);
server.processMessage(*io_message, parse_message, response_renderer);
EXPECT_FALSE(xfrout.isConnected()); // see above
EXPECT_TRUE(xfrout.isConnected());
xfrout.disableSend();
parse_message.clear(Message::PARSE);
......@@ -540,7 +536,7 @@ TEST_F(AuthSrvTest, AXFRDisconnectFail) {
TEST_F(AuthSrvTest, notify) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -572,7 +568,7 @@ TEST_F(AuthSrvTest, notifyForCHClass) {
// Same as the previous test, but for the CH RRClass.
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::CH(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -588,7 +584,7 @@ TEST_F(AuthSrvTest, notifyEmptyQuestion) {
request_message.clear(Message::RENDER);
request_message.setOpcode(Opcode::NOTIFY());
request_message.setRcode(Rcode::NOERROR());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setQid(default_qid);
request_message.toWire(request_renderer);
createRequestPacket(IPPROTO_UDP);
......@@ -604,7 +600,7 @@ TEST_F(AuthSrvTest, notifyMultiQuestions) {
// add one more SOA question
request_message.addQuestion(Question(Name("example.com"), RRClass::IN(),
RRType::SOA()));
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -615,7 +611,7 @@ TEST_F(AuthSrvTest, notifyMultiQuestions) {
TEST_F(AuthSrvTest, notifyNonSOAQuestion) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::NS());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -636,7 +632,7 @@ TEST_F(AuthSrvTest, notifyWithoutAA) {
TEST_F(AuthSrvTest, notifyWithErrorRcode) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
request_message.setRcode(Rcode::SERVFAIL());
createRequestPacket(IPPROTO_UDP);
EXPECT_TRUE(server.processMessage(*io_message, parse_message,
......@@ -650,7 +646,7 @@ TEST_F(AuthSrvTest, notifyWithoutSession) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
// we simply ignore the notify and let it be resent if an internal error
......@@ -664,7 +660,7 @@ TEST_F(AuthSrvTest, notifySendFail) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
......@@ -676,7 +672,7 @@ TEST_F(AuthSrvTest, notifyReceiveFail) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -687,7 +683,7 @@ TEST_F(AuthSrvTest, notifyWithBogusSessionMessage) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......@@ -699,7 +695,7 @@ TEST_F(AuthSrvTest, notifyWithSessionMessageError) {
createRequestMessage(Opcode::NOTIFY(), Name("example.com"), RRClass::IN(),
RRType::SOA());
request_message.setHeaderFlag(MessageFlag::AA());
request_message.setHeaderFlag(Message::HEADERFLAG_AA);
createRequestPacket(IPPROTO_UDP);
EXPECT_FALSE(server.processMessage(*io_message, parse_message,
response_renderer));
......
......@@ -58,7 +58,7 @@ host_lookup(const char* const name, const char* const type) {
msg.setOpcode(Opcode::QUERY());
msg.setRcode(Rcode::NOERROR());
if (recursive_bit) {
msg.setHeaderFlag(MessageFlag::RD()); // set recursive bit
msg.setHeaderFlag(Message::HEADERFLAG_RD); // set recursive bit
}
msg.addQuestion(Question(Name(name),
......@@ -122,9 +122,10 @@ host_lookup(const char* const name, const char* const type) {
rmsg.fromWire(ibuffer);
if (!verbose) {
for (RRsetIterator it = rmsg.beginSection(Section::ANSWER());
it != rmsg.endSection(Section::ANSWER());
++it) {
for (RRsetIterator it =
rmsg.beginSection(Message::SECTION_ANSWER);
it != rmsg.endSection(Message::SECTION_ANSWER);
++it) {
if ((*it)->getType() != RRType::A()) {
continue;
}
......
......@@ -135,9 +135,9 @@ class MockXfrinConnection(XfrinConnection):
resp.set_opcode(Opcode.QUERY())
resp.set_rcode(rcode)
if response:
resp.set_header_flag(MessageFlag.QR())
resp.set_header_flag(Message.HEADERFLAG_QR)
[resp.add_question(q) for q in questions]
[resp.add_rrset(Section.ANSWER(), a) for a in answers]
[resp.add_rrset(Message.SECTION_ANSWER, a) for a in answers]
renderer = MessageRenderer()
resp.to_wire(renderer)
......
......@@ -240,7 +240,7 @@ class XfrinConnection(asyncore.dispatcher):
if msg_rcode != Rcode.NOERROR():
raise XfrinException('error response: %s' % msg_rcode.to_text())
if not msg.get_header_flag(MessageFlag.QR()):
if not msg.get_header_flag(Message.HEADERFLAG_QR):
raise XfrinException('response is not a response ')
if msg.get_qid() != self._query_id:
......@@ -251,10 +251,10 @@ class XfrinConnection(asyncore.dispatcher):
self._check_response_header(msg)
if msg.get_rr_count(Section.ANSWER()) == 0:
if msg.get_rr_count(Message.SECTION_ANSWER) == 0:
raise XfrinException('answer section is empty')
if msg.get_rr_count(Section.QUESTION()) > 1:
if msg.get_rr_count(Message.SECTION_QUESTION) > 1:
raise XfrinException('query section count greater than 1')
def _handle_answer_section(self, answer_section):
......@@ -294,7 +294,7 @@ class XfrinConnection(asyncore.dispatcher):
msg.from_wire(recvdata)
self._check_response_status(msg)
answer_section = msg.get_section(Section.ANSWER())
answer_section = msg.get_section(Message.SECTION_ANSWER)
for rr in self._handle_answer_section(answer_section):
yield rr
......
......@@ -47,22 +47,29 @@ class MySocket():
result = self.sendqueue[:size]
self.sendqueue = self.sendqueue[size:]
return result
def read_msg(self):
sent_data = self.readsent()
get_msg = Message(Message.PARSE)
get_msg.from_wire(bytes(sent_data[2:]))
return get_msg
def clear_send(self):
del self.sendqueue[:]
# We subclass the Session class we're testing here, only
# to override the __init__() method, which wants a socket,
# to override the handle() and _send_data() method
class MyXfroutSession(XfroutSession):
def handle(self):
pass
def _send_data(self, sock, data):
size = len(data)
total_count = 0
while total_count < size:
count = sock.send(data[total_count:])
total_count += count
class Dbserver:
def __init__(self):
self._shutdown_event = threading.Event()
......@@ -80,12 +87,21 @@ class TestXfroutSession(unittest.TestCase):
def setUp(self):
request = MySocket(socket.AF_INET,socket.SOCK_STREAM)
self.log = isc.log.NSLogger('xfrout', '', severity = 'critical', log_to_console = False )
self.xfrsess = MyXfroutSession(request, None, None, self.log)
(self.write_sock, self.read_sock) = socket.socketpair()
self.xfrsess = MyXfroutSession(request, None, None, self.log, self.read_sock)
self.xfrsess.server = Dbserver()
self.mdata = bytes(b'\xd6=\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07example\x03com\x00\x00\xfc\x00\x01')
self.sock = MySocket(socket.AF_INET,socket.SOCK_STREAM)
self.soa_record = (4, 3, 'example.com.', 'com.example.', 3600, 'SOA', None, 'master.example.com. admin.example.com. 1234 3600 1800 2419200 7200')
def test_receive_query_message(self):
send_msg = b"\xd6=\x00\x00\x00\x01\x00"
msg_len = struct.pack('H', socket.htons(len(send_msg)))
self.write_sock.send(msg_len)
self.write_sock.send(send_msg)
recv_msg = self.xfrsess._receive_query_message(self.read_sock)
self.assertEqual(recv_msg, send_msg)
def test_parse_query_message(self):
[get_rcode, get_msg] = self.xfrsess._parse_query_message(self.mdata)
self.assertEqual(get_rcode.to_text(), "NOERROR")
......@@ -93,7 +109,7 @@ class TestXfroutSession(unittest.TestCase):
def test_get_query_zone_name(self):
msg = self.getmsg()
self.assertEqual(self.xfrsess._get_query_zone_name(msg), "example.com.")
def test_send_data(self):
self.xfrsess._send_data(self.sock, self.mdata)
senddata = self.sock.readsent()
......@@ -103,8 +119,8 @@ class TestXfroutSession(unittest.TestCase):
msg = self.getmsg()
self.xfrsess._reply_query_with_error_rcode(msg, self.sock, Rcode(3))
get_msg = self.sock.read_msg()
self.assertEqual(get_msg.get_rcode().to_text(), "NXDOMAIN")