Beispiel #1
0
    def testDetectsQR(self):
	"""Test whether DNSFlags detects whether the message is a query or response"""
	from Strangle import libbind

	for message in self.queries:
	    messageText = message['data']
	    message = libbind.ns_msg(messageText)
	    flags = Strangle.DNSFlags(message)
	    self.assertEquals(flags.type, 'question')
	for message in self.responses:
	    messageText = message['data']
	    message = libbind.ns_msg(messageText)
	    flags = Strangle.DNSFlags(message)
	    self.assertEquals(flags.type, 'answer')
Beispiel #2
0
    def testlibbind_ns_msg_getflag(self):
	"""Test whether libbind correctly returns the message flags"""
	for message in self.queries + self.responses:
	    msg = libbind.ns_msg(message['data'])
	    for flag in self.flags:
		flagVal = getattr(libbind, flag)
		self.assertEquals(libbind.ns_msg_getflag(msg, flagVal), message['flags'][flag])
Beispiel #3
0
    def testlibbind_ns_msg_count(self):
	"""Test whether ns_msg_count correctly returns the section counts"""
	for message in self.queries + self.responses:
	    msg = libbind.ns_msg(message['data'])
	    for section in self.sections:
		sectionVal = getattr(libbind, section)
		self.assertEquals(libbind.ns_msg_count(msg, sectionVal), message['sections'][section])
Beispiel #4
0
    def testlibbind_ns_msg_countArgs(self):
	"""Test whether ns_msg_count accepts the proper arguments"""
	self.assertRaises(TypeError, libbind.ns_msg_count)

	msg = libbind.ns_msg(self.queries[0]['data'])
	self.assertRaises(TypeError, libbind.ns_msg_count, msg)

	self.assertRaises(TypeError, libbind.ns_msg_count, msg, 'not an int')
Beispiel #5
0
    def testGetsAuthor(self):
	"""Test whether DNSFlags determines whether the message is authoritative"""
	from Strangle import libbind

	for message in self.queries + self.responses:
	    msg   = libbind.ns_msg(message['data'])
	    flags = Strangle.DNSFlags(msg)
	    self.assertEquals(flags.authoritative, message['flags']['ns_f_aa'])
Beispiel #6
0
    def setUp(self):
	from Strangle import libbind

	self.queries   = testutils.queries
	self.responses = testutils.responses

	self.msgFileName = "data/www.microsoft.com-response"
	self.msg         = libbind.ns_msg( file(self.msgFileName).read() )
Beispiel #7
0
    def testGetsResponse(self):
	"""Test whether DNSFlags determines the correct response code"""
	from Strangle import libbind

	for message in self.queries + self.responses:
	    msg   = libbind.ns_msg(message['data'])
	    flags = Strangle.DNSFlags(msg)
	    self.assertEquals(flags.response, message['flags']['ns_f_rcode'])
Beispiel #8
0
    def testGetsRA(self):
	"""Test whether DNSFlags determines whether recursion is available"""
	from Strangle import libbind

	for message in self.queries + self.responses:
	    msg   = libbind.ns_msg(message['data'])
	    flags = Strangle.DNSFlags(msg)
	    self.assertEquals(flags.recursionAvailable, message['flags']['ns_f_ra'])
Beispiel #9
0
    def testGetsTrunc(self):
	"""Test whether DNSFlags determines whether the message is truncated"""
	from Strangle import libbind

	for message in self.queries + self.responses:
	    msg   = libbind.ns_msg(message['data'])
	    flags = Strangle.DNSFlags(msg)
	    self.assertEquals(flags.truncated, message['flags']['ns_f_tc'])
Beispiel #10
0
    def testlibbind_ns_data_offsetNone(self):
	"""Test that ns_data_offset properly handles None's ref count"""

	msg = libbind.ns_msg(self.responses[0]['data'])
	rr  = libbind.ns_rr(msg, libbind.ns_s_qd, 0)

	# There is no way to test this with assert.  We just run a bunch of times
	# and if Python crashes, well, then we failed the test.
	for i in xrange(1, 10000):
	    data = libbind.ns_data_offset(msg, rr)
	    del data
	
	assert True
Beispiel #11
0
    def setUp(self):
	import os, re

	self.queries = testutils.queries
	self.responses = testutils.responses

	self.packetData = file("data/oreilly.com-response").read()
	self.msg = libbind.ns_msg(self.packetData)

	self.flags = ['qr', 'opcode', 'aa', 'tc', 'rd', 'ra', 'z', 'ad', 'cd', 'rcode', 'max']
	self.flags = map(lambda str: 'ns_f_' + str, self.flags)

	self.sections = ['qd', 'an', 'ns', 'ar']
	self.sections = map(lambda str: 'ns_s_' + str, self.sections)
Beispiel #12
0
    def testlibbind_ns_data_offset(self):
	"""Test whether ns_data_offset returns the correct offsets"""
	msg = libbind.ns_msg(self.responses[0]['data'])

	# Query has no name record
	rr = libbind.ns_rr(msg, libbind.ns_s_qd, 0)
	assert libbind.ns_data_offset(msg, rr) is None

	# Answer
	rr = libbind.ns_rr(msg, libbind.ns_s_an, 0)
	self.assertEquals(libbind.ns_data_offset(msg, rr), 49)

	# Name servers
	rr = libbind.ns_rr(msg, libbind.ns_s_ns, 0)
	self.assertEquals(libbind.ns_data_offset(msg, rr), 65)

	# Additional
	rr = libbind.ns_rr(msg, libbind.ns_s_ar, 0)
	self.assertEquals(libbind.ns_data_offset(msg, rr), 83)
Beispiel #13
0
    def testlibbind_ns_name_uncompress(self):
	"""Test whether ns_name_uncompress returns the correct name"""
	msg = libbind.ns_msg(self.responses[2]['data'])

	# Query has no name record

	# Answer
	rr = libbind.ns_rr(msg, libbind.ns_s_an, 0)
	assert(libbind.ns_name_uncompress(msg, rr) == 'smtp1.oreilly.com')
	rr = libbind.ns_rr(msg, libbind.ns_s_an, 1)
	assert(libbind.ns_name_uncompress(msg, rr) == 'smtp2.oreilly.com')

	# Name servers
	rr = libbind.ns_rr(msg, libbind.ns_s_ns, 0)
	assert(libbind.ns_name_uncompress(msg, rr) == 'ns1.sonic.net')
	rr = libbind.ns_rr(msg, libbind.ns_s_ns, 1)
	assert(libbind.ns_name_uncompress(msg, rr) == 'ns2.sonic.net')
	rr = libbind.ns_rr(msg, libbind.ns_s_ns, 2)
	assert(libbind.ns_name_uncompress(msg, rr) == 'ns.oreilly.com')
Beispiel #14
0
    def testDetectsMissingSect(self):
	"""Test that DNSSection detects a section that does not exist in the message"""
	from Strangle import libbind
	msg = libbind.ns_msg(file("data/www.microsoft.com-query").read())
	self.assertRaises(Strangle.DNSSectionError, Strangle.DNSSection, msg, 'authority')
Beispiel #15
0
    def setUp(self):
	from Strangle import libbind

	msgFileName = "data/oreilly.com-response"
	self.msg    = libbind.ns_msg( file(msgFileName).read() )
Beispiel #16
0
    def setUp(self):
	self.packetData = file("data/oreilly.com-response").read()
	self.msg = libbind.ns_msg(self.packetData)
Beispiel #17
0
    def testParseValidResponse(self):
	"""Test whether ns_msg initialization parses valid NS queries"""
	packetData = file("data/www.company.example-response").read()
	n = libbind.ns_msg(packetData)
	assert(type(n) is libbind.ns_msg)