Commit 76fb414e authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[master] Merge branch 'trac1370'

parents e5f37058 226dc3ee
......@@ -470,34 +470,28 @@ class TestXfroutSession(TestXfroutSessionBase):
msg = self.getmsg()
msg.make_response()
# packet number less than TSIG_SIGN_EVERY_NTH
packet_neet_not_sign = xfrout.TSIG_SIGN_EVERY_NTH - 1
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset, 0,
packet_neet_not_sign)
self.soa_rrset, 0)
get_msg = self.sock.read_msg()
# tsig context is not exist
# tsig context does not exist
self.assertFalse(self.message_has_tsig(get_msg))
self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
#answer_rrset_iter = section_iter(get_msg, section.ANSWER())
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]#answer_rrset_iter.get_rrset()
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
self.assertEqual(answer.get_name().to_text(), "example.com.")
self.assertEqual(answer.get_class(), RRClass("IN"))
self.assertEqual(answer.get_type().to_text(), "SOA")
rdata = answer.get_rdata()
self.assertEqual(rdata[0], self.soa_rrset.get_rdata()[0])
# msg is the TSIG_SIGN_EVERY_NTH one
# sending the message with last soa together
# Sending the message with last soa together
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset, 0,
TSIG_SIGN_EVERY_NTH)
self.soa_rrset, 0)
get_msg = self.sock.read_msg()
# tsig context is not exist
# tsig context does not exist
self.assertFalse(self.message_has_tsig(get_msg))
def test_send_message_with_last_soa_with_tsig(self):
......@@ -507,13 +501,9 @@ class TestXfroutSession(TestXfroutSessionBase):
msg = self.getmsg()
msg.make_response()
# packet number less than TSIG_SIGN_EVERY_NTH
packet_neet_not_sign = xfrout.TSIG_SIGN_EVERY_NTH - 1
# msg is not the TSIG_SIGN_EVERY_NTH one
# sending the message with last soa together
# Sending the message with last soa together
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset, 0,
packet_neet_not_sign)
self.soa_rrset, 0)
get_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(get_msg))
......@@ -521,14 +511,6 @@ class TestXfroutSession(TestXfroutSessionBase):
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
# msg is the TSIG_SIGN_EVERY_NTH one
# sending the message with last soa together
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset, 0,
TSIG_SIGN_EVERY_NTH)
get_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(get_msg))
def test_trigger_send_message_with_last_soa(self):
rrset_a = RRset(Name("example.com"), RRClass.IN(), RRType.A(), RRTTL(3600))
rrset_a.add_rdata(Rdata(RRType.A(), RRClass.IN(), "192.0.2.1"))
......@@ -540,8 +522,6 @@ class TestXfroutSession(TestXfroutSessionBase):
# length larger than MAX-len(rrset)
length_need_split = xfrout.XFROUT_MAX_MESSAGE_SIZE - \
get_rrset_len(self.soa_rrset) + 1
# packet number less than TSIG_SIGN_EVERY_NTH
packet_neet_not_sign = xfrout.TSIG_SIGN_EVERY_NTH - 1
# give the function a value that is larger than MAX-len(rrset)
# this should have triggered the sending of two messages
......@@ -549,8 +529,7 @@ class TestXfroutSession(TestXfroutSessionBase):
# the sending in _with_last_soa)
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset,
length_need_split,
packet_neet_not_sign)
length_need_split)
get_msg = self.sock.read_msg()
self.assertFalse(self.message_has_tsig(get_msg))
self.assertEqual(get_msg.get_rr_count(Message.SECTION_QUESTION), 1)
......@@ -570,7 +549,6 @@ class TestXfroutSession(TestXfroutSessionBase):
self.assertEqual(get_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertEqual(get_msg.get_rr_count(Message.SECTION_AUTHORITY), 0)
#answer_rrset_iter = section_iter(get_msg, Message.SECTION_ANSWER)
answer = get_msg.get_section(Message.SECTION_ANSWER)[0]
self.assertEqual(answer.get_name().to_text(), "example.com.")
self.assertEqual(answer.get_class(), RRClass("IN"))
......@@ -590,8 +568,6 @@ class TestXfroutSession(TestXfroutSessionBase):
# length larger than MAX-len(rrset)
length_need_split = xfrout.XFROUT_MAX_MESSAGE_SIZE - \
get_rrset_len(self.soa_rrset) + 1
# packet number less than TSIG_SIGN_EVERY_NTH
packet_neet_not_sign = xfrout.TSIG_SIGN_EVERY_NTH - 1
# give the function a value that is larger than MAX-len(rrset)
# this should have triggered the sending of two messages
......@@ -599,26 +575,10 @@ class TestXfroutSession(TestXfroutSessionBase):
# the sending in _with_last_soa)
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset,
length_need_split,
packet_neet_not_sign)
get_msg = self.sock.read_msg()
# msg is not the TSIG_SIGN_EVERY_NTH one, it shouldn't be tsig signed
self.assertFalse(self.message_has_tsig(get_msg))
# the last packet should be tsig signed
length_need_split)
# Both messages should have TSIG RRs
get_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(get_msg))
# and it should not have sent anything else
self.assertEqual(0, len(self.sock.sendqueue))
# msg is the TSIG_SIGN_EVERY_NTH one, it should be tsig signed
self.xfrsess._send_message_with_last_soa(msg, self.sock,
self.soa_rrset,
length_need_split,
xfrout.TSIG_SIGN_EVERY_NTH)
get_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(get_msg))
# the last packet should be tsig signed
get_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(get_msg))
# and it should not have sent anything else
......@@ -697,29 +657,18 @@ class TestXfroutSession(TestXfroutSessionBase):
self.xfrsess._tsig_ctx = self.create_mock_tsig_ctx(TSIGError.NOERROR)
self.xfrsess._reply_xfrout_query(self.getmsg(), self.sock)
# tsig signed first package
reply_msg = self.sock.read_msg()
self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertTrue(self.message_has_tsig(reply_msg))
# (TSIG_SIGN_EVERY_NTH - 1) packets have no tsig
for i in range(0, xfrout.TSIG_SIGN_EVERY_NTH - 1):
reply_msg = self.sock.read_msg()
self.assertFalse(self.message_has_tsig(reply_msg))
# TSIG_SIGN_EVERY_NTH packet has tsig
reply_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(reply_msg))
for i in range(0, 100 - TSIG_SIGN_EVERY_NTH):
# All messages must have TSIG as we don't support the feature of
# skipping intermediate TSIG records (with bulk signing).
for i in range(0, 102): # 102 = all 100 RRs from iterator and 2 SOAs
reply_msg = self.sock.read_msg()
self.assertFalse(self.message_has_tsig(reply_msg))
# tsig signed last package
reply_msg = self.sock.read_msg()
self.assertTrue(self.message_has_tsig(reply_msg))
# With the hack of get_rrset_len() above, every message must have
# exactly one RR in the answer section.
self.assertEqual(reply_msg.get_rr_count(Message.SECTION_ANSWER), 1)
self.assertTrue(self.message_has_tsig(reply_msg))
# and it should not have sent anything else
self.assertEqual(0, len(self.sock.sendqueue))
class TestXfroutSessionWithSQLite3(TestXfroutSessionBase):
'''Tests for XFR-out sessions using an SQLite3 DB.
......
......@@ -92,9 +92,6 @@ init_paths()
SPECFILE_LOCATION = SPECFILE_PATH + "/xfrout.spec"
AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + os.sep + "auth.spec"
VERBOSE_MODE = False
# tsig sign every N axfr packets.
TSIG_SIGN_EVERY_NTH = 96
XFROUT_MAX_MESSAGE_SIZE = 65535
# borrowed from xfrin.py @ #1298. We should eventually unify it.
......@@ -398,22 +395,15 @@ class XfroutSession():
msg.set_header_flag(Message.HEADERFLAG_QR)
return msg
def _send_message_with_last_soa(self, msg, sock_fd, rrset_soa, message_upper_len,
count_since_last_tsig_sign):
def _send_message_with_last_soa(self, msg, sock_fd, rrset_soa,
message_upper_len):
'''Add the SOA record to the end of message. If it can't be
added, a new message should be created to send out the last soa .
'''
rrset_len = get_rrset_len(rrset_soa)
if (count_since_last_tsig_sign == TSIG_SIGN_EVERY_NTH and
message_upper_len + rrset_len >= XFROUT_MAX_MESSAGE_SIZE):
# If tsig context exist, sign the packet with serial number TSIG_SIGN_EVERY_NTH
if (message_upper_len + self._tsig_len + get_rrset_len(rrset_soa) >=
XFROUT_MAX_MESSAGE_SIZE):
self._send_message(sock_fd, msg, self._tsig_ctx)
msg = self._clear_message(msg)
elif (count_since_last_tsig_sign != TSIG_SIGN_EVERY_NTH and
message_upper_len + rrset_len + self._tsig_len >= XFROUT_MAX_MESSAGE_SIZE):
self._send_message(sock_fd, msg)
msg = self._clear_message(msg)
# If tsig context exist, sign the last packet
msg.add_rrset(Message.SECTION_ANSWER, rrset_soa)
......@@ -422,7 +412,6 @@ class XfroutSession():
def _reply_xfrout_query(self, msg, sock_fd):
#TODO, there should be a better way to insert rrset.
count_since_last_tsig_sign = TSIG_SIGN_EVERY_NTH
msg.make_response()
msg.set_header_flag(Message.HEADERFLAG_AA)
msg.add_rrset(Message.SECTION_ANSWER, self._soa)
......@@ -447,27 +436,17 @@ class XfroutSession():
message_upper_len += rrset_len
continue
# If tsig context exist, sign every N packets
if count_since_last_tsig_sign == TSIG_SIGN_EVERY_NTH:
count_since_last_tsig_sign = 0
self._send_message(sock_fd, msg, self._tsig_ctx)
else:
self._send_message(sock_fd, msg)
self._send_message(sock_fd, msg, self._tsig_ctx)
count_since_last_tsig_sign += 1
msg = self._clear_message(msg)
# Add the RRset to the new message
msg.add_rrset(Message.SECTION_ANSWER, rrset)
# Reserve tsig space for signed packet
if count_since_last_tsig_sign == TSIG_SIGN_EVERY_NTH:
message_upper_len = rrset_len + self._tsig_len
else:
message_upper_len = rrset_len
message_upper_len = rrset_len + self._tsig_len
self._send_message_with_last_soa(msg, sock_fd, self._soa,
message_upper_len,
count_since_last_tsig_sign)
message_upper_len)
class UnixSockServer(socketserver_mixin.NoPollMixIn,
ThreadingUnixStreamServer):
......
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