1
# test-case-name: twisted.names.test.test_dns
2
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
Tests for twisted.names.dns.
10
from cStringIO import StringIO
12
from StringIO import StringIO
16
from twisted.python.failure import Failure
17
from twisted.internet import address, task
18
from twisted.internet.error import CannotListenError, ConnectionDone
19
from twisted.trial import unittest
20
from twisted.names import dns
22
from twisted.test import proto_helpers
26
class RoundtripDNSTestCase(unittest.TestCase):
27
"""Encoding and then decoding various objects."""
29
names = ["example.org", "go-away.fish.tv", "23strikesback.net"]
41
self.assertEquals(result.name, n)
45
for dnstype in range(1, 17):
46
for dnscls in range(1, 5):
49
dns.Query(n, dnstype, dnscls).encode(f)
55
self.assertEquals(result.name.name, n)
56
self.assertEquals(result.type, dnstype)
57
self.assertEquals(result.cls, dnscls)
62
dns.RRHeader("test.org", 3, 4, 17).encode(f)
66
result = dns.RRHeader()
68
self.assertEquals(str(result.name), "test.org")
69
self.assertEquals(result.type, 3)
70
self.assertEquals(result.cls, 4)
71
self.assertEquals(result.ttl, 17)
74
def testResources(self):
77
"will.compress.will.this.will.name.will.hopefully",
78
"test.CASE.preSErVatIOn.YeAH",
79
"a.s.h.o.r.t.c.a.s.e.t.o.t.e.s.t",
84
dns.SimpleRecord(s).encode(f)
86
result = dns.SimpleRecord()
88
self.assertEquals(str(result.name), s)
90
def test_hashable(self):
92
Instances of all record types are hashable.
95
dns.Record_NS, dns.Record_MD, dns.Record_MF, dns.Record_CNAME,
96
dns.Record_MB, dns.Record_MG, dns.Record_MR, dns.Record_PTR,
97
dns.Record_DNAME, dns.Record_A, dns.Record_SOA, dns.Record_NULL,
98
dns.Record_WKS, dns.Record_SRV, dns.Record_AFSDB, dns.Record_RP,
99
dns.Record_HINFO, dns.Record_MINFO, dns.Record_MX, dns.Record_TXT,
100
dns.Record_AAAA, dns.Record_A6, dns.Record_NAPTR
107
self.assertEquals(hk1, hk2, "%s != %s (for %s)" % (hk1,hk2,k))
110
def test_Charstr(self):
112
Test L{dns.Charstr} encode and decode.
117
dns.Charstr(n).encode(f)
121
result = dns.Charstr()
123
self.assertEquals(result.string, n)
126
def test_NAPTR(self):
128
Test L{dns.Record_NAPTR} encode and decode.
130
naptrs = [(100, 10, "u", "sip+E2U",
131
"!^.*$!sip:information@domain.tld!", ""),
132
(100, 50, "s", "http+I2L+I2C+I2R", "",
133
"_http._tcp.gatech.edu")]
135
for (order, preference, flags, service, regexp, replacement) in naptrs:
136
rin = dns.Record_NAPTR(order, preference, flags, service, regexp,
141
rout = dns.Record_NAPTR()
143
self.assertEquals(rin.order, rout.order)
144
self.assertEquals(rin.preference, rout.preference)
145
self.assertEquals(rin.flags, rout.flags)
146
self.assertEquals(rin.service, rout.service)
147
self.assertEquals(rin.regexp, rout.regexp)
148
self.assertEquals(rin.replacement.name, rout.replacement.name)
149
self.assertEquals(rin.ttl, rout.ttl)
153
class MessageTestCase(unittest.TestCase):
154
def testEmptyMessage(self):
156
Test that a message which has been truncated causes an EOFError to
157
be raised when it is parsed.
160
self.assertRaises(EOFError, msg.fromStr, '')
163
def testEmptyQuery(self):
165
Test that bytes representing an empty query message can be decoded
170
'\x01\x00' # Message ID
171
'\x00' # answer bit, opCode nibble, auth bit, trunc bit, recursive bit
172
'\x00' # recursion bit, empty bit, empty bit, empty bit, response code nibble
173
'\x00\x00' # number of queries
174
'\x00\x00' # number of answers
175
'\x00\x00' # number of authorities
176
'\x00\x00' # number of additionals
178
self.assertEquals(msg.id, 256)
179
self.failIf(msg.answer, "Message was not supposed to be an answer.")
180
self.assertEquals(msg.opCode, dns.OP_QUERY)
181
self.failIf(msg.auth, "Message was not supposed to be authoritative.")
182
self.failIf(msg.trunc, "Message was not supposed to be truncated.")
183
self.assertEquals(msg.queries, [])
184
self.assertEquals(msg.answers, [])
185
self.assertEquals(msg.authority, [])
186
self.assertEquals(msg.additional, [])
190
bytes = ''.join([chr(i) for i in range(256)])
191
rec = dns.Record_NULL(bytes)
192
rr = dns.RRHeader('testname', dns.NULL, payload=rec)
194
msg1.answers.append(rr)
201
self.failUnless(isinstance(msg2.answers[0].payload, dns.Record_NULL))
202
self.assertEquals(msg2.answers[0].payload.payload, bytes)
206
class TestController(object):
208
Pretend to be a DNS query processor for a DNSDatagramProtocol.
210
@ivar messages: the list of received messages.
211
@type messages: C{list} of (msg, protocol, address)
216
Initialize the controller: create a list of messages.
221
def messageReceived(self, msg, proto, addr):
223
Save the message so that it can be checked during the tests.
225
self.messages.append((msg, proto, addr))
229
class DatagramProtocolTestCase(unittest.TestCase):
231
Test various aspects of L{dns.DNSDatagramProtocol}.
236
Create a L{dns.DNSDatagramProtocol} with a deterministic clock.
238
self.clock = task.Clock()
239
self.controller = TestController()
240
self.proto = dns.DNSDatagramProtocol(self.controller)
241
transport = proto_helpers.FakeDatagramTransport()
242
self.proto.makeConnection(transport)
243
self.proto.callLater = self.clock.callLater
246
def test_truncatedPacket(self):
248
Test that when a short datagram is received, datagramReceived does
249
not raise an exception while processing it.
251
self.proto.datagramReceived('',
252
address.IPv4Address('UDP', '127.0.0.1', 12345))
253
self.assertEquals(self.controller.messages, [])
256
def test_simpleQuery(self):
258
Test content received after a query.
260
d = self.proto.query(('127.0.0.1', 21345), [dns.Query('foo')])
261
self.assertEquals(len(self.proto.liveMessages.keys()), 1)
263
m.id = self.proto.liveMessages.items()[0][0]
264
m.answers = [dns.RRHeader(payload=dns.Record_A(address='1.2.3.4'))]
267
self.assertEquals(result.answers[0].payload.dottedQuad(), '1.2.3.4')
269
self.proto.datagramReceived(m.toStr(), ('127.0.0.1', 21345))
273
def test_queryTimeout(self):
275
Test that query timeouts after some seconds.
277
d = self.proto.query(('127.0.0.1', 21345), [dns.Query('foo')])
278
self.assertEquals(len(self.proto.liveMessages), 1)
279
self.clock.advance(10)
280
self.assertFailure(d, dns.DNSQueryTimeoutError)
281
self.assertEquals(len(self.proto.liveMessages), 0)
285
def test_writeError(self):
287
Exceptions raised by the transport's write method should be turned into
288
C{Failure}s passed to errbacks of the C{Deferred} returned by
289
L{DNSDatagramProtocol.query}.
291
def writeError(message, addr):
292
raise RuntimeError("bar")
293
self.proto.transport.write = writeError
295
d = self.proto.query(('127.0.0.1', 21345), [dns.Query('foo')])
296
return self.assertFailure(d, RuntimeError)
299
def test_listenError(self):
301
Exception L{CannotListenError} raised by C{listenUDP} should be turned
302
into a C{Failure} passed to errback of the C{Deferred} returned by
303
L{DNSDatagramProtocol.query}.
305
def startListeningError():
306
raise CannotListenError(None, None, None)
307
self.proto.startListening = startListeningError
308
# Clean up transport so that the protocol calls startListening again
309
self.proto.transport = None
311
d = self.proto.query(('127.0.0.1', 21345), [dns.Query('foo')])
312
return self.assertFailure(d, CannotListenError)
316
class TestTCPController(TestController):
318
Pretend to be a DNS query processor for a DNSProtocol.
320
@ivar connections: A list of L{DNSProtocol} instances which have
321
notified this controller that they are connected and have not
322
yet notified it that their connection has been lost.
325
TestController.__init__(self)
326
self.connections = []
329
def connectionMade(self, proto):
330
self.connections.append(proto)
333
def connectionLost(self, proto):
334
self.connections.remove(proto)
338
class DNSProtocolTestCase(unittest.TestCase):
340
Test various aspects of L{dns.DNSProtocol}.
345
Create a L{dns.DNSProtocol} with a deterministic clock.
347
self.clock = task.Clock()
348
self.controller = TestTCPController()
349
self.proto = dns.DNSProtocol(self.controller)
350
self.proto.makeConnection(proto_helpers.StringTransport())
351
self.proto.callLater = self.clock.callLater
354
def test_connectionTracking(self):
356
L{dns.DNSProtocol} calls its controller's C{connectionMade}
357
method with itself when it is connected to a transport and its
358
controller's C{connectionLost} method when it is disconnected.
360
self.assertEqual(self.controller.connections, [self.proto])
361
self.proto.connectionLost(
362
Failure(ConnectionDone("Fake Connection Done")))
363
self.assertEqual(self.controller.connections, [])
366
def test_queryTimeout(self):
368
Test that query timeouts after some seconds.
370
d = self.proto.query([dns.Query('foo')])
371
self.assertEquals(len(self.proto.liveMessages), 1)
372
self.clock.advance(60)
373
self.assertFailure(d, dns.DNSQueryTimeoutError)
374
self.assertEquals(len(self.proto.liveMessages), 0)
378
def test_simpleQuery(self):
380
Test content received after a query.
382
d = self.proto.query([dns.Query('foo')])
383
self.assertEquals(len(self.proto.liveMessages.keys()), 1)
385
m.id = self.proto.liveMessages.items()[0][0]
386
m.answers = [dns.RRHeader(payload=dns.Record_A(address='1.2.3.4'))]
389
self.assertEquals(result.answers[0].payload.dottedQuad(), '1.2.3.4')
392
s = struct.pack('!H', len(s)) + s
393
self.proto.dataReceived(s)
397
def test_writeError(self):
399
Exceptions raised by the transport's write method should be turned into
400
C{Failure}s passed to errbacks of the C{Deferred} returned by
401
L{DNSProtocol.query}.
403
def writeError(message):
404
raise RuntimeError("bar")
405
self.proto.transport.write = writeError
407
d = self.proto.query([dns.Query('foo')])
408
return self.assertFailure(d, RuntimeError)
412
class ReprTests(unittest.TestCase):
414
Tests for the C{__repr__} implementation of record classes.
418
The repr of a L{dns.Record_NS} instance includes the name of the
419
nameserver and the TTL of the record.
422
repr(dns.Record_NS('example.com', 4321)),
423
"<NS name=example.com ttl=4321>")
428
The repr of a L{dns.Record_MD} instance includes the name of the
429
mail destination and the TTL of the record.
432
repr(dns.Record_MD('example.com', 4321)),
433
"<MD name=example.com ttl=4321>")
438
The repr of a L{dns.Record_MF} instance includes the name of the
439
mail forwarder and the TTL of the record.
442
repr(dns.Record_MF('example.com', 4321)),
443
"<MF name=example.com ttl=4321>")
446
def test_cname(self):
448
The repr of a L{dns.Record_CNAME} instance includes the name of the
449
mail forwarder and the TTL of the record.
452
repr(dns.Record_CNAME('example.com', 4321)),
453
"<CNAME name=example.com ttl=4321>")
458
The repr of a L{dns.Record_MB} instance includes the name of the
459
mailbox and the TTL of the record.
462
repr(dns.Record_MB('example.com', 4321)),
463
"<MB name=example.com ttl=4321>")
468
The repr of a L{dns.Record_MG} instance includes the name of the
469
mail group memeber and the TTL of the record.
472
repr(dns.Record_MG('example.com', 4321)),
473
"<MG name=example.com ttl=4321>")
478
The repr of a L{dns.Record_MR} instance includes the name of the
479
mail rename domain and the TTL of the record.
482
repr(dns.Record_MR('example.com', 4321)),
483
"<MR name=example.com ttl=4321>")
488
The repr of a L{dns.Record_PTR} instance includes the name of the
489
pointer and the TTL of the record.
492
repr(dns.Record_PTR('example.com', 4321)),
493
"<PTR name=example.com ttl=4321>")
496
def test_dname(self):
498
The repr of a L{dns.Record_DNAME} instance includes the name of the
499
non-terminal DNS name redirection and the TTL of the record.
502
repr(dns.Record_DNAME('example.com', 4321)),
503
"<DNAME name=example.com ttl=4321>")
508
The repr of a L{dns.Record_A} instance includes the dotted-quad
509
string representation of the address it is for and the TTL of the
513
repr(dns.Record_A('1.2.3.4', 567)),
514
'<A address=1.2.3.4 ttl=567>')
519
The repr of a L{dns.Record_SOA} instance includes all of the
523
repr(dns.Record_SOA(mname='mName', rname='rName', serial=123,
524
refresh=456, retry=789, expire=10,
525
minimum=11, ttl=12)),
526
"<SOA mname=mName rname=rName serial=123 refresh=456 "
527
"retry=789 expire=10 minimum=11 ttl=12>")
532
The repr of a L{dns.Record_NULL} instance includes the repr of its
533
payload and the TTL of the record.
536
repr(dns.Record_NULL('abcd', 123)),
537
"<NULL payload='abcd' ttl=123>")
542
The repr of a L{dns.Record_WKS} instance includes the dotted-quad
543
string representation of the address it is for, the IP protocol
544
number it is for, and the TTL of the record.
547
repr(dns.Record_WKS('2.3.4.5', 7, ttl=8)),
548
"<WKS address=2.3.4.5 protocol=7 ttl=8>")
553
The repr of a L{dns.Record_AAAA} instance includes the colon-separated
554
hex string representation of the address it is for and the TTL of the
558
repr(dns.Record_AAAA('8765::1234', ttl=10)),
559
"<AAAA address=8765::1234 ttl=10>")
564
The repr of a L{dns.Record_A6} instance includes the colon-separated
565
hex string representation of the address it is for and the TTL of the
569
repr(dns.Record_A6(0, '1234::5678', 'foo.bar', ttl=10)),
570
"<A6 suffix=1234::5678 prefix=foo.bar ttl=10>")
575
The repr of a L{dns.Record_SRV} instance includes the name and port of
576
the target and the priority, weight, and TTL of the record.
579
repr(dns.Record_SRV(1, 2, 3, 'example.org', 4)),
580
"<SRV priority=1 weight=2 target=example.org port=3 ttl=4>")
583
def test_naptr(self):
585
The repr of a L{dns.Record_NAPTR} instance includes the order,
586
preference, flags, service, regular expression, replacement, and TTL of
590
repr(dns.Record_NAPTR(5, 9, "S", "http", "/foo/bar/i", "baz", 3)),
591
"<NAPTR order=5 preference=9 flags=S service=http "
592
"regexp=/foo/bar/i replacement=baz ttl=3>")
595
def test_afsdb(self):
597
The repr of a L{dns.Record_AFSDB} instance includes the subtype,
598
hostname, and TTL of the record.
601
repr(dns.Record_AFSDB(3, 'example.org', 5)),
602
"<AFSDB subtype=3 hostname=example.org ttl=5>")
607
The repr of a L{dns.Record_RP} instance includes the mbox, txt, and TTL
608
fields of the record.
611
repr(dns.Record_RP('alice.example.com', 'admin.example.com', 3)),
612
"<RP mbox=alice.example.com txt=admin.example.com ttl=3>")
615
def test_hinfo(self):
617
The repr of a L{dns.Record_HINFO} instance includes the cpu, os, and
618
TTL fields of the record.
621
repr(dns.Record_HINFO('sparc', 'minix', 12)),
622
"<HINFO cpu='sparc' os='minix' ttl=12>")
625
def test_minfo(self):
627
The repr of a L{dns.Record_MINFO} instance includes the rmailbx,
628
emailbx, and TTL fields of the record.
631
repr(dns.Record_MINFO('alice.example.com', 'bob.example.com', 15)),
632
"<MINFO responsibility=alice.example.com "
633
"errors=bob.example.com ttl=15>")
638
The repr of a L{dns.Record_MX} instance includes the preference, name,
639
and TTL fields of the record.
642
repr(dns.Record_MX(13, 'mx.example.com', 2)),
643
"<MX preference=13 name=mx.example.com ttl=2>")
648
The repr of a L{dns.Record_TXT} instance includes the data and ttl
649
fields of the record.
652
repr(dns.Record_TXT("foo", "bar", ttl=15)),
653
"<TXT data=['foo', 'bar'] ttl=15>")
657
class _Equal(object):
659
A class the instances of which are equal to anything and everything.
661
def __eq__(self, other):
665
def __ne__(self, other):
670
class _NotEqual(object):
672
A class the instances of which are equal to nothing.
674
def __eq__(self, other):
678
def __ne__(self, other):
683
class EqualityTests(unittest.TestCase):
685
Tests for the equality and non-equality behavior of record classes.
687
def _equalityTest(self, firstValueOne, secondValueOne, valueTwo):
689
Assert that C{firstValueOne} is equal to C{secondValueOne} but not
690
equal to C{valueOne} and that it defines equality cooperatively with
691
other types it doesn't know about.
693
# This doesn't use assertEqual and assertNotEqual because the exact
694
# operator those functions use is not very well defined. The point
695
# of these assertions is to check the results of the use of specific
696
# operators (precisely to ensure that using different permutations
697
# (eg "x == y" or "not (x != y)") which should yield the same results
698
# actually does yield the same result). -exarkun
699
self.assertTrue(firstValueOne == firstValueOne)
700
self.assertTrue(firstValueOne == secondValueOne)
701
self.assertFalse(firstValueOne == valueTwo)
702
self.assertFalse(firstValueOne != firstValueOne)
703
self.assertFalse(firstValueOne != secondValueOne)
704
self.assertTrue(firstValueOne != valueTwo)
705
self.assertTrue(firstValueOne == _Equal())
706
self.assertFalse(firstValueOne != _Equal())
707
self.assertFalse(firstValueOne == _NotEqual())
708
self.assertTrue(firstValueOne != _NotEqual())
711
def _simpleEqualityTest(self, cls):
714
cls('example.com', 123),
715
cls('example.com', 123),
716
cls('example.com', 321))
719
cls('example.com', 123),
720
cls('example.com', 123),
721
cls('example.org', 123))
724
def test_rrheader(self):
726
Two L{dns.RRHeader} instances compare equal if and only if they have
727
the same name, type, class, time to live, payload, and authoritative
732
dns.RRHeader('example.com', payload=dns.Record_A('1.2.3.4')),
733
dns.RRHeader('example.com', payload=dns.Record_A('1.2.3.4')),
734
dns.RRHeader('example.org', payload=dns.Record_A('1.2.3.4')))
738
dns.RRHeader('example.com', payload=dns.Record_A('1.2.3.4')),
739
dns.RRHeader('example.com', payload=dns.Record_A('1.2.3.4')),
740
dns.RRHeader('example.com', payload=dns.Record_A('1.2.3.5')))
742
# Vary the type. Leave the payload as None so that we don't have to
743
# provide non-equal values.
745
dns.RRHeader('example.com', dns.A),
746
dns.RRHeader('example.com', dns.A),
747
dns.RRHeader('example.com', dns.MX))
749
# Probably not likely to come up. Most people use the internet.
751
dns.RRHeader('example.com', cls=dns.IN, payload=dns.Record_A('1.2.3.4')),
752
dns.RRHeader('example.com', cls=dns.IN, payload=dns.Record_A('1.2.3.4')),
753
dns.RRHeader('example.com', cls=dns.CS, payload=dns.Record_A('1.2.3.4')))
757
dns.RRHeader('example.com', ttl=60, payload=dns.Record_A('1.2.3.4')),
758
dns.RRHeader('example.com', ttl=60, payload=dns.Record_A('1.2.3.4')),
759
dns.RRHeader('example.com', ttl=120, payload=dns.Record_A('1.2.3.4')))
763
dns.RRHeader('example.com', auth=1, payload=dns.Record_A('1.2.3.4')),
764
dns.RRHeader('example.com', auth=1, payload=dns.Record_A('1.2.3.4')),
765
dns.RRHeader('example.com', auth=0, payload=dns.Record_A('1.2.3.4')))
770
Two L{dns.Record_NS} instances compare equal if and only if they have
771
the same name and TTL.
773
self._simpleEqualityTest(dns.Record_NS)
778
Two L{dns.Record_MD} instances compare equal if and only if they have
779
the same name and TTL.
781
self._simpleEqualityTest(dns.Record_MD)
786
Two L{dns.Record_MF} instances compare equal if and only if they have
787
the same name and TTL.
789
self._simpleEqualityTest(dns.Record_MF)
792
def test_cname(self):
794
Two L{dns.Record_CNAME} instances compare equal if and only if they
795
have the same name and TTL.
797
self._simpleEqualityTest(dns.Record_CNAME)
802
Two L{dns.Record_MB} instances compare equal if and only if they have
803
the same name and TTL.
805
self._simpleEqualityTest(dns.Record_MB)
810
Two L{dns.Record_MG} instances compare equal if and only if they have
811
the same name and TTL.
813
self._simpleEqualityTest(dns.Record_MG)
818
Two L{dns.Record_MR} instances compare equal if and only if they have
819
the same name and TTL.
821
self._simpleEqualityTest(dns.Record_MR)
826
Two L{dns.Record_PTR} instances compare equal if and only if they have
827
the same name and TTL.
829
self._simpleEqualityTest(dns.Record_PTR)
832
def test_dname(self):
834
Two L{dns.Record_MD} instances compare equal if and only if they have
835
the same name and TTL.
837
self._simpleEqualityTest(dns.Record_DNAME)
842
Two L{dns.Record_A} instances compare equal if and only if they have
843
the same address and TTL.
847
dns.Record_A('1.2.3.4', 5),
848
dns.Record_A('1.2.3.4', 5),
849
dns.Record_A('1.2.3.4', 6))
852
dns.Record_A('1.2.3.4', 5),
853
dns.Record_A('1.2.3.4', 5),
854
dns.Record_A('1.2.3.5', 5))
859
Two L{dns.Record_SOA} instances compare equal if and only if they have
860
the same mname, rname, serial, refresh, minimum, expire, retry, and
865
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
866
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
867
dns.Record_SOA('xname', 'rname', 123, 456, 789, 10, 20, 30))
870
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
871
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
872
dns.Record_SOA('mname', 'xname', 123, 456, 789, 10, 20, 30))
875
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
876
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
877
dns.Record_SOA('mname', 'rname', 1, 456, 789, 10, 20, 30))
880
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
881
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
882
dns.Record_SOA('mname', 'rname', 123, 1, 789, 10, 20, 30))
885
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
886
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
887
dns.Record_SOA('mname', 'rname', 123, 456, 1, 10, 20, 30))
890
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
891
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
892
dns.Record_SOA('mname', 'rname', 123, 456, 789, 1, 20, 30))
895
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
896
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
897
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 1, 30))
900
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
901
dns.Record_SOA('mname', 'rname', 123, 456, 789, 10, 20, 30),
902
dns.Record_SOA('mname', 'xname', 123, 456, 789, 10, 20, 1))
907
Two L{dns.Record_NULL} instances compare equal if and only if they have
908
the same payload and ttl.
912
dns.Record_NULL('foo bar', 10),
913
dns.Record_NULL('foo bar', 10),
914
dns.Record_NULL('bar foo', 10))
917
dns.Record_NULL('foo bar', 10),
918
dns.Record_NULL('foo bar', 10),
919
dns.Record_NULL('foo bar', 100))
924
Two L{dns.Record_WKS} instances compare equal if and only if they have
925
the same address, protocol, map, and ttl.
929
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
930
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
931
dns.Record_WKS('4.3.2.1', 1, 'foo', 2))
934
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
935
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
936
dns.Record_WKS('1.2.3.4', 100, 'foo', 2))
939
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
940
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
941
dns.Record_WKS('1.2.3.4', 1, 'bar', 2))
944
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
945
dns.Record_WKS('1.2.3.4', 1, 'foo', 2),
946
dns.Record_WKS('1.2.3.4', 1, 'foo', 200))
951
Two L{dns.Record_AAAA} instances compare equal if and only if they have
952
the same address and ttl.
956
dns.Record_AAAA('1::2', 1),
957
dns.Record_AAAA('1::2', 1),
958
dns.Record_AAAA('2::1', 1))
961
dns.Record_AAAA('1::2', 1),
962
dns.Record_AAAA('1::2', 1),
963
dns.Record_AAAA('1::2', 10))
968
Two L{dns.Record_A6} instances compare equal if and only if they have
969
the same prefix, prefix length, suffix, and ttl.
971
# Note, A6 is crazy, I'm not sure these values are actually legal.
972
# Hopefully that doesn't matter for this test. -exarkun
974
# Vary the prefix length
976
dns.Record_A6(16, '::abcd', 'example.com', 10),
977
dns.Record_A6(16, '::abcd', 'example.com', 10),
978
dns.Record_A6(32, '::abcd', 'example.com', 10))
981
dns.Record_A6(16, '::abcd', 'example.com', 10),
982
dns.Record_A6(16, '::abcd', 'example.com', 10),
983
dns.Record_A6(16, '::abcd:0', 'example.com', 10))
986
dns.Record_A6(16, '::abcd', 'example.com', 10),
987
dns.Record_A6(16, '::abcd', 'example.com', 10),
988
dns.Record_A6(16, '::abcd', 'example.org', 10))
991
dns.Record_A6(16, '::abcd', 'example.com', 10),
992
dns.Record_A6(16, '::abcd', 'example.com', 10),
993
dns.Record_A6(16, '::abcd', 'example.com', 100))
998
Two L{dns.Record_SRV} instances compare equal if and only if they have
999
the same priority, weight, port, target, and ttl.
1003
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1004
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1005
dns.Record_SRV(100, 20, 30, 'example.com', 40))
1008
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1009
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1010
dns.Record_SRV(10, 200, 30, 'example.com', 40))
1013
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1014
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1015
dns.Record_SRV(10, 20, 300, 'example.com', 40))
1018
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1019
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1020
dns.Record_SRV(10, 20, 30, 'example.org', 40))
1023
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1024
dns.Record_SRV(10, 20, 30, 'example.com', 40),
1025
dns.Record_SRV(10, 20, 30, 'example.com', 400))
1028
def test_naptr(self):
1030
Two L{dns.Record_NAPTR} instances compare equal if and only if they
1031
have the same order, preference, flags, service, regexp, replacement,
1036
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1037
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1038
dns.Record_NAPTR(2, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12))
1039
# Vary the preference
1041
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1042
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1043
dns.Record_NAPTR(1, 3, "u", "sip+E2U", "/foo/bar/", "baz", 12))
1046
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1047
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1048
dns.Record_NAPTR(1, 2, "p", "sip+E2U", "/foo/bar/", "baz", 12))
1051
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1052
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1053
dns.Record_NAPTR(1, 2, "u", "http", "/foo/bar/", "baz", 12))
1056
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1057
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1058
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/bar/foo/", "baz", 12))
1059
# Vary the replacement
1061
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1062
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1063
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/bar/foo/", "quux", 12))
1066
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1067
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/foo/bar/", "baz", 12),
1068
dns.Record_NAPTR(1, 2, "u", "sip+E2U", "/bar/foo/", "baz", 5))
1071
def test_afsdb(self):
1073
Two L{dns.Record_AFSDB} instances compare equal if and only if they
1074
have the same subtype, hostname, and ttl.
1078
dns.Record_AFSDB(1, 'example.com', 2),
1079
dns.Record_AFSDB(1, 'example.com', 2),
1080
dns.Record_AFSDB(2, 'example.com', 2))
1083
dns.Record_AFSDB(1, 'example.com', 2),
1084
dns.Record_AFSDB(1, 'example.com', 2),
1085
dns.Record_AFSDB(1, 'example.org', 2))
1088
dns.Record_AFSDB(1, 'example.com', 2),
1089
dns.Record_AFSDB(1, 'example.com', 2),
1090
dns.Record_AFSDB(1, 'example.com', 3))
1095
Two L{Record_RP} instances compare equal if and only if they have the
1096
same mbox, txt, and ttl.
1100
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1101
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1102
dns.Record_RP('bob.example.com', 'alice is nice', 10))
1105
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1106
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1107
dns.Record_RP('alice.example.com', 'alice is not nice', 10))
1110
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1111
dns.Record_RP('alice.example.com', 'alice is nice', 10),
1112
dns.Record_RP('alice.example.com', 'alice is nice', 100))
1115
def test_hinfo(self):
1117
Two L{dns.Record_HINFO} instances compare equal if and only if they
1118
have the same cpu, os, and ttl.
1122
dns.Record_HINFO('x86-64', 'plan9', 10),
1123
dns.Record_HINFO('x86-64', 'plan9', 10),
1124
dns.Record_HINFO('i386', 'plan9', 10))
1127
dns.Record_HINFO('x86-64', 'plan9', 10),
1128
dns.Record_HINFO('x86-64', 'plan9', 10),
1129
dns.Record_HINFO('x86-64', 'plan11', 10))
1132
dns.Record_HINFO('x86-64', 'plan9', 10),
1133
dns.Record_HINFO('x86-64', 'plan9', 10),
1134
dns.Record_HINFO('x86-64', 'plan9', 100))
1137
def test_minfo(self):
1139
Two L{dns.Record_MINFO} instances compare equal if and only if they
1140
have the same rmailbx, emailbx, and ttl.
1144
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1145
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1146
dns.Record_MINFO('someplace', 'emailbox', 10))
1149
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1150
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1151
dns.Record_MINFO('rmailbox', 'something', 10))
1154
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1155
dns.Record_MINFO('rmailbox', 'emailbox', 10),
1156
dns.Record_MINFO('rmailbox', 'emailbox', 100))
1161
Two L{dns.Record_MX} instances compare equal if and only if they have
1162
the same preference, name, and ttl.
1164
# Vary the preference
1166
dns.Record_MX(10, 'example.org', 20),
1167
dns.Record_MX(10, 'example.org', 20),
1168
dns.Record_MX(100, 'example.org', 20))
1171
dns.Record_MX(10, 'example.org', 20),
1172
dns.Record_MX(10, 'example.org', 20),
1173
dns.Record_MX(10, 'example.net', 20))
1176
dns.Record_MX(10, 'example.org', 20),
1177
dns.Record_MX(10, 'example.org', 20),
1178
dns.Record_MX(10, 'example.org', 200))
1183
Two L{dns.Record_TXT} instances compare equal if and only if they have
1184
the same data and ttl.
1186
# Vary the length of the data
1188
dns.Record_TXT(['foo', 'bar'], 10),
1189
dns.Record_TXT(['foo', 'bar'], 10),
1190
dns.Record_TXT(['foo', 'bar', 'baz'], 10))
1191
# Vary the value of the data
1193
dns.Record_TXT(['foo', 'bar'], 10),
1194
dns.Record_TXT(['foo', 'bar'], 10),
1195
dns.Record_TXT(['bar', 'foo'], 10))
1198
dns.Record_TXT(['foo', 'bar'], 10),
1199
dns.Record_TXT(['foo', 'bar'], 10),
1200
dns.Record_TXT(['foo', 'bar'], 100))