diff -Nru dnspython-1.11.1/ChangeLog dnspython-1.12.0/ChangeLog --- dnspython-1.11.1/ChangeLog 2013-09-02 18:50:25.000000000 +0000 +++ dnspython-1.12.0/ChangeLog 2014-09-01 12:59:01.000000000 +0000 @@ -1,3 +1,86 @@ +2014-09-01 Bob Halley + + * (Version 1.12.0 released) + +2014-08-31 Bob Halley + + * The test system can now run the tests without requiring dnspython + to be installed. + +2014-07-24 Bob Halley + + * The 64-bit version of Python on Windows has sys.maxint set to + 2^31-1, yet passes 2^63-1 as the "unspecified bound" value in + slices. This is a bug in Python as the documentation says the + unspecified bound value should be sys.maxint. We now cope with + this. Thanks to Matthäus Wander for reporting the problem. + +2014-06-21 Bob Halley + + * When reading from a masterfile, if the first content line + started with leading whitespace, we raised an ugly exception + instead of doing the right thing, namely using the zone origin as + the name. [#73] Thanks to Tassatux for reporting the issue. + + * Added dns.zone.to_text() convenience method. Thanks to Brandon + Whaley for the patch. + + * The /etc/resolv.conf setting "options rotate" is now understood + by the resolver. If present, the resolver will shuffle the + nameserver list each time dns.resolver.query() is called. Thanks + to underrun for the patch. Note that you don't want to add + "options rotate" to your /etc/resolv.conf if your system's + resolver library does not understand it. In this case, just set + resolver.rotate = True by hand. + +2014-06-19 Bob Halley + + * Escaping of Unicode has been corrected. Previously we escaped + and then converted to Unicode, but the right thing to do is + convert to Unicode, then escape. Also, characters > 0x7f should + NOT be escaped in Unicode mode. Thanks to Martin Basti for the + patch. + + * dns.rdtypes.ANY.DNSKEY now has helpers functions to convert + between the numeric form of the flags and a set of human-friendly + strings. Thanks to Petr Spacek for the patch. + + * RRSIGs did not respect relativization settings in to_text(). + Thanks to Brian Smith for reporting the bug and submitting a + (slightly different) patch. + +2014-06-18 Bob Halley + + * dns/rdtypes/IN/APL.py: The APL from_wire() method did not accept an + rdata length of 0 as valid. Thanks to salzmdan for reporting the + problem. + +2014-05-31 Bob Halley + + * dns/ipv6.py: Add is_mapped() + + * dns/reversename.py: Lookup IPv6 mapped IPv4 addresses in the v4 + reverse namespace. Thanks to Devin Bayer. Yes, I finally fixed + this one :) + +2014-04-11 Bob Halley + + * dns/zone.py: Do not put back an unescaped token. This was + causing escape processing for domain names to break. Thanks to + connormclaud for reporting the problem. + +2014-04-04 Bob Halley + + * dns/message.py: Making a response didn't work correctly if the + query was signed with TSIG and we knew the key. Thanks to Jeffrey + Stiles for reporting the problem. + +2013-12-11 Bob Halley + + * dns/query.py: Fix problems with the IXFR state machine which caused + long diffs to fail. Thanks to James Raftery for the fix and the + repeated prodding to get it applied :) + 2013-09-02 Bob Halley * (Version 1.11.1 released) diff -Nru dnspython-1.11.1/debian/changelog dnspython-1.12.0/debian/changelog --- dnspython-1.11.1/debian/changelog 2014-02-23 13:47:10.000000000 +0000 +++ dnspython-1.12.0/debian/changelog 2015-04-01 14:29:36.000000000 +0000 @@ -1,8 +1,15 @@ -dnspython (1.11.1-1build1) trusty; urgency=medium +dnspython (1.12.0-1~cloud0) trusty-kilo; urgency=medium - * Rebuild to drop files installed into /usr/share/pyshared. + * New upstream release for the Ubuntu Cloud Archive. - -- Matthias Klose Sun, 23 Feb 2014 13:47:10 +0000 + -- Openstack Ubuntu Testing Bot Wed, 01 Apr 2015 14:29:36 +0000 + +dnspython (1.12.0-1) unstable; urgency=medium + + * New upstream release + * Add explicit build-dep on dh-python to make use of the newer version + + -- Scott Kitterman Sun, 14 Sep 2014 22:46:43 -0400 dnspython (1.11.1-1) unstable; urgency=low diff -Nru dnspython-1.11.1/debian/control dnspython-1.12.0/debian/control --- dnspython-1.11.1/debian/control 2013-11-06 07:03:41.000000000 +0000 +++ dnspython-1.12.0/debian/control 2014-09-15 02:48:57.000000000 +0000 @@ -3,7 +3,7 @@ Priority: optional Maintainer: Debian Python Modules Team Uploaders: Robert S. Edmonds , Scott Kitterman -Build-Depends: debhelper (>= 8.1~), python-all (>= 2.6.6-3~) +Build-Depends: debhelper (>= 8.1~), python-all (>= 2.6.6-3~), dh-python Homepage: http://www.dnspython.org Standards-Version: 3.9.5 Vcs-Svn: svn://anonscm.debian.org/python-modules/packages/dnspython/trunk/ diff -Nru dnspython-1.11.1/dns/dnssec.py dnspython-1.12.0/dns/dnssec.py --- dnspython-1.11.1/dns/dnssec.py 2013-08-09 17:03:27.000000000 +0000 +++ dnspython-1.12.0/dns/dnssec.py 2014-05-31 18:00:16.000000000 +0000 @@ -45,6 +45,8 @@ RSASHA1NSEC3SHA1 = 7 RSASHA256 = 8 RSASHA512 = 10 +ECDSAP256SHA256 = 13 +ECDSAP384SHA384 = 14 INDIRECT = 252 PRIVATEDNS = 253 PRIVATEOID = 254 @@ -60,6 +62,8 @@ 'RSASHA256' : RSASHA256, 'RSASHA512' : RSASHA512, 'INDIRECT' : INDIRECT, + 'ECDSAP256SHA256' : ECDSAP256SHA256, + 'ECDSAP384SHA384' : ECDSAP384SHA384, 'PRIVATEDNS' : PRIVATEDNS, 'PRIVATEOID' : PRIVATEOID, } @@ -153,6 +157,9 @@ def _is_dsa(algorithm): return algorithm in (DSA, DSANSEC3SHA1) +def _is_ecdsa(algorithm): + return _have_ecdsa and (algorithm in (ECDSAP256SHA256, ECDSAP384SHA384)) + def _is_md5(algorithm): return algorithm == RSAMD5 @@ -161,7 +168,10 @@ DSANSEC3SHA1, RSASHA1NSEC3SHA1) def _is_sha256(algorithm): - return algorithm == RSASHA256 + return algorithm in (RSASHA256, ECDSAP256SHA256) + +def _is_sha384(algorithm): + return algorithm == ECDSAP384SHA384 def _is_sha512(algorithm): return algorithm == RSASHA512 @@ -173,6 +183,8 @@ return dns.hash.get('SHA1')() if _is_sha256(algorithm): return dns.hash.get('SHA256')() + if _is_sha384(algorithm): + return dns.hash.get('SHA384')() if _is_sha512(algorithm): return dns.hash.get('SHA512')() raise ValidationFailure, 'unknown hash for algorithm %u' % algorithm @@ -274,6 +286,30 @@ (dsa_r, dsa_s) = struct.unpack('!20s20s', rrsig.signature[1:]) sig = (Crypto.Util.number.bytes_to_long(dsa_r), Crypto.Util.number.bytes_to_long(dsa_s)) + elif _is_ecdsa(rrsig.algorithm): + if rrsig.algorithm == ECDSAP256SHA256: + curve = ecdsa.curves.NIST256p + key_len = 32 + digest_len = 32 + elif rrsig.algorithm == ECDSAP384SHA384: + curve = ecdsa.curves.NIST384p + key_len = 48 + digest_len = 48 + else: + # shouldn't happen + raise ValidationFailure, 'unknown ECDSA curve' + keyptr = candidate_key.key + x = Crypto.Util.number.bytes_to_long(keyptr[0:key_len]) + y = Crypto.Util.number.bytes_to_long(keyptr[key_len:key_len * 2]) + assert ecdsa.ecdsa.point_is_valid(curve.generator, x, y) + point = ecdsa.ellipticcurve.Point(curve.curve, x, y, curve.order) + verifying_key = ecdsa.keys.VerifyingKey.from_public_point(point, + curve) + pubkey = ECKeyWrapper(verifying_key, key_len) + r = rrsig.signature[:key_len] + s = rrsig.signature[key_len:] + sig = ecdsa.ecdsa.Signature(Crypto.Util.number.bytes_to_long(r), + Crypto.Util.number.bytes_to_long(s)) else: raise ValidationFailure, 'unknown algorithm %u' % rrsig.algorithm @@ -302,7 +338,7 @@ digest = _make_algorithm_id(rrsig.algorithm) + digest padlen = keylen // 8 - len(digest) - 3 digest = chr(0) + chr(1) + chr(0xFF) * padlen + chr(0) + digest - elif _is_dsa(rrsig.algorithm): + elif _is_dsa(rrsig.algorithm) or _is_ecdsa(rrsig.algorithm): pass else: # Raise here for code clarity; this won't actually ever happen @@ -369,6 +405,26 @@ import Crypto.Util.number validate = _validate validate_rrsig = _validate_rrsig + _have_pycrypto = True except ImportError: validate = _need_pycrypto validate_rrsig = _need_pycrypto + _have_pycrypto = False + +try: + import ecdsa + import ecdsa.ecdsa + import ecdsa.ellipticcurve + import ecdsa.keys + _have_ecdsa = True + + class ECKeyWrapper(object): + def __init__(self, key, key_len): + self.key = key + self.key_len = key_len + def verify(self, digest, sig): + diglong = Crypto.Util.number.bytes_to_long(digest) + return self.key.pubkey.verifies(diglong, sig) + +except ImportError: + _have_ecdsa = False diff -Nru dnspython-1.11.1/dns/ipv6.py dnspython-1.12.0/dns/ipv6.py --- dnspython-1.11.1/dns/ipv6.py 2013-04-26 11:56:42.000000000 +0000 +++ dnspython-1.12.0/dns/ipv6.py 2014-05-31 18:10:43.000000000 +0000 @@ -161,3 +161,8 @@ return text.decode('hex_codec') except TypeError: raise dns.exception.SyntaxError + +_mapped_prefix = '\x00' * 10 + '\xff\xff' + +def is_mapped(address): + return address.startswith(_mapped_prefix) diff -Nru dnspython-1.11.1/dns/message.py dnspython-1.12.0/dns/message.py --- dnspython-1.11.1/dns/message.py 2012-04-08 12:47:22.000000000 +0000 +++ dnspython-1.12.0/dns/message.py 2014-04-04 12:36:11.000000000 +0000 @@ -665,6 +665,10 @@ secret = self.message.keyring.get(absolute_name) if secret is None: raise UnknownTSIGKey("key '%s' unknown" % name) + self.message.keyname = absolute_name + (self.message.keyalgorithm, self.message.mac) = \ + dns.tsig.get_algorithm_and_mac(self.wire, self.current, + rdlen) self.message.tsig_ctx = \ dns.tsig.validate(self.wire, absolute_name, @@ -1071,7 +1075,8 @@ m.want_dnssec(want_dnssec) return m -def make_response(query, recursion_available=False, our_payload=8192): +def make_response(query, recursion_available=False, our_payload=8192, + fudge=300): """Make a message which is a response for the specified query. The message returned is really a response skeleton; it has all of the infrastructure required of a response, but none of the @@ -1088,6 +1093,8 @@ @param our_payload: payload size to advertise in EDNS responses; default is 8192. @type our_payload: int + @param fudge: TSIG time fudge; default is 300 seconds. + @type fudge: int @rtype: dns.message.Message object""" if query.flags & dns.flags.QR: @@ -1100,8 +1107,8 @@ response.question = list(query.question) if query.edns >= 0: response.use_edns(0, 0, our_payload, query.payload) - if not query.keyname is None: - response.keyname = query.keyname - response.keyring = query.keyring + if query.had_tsig: + response.use_tsig(query.keyring, query.keyname, fudge, None, 0, '', + query.keyalgorithm) response.request_mac = query.mac return response diff -Nru dnspython-1.11.1/dns/name.py dnspython-1.12.0/dns/name.py --- dnspython-1.11.1/dns/name.py 2013-04-28 08:17:17.000000000 +0000 +++ dnspython-1.12.0/dns/name.py 2014-06-19 12:35:07.000000000 +0000 @@ -24,6 +24,7 @@ import cStringIO import struct import sys +import copy if sys.hexversion >= 0x02030000: import encodings.idna @@ -87,8 +88,10 @@ '$' : True } -def _escapify(label): +def _escapify(label, unicode_mode=False): """Escape the characters in label which need it. + @param unicode_mode: escapify only special and whitespace (<= 0x20) + characters @returns: the escaped string @rtype: string""" text = '' @@ -98,7 +101,10 @@ elif ord(c) > 0x20 and ord(c) < 0x7F: text += c else: - text += '\\%03d' % ord(c) + if unicode_mode and ord(c) >= 0x7F: + text += c + else: + text += '\\%03d' % ord(c) return text def _validate_labels(labels): @@ -149,6 +155,12 @@ def __setattr__(self, name, value): raise TypeError("object doesn't support attribute assignment") + def __copy__(self): + return Name(self.labels) + + def __deepcopy__(self, memo): + return Name(copy.deepcopy(self.labels, memo)) + def is_absolute(self): """Is the most significant label of this name the root label? @rtype: bool @@ -345,7 +357,7 @@ l = self.labels[:-1] else: l = self.labels - s = u'.'.join([encodings.idna.ToUnicode(_escapify(x)) for x in l]) + s = u'.'.join([_escapify(encodings.idna.ToUnicode(x), True) for x in l]) return s def to_digestable(self, origin=None): diff -Nru dnspython-1.11.1/dns/query.py dnspython-1.12.0/dns/query.py --- dnspython-1.11.1/dns/query.py 2013-08-26 16:04:21.000000000 +0000 +++ dnspython-1.12.0/dns/query.py 2014-06-21 15:33:25.000000000 +0000 @@ -411,6 +411,8 @@ tcpmsg = struct.pack("!H", l) + wire _net_write(s, tcpmsg, expiration) done = False + delete_mode = True + expecting_SOA = False soa_rrset = None soa_count = 0 if relativize: @@ -439,18 +441,16 @@ tsig_ctx = r.tsig_ctx first = False answer_index = 0 - delete_mode = False - expecting_SOA = False if soa_rrset is None: if not r.answer or r.answer[0].name != oname: - raise dns.exception.FormError + raise dns.exception.FormError("No answer or RRset not for qname") rrset = r.answer[0] if rrset.rdtype != dns.rdatatype.SOA: raise dns.exception.FormError("first RRset is not an SOA") answer_index = 1 soa_rrset = rrset.copy() if rdtype == dns.rdatatype.IXFR: - if soa_rrset[0].serial == serial: + if soa_rrset[0].serial <= serial: # # We're already up-to-date. # @@ -471,7 +471,14 @@ expecting_SOA = False elif rdtype == dns.rdatatype.IXFR: delete_mode = not delete_mode - if rrset == soa_rrset and not delete_mode: + # + # If this SOA RRset is equal to the first we saw then we're + # finished. If this is an IXFR we also check that we're seeing + # the record in the expected part of the response. + # + if rrset == soa_rrset and \ + (rdtype == dns.rdatatype.AXFR or \ + (rdtype == dns.rdatatype.IXFR and delete_mode)): done = True elif expecting_SOA: # diff -Nru dnspython-1.11.1/dns/rdtypes/ANY/DNSKEY.py dnspython-1.12.0/dns/rdtypes/ANY/DNSKEY.py --- dnspython-1.11.1/dns/rdtypes/ANY/DNSKEY.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/rdtypes/ANY/DNSKEY.py 2014-06-19 12:32:55.000000000 +0000 @@ -20,11 +20,54 @@ import dns.dnssec import dns.rdata + # flag constants SEP = 0x0001 REVOKE = 0x0080 ZONE = 0x0100 +_flag_by_text = { + 'SEP': SEP, + 'REVOKE': REVOKE, + 'ZONE': ZONE + } + +# We construct the inverse mapping programmatically to ensure that we +# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that +# would cause the mapping not to be true inverse. +_flag_by_value = dict([(y, x) for x, y in _flag_by_text.iteritems()]) + + +def flags_to_text_set(flags): + """Convert a DNSKEY flags value to set texts + @rtype: set([string])""" + + flags_set = set() + mask = 0x1 + while mask <= 0x8000: + if flags & mask: + text = _flag_by_value.get(mask) + if not text: + text = hex(mask) + flags_set.add(text) + mask <<= 1 + return flags_set + + +def flags_from_text_set(texts_set): + """Convert set of DNSKEY flag mnemonic texts to DNSKEY flag value + @rtype: int""" + + flags = 0 + for text in texts_set: + try: + flags += _flag_by_text[text] + except KeyError: + raise NotImplementedError( + "DNSKEY flag '%s' is not supported" % text) + return flags + + class DNSKEY(dns.rdata.Rdata): """DNSKEY record @@ -92,3 +135,8 @@ if v == 0: v = cmp(self.key, other.key) return v + + def flags_to_text_set(self): + """Convert a DNSKEY flags value to set texts + @rtype: set([string])""" + return flags_to_text_set(self.flags) diff -Nru dnspython-1.11.1/dns/rdtypes/ANY/LOC.py dnspython-1.12.0/dns/rdtypes/ANY/LOC.py --- dnspython-1.11.1/dns/rdtypes/ANY/LOC.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/rdtypes/ANY/LOC.py 2014-03-03 16:57:58.000000000 +0000 @@ -22,7 +22,14 @@ _pows = (1L, 10L, 100L, 1000L, 10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L, 10000000000L) +# default values are in centimeters +_default_size = 100.0 +_default_hprec = 1000000.0 +_default_vprec = 1000.0 + def _exponent_of(what, desc): + if what == 0: + return 0 exp = None for i in xrange(len(_pows)): if what // _pows[i] == 0L: @@ -98,13 +105,14 @@ 'horizontal_precision', 'vertical_precision'] def __init__(self, rdclass, rdtype, latitude, longitude, altitude, - size=1.0, hprec=10000.0, vprec=10.0): + size=_default_size, hprec=_default_hprec, vprec=_default_vprec): """Initialize a LOC record instance. The parameters I{latitude} and I{longitude} may be either a 4-tuple of integers specifying (degrees, minutes, seconds, milliseconds), or they may be floating point values specifying the number of - degrees. The other parameters are floats.""" + degrees. The other parameters are floats. Size, horizontal precision, + and vertical precision are specified in centimeters.""" super(LOC, self).__init__(rdclass, rdtype) if isinstance(latitude, int) or isinstance(latitude, long): @@ -141,8 +149,10 @@ self.longitude[3], long_hemisphere, self.altitude / 100.0 ) - if self.size != 1.0 or self.horizontal_precision != 10000.0 or \ - self.vertical_precision != 10.0: + # do not print default values + if self.size != _default_size or \ + self.horizontal_precision != _default_hprec or \ + self.vertical_precision != _default_vprec: text += " %0.2fm %0.2fm %0.2fm" % ( self.size / 100.0, self.horizontal_precision / 100.0, self.vertical_precision / 100.0 @@ -152,9 +162,9 @@ def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True): latitude = [0, 0, 0, 0] longitude = [0, 0, 0, 0] - size = 1.0 - hprec = 10000.0 - vprec = 10.0 + size = _default_size + hprec = _default_hprec + vprec = _default_vprec latitude[0] = tok.get_int() t = tok.get_string() @@ -240,8 +250,8 @@ value = token.value if value[-1] == 'm': value = value[0 : -1] - vprec = float(value) * 100.0 # m -> cm - tok.get_eol() + vprec = float(value) * 100.0 # m -> cm + tok.get_eol() return cls(rdclass, rdtype, latitude, longitude, altitude, size, hprec, vprec) diff -Nru dnspython-1.11.1/dns/rdtypes/ANY/NSEC3PARAM.py dnspython-1.12.0/dns/rdtypes/ANY/NSEC3PARAM.py --- dnspython-1.11.1/dns/rdtypes/ANY/NSEC3PARAM.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/rdtypes/ANY/NSEC3PARAM.py 2014-07-24 13:21:54.000000000 +0000 @@ -56,6 +56,7 @@ salt = '' else: salt = salt.decode('hex-codec') + tok.get_eol() return cls(rdclass, rdtype, algorithm, flags, iterations, salt) from_text = classmethod(from_text) diff -Nru dnspython-1.11.1/dns/rdtypes/ANY/RRSIG.py dnspython-1.12.0/dns/rdtypes/ANY/RRSIG.py --- dnspython-1.11.1/dns/rdtypes/ANY/RRSIG.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/rdtypes/ANY/RRSIG.py 2014-06-19 13:17:41.000000000 +0000 @@ -93,7 +93,7 @@ posixtime_to_sigtime(self.expiration), posixtime_to_sigtime(self.inception), self.key_tag, - self.signer, + self.signer.choose_relativity(origin, relativize), dns.rdata._base64ify(self.signature) ) diff -Nru dnspython-1.11.1/dns/rdtypes/IN/APL.py dnspython-1.12.0/dns/rdtypes/IN/APL.py --- dnspython-1.11.1/dns/rdtypes/IN/APL.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/rdtypes/IN/APL.py 2014-06-18 23:02:56.000000000 +0000 @@ -118,6 +118,8 @@ def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None): items = [] while 1: + if rdlen == 0: + break if rdlen < 4: raise dns.exception.FormError header = struct.unpack('!HBB', wire[current : current + 4]) @@ -151,8 +153,6 @@ rdlen -= afdlen item = APLItem(header[0], negation, address, header[1]) items.append(item) - if rdlen == 0: - break return cls(rdclass, rdtype, items) from_wire = classmethod(from_wire) diff -Nru dnspython-1.11.1/dns/resolver.py dnspython-1.12.0/dns/resolver.py --- dnspython-1.11.1/dns/resolver.py 2013-07-17 07:20:28.000000000 +0000 +++ dnspython-1.12.0/dns/resolver.py 2014-06-21 16:12:55.000000000 +0000 @@ -21,6 +21,7 @@ import socket import sys import time +import random try: import threading as _threading @@ -508,6 +509,7 @@ self.cache = None self.flags = None self.retry_servfail = False + self.rotate = False def read_resolv_conf(self, f): """Process f as a file in the /etc/resolv.conf format. If f is @@ -538,6 +540,9 @@ elif tokens[0] == 'search': for suffix in tokens[1:]: self.search.append(dns.name.from_text(suffix)) + elif tokens[0] == 'options': + if 'rotate' in tokens[1:]: + self.rotate = True finally: if want_close: f.close() @@ -811,6 +816,8 @@ # make a copy of the servers list so we can alter it later. # nameservers = self.nameservers[:] + if self.rotate: + random.shuffle(nameservers) backoff = 0.10 while response is None: if len(nameservers) == 0: diff -Nru dnspython-1.11.1/dns/reversename.py dnspython-1.12.0/dns/reversename.py --- dnspython-1.11.1/dns/reversename.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/reversename.py 2014-05-31 18:10:43.000000000 +0000 @@ -37,8 +37,13 @@ @rtype: dns.name.Name object """ try: - parts = list(dns.ipv6.inet_aton(text).encode('hex_codec')) - origin = ipv6_reverse_domain + v6 = dns.ipv6.inet_aton(text) + if dns.ipv6.is_mapped(v6): + parts = ['%d' % ord(byte) for byte in v6[12:]] + origin = ipv4_reverse_domain + else: + parts = list(v6.encode('hex_codec')) + origin = ipv6_reverse_domain except: parts = ['%d' % ord(byte) for byte in dns.ipv4.inet_aton(text)] origin = ipv4_reverse_domain diff -Nru dnspython-1.11.1/dns/tsig.py dnspython-1.12.0/dns/tsig.py --- dnspython-1.11.1/dns/tsig.py 2013-08-26 16:07:06.000000000 +0000 +++ dnspython-1.12.0/dns/tsig.py 2014-04-04 12:36:11.000000000 +0000 @@ -221,3 +221,19 @@ except KeyError: raise NotImplementedError("TSIG algorithm " + str(algorithm) + " is not supported") + +def get_algorithm_and_mac(wire, tsig_rdata, tsig_rdlen): + """Return the tsig algorithm for the specified tsig_rdata + @raises FormError: The TSIG is badly formed. + """ + current = tsig_rdata + (aname, used) = dns.name.from_wire(wire, current) + current = current + used + (upper_time, lower_time, fudge, mac_size) = \ + struct.unpack("!HIHH", wire[current:current + 10]) + current += 10 + mac = wire[current:current + mac_size] + current += mac_size + if current > tsig_rdata + tsig_rdlen: + raise dns.exception.FormError + return (aname, mac) diff -Nru dnspython-1.11.1/dns/version.py dnspython-1.12.0/dns/version.py --- dnspython-1.11.1/dns/version.py 2013-09-02 18:55:21.000000000 +0000 +++ dnspython-1.12.0/dns/version.py 2014-09-01 12:42:55.000000000 +0000 @@ -16,8 +16,8 @@ """dnspython release version information.""" MAJOR = 1 -MINOR = 11 -MICRO = 1 +MINOR = 12 +MICRO = 0 RELEASELEVEL = 0x0f SERIAL = 0 diff -Nru dnspython-1.11.1/dns/wiredata.py dnspython-1.12.0/dns/wiredata.py --- dnspython-1.11.1/dns/wiredata.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/dns/wiredata.py 2014-07-24 14:35:37.000000000 +0000 @@ -19,6 +19,18 @@ import dns.exception +# Figure out what constant python passes for an unspecified slice bound. +# It's supposed to be sys.maxint, yet on 64-bit windows sys.maxint is 2^31 - 1 +# but Python uses 2^63 - 1 as the constant. Rather than making pointless +# extra comparisons, duplicating code, or weakening WireData, we just figure +# out what constant Python will use. + +class _SliceUnspecifiedBound(str): + def __getslice__(self, i, j): + return j + +_unspecified_bound = _SliceUnspecifiedBound('')[1:] + class WireData(str): # WireData is a string with stricter slicing def __getitem__(self, key): @@ -28,7 +40,7 @@ raise dns.exception.FormError def __getslice__(self, i, j): try: - if j == sys.maxint: + if j == _unspecified_bound: # handle the case where the right bound is unspecified j = len(self) if i < 0 or j < 0: diff -Nru dnspython-1.11.1/dns/zone.py dnspython-1.12.0/dns/zone.py --- dnspython-1.11.1/dns/zone.py 2013-03-31 10:57:45.000000000 +0000 +++ dnspython-1.12.0/dns/zone.py 2014-06-21 15:57:20.000000000 +0000 @@ -31,6 +31,10 @@ import dns.ttl import dns.grange +try: + from cStringIO import StringIO +except ImportError: + from io import StringIO class BadZone(dns.exception.DNSException): """The zone is malformed.""" @@ -506,6 +510,27 @@ if want_close: f.close() + def to_text(self, sorted=True, relativize=True, nl=None): + """Return a zone's text as though it were written to a file. + + @param sorted: if True, the file will be written with the + names sorted in DNSSEC order from least to greatest. Otherwise + the names will be written in whatever order they happen to have + in the zone's dictionary. + @param relativize: if True, domain names in the output will be + relativized to the zone's origin (if possible). + @type relativize: bool + @param nl: The end of line string. If not specified, the + output will use the platform's native end-of-line marker (i.e. + LF on POSIX, CRLF on Windows, CR on Macintosh). + @type nl: string or None + """ + temp_buffer = StringIO() + self.to_file(temp_buffer, sorted, relativize, nl) + return_value = temp_buffer.getvalue() + temp_buffer.close() + return return_value + def check_origin(self): """Do some simple checking of the zone's origin. @@ -558,7 +583,7 @@ self.current_origin = origin self.relativize = relativize self.ttl = 0 - self.last_name = None + self.last_name = self.current_origin self.zone = zone_factory(origin, rdclass, relativize=relativize) self.saved_state = [] self.current_file = None @@ -813,7 +838,7 @@ try: while 1: - token = self.tok.get(True, True).unescape() + token = self.tok.get(True, True) if token.is_eof(): if not self.current_file is None: self.current_file.close() diff -Nru dnspython-1.11.1/PKG-INFO dnspython-1.12.0/PKG-INFO --- dnspython-1.11.1/PKG-INFO 2013-09-02 19:08:36.000000000 +0000 +++ dnspython-1.12.0/PKG-INFO 2014-09-01 13:11:48.000000000 +0000 @@ -1,12 +1,12 @@ Metadata-Version: 1.1 Name: dnspython -Version: 1.11.1 +Version: 1.12.0 Summary: DNS toolkit Home-page: http://www.dnspython.org Author: Bob Halley Author-email: halley@dnspython.org License: BSD-like -Download-URL: http://www.dnspython.org/kits/1.11.1/dnspython-1.11.1.tar.gz +Download-URL: http://www.dnspython.org/kits/1.12.0/dnspython-1.12.0.tar.gz Description: dnspython is a DNS toolkit for Python. It supports almost all record types. It can be used for queries, zone transfers, and dynamic updates. It supports TSIG authenticated messages and EDNS0. diff -Nru dnspython-1.11.1/README dnspython-1.12.0/README --- dnspython-1.11.1/README 2013-09-02 18:55:03.000000000 +0000 +++ dnspython-1.12.0/README 2014-09-01 13:02:03.000000000 +0000 @@ -22,13 +22,51 @@ ABOUT THIS RELEASE -This is dnspython 1.11.1 +This is dnspython 1.12.0 + +New since 1.11.1: + + Added dns.zone.to_text(). + + Added support for "options rotate" in /etc/resolv.conf. + + dns.rdtypes.ANY.DNSKEY now has helpers functions to convert + between the numeric form of the flags and a set of + human-friendly strings + + The reverse name of an IPv6 mapped IPv4 address is now in the + IPv4 reverse namespace. + + The test system can now run the tests without requiring + dnspython to be installed. + + Preliminary Elliptic Curve DNSSEC Validation (requires ecdsa module) + +Bugs fixed since 1.11.1: + + dnspython raised an exception when reading a masterfile starting + with leading whitespace + + dnspython was affected by a python slicing API bug present on + 64-bit windows. + + Unicode escaping was applied at the wrong time. + + RRSIG to_text() did not respect the relativize setting. + + APL RRs with zero rdlength were rejected. + + The tokenizer could put back an unescaped token. + + Making a response to a message signed with TSIG was broken. + + The IXFR state machine didn't handle long IXFR diffs. New since 1.11.0: Nothing -Bugs fixed since 1.11.1: +Bugs fixed since 1.11.0: dns.resolver.Resolver erroneously referred to 'retry_servfail' instead of 'self.retry_servfail'. diff -Nru dnspython-1.11.1/setup.py dnspython-1.12.0/setup.py --- dnspython-1.11.1/setup.py 2013-09-02 18:55:30.000000000 +0000 +++ dnspython-1.12.0/setup.py 2014-09-01 12:42:23.000000000 +0000 @@ -18,7 +18,7 @@ import sys from distutils.core import setup -version = '1.11.1' +version = '1.12.0' kwargs = { 'name' : 'dnspython', diff -Nru dnspython-1.11.1/tests/bugs.py dnspython-1.12.0/tests/bugs.py --- dnspython-1.11.1/tests/bugs.py 2012-08-28 20:41:26.000000000 +0000 +++ dnspython-1.12.0/tests/bugs.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,49 +0,0 @@ -# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.rdata -import dns.rdataclass -import dns.rdatatype -import dns.ttl - -class BugsTestCase(unittest.TestCase): - - def test_float_LOC(self): - rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.LOC, - "30 30 0.000 N 100 30 0.000 W 10.00m 20m 2000m 20m") - self.failUnless(rdata.float_latitude == 30.5) - self.failUnless(rdata.float_longitude == -100.5) - - def test_SOA_BIND8_TTL(self): - rdata1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - "a b 100 1s 1m 1h 1d") - rdata2 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - "a b 100 1 60 3600 86400") - self.failUnless(rdata1 == rdata2) - - def test_TTL_bounds_check(self): - def bad(): - ttl = dns.ttl.from_text("2147483648") - self.failUnlessRaises(dns.ttl.BadTTL, bad) - - def test_empty_NSEC3_window(self): - rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NSEC3, - "1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715") - self.failUnless(rdata.windows == []) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/dnssec.py dnspython-1.12.0/tests/dnssec.py --- dnspython-1.11.1/tests/dnssec.py 2013-03-31 10:33:53.000000000 +0000 +++ dnspython-1.12.0/tests/dnssec.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,156 +0,0 @@ -# Copyright (C) 2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.dnssec -import dns.name -import dns.rdata -import dns.rdataclass -import dns.rdatatype -import dns.rrset - -abs_dnspython_org = dns.name.from_text('dnspython.org') - -abs_keys = { abs_dnspython_org : - dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'DNSKEY', - '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', - '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') - } - -abs_keys_duplicate_keytag = { abs_dnspython_org : - dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'DNSKEY', - '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', - '256 3 5 AwEAAdSSg++++THIS/IS/NOT/THE/CORRECT/KEY++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AaOSydAF', - '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') - } - -rel_keys = { dns.name.empty : - dns.rrset.from_text('@', 3600, 'IN', 'DNSKEY', - '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', - '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') - } - -when = 1290250287 - -abs_soa = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'SOA', - 'howl.dnspython.org. hostmaster.dnspython.org. 2010020047 3600 1800 604800 3600') - -abs_other_soa = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'SOA', - 'foo.dnspython.org. hostmaster.dnspython.org. 2010020047 3600 1800 604800 3600') - -abs_soa_rrsig = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'RRSIG', - 'SOA 5 2 3600 20101127004331 20101119213831 61695 dnspython.org. sDUlltRlFTQw5ITFxOXW3TgmrHeMeNpdqcZ4EXxM9FHhIlte6V9YCnDw t6dvM9jAXdIEi03l9H/RAd9xNNW6gvGMHsBGzpvvqFQxIBR2PoiZA1mX /SWHZFdbt4xjYTtXqpyYvrMK0Dt7bUYPadyhPFCJ1B+I8Zi7B5WJEOd0 8vs=') - -rel_soa = dns.rrset.from_text('@', 3600, 'IN', 'SOA', - 'howl hostmaster 2010020047 3600 1800 604800 3600') - -rel_other_soa = dns.rrset.from_text('@', 3600, 'IN', 'SOA', - 'foo hostmaster 2010020047 3600 1800 604800 3600') - -rel_soa_rrsig = dns.rrset.from_text('@', 3600, 'IN', 'RRSIG', - 'SOA 5 2 3600 20101127004331 20101119213831 61695 @ sDUlltRlFTQw5ITFxOXW3TgmrHeMeNpdqcZ4EXxM9FHhIlte6V9YCnDw t6dvM9jAXdIEi03l9H/RAd9xNNW6gvGMHsBGzpvvqFQxIBR2PoiZA1mX /SWHZFdbt4xjYTtXqpyYvrMK0Dt7bUYPadyhPFCJ1B+I8Zi7B5WJEOd0 8vs=') - -sep_key = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DNSKEY, - '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=') - -good_ds = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, - '57349 5 2 53A79A3E7488AB44FFC56B2D1109F0699D1796DD977E72108B841F96 E47D7013') - -when2 = 1290425644 - -abs_example = dns.name.from_text('example') - -abs_dsa_keys = { abs_example : - dns.rrset.from_text('example.', 86400, 'IN', 'DNSKEY', - '257 3 3 CI3nCqyJsiCJHTjrNsJOT4RaszetzcJPYuoH3F9ZTVt3KJXncCVR3bwn 1w0iavKljb9hDlAYSfHbFCp4ic/rvg4p1L8vh5s8ToMjqDNl40A0hUGQ Ybx5hsECyK+qHoajilUX1phYSAD8d9WAGO3fDWzUPBuzR7o85NiZCDxz yXuNVfni0uhj9n1KYhEO5yAbbruDGN89wIZcxMKuQsdUY2GYD93ssnBv a55W6XRABYWayKZ90WkRVODLVYLSn53Pj/wwxGH+XdhIAZJXimrZL4yl My7rtBsLMqq8Ihs4Tows7LqYwY7cp6y/50tw6pj8tFqMYcPUjKZV36l1 M/2t5BVg3i7IK61Aidt6aoC3TDJtzAxg3ZxfjZWJfhHjMJqzQIfbW5b9 q1mjFsW5EUv39RaNnX+3JWPRLyDqD4pIwDyqfutMsdk/Py3paHn82FGp CaOg+nicqZ9TiMZURN/XXy5JoXUNQ3RNvbHCUiPUe18KUkY6mTfnyHld 1l9YCWmzXQVClkx/hOYxjJ4j8Ife58+Obu5X', - '256 3 3 CJE1yb9YRQiw5d2xZrMUMR+cGCTt1bp1KDCefmYKmS+Z1+q9f42ETVhx JRiQwXclYwmxborzIkSZegTNYIV6mrYwbNB27Q44c3UGcspb3PiOw5TC jNPRYEcdwGvDZ2wWy+vkSV/S9tHXY8O6ODiE6abZJDDg/RnITyi+eoDL R3KZ5n/V1f1T1b90rrV6EewhBGQJpQGDogaXb2oHww9Tm6NfXyo7SoMM pbwbzOckXv+GxRPJIQNSF4D4A9E8XCksuzVVdE/0lr37+uoiAiPia38U 5W2QWe/FJAEPLjIp2eTzf0TrADc1pKP1wrA2ASpdzpm/aX3IB5RPp8Ew S9U72eBFZJAUwg635HxJVxH1maG6atzorR566E+e0OZSaxXS9o1o6QqN 3oPlYLGPORDiExilKfez3C/x/yioOupW9K5eKF0gmtaqrHX0oq9s67f/ RIM2xVaKHgG9Vf2cgJIZkhv7sntujr+E4htnRmy9P9BxyFxsItYxPI6Z bzygHAZpGhlI/7ltEGlIwKxyTK3ZKBm67q7B') - } - -abs_dsa_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', - 'ns1.example. hostmaster.example. 2 10800 3600 604800 86400') - -abs_other_dsa_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', - 'ns1.example. hostmaster.example. 2 10800 3600 604800 86401') - -abs_dsa_soa_rrsig = dns.rrset.from_text('example.', 86400, 'IN', 'RRSIG', - 'SOA 3 1 86400 20101129143231 20101122112731 42088 example. CGul9SuBofsktunV8cJs4eRs6u+3NCS3yaPKvBbD+pB2C76OUXDZq9U=') - -example_sep_key = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DNSKEY, - '257 3 3 CI3nCqyJsiCJHTjrNsJOT4RaszetzcJPYuoH3F9ZTVt3KJXncCVR3bwn 1w0iavKljb9hDlAYSfHbFCp4ic/rvg4p1L8vh5s8ToMjqDNl40A0hUGQ Ybx5hsECyK+qHoajilUX1phYSAD8d9WAGO3fDWzUPBuzR7o85NiZCDxz yXuNVfni0uhj9n1KYhEO5yAbbruDGN89wIZcxMKuQsdUY2GYD93ssnBv a55W6XRABYWayKZ90WkRVODLVYLSn53Pj/wwxGH+XdhIAZJXimrZL4yl My7rtBsLMqq8Ihs4Tows7LqYwY7cp6y/50tw6pj8tFqMYcPUjKZV36l1 M/2t5BVg3i7IK61Aidt6aoC3TDJtzAxg3ZxfjZWJfhHjMJqzQIfbW5b9 q1mjFsW5EUv39RaNnX+3JWPRLyDqD4pIwDyqfutMsdk/Py3paHn82FGp CaOg+nicqZ9TiMZURN/XXy5JoXUNQ3RNvbHCUiPUe18KUkY6mTfnyHld 1l9YCWmzXQVClkx/hOYxjJ4j8Ife58+Obu5X') - -example_ds_sha1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, - '18673 3 1 71b71d4f3e11bbd71b4eff12cde69f7f9215bbe7') - -example_ds_sha256 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, - '18673 3 2 eb8344cbbf07c9d3d3d6c81d10c76653e28d8611a65e639ef8f716e4e4e5d913') - -class DNSSECValidatorTestCase(unittest.TestCase): - - def testAbsoluteRSAGood(self): - dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys, None, when) - - def testDuplicateKeytag(self): - dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys_duplicate_keytag, None, when) - - def testAbsoluteRSABad(self): - def bad(): - dns.dnssec.validate(abs_other_soa, abs_soa_rrsig, abs_keys, None, - when) - self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) - - def testRelativeRSAGood(self): - dns.dnssec.validate(rel_soa, rel_soa_rrsig, rel_keys, - abs_dnspython_org, when) - - def testRelativeRSABad(self): - def bad(): - dns.dnssec.validate(rel_other_soa, rel_soa_rrsig, rel_keys, - abs_dnspython_org, when) - self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) - - def testMakeSHA256DS(self): - ds = dns.dnssec.make_ds(abs_dnspython_org, sep_key, 'SHA256') - self.failUnless(ds == good_ds) - - def testAbsoluteDSAGood(self): - dns.dnssec.validate(abs_dsa_soa, abs_dsa_soa_rrsig, abs_dsa_keys, None, - when2) - - def testAbsoluteDSABad(self): - def bad(): - dns.dnssec.validate(abs_other_dsa_soa, abs_dsa_soa_rrsig, - abs_dsa_keys, None, when2) - self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) - - def testMakeExampleSHA1DS(self): - ds = dns.dnssec.make_ds(abs_example, example_sep_key, 'SHA1') - self.failUnless(ds == example_ds_sha1) - - def testMakeExampleSHA256DS(self): - ds = dns.dnssec.make_ds(abs_example, example_sep_key, 'SHA256') - self.failUnless(ds == example_ds_sha256) - -if __name__ == '__main__': - import_ok = False - try: - import Crypto.Util.number - import_ok = True - except: - pass - if import_ok: - unittest.main() - else: - print 'skipping DNSSEC tests because pycrypto is not installed' diff -Nru dnspython-1.11.1/tests/example3.good dnspython-1.12.0/tests/example3.good --- dnspython-1.11.1/tests/example3.good 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/example3.good 2014-06-21 15:54:11.000000000 +0000 @@ -0,0 +1,117 @@ +@ 300 IN SOA ns1 hostmaster 1 2000 2000 1814400 3600 +@ 300 IN NS ns1 +@ 300 IN NS ns2 +* 300 IN MX 10 mail +a 300 IN TXT "foo foo foo" +a 300 IN PTR foo.net. +a01 3600 IN A 0.0.0.0 +a02 3600 IN A 255.255.255.255 +aaaa01 3600 IN AAAA ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff +aaaa02 3600 IN AAAA ::1 +afsdb01 3600 IN AFSDB 0 hostname +afsdb02 3600 IN AFSDB 65535 . +apl01 3600 IN APL 1:192.168.32.0/21 !1:192.168.38.0/28 +apl02 3600 IN APL 1:224.0.0.0/4 2:FF00:0:0:0:0:0:0:0/8 +b 300 IN CNAME foo.net. +c 300 IN A 73.80.65.49 +cert01 3600 IN CERT 65534 65535 PRIVATEOID MxFcby9k/yvedMfQgKzhH5er0Mu/vILz 45IkskceFGgiWCn/GxHhai6VAuHAoNUz 4YoU1tVfSCSqQYn6//11U6Nld80jEeC8 aTrO+KKmCaY= +cname01 3600 IN CNAME cname-target. +cname02 3600 IN CNAME cname-target +cname03 3600 IN CNAME . +d 300 IN A 73.80.65.49 +dhcid01 3600 IN DHCID AAIBY2/AuCccgoJbsaxcQc9TUapptP69 lOjxfNuVAA2kjEA= +dhcid02 3600 IN DHCID AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQd WL3b/NaiUDlW2No= +dhcid03 3600 IN DHCID AAABxLmlskllE0MVjd57zHcWmEH3pCQ6 VytcKD//7es/deY= +dlv01 3600 IN DLV 12345 3 1 123456789abcdef67890123456789abcdef67890 +dname01 3600 IN DNAME dname-target. +dname02 3600 IN DNAME dname-target +dname03 3600 IN DNAME . +dnskey01 3600 IN DNSKEY 512 255 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= +dnskey02 3600 IN DNSKEY 257 3 1 AQMFD5raczCJHViKtLYhWGz8hMY9UGRu niJDBzC7w0aRyzWZriO6i2odGWWQVucZ qKVsENW91IOW4vqudngPZsY3GvQ/xVA8 /7pyFj6b7Esga60zyGW6LFe9r8n6paHr lG5ojqf0BaqHT+8= +ds01 3600 IN DS 12345 3 1 123456789abcdef67890123456789abcdef67890 +e 300 IN MX 10 mail +e 300 IN TXT "one" +e 300 IN TXT "three" +e 300 IN TXT "two" +e 300 IN A 73.80.65.49 +e 300 IN A 73.80.65.50 +e 300 IN A 73.80.65.52 +e 300 IN A 73.80.65.51 +f 300 IN A 73.80.65.52 +gpos01 3600 IN GPOS -22.6882 116.8652 250.0 +hinfo01 3600 IN HINFO "Generic PC clone" "NetBSD-1.4" +hinfo02 3600 IN HINFO "PC" "NetBSD" +hip01 3600 IN HIP 2 200100107b1a74df365639cc39f1d578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs1.example.com. rvs2 +ipseckey01 3600 IN IPSECKEY 10 1 2 192.0.2.38 AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ== +ipseckey02 3600 IN IPSECKEY 10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ== +ipseckey03 3600 IN IPSECKEY 10 3 2 mygateway.example.com. AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ== +ipseckey04 3600 IN IPSECKEY 10 2 2 2001:0DB8:0:8002::2000:1 AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ== +ipseckey05 3600 IN IPSECKEY 10 3 2 mygateway2 AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ== +isdn01 3600 IN ISDN "isdn-address" +isdn02 3600 IN ISDN "isdn-address" "subaddress" +isdn03 3600 IN ISDN "isdn-address" +isdn04 3600 IN ISDN "isdn-address" "subaddress" +kx01 3600 IN KX 10 kdc +kx02 3600 IN KX 10 . +loc01 3600 IN LOC 60 9 0.000 N 24 39 0.000 E 10.00m 20.00m 2000.00m 20.00m +loc02 3600 IN LOC 60 9 0.000 N 24 39 0.000 E 10.00m 20.00m 2000.00m 20.00m +loc03 3600 IN LOC 60 9 0.000 N 24 39 0.000 E 10.00m 90000000.00m 2000.00m 20.00m +loc04 3600 IN LOC 60 9 1.500 N 24 39 0.000 E 10.00m 20.00m 2000.00m 20.00m +loc05 3600 IN LOC 60 9 1.510 N 24 39 0.000 E 10.00m 20.00m 2000.00m 20.00m +mx01 3600 IN MX 10 mail +mx02 3600 IN MX 10 . +naptr01 3600 IN NAPTR 0 0 "" "" "" . +naptr02 3600 IN NAPTR 65535 65535 "blurgh" "blorf" "blegh" foo. +ns1 300 IN A 10.53.0.1 +ns2 300 IN A 10.53.0.2 +nsap-ptr01 3600 IN NSAP-PTR foo. +nsap-ptr01 3600 IN NSAP-PTR . +nsap01 3600 IN NSAP 0x47000580005a0000000001e133ffffff00016100 +nsap02 3600 IN NSAP 0x47000580005a0000000001e133ffffff00016100 +nsec01 3600 IN NSEC a.secure. A MX RRSIG NSEC TYPE1234 +nsec02 3600 IN NSEC . NSAP-PTR NSEC +nsec03 3600 IN NSEC . NSEC TYPE65535 +nsec301 3600 IN NSEC3 1 1 12 aabbccdd 2t7b4g4vsa5smi47k61mv5bv1a22bojr NS SOA MX RRSIG DNSKEY NSEC3PARAM +nsec302 3600 IN NSEC3 1 1 12 - 2t7b4g4vsa5smi47k61mv5bv1a22bojr NS SOA MX RRSIG DNSKEY NSEC3PARAM +nsec3param01 3600 IN NSEC3PARAM 1 1 12 aabbccdd +nsec3param02 3600 IN NSEC3PARAM 1 1 12 - +ptr01 3600 IN PTR @ +px01 3600 IN PX 65535 foo. bar. +px02 3600 IN PX 65535 . . +rp01 3600 IN RP mbox-dname txt-dname +rp02 3600 IN RP . . +rrsig01 3600 IN RRSIG NSEC 1 3 3600 20200101000000 20030101000000 2143 foo MxFcby9k/yvedMfQgKzhH5er0Mu/vILz 45IkskceFGgiWCn/GxHhai6VAuHAoNUz 4YoU1tVfSCSqQYn6//11U6Nld80jEeC8 aTrO+KKmCaY= +rt01 3600 IN RT 0 intermediate-host +rt02 3600 IN RT 65535 . +s 300 IN NS ns.s +ns.s 300 IN A 73.80.65.49 +spf 3600 IN SPF "v=spf1 mx -all" +srv01 3600 IN SRV 0 0 0 . +srv02 3600 IN SRV 65535 65535 65535 old-slow-box.example.com. +sshfp1 3600 IN SSHFP 1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab +t 301 IN A 73.80.65.49 +tlsa1 3600 IN TLSA 3 1 1 a9cdf989b504fe5dca90c0d2167b6550570734f7c763e09fdf88904e06157065 +tlsa2 3600 IN TLSA 1 0 1 efddf0d915c7bdc5782c0881e1b2a95ad099fbdd06d7b1f77982d9364338d955 +tlsa3 3600 IN TLSA 1 0 2 81ee7f6c0ecc6b09b7785a9418f54432de630dd54dc6ee9e3c49de547708d236d4c413c3e97e44f969e635958aa410495844127c04883503e5b024cf7a8f6a94 +txt01 3600 IN TXT "foo" +txt02 3600 IN TXT "foo" "bar" +txt03 3600 IN TXT "foo" +txt04 3600 IN TXT "foo" "bar" +txt05 3600 IN TXT "foo bar" +txt06 3600 IN TXT "foo bar" +txt07 3600 IN TXT "foo bar" +txt08 3600 IN TXT "foo\010bar" +txt09 3600 IN TXT "foo\010bar" +txt10 3600 IN TXT "foo bar" +txt11 3600 IN TXT "\"foo\"" +txt12 3600 IN TXT "\"foo\"" +txt13 3600 IN TXT "foo" +u 300 IN TXT "txt-not-in-nxt" +a.u 300 IN A 73.80.65.49 +b.u 300 IN A 73.80.65.49 +unknown2 3600 IN TYPE999 \# 8 0a0000010a000001 +unknown3 3600 IN A 127.0.0.2 +wks01 3600 IN WKS 10.0.0.1 6 0 1 2 21 23 +wks02 3600 IN WKS 10.0.0.1 17 0 1 2 53 +wks03 3600 IN WKS 10.0.0.2 6 65535 +x2501 3600 IN X25 "123456789" diff -Nru dnspython-1.11.1/tests/flags.py dnspython-1.12.0/tests/flags.py --- dnspython-1.11.1/tests/flags.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/flags.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.flags -import dns.rcode -import dns.opcode - -class FlagsTestCase(unittest.TestCase): - - def test_rcode1(self): - self.failUnless(dns.rcode.from_text('FORMERR') == dns.rcode.FORMERR) - - def test_rcode2(self): - self.failUnless(dns.rcode.to_text(dns.rcode.FORMERR) == "FORMERR") - - def test_rcode3(self): - self.failUnless(dns.rcode.to_flags(dns.rcode.FORMERR) == (1, 0)) - - def test_rcode4(self): - self.failUnless(dns.rcode.to_flags(dns.rcode.BADVERS) == \ - (0, 0x01000000)) - - def test_rcode6(self): - self.failUnless(dns.rcode.from_flags(0, 0x01000000) == \ - dns.rcode.BADVERS) - - def test_rcode6(self): - self.failUnless(dns.rcode.from_flags(5, 0) == dns.rcode.REFUSED) - - def test_rcode7(self): - def bad(): - dns.rcode.to_flags(4096) - self.failUnlessRaises(ValueError, bad) - - def test_flags1(self): - self.failUnless(dns.flags.from_text("RA RD AA QR") == \ - dns.flags.QR|dns.flags.AA|dns.flags.RD|dns.flags.RA) - - def test_flags2(self): - flags = dns.flags.QR|dns.flags.AA|dns.flags.RD|dns.flags.RA - self.failUnless(dns.flags.to_text(flags) == "QR AA RD RA") - - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/generate.py dnspython-1.12.0/tests/generate.py --- dnspython-1.11.1/tests/generate.py 2013-03-31 10:57:45.000000000 +0000 +++ dnspython-1.12.0/tests/generate.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,499 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import sys -sys.path.insert(0, '../') # Force the local project to be *the* dns - -import cStringIO -import filecmp -import os -import unittest - -import dns.exception -import dns.rdata -import dns.rdataclass -import dns.rdatatype -import dns.rrset -import dns.zone - -import pprint - -pp = pprint.PrettyPrinter(indent=2) - -import pdb -example_text = """$TTL 1h -$ORIGIN 0.0.192.IN-ADDR.ARPA. -$GENERATE 1-2 0 CNAME SERVER$.EXAMPLE. -""" - -example_text1 = """$TTL 1h -$ORIGIN 0.0.192.IN-ADDR.ARPA. -$GENERATE 1-10 fooo$ CNAME $.0 -""" - -example_text2 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 3-5 foo$ A 10.0.0.$ -""" - -example_text3 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 4-8/2 foo$ A 10.0.0.$ -""" - -example_text4 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-13 wp-db${-10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. -""" - -example_text5 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-13 wp-db${10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. -""" - -example_text6 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-13 wp-db${+10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. -""" - -example_text7 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-13 sync${-10}.db IN A 10.10.16.0 -""" - -example_text8 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-12 wp-db${-10,2,d} IN A 10.10.16.0 -""" - -example_text9 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 11-12 wp-db${-10,2,d} IN A 10.10.16.0 -$GENERATE 11-13 sync${-10}.db IN A 10.10.16.0 -""" -example_text10 = """$TTL 1h -@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -$GENERATE 27-28 $.2 PTR zlb${-26}.oob -""" - - -class GenerateTestCase(unittest.TestCase): - - def testFromText(self): - def bad(): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - self.failUnlessRaises(dns.zone.NoSOA, bad) - - def testFromText1(self): - def bad(): - z = dns.zone.from_text(example_text1, 'example.', relativize=True) - self.failUnlessRaises(dns.zone.NoSOA, bad) - - def testIterateAllRdatas2(self): - z = dns.zone.from_text(example_text2, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - (dns.name.from_text('foo3', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.3')), - (dns.name.from_text('foo4', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.4')), - (dns.name.from_text('foo5', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.5'))] - - exl.sort() - self.failUnless(l == exl) - - def testIterateAllRdatas3(self): - z = dns.zone.from_text(example_text3, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - (dns.name.from_text('foo4', None), 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.4')), - (dns.name.from_text('foo6', None), 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.6')), - (dns.name.from_text('foo8', None), 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.8'))] - exl.sort() - self.failUnless(l == exl) - def testGenerate1(self): - z = dns.zone.from_text(example_text4, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - - (dns.name.from_text('wp-db01.services.mozilla.com', None), - 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db02.services.mozilla.com', None), - 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db03.services.mozilla.com', None), - 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.'))] - exl.sort() - self.failUnless(l == exl) - - def testGenerate2(self): - z = dns.zone.from_text(example_text5, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - - (dns.name.from_text('wp-db21.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db22.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db23.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.'))] - exl.sort() - self.failUnless(l == exl) - - def testGenerate3(self): - z = dns.zone.from_text(example_text6, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - (dns.name.from_text('wp-db21.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db22.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.')), - - (dns.name.from_text('wp-db23.services.mozilla.com', None), 0L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, - 'SERVER.FOOBAR.'))] - exl.sort() - self.failUnless(l == exl) - - def testGenerate4(self): - z = dns.zone.from_text(example_text7, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - - (dns.name.from_text('sync1.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - - (dns.name.from_text('sync2.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - - (dns.name.from_text('sync3.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0'))] - exl.sort() - self.failUnless(l == exl) - - def testGenerate6(self): - z = dns.zone.from_text(example_text9, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - - (dns.name.from_text('wp-db01', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - (dns.name.from_text('wp-db02', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - - (dns.name.from_text('sync1.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - - (dns.name.from_text('sync2.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0')), - - (dns.name.from_text('sync3.db', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.10.16.0'))] - exl.sort() - self.failUnless(l == exl) - - def testGenerate7(self): - z = dns.zone.from_text(example_text10, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2')), - - (dns.name.from_text('27.2', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR, - 'zlb1.oob')), - - (dns.name.from_text('28.2', None), 3600L, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR, - 'zlb2.oob'))] - - exl.sort() - self.failUnless(l == exl) - - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/grange.py dnspython-1.12.0/tests/grange.py --- dnspython-1.11.1/tests/grange.py 2013-07-08 10:35:38.000000000 +0000 +++ dnspython-1.12.0/tests/grange.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,95 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import sys -sys.path.insert(0, '../') - -import cStringIO -import filecmp -import os -import unittest - -import dns -import dns.exception -import dns.grange - -import pdb - - - -class GRangeTestCase(unittest.TestCase): - - def testFromText1(self): - start, stop, step = dns.grange.from_text('1-1') - self.assertEqual(start, 1) - self.assertEqual(stop, 1) - self.assertEqual(step, 1) - - def testFromText2(self): - start, stop, step = dns.grange.from_text('1-4') - self.assertEqual(start, 1) - self.assertEqual(stop, 4) - self.assertEqual(step, 1) - - def testFromText3(self): - start, stop, step = dns.grange.from_text('4-255') - self.assertEqual(start, 4) - self.assertEqual(stop, 255) - self.assertEqual(step, 1) - - def testFromText4(self): - start, stop, step = dns.grange.from_text('1-1/1') - self.assertEqual(start, 1) - self.assertEqual(stop, 1) - self.assertEqual(step, 1) - - def testFromText5(self): - start, stop, step = dns.grange.from_text('1-4/2') - self.assertEqual(start, 1) - self.assertEqual(stop, 4) - self.assertEqual(step, 2) - - def testFromText6(self): - start, stop, step = dns.grange.from_text('4-255/77') - self.assertEqual(start, 4) - self.assertEqual(stop, 255) - self.assertEqual(step, 77) - - def testFailFromText1(self): - def bad(): - start = 2 - stop = 1 - step = 1 - dns.grange.from_text('%d-%d/%d' % (start, stop, step)) - self.assertRaises(AssertionError, bad) - - def testFailFromText2(self): - def bad(): - start = '-1' - stop = 3 - step = 1 - dns.grange.from_text('%s-%d/%d' % (start, stop, step)) - self.assertRaises(dns.exception.SyntaxError, bad) - - def testFailFromText2(self): - def bad(): - start = 1 - stop = 4 - step = '-2' - dns.grange.from_text('%d-%d/%s' % (start, stop, step)) - self.assertRaises(dns.exception.SyntaxError, bad) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/Makefile dnspython-1.12.0/tests/Makefile --- dnspython-1.11.1/tests/Makefile 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/Makefile 2014-07-24 13:21:49.000000000 +0000 @@ -20,7 +20,4 @@ check: test test: - @for i in *.py; do \ - echo "Running $$i:"; \ - ${PYTHON} $$i || exit 1; \ - done + ${PYTHON} ./utest.py diff -Nru dnspython-1.11.1/tests/message.py dnspython-1.12.0/tests/message.py --- dnspython-1.11.1/tests/message.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/message.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,179 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import cStringIO -import os -import unittest - -import dns.exception -import dns.message - -query_text = """id 1234 -opcode QUERY -rcode NOERROR -flags RD -edns 0 -eflags DO -payload 4096 -;QUESTION -wwww.dnspython.org. IN A -;ANSWER -;AUTHORITY -;ADDITIONAL""" - -goodhex = '04d201000001000000000001047777777709646e73707974686f6e' \ - '036f726700000100010000291000000080000000' - -goodwire = goodhex.decode('hex_codec') - -answer_text = """id 1234 -opcode QUERY -rcode NOERROR -flags QR AA RD -;QUESTION -dnspython.org. IN SOA -;ANSWER -dnspython.org. 3600 IN SOA woof.dnspython.org. hostmaster.dnspython.org. 2003052700 3600 1800 604800 3600 -;AUTHORITY -dnspython.org. 3600 IN NS ns1.staff.nominum.org. -dnspython.org. 3600 IN NS ns2.staff.nominum.org. -dnspython.org. 3600 IN NS woof.play-bow.org. -;ADDITIONAL -woof.play-bow.org. 3600 IN A 204.152.186.150 -""" - -goodhex2 = '04d2 8500 0001 0001 0003 0001' \ - '09646e73707974686f6e036f726700 0006 0001' \ - 'c00c 0006 0001 00000e10 0028 ' \ - '04776f6f66c00c 0a686f73746d6173746572c00c' \ - '7764289c 00000e10 00000708 00093a80 00000e10' \ - 'c00c 0002 0001 00000e10 0014' \ - '036e7331057374616666076e6f6d696e756dc016' \ - 'c00c 0002 0001 00000e10 0006 036e7332c063' \ - 'c00c 0002 0001 00000e10 0010 04776f6f6608706c61792d626f77c016' \ - 'c091 0001 0001 00000e10 0004 cc98ba96' - - -goodwire2 = goodhex2.replace(' ', '').decode('hex_codec') - -query_text_2 = """id 1234 -opcode QUERY -rcode 4095 -flags RD -edns 0 -eflags DO -payload 4096 -;QUESTION -wwww.dnspython.org. IN A -;ANSWER -;AUTHORITY -;ADDITIONAL""" - -goodhex3 = '04d2010f0001000000000001047777777709646e73707974686f6e' \ - '036f726700000100010000291000ff0080000000' - -goodwire3 = goodhex3.decode('hex_codec') - -class MessageTestCase(unittest.TestCase): - - def test_comparison_eq1(self): - q1 = dns.message.from_text(query_text) - q2 = dns.message.from_text(query_text) - self.failUnless(q1 == q2) - - def test_comparison_ne1(self): - q1 = dns.message.from_text(query_text) - q2 = dns.message.from_text(query_text) - q2.id = 10 - self.failUnless(q1 != q2) - - def test_comparison_ne2(self): - q1 = dns.message.from_text(query_text) - q2 = dns.message.from_text(query_text) - q2.question = [] - self.failUnless(q1 != q2) - - def test_comparison_ne3(self): - q1 = dns.message.from_text(query_text) - self.failUnless(q1 != 1) - - def test_EDNS_to_wire1(self): - q = dns.message.from_text(query_text) - w = q.to_wire() - self.failUnless(w == goodwire) - - def test_EDNS_from_wire1(self): - m = dns.message.from_wire(goodwire) - self.failUnless(str(m) == query_text) - - def test_EDNS_to_wire2(self): - q = dns.message.from_text(query_text_2) - w = q.to_wire() - self.failUnless(w == goodwire3) - - def test_EDNS_from_wire2(self): - m = dns.message.from_wire(goodwire3) - self.failUnless(str(m) == query_text_2) - - def test_TooBig(self): - def bad(): - q = dns.message.from_text(query_text) - for i in xrange(0, 25): - rrset = dns.rrset.from_text('foo%d.' % i, 3600, - dns.rdataclass.IN, - dns.rdatatype.A, - '10.0.0.%d' % i) - q.additional.append(rrset) - w = q.to_wire(max_size=512) - self.failUnlessRaises(dns.exception.TooBig, bad) - - def test_answer1(self): - a = dns.message.from_text(answer_text) - wire = a.to_wire(want_shuffle=False) - self.failUnless(wire == goodwire2) - - def test_TrailingJunk(self): - def bad(): - badwire = goodwire + '\x00' - m = dns.message.from_wire(badwire) - self.failUnlessRaises(dns.message.TrailingJunk, bad) - - def test_ShortHeader(self): - def bad(): - badwire = '\x00' * 11 - m = dns.message.from_wire(badwire) - self.failUnlessRaises(dns.message.ShortHeader, bad) - - def test_RespondingToResponse(self): - def bad(): - q = dns.message.make_query('foo', 'A') - r1 = dns.message.make_response(q) - r2 = dns.message.make_response(r1) - self.failUnlessRaises(dns.exception.FormError, bad) - - def test_ExtendedRcodeSetting(self): - m = dns.message.make_query('foo', 'A') - m.set_rcode(4095) - self.failUnless(m.rcode() == 4095) - m.set_rcode(2) - self.failUnless(m.rcode() == 2) - - def test_EDNSVersionCoherence(self): - m = dns.message.make_query('foo', 'A') - m.use_edns(1) - self.failUnless((m.ednsflags >> 16) & 0xFF == 1) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/namedict.py dnspython-1.12.0/tests/namedict.py --- dnspython-1.11.1/tests/namedict.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/namedict.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,102 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.name -import dns.namedict - -class NameTestCase(unittest.TestCase): - - def setUp(self): - self.ndict = dns.namedict.NameDict() - n1 = dns.name.from_text('foo.bar.') - n2 = dns.name.from_text('bar.') - self.ndict[n1] = 1 - self.ndict[n2] = 2 - self.rndict = dns.namedict.NameDict() - n1 = dns.name.from_text('foo.bar', None) - n2 = dns.name.from_text('bar', None) - self.rndict[n1] = 1 - self.rndict[n2] = 2 - - def testDepth(self): - self.failUnless(self.ndict.max_depth == 3) - - def testLookup1(self): - k = dns.name.from_text('foo.bar.') - self.failUnless(self.ndict[k] == 1) - - def testLookup2(self): - k = dns.name.from_text('foo.bar.') - self.failUnless(self.ndict.get_deepest_match(k)[1] == 1) - - def testLookup3(self): - k = dns.name.from_text('a.b.c.foo.bar.') - self.failUnless(self.ndict.get_deepest_match(k)[1] == 1) - - def testLookup4(self): - k = dns.name.from_text('a.b.c.bar.') - self.failUnless(self.ndict.get_deepest_match(k)[1] == 2) - - def testLookup5(self): - def bad(): - n = dns.name.from_text('a.b.c.') - (k, v) = self.ndict.get_deepest_match(n) - self.failUnlessRaises(KeyError, bad) - - def testLookup6(self): - def bad(): - (k, v) = self.ndict.get_deepest_match(dns.name.empty) - self.failUnlessRaises(KeyError, bad) - - def testLookup7(self): - self.ndict[dns.name.empty] = 100 - n = dns.name.from_text('a.b.c.') - (k, v) = self.ndict.get_deepest_match(n) - self.failUnless(v == 100) - - def testLookup8(self): - def bad(): - self.ndict['foo'] = 100 - self.failUnlessRaises(ValueError, bad) - - def testRelDepth(self): - self.failUnless(self.rndict.max_depth == 2) - - def testRelLookup1(self): - k = dns.name.from_text('foo.bar', None) - self.failUnless(self.rndict[k] == 1) - - def testRelLookup2(self): - k = dns.name.from_text('foo.bar', None) - self.failUnless(self.rndict.get_deepest_match(k)[1] == 1) - - def testRelLookup3(self): - k = dns.name.from_text('a.b.c.foo.bar', None) - self.failUnless(self.rndict.get_deepest_match(k)[1] == 1) - - def testRelLookup4(self): - k = dns.name.from_text('a.b.c.bar', None) - self.failUnless(self.rndict.get_deepest_match(k)[1] == 2) - - def testRelLookup7(self): - self.rndict[dns.name.empty] = 100 - n = dns.name.from_text('a.b.c', None) - (k, v) = self.rndict.get_deepest_match(n) - self.failUnless(v == 100) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/name.py dnspython-1.12.0/tests/name.py --- dnspython-1.11.1/tests/name.py 2011-07-13 01:16:36.000000000 +0000 +++ dnspython-1.12.0/tests/name.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,697 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import cStringIO -import socket - -import dns.name -import dns.reversename -import dns.e164 - -class NameTestCase(unittest.TestCase): - def setUp(self): - self.origin = dns.name.from_text('example.') - - def testFromTextRel1(self): - n = dns.name.from_text('foo.bar') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testFromTextRel2(self): - n = dns.name.from_text('foo.bar', origin=self.origin) - self.failUnless(n.labels == ('foo', 'bar', 'example', '')) - - def testFromTextRel3(self): - n = dns.name.from_text('foo.bar', origin=None) - self.failUnless(n.labels == ('foo', 'bar')) - - def testFromTextRel4(self): - n = dns.name.from_text('@', origin=None) - self.failUnless(n == dns.name.empty) - - def testFromTextRel5(self): - n = dns.name.from_text('@', origin=self.origin) - self.failUnless(n == self.origin) - - def testFromTextAbs1(self): - n = dns.name.from_text('foo.bar.') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testTortureFromText(self): - good = [ - r'.', - r'a', - r'a.', - r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - r'\000.\008.\010.\032.\046.\092.\099.\255', - r'\\', - r'\..\.', - r'\\.\\', - r'!"#%&/()=+-', - r'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255', - ] - bad = [ - r'..', - r'.a', - r'\\..', - '\\', # yes, we don't want the 'r' prefix! - r'\0', - r'\00', - r'\00Z', - r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', - r'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255', - ] - for t in good: - try: - n = dns.name.from_text(t) - except: - self.fail("good test '%s' raised an exception" % t) - for t in bad: - caught = False - try: - n = dns.name.from_text(t) - except: - caught = True - if not caught: - self.fail("bad test '%s' did not raise an exception" % t) - - def testImmutable1(self): - def bad(): - self.origin.labels = () - self.failUnlessRaises(TypeError, bad) - - def testImmutable2(self): - def bad(): - self.origin.labels[0] = 'foo' - self.failUnlessRaises(TypeError, bad) - - def testAbs1(self): - self.failUnless(dns.name.root.is_absolute()) - - def testAbs2(self): - self.failUnless(not dns.name.empty.is_absolute()) - - def testAbs3(self): - self.failUnless(self.origin.is_absolute()) - - def testAbs3(self): - n = dns.name.from_text('foo', origin=None) - self.failUnless(not n.is_absolute()) - - def testWild1(self): - n = dns.name.from_text('*.foo', origin=None) - self.failUnless(n.is_wild()) - - def testWild2(self): - n = dns.name.from_text('*a.foo', origin=None) - self.failUnless(not n.is_wild()) - - def testWild3(self): - n = dns.name.from_text('a.*.foo', origin=None) - self.failUnless(not n.is_wild()) - - def testWild4(self): - self.failUnless(not dns.name.root.is_wild()) - - def testWild5(self): - self.failUnless(not dns.name.empty.is_wild()) - - def testHash1(self): - n1 = dns.name.from_text('fOo.COM') - n2 = dns.name.from_text('foo.com') - self.failUnless(hash(n1) == hash(n2)) - - def testCompare1(self): - n1 = dns.name.from_text('a') - n2 = dns.name.from_text('b') - self.failUnless(n1 < n2) - self.failUnless(n2 > n1) - - def testCompare2(self): - n1 = dns.name.from_text('') - n2 = dns.name.from_text('b') - self.failUnless(n1 < n2) - self.failUnless(n2 > n1) - - def testCompare3(self): - self.failUnless(dns.name.empty < dns.name.root) - self.failUnless(dns.name.root > dns.name.empty) - - def testCompare4(self): - self.failUnless(dns.name.root != 1) - - def testCompare5(self): - self.failUnless(dns.name.root < 1 or dns.name.root > 1) - - def testSubdomain1(self): - self.failUnless(not dns.name.empty.is_subdomain(dns.name.root)) - - def testSubdomain2(self): - self.failUnless(not dns.name.root.is_subdomain(dns.name.empty)) - - def testSubdomain3(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(n.is_subdomain(self.origin)) - - def testSubdomain4(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(n.is_subdomain(dns.name.root)) - - def testSubdomain5(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(n.is_subdomain(n)) - - def testSuperdomain1(self): - self.failUnless(not dns.name.empty.is_superdomain(dns.name.root)) - - def testSuperdomain2(self): - self.failUnless(not dns.name.root.is_superdomain(dns.name.empty)) - - def testSuperdomain3(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(self.origin.is_superdomain(n)) - - def testSuperdomain4(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(dns.name.root.is_superdomain(n)) - - def testSuperdomain5(self): - n = dns.name.from_text('foo', origin=self.origin) - self.failUnless(n.is_superdomain(n)) - - def testCanonicalize1(self): - n = dns.name.from_text('FOO.bar', origin=self.origin) - c = n.canonicalize() - self.failUnless(c.labels == ('foo', 'bar', 'example', '')) - - def testToText1(self): - n = dns.name.from_text('FOO.bar', origin=self.origin) - t = n.to_text() - self.failUnless(t == 'FOO.bar.example.') - - def testToText2(self): - n = dns.name.from_text('FOO.bar', origin=self.origin) - t = n.to_text(True) - self.failUnless(t == 'FOO.bar.example') - - def testToText3(self): - n = dns.name.from_text('FOO.bar', origin=None) - t = n.to_text() - self.failUnless(t == 'FOO.bar') - - def testToText4(self): - t = dns.name.empty.to_text() - self.failUnless(t == '@') - - def testToText5(self): - t = dns.name.root.to_text() - self.failUnless(t == '.') - - def testToText6(self): - n = dns.name.from_text('FOO bar', origin=None) - t = n.to_text() - self.failUnless(t == r'FOO\032bar') - - def testToText7(self): - n = dns.name.from_text(r'FOO\.bar', origin=None) - t = n.to_text() - self.failUnless(t == r'FOO\.bar') - - def testToText8(self): - n = dns.name.from_text(r'\070OO\.bar', origin=None) - t = n.to_text() - self.failUnless(t == r'FOO\.bar') - - def testSlice1(self): - n = dns.name.from_text(r'a.b.c.', origin=None) - s = n[:] - self.failUnless(s == ('a', 'b', 'c', '')) - - def testSlice2(self): - n = dns.name.from_text(r'a.b.c.', origin=None) - s = n[:2] - self.failUnless(s == ('a', 'b')) - - def testSlice3(self): - n = dns.name.from_text(r'a.b.c.', origin=None) - s = n[2:] - self.failUnless(s == ('c', '')) - - def testEmptyLabel1(self): - def bad(): - n = dns.name.Name(['a', '', 'b']) - self.failUnlessRaises(dns.name.EmptyLabel, bad) - - def testEmptyLabel2(self): - def bad(): - n = dns.name.Name(['', 'b']) - self.failUnlessRaises(dns.name.EmptyLabel, bad) - - def testEmptyLabel3(self): - n = dns.name.Name(['b', '']) - self.failUnless(n) - - def testLongLabel(self): - n = dns.name.Name(['a' * 63]) - self.failUnless(n) - - def testLabelTooLong(self): - def bad(): - n = dns.name.Name(['a' * 64, 'b']) - self.failUnlessRaises(dns.name.LabelTooLong, bad) - - def testLongName(self): - n = dns.name.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 62]) - self.failUnless(n) - - def testNameTooLong(self): - def bad(): - n = dns.name.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 63]) - self.failUnlessRaises(dns.name.NameTooLong, bad) - - def testConcat1(self): - n1 = dns.name.Name(['a', 'b']) - n2 = dns.name.Name(['c', 'd']) - e = dns.name.Name(['a', 'b', 'c', 'd']) - r = n1 + n2 - self.failUnless(r == e) - - def testConcat2(self): - n1 = dns.name.Name(['a', 'b']) - n2 = dns.name.Name([]) - e = dns.name.Name(['a', 'b']) - r = n1 + n2 - self.failUnless(r == e) - - def testConcat2(self): - n1 = dns.name.Name([]) - n2 = dns.name.Name(['a', 'b']) - e = dns.name.Name(['a', 'b']) - r = n1 + n2 - self.failUnless(r == e) - - def testConcat3(self): - n1 = dns.name.Name(['a', 'b', '']) - n2 = dns.name.Name([]) - e = dns.name.Name(['a', 'b', '']) - r = n1 + n2 - self.failUnless(r == e) - - def testConcat4(self): - n1 = dns.name.Name(['a', 'b']) - n2 = dns.name.Name(['c', '']) - e = dns.name.Name(['a', 'b', 'c', '']) - r = n1 + n2 - self.failUnless(r == e) - - def testConcat5(self): - def bad(): - n1 = dns.name.Name(['a', 'b', '']) - n2 = dns.name.Name(['c']) - r = n1 + n2 - self.failUnlessRaises(dns.name.AbsoluteConcatenation, bad) - - def testBadEscape(self): - def bad(): - n = dns.name.from_text(r'a.b\0q1.c.') - print n - self.failUnlessRaises(dns.name.BadEscape, bad) - - def testDigestable1(self): - n = dns.name.from_text('FOO.bar') - d = n.to_digestable() - self.failUnless(d == '\x03foo\x03bar\x00') - - def testDigestable2(self): - n1 = dns.name.from_text('FOO.bar') - n2 = dns.name.from_text('foo.BAR.') - d1 = n1.to_digestable() - d2 = n2.to_digestable() - self.failUnless(d1 == d2) - - def testDigestable3(self): - d = dns.name.root.to_digestable() - self.failUnless(d == '\x00') - - def testDigestable4(self): - n = dns.name.from_text('FOO.bar', None) - d = n.to_digestable(dns.name.root) - self.failUnless(d == '\x03foo\x03bar\x00') - - def testBadDigestable(self): - def bad(): - n = dns.name.from_text('FOO.bar', None) - d = n.to_digestable() - self.failUnlessRaises(dns.name.NeedAbsoluteNameOrOrigin, bad) - - def testToWire1(self): - n = dns.name.from_text('FOO.bar') - f = cStringIO.StringIO() - compress = {} - n.to_wire(f, compress) - self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00') - - def testToWire2(self): - n = dns.name.from_text('FOO.bar') - f = cStringIO.StringIO() - compress = {} - n.to_wire(f, compress) - n.to_wire(f, compress) - self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\xc0\x00') - - def testToWire3(self): - n1 = dns.name.from_text('FOO.bar') - n2 = dns.name.from_text('foo.bar') - f = cStringIO.StringIO() - compress = {} - n1.to_wire(f, compress) - n2.to_wire(f, compress) - self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\xc0\x00') - - def testToWire4(self): - n1 = dns.name.from_text('FOO.bar') - n2 = dns.name.from_text('a.foo.bar') - f = cStringIO.StringIO() - compress = {} - n1.to_wire(f, compress) - n2.to_wire(f, compress) - self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\x01\x61\xc0\x00') - - def testToWire5(self): - n1 = dns.name.from_text('FOO.bar') - n2 = dns.name.from_text('a.foo.bar') - f = cStringIO.StringIO() - compress = {} - n1.to_wire(f, compress) - n2.to_wire(f, None) - self.failUnless(f.getvalue() == \ - '\x03FOO\x03bar\x00\x01\x61\x03foo\x03bar\x00') - - def testToWire6(self): - n = dns.name.from_text('FOO.bar') - v = n.to_wire() - self.failUnless(v == '\x03FOO\x03bar\x00') - - def testBadToWire(self): - def bad(): - n = dns.name.from_text('FOO.bar', None) - f = cStringIO.StringIO() - compress = {} - n.to_wire(f, compress) - self.failUnlessRaises(dns.name.NeedAbsoluteNameOrOrigin, bad) - - def testSplit1(self): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(2) - ep = dns.name.from_text('foo', None) - es = dns.name.from_text('bar.', None) - self.failUnless(prefix == ep and suffix == es) - - def testSplit2(self): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(1) - ep = dns.name.from_text('foo.bar', None) - es = dns.name.from_text('.', None) - self.failUnless(prefix == ep and suffix == es) - - def testSplit3(self): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(0) - ep = dns.name.from_text('foo.bar.', None) - es = dns.name.from_text('', None) - self.failUnless(prefix == ep and suffix == es) - - def testSplit4(self): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(3) - ep = dns.name.from_text('', None) - es = dns.name.from_text('foo.bar.', None) - self.failUnless(prefix == ep and suffix == es) - - def testBadSplit1(self): - def bad(): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(-1) - self.failUnlessRaises(ValueError, bad) - - def testBadSplit2(self): - def bad(): - n = dns.name.from_text('foo.bar.') - (prefix, suffix) = n.split(4) - self.failUnlessRaises(ValueError, bad) - - def testRelativize1(self): - n = dns.name.from_text('a.foo.bar.', None) - o = dns.name.from_text('bar.', None) - e = dns.name.from_text('a.foo', None) - self.failUnless(n.relativize(o) == e) - - def testRelativize2(self): - n = dns.name.from_text('a.foo.bar.', None) - o = n - e = dns.name.empty - self.failUnless(n.relativize(o) == e) - - def testRelativize3(self): - n = dns.name.from_text('a.foo.bar.', None) - o = dns.name.from_text('blaz.', None) - e = n - self.failUnless(n.relativize(o) == e) - - def testRelativize4(self): - n = dns.name.from_text('a.foo', None) - o = dns.name.root - e = n - self.failUnless(n.relativize(o) == e) - - def testDerelativize1(self): - n = dns.name.from_text('a.foo', None) - o = dns.name.from_text('bar.', None) - e = dns.name.from_text('a.foo.bar.', None) - self.failUnless(n.derelativize(o) == e) - - def testDerelativize2(self): - n = dns.name.empty - o = dns.name.from_text('a.foo.bar.', None) - e = o - self.failUnless(n.derelativize(o) == e) - - def testDerelativize3(self): - n = dns.name.from_text('a.foo.bar.', None) - o = dns.name.from_text('blaz.', None) - e = n - self.failUnless(n.derelativize(o) == e) - - def testChooseRelativity1(self): - n = dns.name.from_text('a.foo.bar.', None) - o = dns.name.from_text('bar.', None) - e = dns.name.from_text('a.foo', None) - self.failUnless(n.choose_relativity(o, True) == e) - - def testChooseRelativity2(self): - n = dns.name.from_text('a.foo.bar.', None) - o = dns.name.from_text('bar.', None) - e = n - self.failUnless(n.choose_relativity(o, False) == e) - - def testChooseRelativity3(self): - n = dns.name.from_text('a.foo', None) - o = dns.name.from_text('bar.', None) - e = dns.name.from_text('a.foo.bar.', None) - self.failUnless(n.choose_relativity(o, False) == e) - - def testChooseRelativity4(self): - n = dns.name.from_text('a.foo', None) - o = None - e = n - self.failUnless(n.choose_relativity(o, True) == e) - - def testChooseRelativity5(self): - n = dns.name.from_text('a.foo', None) - o = None - e = n - self.failUnless(n.choose_relativity(o, False) == e) - - def testChooseRelativity6(self): - n = dns.name.from_text('a.foo.', None) - o = None - e = n - self.failUnless(n.choose_relativity(o, True) == e) - - def testChooseRelativity7(self): - n = dns.name.from_text('a.foo.', None) - o = None - e = n - self.failUnless(n.choose_relativity(o, False) == e) - - def testFromWire1(self): - w = '\x03foo\x00\xc0\x00' - (n1, cused1) = dns.name.from_wire(w, 0) - (n2, cused2) = dns.name.from_wire(w, cused1) - en1 = dns.name.from_text('foo.') - en2 = en1 - ecused1 = 5 - ecused2 = 2 - self.failUnless(n1 == en1 and cused1 == ecused1 and \ - n2 == en2 and cused2 == ecused2) - - def testFromWire1(self): - w = '\x03foo\x00\x01a\xc0\x00\x01b\xc0\x05' - current = 0 - (n1, cused1) = dns.name.from_wire(w, current) - current += cused1 - (n2, cused2) = dns.name.from_wire(w, current) - current += cused2 - (n3, cused3) = dns.name.from_wire(w, current) - en1 = dns.name.from_text('foo.') - en2 = dns.name.from_text('a.foo.') - en3 = dns.name.from_text('b.a.foo.') - ecused1 = 5 - ecused2 = 4 - ecused3 = 4 - self.failUnless(n1 == en1 and cused1 == ecused1 and \ - n2 == en2 and cused2 == ecused2 and \ - n3 == en3 and cused3 == ecused3) - - def testBadFromWire1(self): - def bad(): - w = '\x03foo\xc0\x04' - (n, cused) = dns.name.from_wire(w, 0) - self.failUnlessRaises(dns.name.BadPointer, bad) - - def testBadFromWire2(self): - def bad(): - w = '\x03foo\xc0\x05' - (n, cused) = dns.name.from_wire(w, 0) - self.failUnlessRaises(dns.name.BadPointer, bad) - - def testBadFromWire3(self): - def bad(): - w = '\xbffoo' - (n, cused) = dns.name.from_wire(w, 0) - self.failUnlessRaises(dns.name.BadLabelType, bad) - - def testBadFromWire4(self): - def bad(): - w = '\x41foo' - (n, cused) = dns.name.from_wire(w, 0) - self.failUnlessRaises(dns.name.BadLabelType, bad) - - def testParent1(self): - n = dns.name.from_text('foo.bar.') - self.failUnless(n.parent() == dns.name.from_text('bar.')) - self.failUnless(n.parent().parent() == dns.name.root) - - def testParent2(self): - n = dns.name.from_text('foo.bar', None) - self.failUnless(n.parent() == dns.name.from_text('bar', None)) - self.failUnless(n.parent().parent() == dns.name.empty) - - def testParent3(self): - def bad(): - n = dns.name.root - n.parent() - self.failUnlessRaises(dns.name.NoParent, bad) - - def testParent4(self): - def bad(): - n = dns.name.empty - n.parent() - self.failUnlessRaises(dns.name.NoParent, bad) - - def testFromUnicode1(self): - n = dns.name.from_text(u'foo.bar') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testFromUnicode2(self): - n = dns.name.from_text(u'foo\u1234bar.bar') - self.failUnless(n.labels == ('xn--foobar-r5z', 'bar', '')) - - def testFromUnicodeAlternateDot1(self): - n = dns.name.from_text(u'foo\u3002bar') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testFromUnicodeAlternateDot2(self): - n = dns.name.from_text(u'foo\uff0ebar') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testFromUnicodeAlternateDot3(self): - n = dns.name.from_text(u'foo\uff61bar') - self.failUnless(n.labels == ('foo', 'bar', '')) - - def testToUnicode1(self): - n = dns.name.from_text(u'foo.bar') - s = n.to_unicode() - self.failUnless(s == u'foo.bar.') - - def testToUnicode2(self): - n = dns.name.from_text(u'foo\u1234bar.bar') - s = n.to_unicode() - self.failUnless(s == u'foo\u1234bar.bar.') - - def testToUnicode3(self): - n = dns.name.from_text('foo.bar') - s = n.to_unicode() - self.failUnless(s == u'foo.bar.') - - def testReverseIPv4(self): - e = dns.name.from_text('1.0.0.127.in-addr.arpa.') - n = dns.reversename.from_address('127.0.0.1') - self.failUnless(e == n) - - def testReverseIPv6(self): - e = dns.name.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.') - n = dns.reversename.from_address('::1') - self.failUnless(e == n) - - def testBadReverseIPv4(self): - def bad(): - n = dns.reversename.from_address('127.0.foo.1') - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testBadReverseIPv6(self): - def bad(): - n = dns.reversename.from_address('::1::1') - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testForwardIPv4(self): - n = dns.name.from_text('1.0.0.127.in-addr.arpa.') - e = '127.0.0.1' - text = dns.reversename.to_address(n) - self.failUnless(text == e) - - def testForwardIPv6(self): - n = dns.name.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.') - e = '::1' - text = dns.reversename.to_address(n) - self.failUnless(text == e) - - def testE164ToEnum(self): - text = '+1 650 555 1212' - e = dns.name.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.') - n = dns.e164.from_e164(text) - self.failUnless(n == e) - - def testEnumToE164(self): - n = dns.name.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.') - e = '+16505551212' - text = dns.e164.to_e164(n) - self.failUnless(text == e) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/ntoaaton.py dnspython-1.12.0/tests/ntoaaton.py --- dnspython-1.11.1/tests/ntoaaton.py 2013-04-26 11:56:08.000000000 +0000 +++ dnspython-1.12.0/tests/ntoaaton.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,203 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.exception -import dns.ipv4 -import dns.ipv6 - -# for convenience -aton4 = dns.ipv4.inet_aton -ntoa4 = dns.ipv4.inet_ntoa -aton6 = dns.ipv6.inet_aton -ntoa6 = dns.ipv6.inet_ntoa - -v4_bad_addrs = ['256.1.1.1', '1.1.1', '1.1.1.1.1', '01.1.1.1', - '+1.1.1.1', '1.1.1.1+', '1..2.3.4', '.1.2.3.4', - '1.2.3.4.'] - -class NtoAAtoNTestCase(unittest.TestCase): - - def test_aton1(self): - a = aton6('::') - self.failUnless(a == '\x00' * 16) - - def test_aton2(self): - a = aton6('::1') - self.failUnless(a == '\x00' * 15 + '\x01') - - def test_aton3(self): - a = aton6('::10.0.0.1') - self.failUnless(a == '\x00' * 12 + '\x0a\x00\x00\x01') - - def test_aton4(self): - a = aton6('abcd::dcba') - self.failUnless(a == '\xab\xcd' + '\x00' * 12 + '\xdc\xba') - - def test_aton5(self): - a = aton6('1:2:3:4:5:6:7:8') - self.failUnless(a == \ - '00010002000300040005000600070008'.decode('hex_codec')) - - def test_bad_aton1(self): - def bad(): - a = aton6('abcd:dcba') - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def test_bad_aton2(self): - def bad(): - a = aton6('abcd::dcba::1') - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def test_bad_aton3(self): - def bad(): - a = aton6('1:2:3:4:5:6:7:8:9') - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def test_aton1(self): - a = aton6('::') - self.failUnless(a == '\x00' * 16) - - def test_aton2(self): - a = aton6('::1') - self.failUnless(a == '\x00' * 15 + '\x01') - - def test_aton3(self): - a = aton6('::10.0.0.1') - self.failUnless(a == '\x00' * 12 + '\x0a\x00\x00\x01') - - def test_aton4(self): - a = aton6('abcd::dcba') - self.failUnless(a == '\xab\xcd' + '\x00' * 12 + '\xdc\xba') - - def test_ntoa1(self): - b = '00010002000300040005000600070008'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '1:2:3:4:5:6:7:8') - - def test_ntoa2(self): - b = '\x00' * 16 - t = ntoa6(b) - self.failUnless(t == '::') - - def test_ntoa3(self): - b = '\x00' * 15 + '\x01' - t = ntoa6(b) - self.failUnless(t == '::1') - - def test_ntoa4(self): - b = '\x80' + '\x00' * 15 - t = ntoa6(b) - self.failUnless(t == '8000::') - - def test_ntoa5(self): - b = '\x01\xcd' + '\x00' * 12 + '\x03\xef' - t = ntoa6(b) - self.failUnless(t == '1cd::3ef') - - def test_ntoa6(self): - b = 'ffff00000000ffff000000000000ffff'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == 'ffff:0:0:ffff::ffff') - - def test_ntoa7(self): - b = '00000000ffff000000000000ffffffff'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '0:0:ffff::ffff:ffff') - - def test_ntoa8(self): - b = 'ffff0000ffff00000000ffff00000000'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == 'ffff:0:ffff::ffff:0:0') - - def test_ntoa9(self): - b = '0000000000000000000000000a000001'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::10.0.0.1') - - def test_ntoa10(self): - b = '0000000000000000000000010a000001'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::1:a00:1') - - def test_ntoa11(self): - b = '00000000000000000000ffff0a000001'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::ffff:10.0.0.1') - - def test_ntoa12(self): - b = '000000000000000000000000ffffffff'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::255.255.255.255') - - def test_ntoa13(self): - b = '00000000000000000000ffffffffffff'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::ffff:255.255.255.255') - - def test_ntoa14(self): - b = '0000000000000000000000000001ffff'.decode('hex_codec') - t = ntoa6(b) - self.failUnless(t == '::0.1.255.255') - - def test_bad_ntoa1(self): - def bad(): - a = ntoa6('') - self.failUnlessRaises(ValueError, bad) - - def test_bad_ntoa2(self): - def bad(): - a = ntoa6('\x00' * 17) - self.failUnlessRaises(ValueError, bad) - - def test_good_v4_aton(self): - pairs = [('1.2.3.4', '\x01\x02\x03\x04'), - ('255.255.255.255', '\xff\xff\xff\xff'), - ('0.0.0.0', '\x00\x00\x00\x00')] - for (t, b) in pairs: - b1 = aton4(t) - t1 = ntoa4(b1) - self.failUnless(b1 == b) - self.failUnless(t1 == t) - - def test_bad_v4_aton(self): - def make_bad(a): - def bad(): - return aton4(a) - return bad - for addr in v4_bad_addrs: - self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) - - def test_bad_v6_aton(self): - addrs = ['+::0', '0::0::', '::0::', '1:2:3:4:5:6:7:8:9', - ':::::::'] - embedded = ['::' + x for x in v4_bad_addrs] - addrs.extend(embedded) - def make_bad(a): - def bad(): - x = aton6(a) - return bad - for addr in addrs: - self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) - - def test_rfc5952_section_4_2_2(self): - addr = '2001:db8:0:1:1:1:1:1' - b1 = aton6(addr) - t1 = ntoa6(b1) - self.failUnless(t1 == addr) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/rdtypeandclass.py dnspython-1.12.0/tests/rdtypeandclass.py --- dnspython-1.11.1/tests/rdtypeandclass.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/rdtypeandclass.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,123 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.rdataclass -import dns.rdatatype - -class RdTypeAndClassTestCase(unittest.TestCase): - - # Classes - - def test_class_meta1(self): - self.failUnless(dns.rdataclass.is_metaclass(dns.rdataclass.ANY)) - - def test_class_meta2(self): - self.failUnless(not dns.rdataclass.is_metaclass(dns.rdataclass.IN)) - - def test_class_bytext1(self): - self.failUnless(dns.rdataclass.from_text('IN') == dns.rdataclass.IN) - - def test_class_bytext2(self): - self.failUnless(dns.rdataclass.from_text('CLASS1') == - dns.rdataclass.IN) - - def test_class_bytext_bounds1(self): - self.failUnless(dns.rdataclass.from_text('CLASS0') == 0) - self.failUnless(dns.rdataclass.from_text('CLASS65535') == 65535) - - def test_class_bytext_bounds2(self): - def bad(): - junk = dns.rdataclass.from_text('CLASS65536') - self.failUnlessRaises(ValueError, bad) - - def test_class_bytext_unknown(self): - def bad(): - junk = dns.rdataclass.from_text('XXX') - self.failUnlessRaises(dns.rdataclass.UnknownRdataclass, bad) - - def test_class_totext1(self): - self.failUnless(dns.rdataclass.to_text(dns.rdataclass.IN) == 'IN') - - def test_class_totext1(self): - self.failUnless(dns.rdataclass.to_text(999) == 'CLASS999') - - def test_class_totext_bounds1(self): - def bad(): - junk = dns.rdataclass.to_text(-1) - self.failUnlessRaises(ValueError, bad) - - def test_class_totext_bounds2(self): - def bad(): - junk = dns.rdataclass.to_text(65536) - self.failUnlessRaises(ValueError, bad) - - # Types - - def test_type_meta1(self): - self.failUnless(dns.rdatatype.is_metatype(dns.rdatatype.ANY)) - - def test_type_meta2(self): - self.failUnless(dns.rdatatype.is_metatype(dns.rdatatype.OPT)) - - def test_type_meta3(self): - self.failUnless(not dns.rdatatype.is_metatype(dns.rdatatype.A)) - - def test_type_singleton1(self): - self.failUnless(dns.rdatatype.is_singleton(dns.rdatatype.SOA)) - - def test_type_singleton2(self): - self.failUnless(not dns.rdatatype.is_singleton(dns.rdatatype.A)) - - def test_type_bytext1(self): - self.failUnless(dns.rdatatype.from_text('A') == dns.rdatatype.A) - - def test_type_bytext2(self): - self.failUnless(dns.rdatatype.from_text('TYPE1') == - dns.rdatatype.A) - - def test_type_bytext_bounds1(self): - self.failUnless(dns.rdatatype.from_text('TYPE0') == 0) - self.failUnless(dns.rdatatype.from_text('TYPE65535') == 65535) - - def test_type_bytext_bounds2(self): - def bad(): - junk = dns.rdatatype.from_text('TYPE65536') - self.failUnlessRaises(ValueError, bad) - - def test_type_bytext_unknown(self): - def bad(): - junk = dns.rdatatype.from_text('XXX') - self.failUnlessRaises(dns.rdatatype.UnknownRdatatype, bad) - - def test_type_totext1(self): - self.failUnless(dns.rdatatype.to_text(dns.rdatatype.A) == 'A') - - def test_type_totext1(self): - self.failUnless(dns.rdatatype.to_text(999) == 'TYPE999') - - def test_type_totext_bounds1(self): - def bad(): - junk = dns.rdatatype.to_text(-1) - self.failUnlessRaises(ValueError, bad) - - def test_type_totext_bounds2(self): - def bad(): - junk = dns.rdatatype.to_text(65536) - self.failUnlessRaises(ValueError, bad) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/resolver.py dnspython-1.12.0/tests/resolver.py --- dnspython-1.11.1/tests/resolver.py 2011-08-29 16:45:52.000000000 +0000 +++ dnspython-1.12.0/tests/resolver.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,184 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import cStringIO -import select -import sys -import time -import unittest - -import dns.name -import dns.message -import dns.name -import dns.rdataclass -import dns.rdatatype -import dns.resolver - -resolv_conf = """ - /t/t -# comment 1 -; comment 2 -domain foo -nameserver 10.0.0.1 -nameserver 10.0.0.2 -""" - -message_text = """id 1234 -opcode QUERY -rcode NOERROR -flags QR AA RD -;QUESTION -example. IN A -;ANSWER -example. 1 IN A 10.0.0.1 -;AUTHORITY -;ADDITIONAL -""" - -class FakeAnswer(object): - def __init__(self, expiration): - self.expiration = expiration - -class BaseResolverTests(object): - - if sys.platform != 'win32': - def testRead(self): - f = cStringIO.StringIO(resolv_conf) - r = dns.resolver.Resolver(f) - self.failUnless(r.nameservers == ['10.0.0.1', '10.0.0.2'] and - r.domain == dns.name.from_text('foo')) - - def testCacheExpiration(self): - message = dns.message.from_text(message_text) - name = dns.name.from_text('example.') - answer = dns.resolver.Answer(name, dns.rdatatype.A, dns.rdataclass.IN, - message) - cache = dns.resolver.Cache() - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - time.sleep(2) - self.failUnless(cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) - is None) - - def testCacheCleaning(self): - message = dns.message.from_text(message_text) - name = dns.name.from_text('example.') - answer = dns.resolver.Answer(name, dns.rdatatype.A, dns.rdataclass.IN, - message) - cache = dns.resolver.Cache(cleaning_interval=1.0) - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - time.sleep(2) - self.failUnless(cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) - is None) - - def testZoneForName1(self): - name = dns.name.from_text('www.dnspython.org.') - ezname = dns.name.from_text('dnspython.org.') - zname = dns.resolver.zone_for_name(name) - self.failUnless(zname == ezname) - - def testZoneForName2(self): - name = dns.name.from_text('a.b.www.dnspython.org.') - ezname = dns.name.from_text('dnspython.org.') - zname = dns.resolver.zone_for_name(name) - self.failUnless(zname == ezname) - - def testZoneForName3(self): - name = dns.name.from_text('dnspython.org.') - ezname = dns.name.from_text('dnspython.org.') - zname = dns.resolver.zone_for_name(name) - self.failUnless(zname == ezname) - - def testZoneForName4(self): - def bad(): - name = dns.name.from_text('dnspython.org', None) - zname = dns.resolver.zone_for_name(name) - self.failUnlessRaises(dns.resolver.NotAbsolute, bad) - - def testLRUReplace(self): - cache = dns.resolver.LRUCache(4) - for i in xrange(0, 5): - name = dns.name.from_text('example%d.' % i) - answer = FakeAnswer(time.time() + 1) - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - for i in xrange(0, 5): - name = dns.name.from_text('example%d.' % i) - if i == 0: - self.failUnless(cache.get((name, dns.rdatatype.A, - dns.rdataclass.IN)) - is None) - else: - self.failUnless(not cache.get((name, dns.rdatatype.A, - dns.rdataclass.IN)) - is None) - - def testLRUDoesLRU(self): - cache = dns.resolver.LRUCache(4) - for i in xrange(0, 4): - name = dns.name.from_text('example%d.' % i) - answer = FakeAnswer(time.time() + 1) - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - name = dns.name.from_text('example0.') - cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) - # The LRU is now example1. - name = dns.name.from_text('example4.') - answer = FakeAnswer(time.time() + 1) - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - for i in xrange(0, 5): - name = dns.name.from_text('example%d.' % i) - if i == 1: - self.failUnless(cache.get((name, dns.rdatatype.A, - dns.rdataclass.IN)) - is None) - else: - self.failUnless(not cache.get((name, dns.rdatatype.A, - dns.rdataclass.IN)) - is None) - - def testLRUExpiration(self): - cache = dns.resolver.LRUCache(4) - for i in xrange(0, 4): - name = dns.name.from_text('example%d.' % i) - answer = FakeAnswer(time.time() + 1) - cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) - time.sleep(2) - for i in xrange(0, 4): - name = dns.name.from_text('example%d.' % i) - self.failUnless(cache.get((name, dns.rdatatype.A, - dns.rdataclass.IN)) - is None) - -class PollingMonkeyPatchMixin(object): - def setUp(self): - self.__native_polling_backend = dns.query._polling_backend - dns.query._set_polling_backend(self.polling_backend()) - - unittest.TestCase.setUp(self) - - def tearDown(self): - dns.query._set_polling_backend(self.__native_polling_backend) - - unittest.TestCase.tearDown(self) - -class SelectResolverTestCase(PollingMonkeyPatchMixin, BaseResolverTests, unittest.TestCase): - def polling_backend(self): - return dns.query._select_for - -if hasattr(select, 'poll'): - class PollResolverTestCase(PollingMonkeyPatchMixin, BaseResolverTests, unittest.TestCase): - def polling_backend(self): - return dns.query._poll_for - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/rrset.py dnspython-1.12.0/tests/rrset.py --- dnspython-1.11.1/tests/rrset.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/rrset.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.rrset - -class RRsetTestCase(unittest.TestCase): - - def testEqual1(self): - r1 = dns.rrset.from_text('foo', 300, 'in', 'a', '10.0.0.1', '10.0.0.2') - r2 = dns.rrset.from_text('FOO', 300, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 == r2) - - def testEqual2(self): - r1 = dns.rrset.from_text('foo', 300, 'in', 'a', '10.0.0.1', '10.0.0.2') - r2 = dns.rrset.from_text('FOO', 600, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 == r2) - - def testNotEqual1(self): - r1 = dns.rrset.from_text('fooa', 30, 'in', 'a', '10.0.0.1', '10.0.0.2') - r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 != r2) - - def testNotEqual2(self): - r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1', '10.0.0.3') - r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 != r2) - - def testNotEqual3(self): - r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1', '10.0.0.2', - '10.0.0.3') - r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 != r2) - - def testNotEqual4(self): - r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1') - r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') - self.failUnless(r1 != r2) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/set.py dnspython-1.12.0/tests/set.py --- dnspython-1.11.1/tests/set.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/set.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,208 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.set - -# for convenience -S = dns.set.Set - -class SimpleSetTestCase(unittest.TestCase): - - def testLen1(self): - s1 = S() - self.failUnless(len(s1) == 0) - - def testLen2(self): - s1 = S([1, 2, 3]) - self.failUnless(len(s1) == 3) - - def testLen3(self): - s1 = S([1, 2, 3, 3, 3]) - self.failUnless(len(s1) == 3) - - def testUnion1(self): - s1 = S([1, 2, 3]) - s2 = S([1, 2, 3]) - e = S([1, 2, 3]) - self.failUnless(s1 | s2 == e) - - def testUnion2(self): - s1 = S([1, 2, 3]) - s2 = S([]) - e = S([1, 2, 3]) - self.failUnless(s1 | s2 == e) - - def testUnion3(self): - s1 = S([1, 2, 3]) - s2 = S([3, 4]) - e = S([1, 2, 3, 4]) - self.failUnless(s1 | s2 == e) - - def testIntersection1(self): - s1 = S([1, 2, 3]) - s2 = S([1, 2, 3]) - e = S([1, 2, 3]) - self.failUnless(s1 & s2 == e) - - def testIntersection2(self): - s1 = S([0, 1, 2, 3]) - s2 = S([1, 2, 3, 4]) - e = S([1, 2, 3]) - self.failUnless(s1 & s2 == e) - - def testIntersection3(self): - s1 = S([1, 2, 3]) - s2 = S([]) - e = S([]) - self.failUnless(s1 & s2 == e) - - def testIntersection4(self): - s1 = S([1, 2, 3]) - s2 = S([5, 4]) - e = S([]) - self.failUnless(s1 & s2 == e) - - def testDifference1(self): - s1 = S([1, 2, 3]) - s2 = S([5, 4]) - e = S([1, 2, 3]) - self.failUnless(s1 - s2 == e) - - def testDifference2(self): - s1 = S([1, 2, 3]) - s2 = S([]) - e = S([1, 2, 3]) - self.failUnless(s1 - s2 == e) - - def testDifference3(self): - s1 = S([1, 2, 3]) - s2 = S([3, 2]) - e = S([1]) - self.failUnless(s1 - s2 == e) - - def testDifference4(self): - s1 = S([1, 2, 3]) - s2 = S([3, 2, 1]) - e = S([]) - self.failUnless(s1 - s2 == e) - - def testSubset1(self): - s1 = S([1, 2, 3]) - s2 = S([3, 2, 1]) - self.failUnless(s1.issubset(s2)) - - def testSubset2(self): - s1 = S([1, 2, 3]) - self.failUnless(s1.issubset(s1)) - - def testSubset3(self): - s1 = S([]) - s2 = S([1, 2, 3]) - self.failUnless(s1.issubset(s2)) - - def testSubset4(self): - s1 = S([1]) - s2 = S([1, 2, 3]) - self.failUnless(s1.issubset(s2)) - - def testSubset5(self): - s1 = S([]) - s2 = S([]) - self.failUnless(s1.issubset(s2)) - - def testSubset6(self): - s1 = S([1, 4]) - s2 = S([1, 2, 3]) - self.failUnless(not s1.issubset(s2)) - - def testSuperset1(self): - s1 = S([1, 2, 3]) - s2 = S([3, 2, 1]) - self.failUnless(s1.issuperset(s2)) - - def testSuperset2(self): - s1 = S([1, 2, 3]) - self.failUnless(s1.issuperset(s1)) - - def testSuperset3(self): - s1 = S([1, 2, 3]) - s2 = S([]) - self.failUnless(s1.issuperset(s2)) - - def testSuperset4(self): - s1 = S([1, 2, 3]) - s2 = S([1]) - self.failUnless(s1.issuperset(s2)) - - def testSuperset5(self): - s1 = S([]) - s2 = S([]) - self.failUnless(s1.issuperset(s2)) - - def testSuperset6(self): - s1 = S([1, 2, 3]) - s2 = S([1, 4]) - self.failUnless(not s1.issuperset(s2)) - - def testUpdate1(self): - s1 = S([1, 2, 3]) - u = (4, 5, 6) - e = S([1, 2, 3, 4, 5, 6]) - s1.update(u) - self.failUnless(s1 == e) - - def testUpdate2(self): - s1 = S([1, 2, 3]) - u = [] - e = S([1, 2, 3]) - s1.update(u) - self.failUnless(s1 == e) - - def testGetitem(self): - s1 = S([1, 2, 3]) - i0 = s1[0] - i1 = s1[1] - i2 = s1[2] - s2 = S([i0, i1, i2]) - self.failUnless(s1 == s2) - - def testGetslice(self): - s1 = S([1, 2, 3]) - slice = s1[0:2] - self.failUnless(len(slice) == 2) - item = s1[2] - slice.append(item) - s2 = S(slice) - self.failUnless(s1 == s2) - - def testDelitem(self): - s1 = S([1, 2, 3]) - del s1[0] - i1 = s1[0] - i2 = s1[1] - self.failUnless(i1 != i2) - self.failUnless(i1 == 1 or i1 == 2 or i1 == 3) - self.failUnless(i2 == 1 or i2 == 2 or i2 == 3) - - def testDelslice(self): - s1 = S([1, 2, 3]) - del s1[0:2] - i1 = s1[0] - self.failUnless(i1 == 1 or i1 == 2 or i1 == 3) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/test_bugs.py dnspython-1.12.0/tests/test_bugs.py --- dnspython-1.11.1/tests/test_bugs.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_bugs.py 2014-06-18 23:01:42.000000000 +0000 @@ -0,0 +1,56 @@ +# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.rdata +import dns.rdataclass +import dns.rdatatype +import dns.ttl + +class BugsTestCase(unittest.TestCase): + + def test_float_LOC(self): + rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.LOC, + "30 30 0.000 N 100 30 0.000 W 10.00m 20m 2000m 20m") + self.failUnless(rdata.float_latitude == 30.5) + self.failUnless(rdata.float_longitude == -100.5) + + def test_SOA_BIND8_TTL(self): + rdata1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + "a b 100 1s 1m 1h 1d") + rdata2 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + "a b 100 1 60 3600 86400") + self.failUnless(rdata1 == rdata2) + + def test_TTL_bounds_check(self): + def bad(): + ttl = dns.ttl.from_text("2147483648") + self.failUnlessRaises(dns.ttl.BadTTL, bad) + + def test_empty_NSEC3_window(self): + rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NSEC3, + "1 0 100 ABCD SCBCQHKU35969L2A68P3AD59LHF30715") + self.failUnless(rdata.windows == []) + + def test_zero_size_APL(self): + rdata = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.APL, + "") + rdata2 = dns.rdata.from_wire(dns.rdataclass.IN, dns.rdatatype.APL, + "", 0, 0) + self.failUnless(rdata == rdata2) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_dnssec.py dnspython-1.12.0/tests/test_dnssec.py --- dnspython-1.11.1/tests/test_dnssec.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_dnssec.py 2014-05-31 18:01:12.000000000 +0000 @@ -0,0 +1,233 @@ +# Copyright (C) 2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.dnssec +import dns.name +import dns.rdata +import dns.rdataclass +import dns.rdatatype +import dns.rrset + +abs_dnspython_org = dns.name.from_text('dnspython.org') + +abs_keys = { abs_dnspython_org : + dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'DNSKEY', + '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', + '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') + } + +abs_keys_duplicate_keytag = { abs_dnspython_org : + dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'DNSKEY', + '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', + '256 3 5 AwEAAdSSg++++THIS/IS/NOT/THE/CORRECT/KEY++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ AaOSydAF', + '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') + } + +rel_keys = { dns.name.empty : + dns.rrset.from_text('@', 3600, 'IN', 'DNSKEY', + '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=', + '256 3 5 AwEAAdSSghOGjU33IQZgwZM2Hh771VGXX05olJK49FxpSyuEAjDBXY58 LGU9R2Zgeecnk/b9EAhFu/vCV9oECtiTCvwuVAkt9YEweqYDluQInmgP NGMJCKdSLlnX93DkjDw8rMYv5dqXCuSGPlKChfTJOLQxIAxGloS7lL+c 0CTZydAF') + } + +when = 1290250287 + +abs_soa = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'SOA', + 'howl.dnspython.org. hostmaster.dnspython.org. 2010020047 3600 1800 604800 3600') + +abs_other_soa = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'SOA', + 'foo.dnspython.org. hostmaster.dnspython.org. 2010020047 3600 1800 604800 3600') + +abs_soa_rrsig = dns.rrset.from_text('dnspython.org.', 3600, 'IN', 'RRSIG', + 'SOA 5 2 3600 20101127004331 20101119213831 61695 dnspython.org. sDUlltRlFTQw5ITFxOXW3TgmrHeMeNpdqcZ4EXxM9FHhIlte6V9YCnDw t6dvM9jAXdIEi03l9H/RAd9xNNW6gvGMHsBGzpvvqFQxIBR2PoiZA1mX /SWHZFdbt4xjYTtXqpyYvrMK0Dt7bUYPadyhPFCJ1B+I8Zi7B5WJEOd0 8vs=') + +rel_soa = dns.rrset.from_text('@', 3600, 'IN', 'SOA', + 'howl hostmaster 2010020047 3600 1800 604800 3600') + +rel_other_soa = dns.rrset.from_text('@', 3600, 'IN', 'SOA', + 'foo hostmaster 2010020047 3600 1800 604800 3600') + +rel_soa_rrsig = dns.rrset.from_text('@', 3600, 'IN', 'RRSIG', + 'SOA 5 2 3600 20101127004331 20101119213831 61695 @ sDUlltRlFTQw5ITFxOXW3TgmrHeMeNpdqcZ4EXxM9FHhIlte6V9YCnDw t6dvM9jAXdIEi03l9H/RAd9xNNW6gvGMHsBGzpvvqFQxIBR2PoiZA1mX /SWHZFdbt4xjYTtXqpyYvrMK0Dt7bUYPadyhPFCJ1B+I8Zi7B5WJEOd0 8vs=') + +sep_key = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DNSKEY, + '257 3 5 AwEAAenVTr9L1OMlL1/N2ta0Qj9LLLnnmFWIr1dJoAsWM9BQfsbV7kFZ XbAkER/FY9Ji2o7cELxBwAsVBuWn6IUUAJXLH74YbC1anY0lifjgt29z SwDzuB7zmC7yVYZzUunBulVW4zT0tg1aePbpVL2EtTL8VzREqbJbE25R KuQYHZtFwG8S4iBxJUmT2Bbd0921LLxSQgVoFXlQx/gFV2+UERXcJ5ce iX6A6wc02M/pdg/YbJd2rBa0MYL3/Fz/Xltre0tqsImZGxzi6YtYDs45 NC8gH+44egz82e2DATCVM1ICPmRDjXYTLldQiWA2ZXIWnK0iitl5ue24 7EsWJefrIhE=') + +good_ds = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, + '57349 5 2 53A79A3E7488AB44FFC56B2D1109F0699D1796DD977E72108B841F96 E47D7013') + +when2 = 1290425644 + +abs_example = dns.name.from_text('example') + +abs_dsa_keys = { abs_example : + dns.rrset.from_text('example.', 86400, 'IN', 'DNSKEY', + '257 3 3 CI3nCqyJsiCJHTjrNsJOT4RaszetzcJPYuoH3F9ZTVt3KJXncCVR3bwn 1w0iavKljb9hDlAYSfHbFCp4ic/rvg4p1L8vh5s8ToMjqDNl40A0hUGQ Ybx5hsECyK+qHoajilUX1phYSAD8d9WAGO3fDWzUPBuzR7o85NiZCDxz yXuNVfni0uhj9n1KYhEO5yAbbruDGN89wIZcxMKuQsdUY2GYD93ssnBv a55W6XRABYWayKZ90WkRVODLVYLSn53Pj/wwxGH+XdhIAZJXimrZL4yl My7rtBsLMqq8Ihs4Tows7LqYwY7cp6y/50tw6pj8tFqMYcPUjKZV36l1 M/2t5BVg3i7IK61Aidt6aoC3TDJtzAxg3ZxfjZWJfhHjMJqzQIfbW5b9 q1mjFsW5EUv39RaNnX+3JWPRLyDqD4pIwDyqfutMsdk/Py3paHn82FGp CaOg+nicqZ9TiMZURN/XXy5JoXUNQ3RNvbHCUiPUe18KUkY6mTfnyHld 1l9YCWmzXQVClkx/hOYxjJ4j8Ife58+Obu5X', + '256 3 3 CJE1yb9YRQiw5d2xZrMUMR+cGCTt1bp1KDCefmYKmS+Z1+q9f42ETVhx JRiQwXclYwmxborzIkSZegTNYIV6mrYwbNB27Q44c3UGcspb3PiOw5TC jNPRYEcdwGvDZ2wWy+vkSV/S9tHXY8O6ODiE6abZJDDg/RnITyi+eoDL R3KZ5n/V1f1T1b90rrV6EewhBGQJpQGDogaXb2oHww9Tm6NfXyo7SoMM pbwbzOckXv+GxRPJIQNSF4D4A9E8XCksuzVVdE/0lr37+uoiAiPia38U 5W2QWe/FJAEPLjIp2eTzf0TrADc1pKP1wrA2ASpdzpm/aX3IB5RPp8Ew S9U72eBFZJAUwg635HxJVxH1maG6atzorR566E+e0OZSaxXS9o1o6QqN 3oPlYLGPORDiExilKfez3C/x/yioOupW9K5eKF0gmtaqrHX0oq9s67f/ RIM2xVaKHgG9Vf2cgJIZkhv7sntujr+E4htnRmy9P9BxyFxsItYxPI6Z bzygHAZpGhlI/7ltEGlIwKxyTK3ZKBm67q7B') + } + +abs_dsa_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 2 10800 3600 604800 86400') + +abs_other_dsa_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 2 10800 3600 604800 86401') + +abs_dsa_soa_rrsig = dns.rrset.from_text('example.', 86400, 'IN', 'RRSIG', + 'SOA 3 1 86400 20101129143231 20101122112731 42088 example. CGul9SuBofsktunV8cJs4eRs6u+3NCS3yaPKvBbD+pB2C76OUXDZq9U=') + +example_sep_key = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DNSKEY, + '257 3 3 CI3nCqyJsiCJHTjrNsJOT4RaszetzcJPYuoH3F9ZTVt3KJXncCVR3bwn 1w0iavKljb9hDlAYSfHbFCp4ic/rvg4p1L8vh5s8ToMjqDNl40A0hUGQ Ybx5hsECyK+qHoajilUX1phYSAD8d9WAGO3fDWzUPBuzR7o85NiZCDxz yXuNVfni0uhj9n1KYhEO5yAbbruDGN89wIZcxMKuQsdUY2GYD93ssnBv a55W6XRABYWayKZ90WkRVODLVYLSn53Pj/wwxGH+XdhIAZJXimrZL4yl My7rtBsLMqq8Ihs4Tows7LqYwY7cp6y/50tw6pj8tFqMYcPUjKZV36l1 M/2t5BVg3i7IK61Aidt6aoC3TDJtzAxg3ZxfjZWJfhHjMJqzQIfbW5b9 q1mjFsW5EUv39RaNnX+3JWPRLyDqD4pIwDyqfutMsdk/Py3paHn82FGp CaOg+nicqZ9TiMZURN/XXy5JoXUNQ3RNvbHCUiPUe18KUkY6mTfnyHld 1l9YCWmzXQVClkx/hOYxjJ4j8Ife58+Obu5X') + +example_ds_sha1 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, + '18673 3 1 71b71d4f3e11bbd71b4eff12cde69f7f9215bbe7') + +example_ds_sha256 = dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.DS, + '18673 3 2 eb8344cbbf07c9d3d3d6c81d10c76653e28d8611a65e639ef8f716e4e4e5d913') + +when3 = 1379801800 + +abs_ecdsa256_keys = { abs_example : + dns.rrset.from_text('example.', 86400, 'IN', 'DNSKEY', + "256 3 13 +3ss1sCpdARVA61DJigEsL/8quo2a8MszKtn2gkkfxgzFs8S2UHtpb4N fY+XFmNW+JK6MsCkI3jHYN8eEQUgMw==", + "257 3 13 eJCEVH7AS3wnoaQpaNlAXH0W8wxymtT9P6P3qjN2ZCV641ED8pF7wZ5V yWfOpgTs6oaZevbJgehl/GaRPUgVyQ==") + } + +abs_ecdsa256_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 4 10800 3600 604800 86400') + +abs_other_ecdsa256_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 2 10800 3600 604800 86401') + +abs_ecdsa256_soa_rrsig = dns.rrset.from_text('example.', 86400, 'IN', 'RRSIG', + "SOA 13 1 86400 20130921221753 20130921221638 7460 example. Sm09SOGz1ULB5D/duwdE2Zpn8bWbVBM77H6N1wPkc42LevvVO+kZEjpq 2nq4GOMJcih52667GIAbMrwmU5P2MQ==") + +when4 = 1379804850 + +abs_ecdsa384_keys = { abs_example : + dns.rrset.from_text('example.', 86400, 'IN', 'DNSKEY', + "256 3 14 1bG8qWviKNXQX3BIuG6/T5jrP1FISiLW/8qGF6BsM9DQtWYhhZUA3Owr OAEiyHAhQwjkN2kTvWiAYoPN80Ii+5ff9/atzY4F9W50P4l75Dj9PYrL HN/hLUgWMNVc9pvA", + "257 3 14 mSub2n0KRt6u2FaD5XJ3oQu0R4XvB/9vUJcyW6+oo0y+KzfQeTdkf1ro ZMVKoyWXW9zUKBYGJpMUIdbAxzrYi7f5HyZ3yDpBFz1hw9+o3CX+gtgb +RyhHfJDwwFXBid9") + } + +abs_ecdsa384_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 2 10800 3600 604800 86400') + +abs_other_ecdsa384_soa = dns.rrset.from_text('example.', 86400, 'IN', 'SOA', + 'ns1.example. hostmaster.example. 2 10800 3600 604800 86401') + +abs_ecdsa384_soa_rrsig = dns.rrset.from_text('example.', 86400, 'IN', 'RRSIG', + "SOA 14 1 86400 20130929021229 20130921230729 63571 example. CrnCu34EeeRz0fEhL9PLlwjpBKGYW8QjBjFQTwd+ViVLRAS8tNkcDwQE NhSV89NEjj7ze1a/JcCfcJ+/mZgnvH4NHLNg3Tf6KuLZsgs2I4kKQXEk 37oIHravPEOlGYNI") + +class DNSSECValidatorTestCase(unittest.TestCase): + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testAbsoluteRSAGood(self): + dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys, None, when) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testDuplicateKeytag(self): + dns.dnssec.validate(abs_soa, abs_soa_rrsig, abs_keys_duplicate_keytag, None, when) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testAbsoluteRSABad(self): + def bad(): + dns.dnssec.validate(abs_other_soa, abs_soa_rrsig, abs_keys, None, + when) + self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testRelativeRSAGood(self): + dns.dnssec.validate(rel_soa, rel_soa_rrsig, rel_keys, + abs_dnspython_org, when) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testRelativeRSABad(self): + def bad(): + dns.dnssec.validate(rel_other_soa, rel_soa_rrsig, rel_keys, + abs_dnspython_org, when) + self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) + + def testMakeSHA256DS(self): + ds = dns.dnssec.make_ds(abs_dnspython_org, sep_key, 'SHA256') + self.failUnless(ds == good_ds) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testAbsoluteDSAGood(self): + dns.dnssec.validate(abs_dsa_soa, abs_dsa_soa_rrsig, abs_dsa_keys, None, + when2) + + @unittest.skipIf(not dns.dnssec._have_pycrypto, + "PyCrypto cannot be imported") + def testAbsoluteDSABad(self): + def bad(): + dns.dnssec.validate(abs_other_dsa_soa, abs_dsa_soa_rrsig, + abs_dsa_keys, None, when2) + self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) + + def testMakeExampleSHA1DS(self): + ds = dns.dnssec.make_ds(abs_example, example_sep_key, 'SHA1') + self.failUnless(ds == example_ds_sha1) + + def testMakeExampleSHA256DS(self): + ds = dns.dnssec.make_ds(abs_example, example_sep_key, 'SHA256') + self.failUnless(ds == example_ds_sha256) + + @unittest.skipIf(not dns.dnssec._have_ecdsa, + "python ECDSA cannot be imported") + def testAbsoluteECDSA256Good(self): + dns.dnssec.validate(abs_ecdsa256_soa, abs_ecdsa256_soa_rrsig, + abs_ecdsa256_keys, None, when3) + + @unittest.skipIf(not dns.dnssec._have_ecdsa, + "python ECDSA cannot be imported") + def testAbsoluteECDSA256Bad(self): + def bad(): + dns.dnssec.validate(abs_other_ecdsa256_soa, abs_ecdsa256_soa_rrsig, + abs_ecdsa256_keys, None, when3) + self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) + + @unittest.skipIf(not dns.dnssec._have_ecdsa, + "python ECDSA can not be imported") + def testAbsoluteECDSA384Good(self): + dns.dnssec.validate(abs_ecdsa384_soa, abs_ecdsa384_soa_rrsig, + abs_ecdsa384_keys, None, when4) + + @unittest.skipIf(not dns.dnssec._have_ecdsa, + "python ECDSA can not be imported") + def testAbsoluteECDSA384Bad(self): + def bad(): + dns.dnssec.validate(abs_other_ecdsa384_soa, abs_ecdsa384_soa_rrsig, + abs_ecdsa384_keys, None, when4) + self.failUnlessRaises(dns.dnssec.ValidationFailure, bad) + + +if __name__ == '__main__': + import_ok = False + try: + import Crypto.Util.number + import_ok = True + except: + pass + if import_ok: + unittest.main() + else: + print 'skipping DNSSEC tests because pycrypto is not installed' diff -Nru dnspython-1.11.1/tests/test_flags.py dnspython-1.12.0/tests/test_flags.py --- dnspython-1.11.1/tests/test_flags.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_flags.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,59 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.flags +import dns.rcode +import dns.opcode + +class FlagsTestCase(unittest.TestCase): + + def test_rcode1(self): + self.failUnless(dns.rcode.from_text('FORMERR') == dns.rcode.FORMERR) + + def test_rcode2(self): + self.failUnless(dns.rcode.to_text(dns.rcode.FORMERR) == "FORMERR") + + def test_rcode3(self): + self.failUnless(dns.rcode.to_flags(dns.rcode.FORMERR) == (1, 0)) + + def test_rcode4(self): + self.failUnless(dns.rcode.to_flags(dns.rcode.BADVERS) == \ + (0, 0x01000000)) + + def test_rcode6(self): + self.failUnless(dns.rcode.from_flags(0, 0x01000000) == \ + dns.rcode.BADVERS) + + def test_rcode6(self): + self.failUnless(dns.rcode.from_flags(5, 0) == dns.rcode.REFUSED) + + def test_rcode7(self): + def bad(): + dns.rcode.to_flags(4096) + self.failUnlessRaises(ValueError, bad) + + def test_flags1(self): + self.failUnless(dns.flags.from_text("RA RD AA QR") == \ + dns.flags.QR|dns.flags.AA|dns.flags.RD|dns.flags.RA) + + def test_flags2(self): + flags = dns.flags.QR|dns.flags.AA|dns.flags.RD|dns.flags.RA + self.failUnless(dns.flags.to_text(flags) == "QR AA RD RA") + + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_generate.py dnspython-1.12.0/tests/test_generate.py --- dnspython-1.11.1/tests/test_generate.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_generate.py 2013-03-31 10:57:45.000000000 +0000 @@ -0,0 +1,499 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import sys +sys.path.insert(0, '../') # Force the local project to be *the* dns + +import cStringIO +import filecmp +import os +import unittest + +import dns.exception +import dns.rdata +import dns.rdataclass +import dns.rdatatype +import dns.rrset +import dns.zone + +import pprint + +pp = pprint.PrettyPrinter(indent=2) + +import pdb +example_text = """$TTL 1h +$ORIGIN 0.0.192.IN-ADDR.ARPA. +$GENERATE 1-2 0 CNAME SERVER$.EXAMPLE. +""" + +example_text1 = """$TTL 1h +$ORIGIN 0.0.192.IN-ADDR.ARPA. +$GENERATE 1-10 fooo$ CNAME $.0 +""" + +example_text2 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 3-5 foo$ A 10.0.0.$ +""" + +example_text3 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 4-8/2 foo$ A 10.0.0.$ +""" + +example_text4 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-13 wp-db${-10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. +""" + +example_text5 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-13 wp-db${10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. +""" + +example_text6 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-13 wp-db${+10,2,d}.services.mozilla.com 0 CNAME SERVER.FOOBAR. +""" + +example_text7 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-13 sync${-10}.db IN A 10.10.16.0 +""" + +example_text8 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-12 wp-db${-10,2,d} IN A 10.10.16.0 +""" + +example_text9 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 11-12 wp-db${-10,2,d} IN A 10.10.16.0 +$GENERATE 11-13 sync${-10}.db IN A 10.10.16.0 +""" +example_text10 = """$TTL 1h +@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +$GENERATE 27-28 $.2 PTR zlb${-26}.oob +""" + + +class GenerateTestCase(unittest.TestCase): + + def testFromText(self): + def bad(): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + self.failUnlessRaises(dns.zone.NoSOA, bad) + + def testFromText1(self): + def bad(): + z = dns.zone.from_text(example_text1, 'example.', relativize=True) + self.failUnlessRaises(dns.zone.NoSOA, bad) + + def testIterateAllRdatas2(self): + z = dns.zone.from_text(example_text2, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + (dns.name.from_text('foo3', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.3')), + (dns.name.from_text('foo4', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.4')), + (dns.name.from_text('foo5', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.5'))] + + exl.sort() + self.failUnless(l == exl) + + def testIterateAllRdatas3(self): + z = dns.zone.from_text(example_text3, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + (dns.name.from_text('foo4', None), 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.4')), + (dns.name.from_text('foo6', None), 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.6')), + (dns.name.from_text('foo8', None), 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.8'))] + exl.sort() + self.failUnless(l == exl) + def testGenerate1(self): + z = dns.zone.from_text(example_text4, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + + (dns.name.from_text('wp-db01.services.mozilla.com', None), + 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db02.services.mozilla.com', None), + 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db03.services.mozilla.com', None), + 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.'))] + exl.sort() + self.failUnless(l == exl) + + def testGenerate2(self): + z = dns.zone.from_text(example_text5, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + + (dns.name.from_text('wp-db21.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db22.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db23.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.'))] + exl.sort() + self.failUnless(l == exl) + + def testGenerate3(self): + z = dns.zone.from_text(example_text6, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + (dns.name.from_text('wp-db21.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db22.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.')), + + (dns.name.from_text('wp-db23.services.mozilla.com', None), 0L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.CNAME, + 'SERVER.FOOBAR.'))] + exl.sort() + self.failUnless(l == exl) + + def testGenerate4(self): + z = dns.zone.from_text(example_text7, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + + (dns.name.from_text('sync1.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + + (dns.name.from_text('sync2.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + + (dns.name.from_text('sync3.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0'))] + exl.sort() + self.failUnless(l == exl) + + def testGenerate6(self): + z = dns.zone.from_text(example_text9, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + + (dns.name.from_text('wp-db01', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + (dns.name.from_text('wp-db02', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + + (dns.name.from_text('sync1.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + + (dns.name.from_text('sync2.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0')), + + (dns.name.from_text('sync3.db', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.10.16.0'))] + exl.sort() + self.failUnless(l == exl) + + def testGenerate7(self): + z = dns.zone.from_text(example_text10, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2')), + + (dns.name.from_text('27.2', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR, + 'zlb1.oob')), + + (dns.name.from_text('28.2', None), 3600L, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.PTR, + 'zlb2.oob'))] + + exl.sort() + self.failUnless(l == exl) + + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_grange.py dnspython-1.12.0/tests/test_grange.py --- dnspython-1.11.1/tests/test_grange.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_grange.py 2013-07-08 10:35:38.000000000 +0000 @@ -0,0 +1,95 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import sys +sys.path.insert(0, '../') + +import cStringIO +import filecmp +import os +import unittest + +import dns +import dns.exception +import dns.grange + +import pdb + + + +class GRangeTestCase(unittest.TestCase): + + def testFromText1(self): + start, stop, step = dns.grange.from_text('1-1') + self.assertEqual(start, 1) + self.assertEqual(stop, 1) + self.assertEqual(step, 1) + + def testFromText2(self): + start, stop, step = dns.grange.from_text('1-4') + self.assertEqual(start, 1) + self.assertEqual(stop, 4) + self.assertEqual(step, 1) + + def testFromText3(self): + start, stop, step = dns.grange.from_text('4-255') + self.assertEqual(start, 4) + self.assertEqual(stop, 255) + self.assertEqual(step, 1) + + def testFromText4(self): + start, stop, step = dns.grange.from_text('1-1/1') + self.assertEqual(start, 1) + self.assertEqual(stop, 1) + self.assertEqual(step, 1) + + def testFromText5(self): + start, stop, step = dns.grange.from_text('1-4/2') + self.assertEqual(start, 1) + self.assertEqual(stop, 4) + self.assertEqual(step, 2) + + def testFromText6(self): + start, stop, step = dns.grange.from_text('4-255/77') + self.assertEqual(start, 4) + self.assertEqual(stop, 255) + self.assertEqual(step, 77) + + def testFailFromText1(self): + def bad(): + start = 2 + stop = 1 + step = 1 + dns.grange.from_text('%d-%d/%d' % (start, stop, step)) + self.assertRaises(AssertionError, bad) + + def testFailFromText2(self): + def bad(): + start = '-1' + stop = 3 + step = 1 + dns.grange.from_text('%s-%d/%d' % (start, stop, step)) + self.assertRaises(dns.exception.SyntaxError, bad) + + def testFailFromText2(self): + def bad(): + start = 1 + stop = 4 + step = '-2' + dns.grange.from_text('%d-%d/%s' % (start, stop, step)) + self.assertRaises(dns.exception.SyntaxError, bad) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_message.py dnspython-1.12.0/tests/test_message.py --- dnspython-1.11.1/tests/test_message.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_message.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,179 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import cStringIO +import os +import unittest + +import dns.exception +import dns.message + +query_text = """id 1234 +opcode QUERY +rcode NOERROR +flags RD +edns 0 +eflags DO +payload 4096 +;QUESTION +wwww.dnspython.org. IN A +;ANSWER +;AUTHORITY +;ADDITIONAL""" + +goodhex = '04d201000001000000000001047777777709646e73707974686f6e' \ + '036f726700000100010000291000000080000000' + +goodwire = goodhex.decode('hex_codec') + +answer_text = """id 1234 +opcode QUERY +rcode NOERROR +flags QR AA RD +;QUESTION +dnspython.org. IN SOA +;ANSWER +dnspython.org. 3600 IN SOA woof.dnspython.org. hostmaster.dnspython.org. 2003052700 3600 1800 604800 3600 +;AUTHORITY +dnspython.org. 3600 IN NS ns1.staff.nominum.org. +dnspython.org. 3600 IN NS ns2.staff.nominum.org. +dnspython.org. 3600 IN NS woof.play-bow.org. +;ADDITIONAL +woof.play-bow.org. 3600 IN A 204.152.186.150 +""" + +goodhex2 = '04d2 8500 0001 0001 0003 0001' \ + '09646e73707974686f6e036f726700 0006 0001' \ + 'c00c 0006 0001 00000e10 0028 ' \ + '04776f6f66c00c 0a686f73746d6173746572c00c' \ + '7764289c 00000e10 00000708 00093a80 00000e10' \ + 'c00c 0002 0001 00000e10 0014' \ + '036e7331057374616666076e6f6d696e756dc016' \ + 'c00c 0002 0001 00000e10 0006 036e7332c063' \ + 'c00c 0002 0001 00000e10 0010 04776f6f6608706c61792d626f77c016' \ + 'c091 0001 0001 00000e10 0004 cc98ba96' + + +goodwire2 = goodhex2.replace(' ', '').decode('hex_codec') + +query_text_2 = """id 1234 +opcode QUERY +rcode 4095 +flags RD +edns 0 +eflags DO +payload 4096 +;QUESTION +wwww.dnspython.org. IN A +;ANSWER +;AUTHORITY +;ADDITIONAL""" + +goodhex3 = '04d2010f0001000000000001047777777709646e73707974686f6e' \ + '036f726700000100010000291000ff0080000000' + +goodwire3 = goodhex3.decode('hex_codec') + +class MessageTestCase(unittest.TestCase): + + def test_comparison_eq1(self): + q1 = dns.message.from_text(query_text) + q2 = dns.message.from_text(query_text) + self.failUnless(q1 == q2) + + def test_comparison_ne1(self): + q1 = dns.message.from_text(query_text) + q2 = dns.message.from_text(query_text) + q2.id = 10 + self.failUnless(q1 != q2) + + def test_comparison_ne2(self): + q1 = dns.message.from_text(query_text) + q2 = dns.message.from_text(query_text) + q2.question = [] + self.failUnless(q1 != q2) + + def test_comparison_ne3(self): + q1 = dns.message.from_text(query_text) + self.failUnless(q1 != 1) + + def test_EDNS_to_wire1(self): + q = dns.message.from_text(query_text) + w = q.to_wire() + self.failUnless(w == goodwire) + + def test_EDNS_from_wire1(self): + m = dns.message.from_wire(goodwire) + self.failUnless(str(m) == query_text) + + def test_EDNS_to_wire2(self): + q = dns.message.from_text(query_text_2) + w = q.to_wire() + self.failUnless(w == goodwire3) + + def test_EDNS_from_wire2(self): + m = dns.message.from_wire(goodwire3) + self.failUnless(str(m) == query_text_2) + + def test_TooBig(self): + def bad(): + q = dns.message.from_text(query_text) + for i in xrange(0, 25): + rrset = dns.rrset.from_text('foo%d.' % i, 3600, + dns.rdataclass.IN, + dns.rdatatype.A, + '10.0.0.%d' % i) + q.additional.append(rrset) + w = q.to_wire(max_size=512) + self.failUnlessRaises(dns.exception.TooBig, bad) + + def test_answer1(self): + a = dns.message.from_text(answer_text) + wire = a.to_wire(want_shuffle=False) + self.failUnless(wire == goodwire2) + + def test_TrailingJunk(self): + def bad(): + badwire = goodwire + '\x00' + m = dns.message.from_wire(badwire) + self.failUnlessRaises(dns.message.TrailingJunk, bad) + + def test_ShortHeader(self): + def bad(): + badwire = '\x00' * 11 + m = dns.message.from_wire(badwire) + self.failUnlessRaises(dns.message.ShortHeader, bad) + + def test_RespondingToResponse(self): + def bad(): + q = dns.message.make_query('foo', 'A') + r1 = dns.message.make_response(q) + r2 = dns.message.make_response(r1) + self.failUnlessRaises(dns.exception.FormError, bad) + + def test_ExtendedRcodeSetting(self): + m = dns.message.make_query('foo', 'A') + m.set_rcode(4095) + self.failUnless(m.rcode() == 4095) + m.set_rcode(2) + self.failUnless(m.rcode() == 2) + + def test_EDNSVersionCoherence(self): + m = dns.message.make_query('foo', 'A') + m.use_edns(1) + self.failUnless((m.ednsflags >> 16) & 0xFF == 1) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_namedict.py dnspython-1.12.0/tests/test_namedict.py --- dnspython-1.11.1/tests/test_namedict.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_namedict.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,102 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.name +import dns.namedict + +class NameTestCase(unittest.TestCase): + + def setUp(self): + self.ndict = dns.namedict.NameDict() + n1 = dns.name.from_text('foo.bar.') + n2 = dns.name.from_text('bar.') + self.ndict[n1] = 1 + self.ndict[n2] = 2 + self.rndict = dns.namedict.NameDict() + n1 = dns.name.from_text('foo.bar', None) + n2 = dns.name.from_text('bar', None) + self.rndict[n1] = 1 + self.rndict[n2] = 2 + + def testDepth(self): + self.failUnless(self.ndict.max_depth == 3) + + def testLookup1(self): + k = dns.name.from_text('foo.bar.') + self.failUnless(self.ndict[k] == 1) + + def testLookup2(self): + k = dns.name.from_text('foo.bar.') + self.failUnless(self.ndict.get_deepest_match(k)[1] == 1) + + def testLookup3(self): + k = dns.name.from_text('a.b.c.foo.bar.') + self.failUnless(self.ndict.get_deepest_match(k)[1] == 1) + + def testLookup4(self): + k = dns.name.from_text('a.b.c.bar.') + self.failUnless(self.ndict.get_deepest_match(k)[1] == 2) + + def testLookup5(self): + def bad(): + n = dns.name.from_text('a.b.c.') + (k, v) = self.ndict.get_deepest_match(n) + self.failUnlessRaises(KeyError, bad) + + def testLookup6(self): + def bad(): + (k, v) = self.ndict.get_deepest_match(dns.name.empty) + self.failUnlessRaises(KeyError, bad) + + def testLookup7(self): + self.ndict[dns.name.empty] = 100 + n = dns.name.from_text('a.b.c.') + (k, v) = self.ndict.get_deepest_match(n) + self.failUnless(v == 100) + + def testLookup8(self): + def bad(): + self.ndict['foo'] = 100 + self.failUnlessRaises(ValueError, bad) + + def testRelDepth(self): + self.failUnless(self.rndict.max_depth == 2) + + def testRelLookup1(self): + k = dns.name.from_text('foo.bar', None) + self.failUnless(self.rndict[k] == 1) + + def testRelLookup2(self): + k = dns.name.from_text('foo.bar', None) + self.failUnless(self.rndict.get_deepest_match(k)[1] == 1) + + def testRelLookup3(self): + k = dns.name.from_text('a.b.c.foo.bar', None) + self.failUnless(self.rndict.get_deepest_match(k)[1] == 1) + + def testRelLookup4(self): + k = dns.name.from_text('a.b.c.bar', None) + self.failUnless(self.rndict.get_deepest_match(k)[1] == 2) + + def testRelLookup7(self): + self.rndict[dns.name.empty] = 100 + n = dns.name.from_text('a.b.c', None) + (k, v) = self.rndict.get_deepest_match(n) + self.failUnless(v == 100) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_name.py dnspython-1.12.0/tests/test_name.py --- dnspython-1.11.1/tests/test_name.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_name.py 2014-05-31 18:10:01.000000000 +0000 @@ -0,0 +1,702 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import cStringIO +import socket + +import dns.name +import dns.reversename +import dns.e164 + +class NameTestCase(unittest.TestCase): + def setUp(self): + self.origin = dns.name.from_text('example.') + + def testFromTextRel1(self): + n = dns.name.from_text('foo.bar') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testFromTextRel2(self): + n = dns.name.from_text('foo.bar', origin=self.origin) + self.failUnless(n.labels == ('foo', 'bar', 'example', '')) + + def testFromTextRel3(self): + n = dns.name.from_text('foo.bar', origin=None) + self.failUnless(n.labels == ('foo', 'bar')) + + def testFromTextRel4(self): + n = dns.name.from_text('@', origin=None) + self.failUnless(n == dns.name.empty) + + def testFromTextRel5(self): + n = dns.name.from_text('@', origin=self.origin) + self.failUnless(n == self.origin) + + def testFromTextAbs1(self): + n = dns.name.from_text('foo.bar.') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testTortureFromText(self): + good = [ + r'.', + r'a', + r'a.', + r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + r'\000.\008.\010.\032.\046.\092.\099.\255', + r'\\', + r'\..\.', + r'\\.\\', + r'!"#%&/()=+-', + r'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255', + ] + bad = [ + r'..', + r'.a', + r'\\..', + '\\', # yes, we don't want the 'r' prefix! + r'\0', + r'\00', + r'\00Z', + r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + r'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', + r'\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255.\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255', + ] + for t in good: + try: + n = dns.name.from_text(t) + except: + self.fail("good test '%s' raised an exception" % t) + for t in bad: + caught = False + try: + n = dns.name.from_text(t) + except: + caught = True + if not caught: + self.fail("bad test '%s' did not raise an exception" % t) + + def testImmutable1(self): + def bad(): + self.origin.labels = () + self.failUnlessRaises(TypeError, bad) + + def testImmutable2(self): + def bad(): + self.origin.labels[0] = 'foo' + self.failUnlessRaises(TypeError, bad) + + def testAbs1(self): + self.failUnless(dns.name.root.is_absolute()) + + def testAbs2(self): + self.failUnless(not dns.name.empty.is_absolute()) + + def testAbs3(self): + self.failUnless(self.origin.is_absolute()) + + def testAbs3(self): + n = dns.name.from_text('foo', origin=None) + self.failUnless(not n.is_absolute()) + + def testWild1(self): + n = dns.name.from_text('*.foo', origin=None) + self.failUnless(n.is_wild()) + + def testWild2(self): + n = dns.name.from_text('*a.foo', origin=None) + self.failUnless(not n.is_wild()) + + def testWild3(self): + n = dns.name.from_text('a.*.foo', origin=None) + self.failUnless(not n.is_wild()) + + def testWild4(self): + self.failUnless(not dns.name.root.is_wild()) + + def testWild5(self): + self.failUnless(not dns.name.empty.is_wild()) + + def testHash1(self): + n1 = dns.name.from_text('fOo.COM') + n2 = dns.name.from_text('foo.com') + self.failUnless(hash(n1) == hash(n2)) + + def testCompare1(self): + n1 = dns.name.from_text('a') + n2 = dns.name.from_text('b') + self.failUnless(n1 < n2) + self.failUnless(n2 > n1) + + def testCompare2(self): + n1 = dns.name.from_text('') + n2 = dns.name.from_text('b') + self.failUnless(n1 < n2) + self.failUnless(n2 > n1) + + def testCompare3(self): + self.failUnless(dns.name.empty < dns.name.root) + self.failUnless(dns.name.root > dns.name.empty) + + def testCompare4(self): + self.failUnless(dns.name.root != 1) + + def testCompare5(self): + self.failUnless(dns.name.root < 1 or dns.name.root > 1) + + def testSubdomain1(self): + self.failUnless(not dns.name.empty.is_subdomain(dns.name.root)) + + def testSubdomain2(self): + self.failUnless(not dns.name.root.is_subdomain(dns.name.empty)) + + def testSubdomain3(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(n.is_subdomain(self.origin)) + + def testSubdomain4(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(n.is_subdomain(dns.name.root)) + + def testSubdomain5(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(n.is_subdomain(n)) + + def testSuperdomain1(self): + self.failUnless(not dns.name.empty.is_superdomain(dns.name.root)) + + def testSuperdomain2(self): + self.failUnless(not dns.name.root.is_superdomain(dns.name.empty)) + + def testSuperdomain3(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(self.origin.is_superdomain(n)) + + def testSuperdomain4(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(dns.name.root.is_superdomain(n)) + + def testSuperdomain5(self): + n = dns.name.from_text('foo', origin=self.origin) + self.failUnless(n.is_superdomain(n)) + + def testCanonicalize1(self): + n = dns.name.from_text('FOO.bar', origin=self.origin) + c = n.canonicalize() + self.failUnless(c.labels == ('foo', 'bar', 'example', '')) + + def testToText1(self): + n = dns.name.from_text('FOO.bar', origin=self.origin) + t = n.to_text() + self.failUnless(t == 'FOO.bar.example.') + + def testToText2(self): + n = dns.name.from_text('FOO.bar', origin=self.origin) + t = n.to_text(True) + self.failUnless(t == 'FOO.bar.example') + + def testToText3(self): + n = dns.name.from_text('FOO.bar', origin=None) + t = n.to_text() + self.failUnless(t == 'FOO.bar') + + def testToText4(self): + t = dns.name.empty.to_text() + self.failUnless(t == '@') + + def testToText5(self): + t = dns.name.root.to_text() + self.failUnless(t == '.') + + def testToText6(self): + n = dns.name.from_text('FOO bar', origin=None) + t = n.to_text() + self.failUnless(t == r'FOO\032bar') + + def testToText7(self): + n = dns.name.from_text(r'FOO\.bar', origin=None) + t = n.to_text() + self.failUnless(t == r'FOO\.bar') + + def testToText8(self): + n = dns.name.from_text(r'\070OO\.bar', origin=None) + t = n.to_text() + self.failUnless(t == r'FOO\.bar') + + def testSlice1(self): + n = dns.name.from_text(r'a.b.c.', origin=None) + s = n[:] + self.failUnless(s == ('a', 'b', 'c', '')) + + def testSlice2(self): + n = dns.name.from_text(r'a.b.c.', origin=None) + s = n[:2] + self.failUnless(s == ('a', 'b')) + + def testSlice3(self): + n = dns.name.from_text(r'a.b.c.', origin=None) + s = n[2:] + self.failUnless(s == ('c', '')) + + def testEmptyLabel1(self): + def bad(): + n = dns.name.Name(['a', '', 'b']) + self.failUnlessRaises(dns.name.EmptyLabel, bad) + + def testEmptyLabel2(self): + def bad(): + n = dns.name.Name(['', 'b']) + self.failUnlessRaises(dns.name.EmptyLabel, bad) + + def testEmptyLabel3(self): + n = dns.name.Name(['b', '']) + self.failUnless(n) + + def testLongLabel(self): + n = dns.name.Name(['a' * 63]) + self.failUnless(n) + + def testLabelTooLong(self): + def bad(): + n = dns.name.Name(['a' * 64, 'b']) + self.failUnlessRaises(dns.name.LabelTooLong, bad) + + def testLongName(self): + n = dns.name.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 62]) + self.failUnless(n) + + def testNameTooLong(self): + def bad(): + n = dns.name.Name(['a' * 63, 'a' * 63, 'a' * 63, 'a' * 63]) + self.failUnlessRaises(dns.name.NameTooLong, bad) + + def testConcat1(self): + n1 = dns.name.Name(['a', 'b']) + n2 = dns.name.Name(['c', 'd']) + e = dns.name.Name(['a', 'b', 'c', 'd']) + r = n1 + n2 + self.failUnless(r == e) + + def testConcat2(self): + n1 = dns.name.Name(['a', 'b']) + n2 = dns.name.Name([]) + e = dns.name.Name(['a', 'b']) + r = n1 + n2 + self.failUnless(r == e) + + def testConcat2(self): + n1 = dns.name.Name([]) + n2 = dns.name.Name(['a', 'b']) + e = dns.name.Name(['a', 'b']) + r = n1 + n2 + self.failUnless(r == e) + + def testConcat3(self): + n1 = dns.name.Name(['a', 'b', '']) + n2 = dns.name.Name([]) + e = dns.name.Name(['a', 'b', '']) + r = n1 + n2 + self.failUnless(r == e) + + def testConcat4(self): + n1 = dns.name.Name(['a', 'b']) + n2 = dns.name.Name(['c', '']) + e = dns.name.Name(['a', 'b', 'c', '']) + r = n1 + n2 + self.failUnless(r == e) + + def testConcat5(self): + def bad(): + n1 = dns.name.Name(['a', 'b', '']) + n2 = dns.name.Name(['c']) + r = n1 + n2 + self.failUnlessRaises(dns.name.AbsoluteConcatenation, bad) + + def testBadEscape(self): + def bad(): + n = dns.name.from_text(r'a.b\0q1.c.') + print n + self.failUnlessRaises(dns.name.BadEscape, bad) + + def testDigestable1(self): + n = dns.name.from_text('FOO.bar') + d = n.to_digestable() + self.failUnless(d == '\x03foo\x03bar\x00') + + def testDigestable2(self): + n1 = dns.name.from_text('FOO.bar') + n2 = dns.name.from_text('foo.BAR.') + d1 = n1.to_digestable() + d2 = n2.to_digestable() + self.failUnless(d1 == d2) + + def testDigestable3(self): + d = dns.name.root.to_digestable() + self.failUnless(d == '\x00') + + def testDigestable4(self): + n = dns.name.from_text('FOO.bar', None) + d = n.to_digestable(dns.name.root) + self.failUnless(d == '\x03foo\x03bar\x00') + + def testBadDigestable(self): + def bad(): + n = dns.name.from_text('FOO.bar', None) + d = n.to_digestable() + self.failUnlessRaises(dns.name.NeedAbsoluteNameOrOrigin, bad) + + def testToWire1(self): + n = dns.name.from_text('FOO.bar') + f = cStringIO.StringIO() + compress = {} + n.to_wire(f, compress) + self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00') + + def testToWire2(self): + n = dns.name.from_text('FOO.bar') + f = cStringIO.StringIO() + compress = {} + n.to_wire(f, compress) + n.to_wire(f, compress) + self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\xc0\x00') + + def testToWire3(self): + n1 = dns.name.from_text('FOO.bar') + n2 = dns.name.from_text('foo.bar') + f = cStringIO.StringIO() + compress = {} + n1.to_wire(f, compress) + n2.to_wire(f, compress) + self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\xc0\x00') + + def testToWire4(self): + n1 = dns.name.from_text('FOO.bar') + n2 = dns.name.from_text('a.foo.bar') + f = cStringIO.StringIO() + compress = {} + n1.to_wire(f, compress) + n2.to_wire(f, compress) + self.failUnless(f.getvalue() == '\x03FOO\x03bar\x00\x01\x61\xc0\x00') + + def testToWire5(self): + n1 = dns.name.from_text('FOO.bar') + n2 = dns.name.from_text('a.foo.bar') + f = cStringIO.StringIO() + compress = {} + n1.to_wire(f, compress) + n2.to_wire(f, None) + self.failUnless(f.getvalue() == \ + '\x03FOO\x03bar\x00\x01\x61\x03foo\x03bar\x00') + + def testToWire6(self): + n = dns.name.from_text('FOO.bar') + v = n.to_wire() + self.failUnless(v == '\x03FOO\x03bar\x00') + + def testBadToWire(self): + def bad(): + n = dns.name.from_text('FOO.bar', None) + f = cStringIO.StringIO() + compress = {} + n.to_wire(f, compress) + self.failUnlessRaises(dns.name.NeedAbsoluteNameOrOrigin, bad) + + def testSplit1(self): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(2) + ep = dns.name.from_text('foo', None) + es = dns.name.from_text('bar.', None) + self.failUnless(prefix == ep and suffix == es) + + def testSplit2(self): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(1) + ep = dns.name.from_text('foo.bar', None) + es = dns.name.from_text('.', None) + self.failUnless(prefix == ep and suffix == es) + + def testSplit3(self): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(0) + ep = dns.name.from_text('foo.bar.', None) + es = dns.name.from_text('', None) + self.failUnless(prefix == ep and suffix == es) + + def testSplit4(self): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(3) + ep = dns.name.from_text('', None) + es = dns.name.from_text('foo.bar.', None) + self.failUnless(prefix == ep and suffix == es) + + def testBadSplit1(self): + def bad(): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(-1) + self.failUnlessRaises(ValueError, bad) + + def testBadSplit2(self): + def bad(): + n = dns.name.from_text('foo.bar.') + (prefix, suffix) = n.split(4) + self.failUnlessRaises(ValueError, bad) + + def testRelativize1(self): + n = dns.name.from_text('a.foo.bar.', None) + o = dns.name.from_text('bar.', None) + e = dns.name.from_text('a.foo', None) + self.failUnless(n.relativize(o) == e) + + def testRelativize2(self): + n = dns.name.from_text('a.foo.bar.', None) + o = n + e = dns.name.empty + self.failUnless(n.relativize(o) == e) + + def testRelativize3(self): + n = dns.name.from_text('a.foo.bar.', None) + o = dns.name.from_text('blaz.', None) + e = n + self.failUnless(n.relativize(o) == e) + + def testRelativize4(self): + n = dns.name.from_text('a.foo', None) + o = dns.name.root + e = n + self.failUnless(n.relativize(o) == e) + + def testDerelativize1(self): + n = dns.name.from_text('a.foo', None) + o = dns.name.from_text('bar.', None) + e = dns.name.from_text('a.foo.bar.', None) + self.failUnless(n.derelativize(o) == e) + + def testDerelativize2(self): + n = dns.name.empty + o = dns.name.from_text('a.foo.bar.', None) + e = o + self.failUnless(n.derelativize(o) == e) + + def testDerelativize3(self): + n = dns.name.from_text('a.foo.bar.', None) + o = dns.name.from_text('blaz.', None) + e = n + self.failUnless(n.derelativize(o) == e) + + def testChooseRelativity1(self): + n = dns.name.from_text('a.foo.bar.', None) + o = dns.name.from_text('bar.', None) + e = dns.name.from_text('a.foo', None) + self.failUnless(n.choose_relativity(o, True) == e) + + def testChooseRelativity2(self): + n = dns.name.from_text('a.foo.bar.', None) + o = dns.name.from_text('bar.', None) + e = n + self.failUnless(n.choose_relativity(o, False) == e) + + def testChooseRelativity3(self): + n = dns.name.from_text('a.foo', None) + o = dns.name.from_text('bar.', None) + e = dns.name.from_text('a.foo.bar.', None) + self.failUnless(n.choose_relativity(o, False) == e) + + def testChooseRelativity4(self): + n = dns.name.from_text('a.foo', None) + o = None + e = n + self.failUnless(n.choose_relativity(o, True) == e) + + def testChooseRelativity5(self): + n = dns.name.from_text('a.foo', None) + o = None + e = n + self.failUnless(n.choose_relativity(o, False) == e) + + def testChooseRelativity6(self): + n = dns.name.from_text('a.foo.', None) + o = None + e = n + self.failUnless(n.choose_relativity(o, True) == e) + + def testChooseRelativity7(self): + n = dns.name.from_text('a.foo.', None) + o = None + e = n + self.failUnless(n.choose_relativity(o, False) == e) + + def testFromWire1(self): + w = '\x03foo\x00\xc0\x00' + (n1, cused1) = dns.name.from_wire(w, 0) + (n2, cused2) = dns.name.from_wire(w, cused1) + en1 = dns.name.from_text('foo.') + en2 = en1 + ecused1 = 5 + ecused2 = 2 + self.failUnless(n1 == en1 and cused1 == ecused1 and \ + n2 == en2 and cused2 == ecused2) + + def testFromWire1(self): + w = '\x03foo\x00\x01a\xc0\x00\x01b\xc0\x05' + current = 0 + (n1, cused1) = dns.name.from_wire(w, current) + current += cused1 + (n2, cused2) = dns.name.from_wire(w, current) + current += cused2 + (n3, cused3) = dns.name.from_wire(w, current) + en1 = dns.name.from_text('foo.') + en2 = dns.name.from_text('a.foo.') + en3 = dns.name.from_text('b.a.foo.') + ecused1 = 5 + ecused2 = 4 + ecused3 = 4 + self.failUnless(n1 == en1 and cused1 == ecused1 and \ + n2 == en2 and cused2 == ecused2 and \ + n3 == en3 and cused3 == ecused3) + + def testBadFromWire1(self): + def bad(): + w = '\x03foo\xc0\x04' + (n, cused) = dns.name.from_wire(w, 0) + self.failUnlessRaises(dns.name.BadPointer, bad) + + def testBadFromWire2(self): + def bad(): + w = '\x03foo\xc0\x05' + (n, cused) = dns.name.from_wire(w, 0) + self.failUnlessRaises(dns.name.BadPointer, bad) + + def testBadFromWire3(self): + def bad(): + w = '\xbffoo' + (n, cused) = dns.name.from_wire(w, 0) + self.failUnlessRaises(dns.name.BadLabelType, bad) + + def testBadFromWire4(self): + def bad(): + w = '\x41foo' + (n, cused) = dns.name.from_wire(w, 0) + self.failUnlessRaises(dns.name.BadLabelType, bad) + + def testParent1(self): + n = dns.name.from_text('foo.bar.') + self.failUnless(n.parent() == dns.name.from_text('bar.')) + self.failUnless(n.parent().parent() == dns.name.root) + + def testParent2(self): + n = dns.name.from_text('foo.bar', None) + self.failUnless(n.parent() == dns.name.from_text('bar', None)) + self.failUnless(n.parent().parent() == dns.name.empty) + + def testParent3(self): + def bad(): + n = dns.name.root + n.parent() + self.failUnlessRaises(dns.name.NoParent, bad) + + def testParent4(self): + def bad(): + n = dns.name.empty + n.parent() + self.failUnlessRaises(dns.name.NoParent, bad) + + def testFromUnicode1(self): + n = dns.name.from_text(u'foo.bar') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testFromUnicode2(self): + n = dns.name.from_text(u'foo\u1234bar.bar') + self.failUnless(n.labels == ('xn--foobar-r5z', 'bar', '')) + + def testFromUnicodeAlternateDot1(self): + n = dns.name.from_text(u'foo\u3002bar') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testFromUnicodeAlternateDot2(self): + n = dns.name.from_text(u'foo\uff0ebar') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testFromUnicodeAlternateDot3(self): + n = dns.name.from_text(u'foo\uff61bar') + self.failUnless(n.labels == ('foo', 'bar', '')) + + def testToUnicode1(self): + n = dns.name.from_text(u'foo.bar') + s = n.to_unicode() + self.failUnless(s == u'foo.bar.') + + def testToUnicode2(self): + n = dns.name.from_text(u'foo\u1234bar.bar') + s = n.to_unicode() + self.failUnless(s == u'foo\u1234bar.bar.') + + def testToUnicode3(self): + n = dns.name.from_text('foo.bar') + s = n.to_unicode() + self.failUnless(s == u'foo.bar.') + + def testReverseIPv4(self): + e = dns.name.from_text('1.0.0.127.in-addr.arpa.') + n = dns.reversename.from_address('127.0.0.1') + self.failUnless(e == n) + + def testReverseIPv6(self): + e = dns.name.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.') + n = dns.reversename.from_address('::1') + self.failUnless(e == n) + + def testReverseIPv6MappedIpv4(self): + e = dns.name.from_text('1.0.0.127.in-addr.arpa.') + n = dns.reversename.from_address('::ffff:127.0.0.1') + self.failUnless(e == n) + + def testBadReverseIPv4(self): + def bad(): + n = dns.reversename.from_address('127.0.foo.1') + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testBadReverseIPv6(self): + def bad(): + n = dns.reversename.from_address('::1::1') + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testForwardIPv4(self): + n = dns.name.from_text('1.0.0.127.in-addr.arpa.') + e = '127.0.0.1' + text = dns.reversename.to_address(n) + self.failUnless(text == e) + + def testForwardIPv6(self): + n = dns.name.from_text('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa.') + e = '::1' + text = dns.reversename.to_address(n) + self.failUnless(text == e) + + def testE164ToEnum(self): + text = '+1 650 555 1212' + e = dns.name.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.') + n = dns.e164.from_e164(text) + self.failUnless(n == e) + + def testEnumToE164(self): + n = dns.name.from_text('2.1.2.1.5.5.5.0.5.6.1.e164.arpa.') + e = '+16505551212' + text = dns.e164.to_e164(n) + self.failUnless(text == e) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_ntoaaton.py dnspython-1.12.0/tests/test_ntoaaton.py --- dnspython-1.11.1/tests/test_ntoaaton.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_ntoaaton.py 2014-05-31 18:16:45.000000000 +0000 @@ -0,0 +1,211 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.exception +import dns.ipv4 +import dns.ipv6 + +# for convenience +aton4 = dns.ipv4.inet_aton +ntoa4 = dns.ipv4.inet_ntoa +aton6 = dns.ipv6.inet_aton +ntoa6 = dns.ipv6.inet_ntoa + +v4_bad_addrs = ['256.1.1.1', '1.1.1', '1.1.1.1.1', '01.1.1.1', + '+1.1.1.1', '1.1.1.1+', '1..2.3.4', '.1.2.3.4', + '1.2.3.4.'] + +class NtoAAtoNTestCase(unittest.TestCase): + + def test_aton1(self): + a = aton6('::') + self.failUnless(a == '\x00' * 16) + + def test_aton2(self): + a = aton6('::1') + self.failUnless(a == '\x00' * 15 + '\x01') + + def test_aton3(self): + a = aton6('::10.0.0.1') + self.failUnless(a == '\x00' * 12 + '\x0a\x00\x00\x01') + + def test_aton4(self): + a = aton6('abcd::dcba') + self.failUnless(a == '\xab\xcd' + '\x00' * 12 + '\xdc\xba') + + def test_aton5(self): + a = aton6('1:2:3:4:5:6:7:8') + self.failUnless(a == \ + '00010002000300040005000600070008'.decode('hex_codec')) + + def test_bad_aton1(self): + def bad(): + a = aton6('abcd:dcba') + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def test_bad_aton2(self): + def bad(): + a = aton6('abcd::dcba::1') + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def test_bad_aton3(self): + def bad(): + a = aton6('1:2:3:4:5:6:7:8:9') + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def test_aton1(self): + a = aton6('::') + self.failUnless(a == '\x00' * 16) + + def test_aton2(self): + a = aton6('::1') + self.failUnless(a == '\x00' * 15 + '\x01') + + def test_aton3(self): + a = aton6('::10.0.0.1') + self.failUnless(a == '\x00' * 12 + '\x0a\x00\x00\x01') + + def test_aton4(self): + a = aton6('abcd::dcba') + self.failUnless(a == '\xab\xcd' + '\x00' * 12 + '\xdc\xba') + + def test_ntoa1(self): + b = '00010002000300040005000600070008'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '1:2:3:4:5:6:7:8') + + def test_ntoa2(self): + b = '\x00' * 16 + t = ntoa6(b) + self.failUnless(t == '::') + + def test_ntoa3(self): + b = '\x00' * 15 + '\x01' + t = ntoa6(b) + self.failUnless(t == '::1') + + def test_ntoa4(self): + b = '\x80' + '\x00' * 15 + t = ntoa6(b) + self.failUnless(t == '8000::') + + def test_ntoa5(self): + b = '\x01\xcd' + '\x00' * 12 + '\x03\xef' + t = ntoa6(b) + self.failUnless(t == '1cd::3ef') + + def test_ntoa6(self): + b = 'ffff00000000ffff000000000000ffff'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == 'ffff:0:0:ffff::ffff') + + def test_ntoa7(self): + b = '00000000ffff000000000000ffffffff'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '0:0:ffff::ffff:ffff') + + def test_ntoa8(self): + b = 'ffff0000ffff00000000ffff00000000'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == 'ffff:0:ffff::ffff:0:0') + + def test_ntoa9(self): + b = '0000000000000000000000000a000001'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::10.0.0.1') + + def test_ntoa10(self): + b = '0000000000000000000000010a000001'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::1:a00:1') + + def test_ntoa11(self): + b = '00000000000000000000ffff0a000001'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::ffff:10.0.0.1') + + def test_ntoa12(self): + b = '000000000000000000000000ffffffff'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::255.255.255.255') + + def test_ntoa13(self): + b = '00000000000000000000ffffffffffff'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::ffff:255.255.255.255') + + def test_ntoa14(self): + b = '0000000000000000000000000001ffff'.decode('hex_codec') + t = ntoa6(b) + self.failUnless(t == '::0.1.255.255') + + def test_bad_ntoa1(self): + def bad(): + a = ntoa6('') + self.failUnlessRaises(ValueError, bad) + + def test_bad_ntoa2(self): + def bad(): + a = ntoa6('\x00' * 17) + self.failUnlessRaises(ValueError, bad) + + def test_good_v4_aton(self): + pairs = [('1.2.3.4', '\x01\x02\x03\x04'), + ('255.255.255.255', '\xff\xff\xff\xff'), + ('0.0.0.0', '\x00\x00\x00\x00')] + for (t, b) in pairs: + b1 = aton4(t) + t1 = ntoa4(b1) + self.failUnless(b1 == b) + self.failUnless(t1 == t) + + def test_bad_v4_aton(self): + def make_bad(a): + def bad(): + return aton4(a) + return bad + for addr in v4_bad_addrs: + self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) + + def test_bad_v6_aton(self): + addrs = ['+::0', '0::0::', '::0::', '1:2:3:4:5:6:7:8:9', + ':::::::'] + embedded = ['::' + x for x in v4_bad_addrs] + addrs.extend(embedded) + def make_bad(a): + def bad(): + x = aton6(a) + return bad + for addr in addrs: + self.failUnlessRaises(dns.exception.SyntaxError, make_bad(addr)) + + def test_rfc5952_section_4_2_2(self): + addr = '2001:db8:0:1:1:1:1:1' + b1 = aton6(addr) + t1 = ntoa6(b1) + self.failUnless(t1 == addr) + + def test_is_mapped(self): + t1 = '2001:db8:0:1:1:1:1:1' + t2 = '::ffff:127.0.0.1' + t3 = '1::ffff:127.0.0.1' + self.failIf(dns.ipv6.is_mapped(aton6(t1))) + self.failUnless(dns.ipv6.is_mapped(aton6(t2))) + self.failIf(dns.ipv6.is_mapped(aton6(t3))) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_rdtypeandclass.py dnspython-1.12.0/tests/test_rdtypeandclass.py --- dnspython-1.11.1/tests/test_rdtypeandclass.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_rdtypeandclass.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,123 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.rdataclass +import dns.rdatatype + +class RdTypeAndClassTestCase(unittest.TestCase): + + # Classes + + def test_class_meta1(self): + self.failUnless(dns.rdataclass.is_metaclass(dns.rdataclass.ANY)) + + def test_class_meta2(self): + self.failUnless(not dns.rdataclass.is_metaclass(dns.rdataclass.IN)) + + def test_class_bytext1(self): + self.failUnless(dns.rdataclass.from_text('IN') == dns.rdataclass.IN) + + def test_class_bytext2(self): + self.failUnless(dns.rdataclass.from_text('CLASS1') == + dns.rdataclass.IN) + + def test_class_bytext_bounds1(self): + self.failUnless(dns.rdataclass.from_text('CLASS0') == 0) + self.failUnless(dns.rdataclass.from_text('CLASS65535') == 65535) + + def test_class_bytext_bounds2(self): + def bad(): + junk = dns.rdataclass.from_text('CLASS65536') + self.failUnlessRaises(ValueError, bad) + + def test_class_bytext_unknown(self): + def bad(): + junk = dns.rdataclass.from_text('XXX') + self.failUnlessRaises(dns.rdataclass.UnknownRdataclass, bad) + + def test_class_totext1(self): + self.failUnless(dns.rdataclass.to_text(dns.rdataclass.IN) == 'IN') + + def test_class_totext1(self): + self.failUnless(dns.rdataclass.to_text(999) == 'CLASS999') + + def test_class_totext_bounds1(self): + def bad(): + junk = dns.rdataclass.to_text(-1) + self.failUnlessRaises(ValueError, bad) + + def test_class_totext_bounds2(self): + def bad(): + junk = dns.rdataclass.to_text(65536) + self.failUnlessRaises(ValueError, bad) + + # Types + + def test_type_meta1(self): + self.failUnless(dns.rdatatype.is_metatype(dns.rdatatype.ANY)) + + def test_type_meta2(self): + self.failUnless(dns.rdatatype.is_metatype(dns.rdatatype.OPT)) + + def test_type_meta3(self): + self.failUnless(not dns.rdatatype.is_metatype(dns.rdatatype.A)) + + def test_type_singleton1(self): + self.failUnless(dns.rdatatype.is_singleton(dns.rdatatype.SOA)) + + def test_type_singleton2(self): + self.failUnless(not dns.rdatatype.is_singleton(dns.rdatatype.A)) + + def test_type_bytext1(self): + self.failUnless(dns.rdatatype.from_text('A') == dns.rdatatype.A) + + def test_type_bytext2(self): + self.failUnless(dns.rdatatype.from_text('TYPE1') == + dns.rdatatype.A) + + def test_type_bytext_bounds1(self): + self.failUnless(dns.rdatatype.from_text('TYPE0') == 0) + self.failUnless(dns.rdatatype.from_text('TYPE65535') == 65535) + + def test_type_bytext_bounds2(self): + def bad(): + junk = dns.rdatatype.from_text('TYPE65536') + self.failUnlessRaises(ValueError, bad) + + def test_type_bytext_unknown(self): + def bad(): + junk = dns.rdatatype.from_text('XXX') + self.failUnlessRaises(dns.rdatatype.UnknownRdatatype, bad) + + def test_type_totext1(self): + self.failUnless(dns.rdatatype.to_text(dns.rdatatype.A) == 'A') + + def test_type_totext1(self): + self.failUnless(dns.rdatatype.to_text(999) == 'TYPE999') + + def test_type_totext_bounds1(self): + def bad(): + junk = dns.rdatatype.to_text(-1) + self.failUnlessRaises(ValueError, bad) + + def test_type_totext_bounds2(self): + def bad(): + junk = dns.rdatatype.to_text(65536) + self.failUnlessRaises(ValueError, bad) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_rdtypeanydnskey.py dnspython-1.12.0/tests/test_rdtypeanydnskey.py --- dnspython-1.11.1/tests/test_rdtypeanydnskey.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_rdtypeanydnskey.py 2014-06-19 12:32:55.000000000 +0000 @@ -0,0 +1,68 @@ +# Copyright (C) 2014 Red Hat, Inc. +# Author: Petr Spacek +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.rrset +import dns.rdtypes.ANY.DNSKEY + + +class RdtypeAnyDnskeyTestCase(unittest.TestCase): + + def testFlagsEmpty(self): + '''Test DNSKEY flag to/from text conversion for zero flag/empty set.''' + good_s = set() + good_f = 0 + from_flags = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(good_f) + self.failUnless(from_flags == good_s, + '"%s" != "%s"' % (from_flags, good_s)) + from_set = dns.rdtypes.ANY.DNSKEY.flags_from_text_set(good_s) + self.failUnless(from_set == good_f, + '"0x%x" != "0x%x"' % (from_set, good_f)) + + def testFlagsAll(self): + '''Test that all defined flags are recognized.''' + good_s = set(['SEP', 'REVOKE', 'ZONE']) + good_f = 0x181 + from_flags = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(good_f) + self.failUnless(from_flags == good_s, + '"%s" != "%s"' % (from_flags, good_s)) + from_text = dns.rdtypes.ANY.DNSKEY.flags_from_text_set(good_s) + self.failUnless(from_text == good_f, + '"0x%x" != "0x%x"' % (from_text, good_f)) + + def testFlagsUnknownToText(self): + '''Test that undefined flags are returned in hexadecimal notation.''' + unk_s = set(['0x8000']) + flags_s = dns.rdtypes.ANY.DNSKEY.flags_to_text_set(0x8000) + self.failUnless(flags_s == unk_s, '"%s" != "%s"' % (flags_s, unk_s)) + + def testFlagsUnknownToFlags(self): + '''Test that conversion from undefined mnemonic raises error.''' + self.failUnlessRaises(NotImplementedError, + dns.rdtypes.ANY.DNSKEY.flags_from_text_set, + (['0x8000'])) + + def testFlagsRRToText(self): + '''Test that RR method returns correct flags.''' + rr = dns.rrset.from_text('foo', 300, 'IN', 'DNSKEY', '257 3 8 KEY=')[0] + rr_s = set(['ZONE', 'SEP']) + flags_s = rr.flags_to_text_set() + self.failUnless(flags_s == rr_s, '"%s" != "%s"' % (flags_s, rr_s)) + + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_rdtypeanyloc.py dnspython-1.12.0/tests/test_rdtypeanyloc.py --- dnspython-1.11.1/tests/test_rdtypeanyloc.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_rdtypeanyloc.py 2014-03-03 16:57:58.000000000 +0000 @@ -0,0 +1,68 @@ +# Copyright (C) 2014 Red Hat, Inc. +# Author: Petr Spacek +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.rrset +import dns.rdtypes.ANY.LOC + +class RdtypeAnyLocTestCase(unittest.TestCase): + + def testEqual1(self): + '''Test default values for size, horizontal and vertical precision.''' + r1 = dns.rrset.from_text('foo', 300, 'IN', 'LOC', + '49 11 42.400 N 16 36 29.600 E 227.64m') + r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc', + '49 11 42.400 N 16 36 29.600 E 227.64m ' + '1.00m 10000.00m 10.00m') + self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2)) + + def testEqual2(self): + '''Test default values for size, horizontal and vertical precision.''' + r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400), + (16, 36, 29, 600), 22764.0) # centimeters + r2 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400), + (16, 36, 29, 600), 22764.0, # centimeters + 100.0, 1000000.00, 1000.0) # centimeters + self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2)) + + def testEqual3(self): + '''Test size, horizontal and vertical precision parsers: 100 cm == 1 m. + + Parsers in from_text() and __init__() have to produce equal results.''' + r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400), + (16, 36, 29, 600), 22764.0, + 200.0, 1000.00, 200.0) # centimeters + r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc', + '49 11 42.400 N 16 36 29.600 E 227.64m ' + '2.00m 10.00m 2.00m')[0] + self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2)) + + def testEqual4(self): + '''Test size, horizontal and vertical precision parsers without unit. + + Parsers in from_text() and __init__() have produce equal result + for values with and without trailing "m".''' + r1 = dns.rdtypes.ANY.LOC.LOC(1, 29, (49, 11, 42, 400), + (16, 36, 29, 600), 22764.0, + 200.0, 1000.00, 200.0) # centimeters + r2 = dns.rrset.from_text('FOO', 600, 'in', 'loc', + '49 11 42.400 N 16 36 29.600 E 227.64 ' + '2 10 2')[0] # meters without explicit unit + self.failUnless(r1 == r2, '"%s" != "%s"' % (r1, r2)) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_resolver.py dnspython-1.12.0/tests/test_resolver.py --- dnspython-1.11.1/tests/test_resolver.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_resolver.py 2011-08-29 16:45:52.000000000 +0000 @@ -0,0 +1,184 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import cStringIO +import select +import sys +import time +import unittest + +import dns.name +import dns.message +import dns.name +import dns.rdataclass +import dns.rdatatype +import dns.resolver + +resolv_conf = """ + /t/t +# comment 1 +; comment 2 +domain foo +nameserver 10.0.0.1 +nameserver 10.0.0.2 +""" + +message_text = """id 1234 +opcode QUERY +rcode NOERROR +flags QR AA RD +;QUESTION +example. IN A +;ANSWER +example. 1 IN A 10.0.0.1 +;AUTHORITY +;ADDITIONAL +""" + +class FakeAnswer(object): + def __init__(self, expiration): + self.expiration = expiration + +class BaseResolverTests(object): + + if sys.platform != 'win32': + def testRead(self): + f = cStringIO.StringIO(resolv_conf) + r = dns.resolver.Resolver(f) + self.failUnless(r.nameservers == ['10.0.0.1', '10.0.0.2'] and + r.domain == dns.name.from_text('foo')) + + def testCacheExpiration(self): + message = dns.message.from_text(message_text) + name = dns.name.from_text('example.') + answer = dns.resolver.Answer(name, dns.rdatatype.A, dns.rdataclass.IN, + message) + cache = dns.resolver.Cache() + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + time.sleep(2) + self.failUnless(cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) + is None) + + def testCacheCleaning(self): + message = dns.message.from_text(message_text) + name = dns.name.from_text('example.') + answer = dns.resolver.Answer(name, dns.rdatatype.A, dns.rdataclass.IN, + message) + cache = dns.resolver.Cache(cleaning_interval=1.0) + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + time.sleep(2) + self.failUnless(cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) + is None) + + def testZoneForName1(self): + name = dns.name.from_text('www.dnspython.org.') + ezname = dns.name.from_text('dnspython.org.') + zname = dns.resolver.zone_for_name(name) + self.failUnless(zname == ezname) + + def testZoneForName2(self): + name = dns.name.from_text('a.b.www.dnspython.org.') + ezname = dns.name.from_text('dnspython.org.') + zname = dns.resolver.zone_for_name(name) + self.failUnless(zname == ezname) + + def testZoneForName3(self): + name = dns.name.from_text('dnspython.org.') + ezname = dns.name.from_text('dnspython.org.') + zname = dns.resolver.zone_for_name(name) + self.failUnless(zname == ezname) + + def testZoneForName4(self): + def bad(): + name = dns.name.from_text('dnspython.org', None) + zname = dns.resolver.zone_for_name(name) + self.failUnlessRaises(dns.resolver.NotAbsolute, bad) + + def testLRUReplace(self): + cache = dns.resolver.LRUCache(4) + for i in xrange(0, 5): + name = dns.name.from_text('example%d.' % i) + answer = FakeAnswer(time.time() + 1) + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + for i in xrange(0, 5): + name = dns.name.from_text('example%d.' % i) + if i == 0: + self.failUnless(cache.get((name, dns.rdatatype.A, + dns.rdataclass.IN)) + is None) + else: + self.failUnless(not cache.get((name, dns.rdatatype.A, + dns.rdataclass.IN)) + is None) + + def testLRUDoesLRU(self): + cache = dns.resolver.LRUCache(4) + for i in xrange(0, 4): + name = dns.name.from_text('example%d.' % i) + answer = FakeAnswer(time.time() + 1) + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + name = dns.name.from_text('example0.') + cache.get((name, dns.rdatatype.A, dns.rdataclass.IN)) + # The LRU is now example1. + name = dns.name.from_text('example4.') + answer = FakeAnswer(time.time() + 1) + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + for i in xrange(0, 5): + name = dns.name.from_text('example%d.' % i) + if i == 1: + self.failUnless(cache.get((name, dns.rdatatype.A, + dns.rdataclass.IN)) + is None) + else: + self.failUnless(not cache.get((name, dns.rdatatype.A, + dns.rdataclass.IN)) + is None) + + def testLRUExpiration(self): + cache = dns.resolver.LRUCache(4) + for i in xrange(0, 4): + name = dns.name.from_text('example%d.' % i) + answer = FakeAnswer(time.time() + 1) + cache.put((name, dns.rdatatype.A, dns.rdataclass.IN), answer) + time.sleep(2) + for i in xrange(0, 4): + name = dns.name.from_text('example%d.' % i) + self.failUnless(cache.get((name, dns.rdatatype.A, + dns.rdataclass.IN)) + is None) + +class PollingMonkeyPatchMixin(object): + def setUp(self): + self.__native_polling_backend = dns.query._polling_backend + dns.query._set_polling_backend(self.polling_backend()) + + unittest.TestCase.setUp(self) + + def tearDown(self): + dns.query._set_polling_backend(self.__native_polling_backend) + + unittest.TestCase.tearDown(self) + +class SelectResolverTestCase(PollingMonkeyPatchMixin, BaseResolverTests, unittest.TestCase): + def polling_backend(self): + return dns.query._select_for + +if hasattr(select, 'poll'): + class PollResolverTestCase(PollingMonkeyPatchMixin, BaseResolverTests, unittest.TestCase): + def polling_backend(self): + return dns.query._poll_for + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_rrset.py dnspython-1.12.0/tests/test_rrset.py --- dnspython-1.11.1/tests/test_rrset.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_rrset.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,54 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.rrset + +class RRsetTestCase(unittest.TestCase): + + def testEqual1(self): + r1 = dns.rrset.from_text('foo', 300, 'in', 'a', '10.0.0.1', '10.0.0.2') + r2 = dns.rrset.from_text('FOO', 300, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 == r2) + + def testEqual2(self): + r1 = dns.rrset.from_text('foo', 300, 'in', 'a', '10.0.0.1', '10.0.0.2') + r2 = dns.rrset.from_text('FOO', 600, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 == r2) + + def testNotEqual1(self): + r1 = dns.rrset.from_text('fooa', 30, 'in', 'a', '10.0.0.1', '10.0.0.2') + r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 != r2) + + def testNotEqual2(self): + r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1', '10.0.0.3') + r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 != r2) + + def testNotEqual3(self): + r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1', '10.0.0.2', + '10.0.0.3') + r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 != r2) + + def testNotEqual4(self): + r1 = dns.rrset.from_text('foo', 30, 'in', 'a', '10.0.0.1') + r2 = dns.rrset.from_text('FOO', 30, 'in', 'a', '10.0.0.2', '10.0.0.1') + self.failUnless(r1 != r2) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_set.py dnspython-1.12.0/tests/test_set.py --- dnspython-1.11.1/tests/test_set.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_set.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,208 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.set + +# for convenience +S = dns.set.Set + +class SimpleSetTestCase(unittest.TestCase): + + def testLen1(self): + s1 = S() + self.failUnless(len(s1) == 0) + + def testLen2(self): + s1 = S([1, 2, 3]) + self.failUnless(len(s1) == 3) + + def testLen3(self): + s1 = S([1, 2, 3, 3, 3]) + self.failUnless(len(s1) == 3) + + def testUnion1(self): + s1 = S([1, 2, 3]) + s2 = S([1, 2, 3]) + e = S([1, 2, 3]) + self.failUnless(s1 | s2 == e) + + def testUnion2(self): + s1 = S([1, 2, 3]) + s2 = S([]) + e = S([1, 2, 3]) + self.failUnless(s1 | s2 == e) + + def testUnion3(self): + s1 = S([1, 2, 3]) + s2 = S([3, 4]) + e = S([1, 2, 3, 4]) + self.failUnless(s1 | s2 == e) + + def testIntersection1(self): + s1 = S([1, 2, 3]) + s2 = S([1, 2, 3]) + e = S([1, 2, 3]) + self.failUnless(s1 & s2 == e) + + def testIntersection2(self): + s1 = S([0, 1, 2, 3]) + s2 = S([1, 2, 3, 4]) + e = S([1, 2, 3]) + self.failUnless(s1 & s2 == e) + + def testIntersection3(self): + s1 = S([1, 2, 3]) + s2 = S([]) + e = S([]) + self.failUnless(s1 & s2 == e) + + def testIntersection4(self): + s1 = S([1, 2, 3]) + s2 = S([5, 4]) + e = S([]) + self.failUnless(s1 & s2 == e) + + def testDifference1(self): + s1 = S([1, 2, 3]) + s2 = S([5, 4]) + e = S([1, 2, 3]) + self.failUnless(s1 - s2 == e) + + def testDifference2(self): + s1 = S([1, 2, 3]) + s2 = S([]) + e = S([1, 2, 3]) + self.failUnless(s1 - s2 == e) + + def testDifference3(self): + s1 = S([1, 2, 3]) + s2 = S([3, 2]) + e = S([1]) + self.failUnless(s1 - s2 == e) + + def testDifference4(self): + s1 = S([1, 2, 3]) + s2 = S([3, 2, 1]) + e = S([]) + self.failUnless(s1 - s2 == e) + + def testSubset1(self): + s1 = S([1, 2, 3]) + s2 = S([3, 2, 1]) + self.failUnless(s1.issubset(s2)) + + def testSubset2(self): + s1 = S([1, 2, 3]) + self.failUnless(s1.issubset(s1)) + + def testSubset3(self): + s1 = S([]) + s2 = S([1, 2, 3]) + self.failUnless(s1.issubset(s2)) + + def testSubset4(self): + s1 = S([1]) + s2 = S([1, 2, 3]) + self.failUnless(s1.issubset(s2)) + + def testSubset5(self): + s1 = S([]) + s2 = S([]) + self.failUnless(s1.issubset(s2)) + + def testSubset6(self): + s1 = S([1, 4]) + s2 = S([1, 2, 3]) + self.failUnless(not s1.issubset(s2)) + + def testSuperset1(self): + s1 = S([1, 2, 3]) + s2 = S([3, 2, 1]) + self.failUnless(s1.issuperset(s2)) + + def testSuperset2(self): + s1 = S([1, 2, 3]) + self.failUnless(s1.issuperset(s1)) + + def testSuperset3(self): + s1 = S([1, 2, 3]) + s2 = S([]) + self.failUnless(s1.issuperset(s2)) + + def testSuperset4(self): + s1 = S([1, 2, 3]) + s2 = S([1]) + self.failUnless(s1.issuperset(s2)) + + def testSuperset5(self): + s1 = S([]) + s2 = S([]) + self.failUnless(s1.issuperset(s2)) + + def testSuperset6(self): + s1 = S([1, 2, 3]) + s2 = S([1, 4]) + self.failUnless(not s1.issuperset(s2)) + + def testUpdate1(self): + s1 = S([1, 2, 3]) + u = (4, 5, 6) + e = S([1, 2, 3, 4, 5, 6]) + s1.update(u) + self.failUnless(s1 == e) + + def testUpdate2(self): + s1 = S([1, 2, 3]) + u = [] + e = S([1, 2, 3]) + s1.update(u) + self.failUnless(s1 == e) + + def testGetitem(self): + s1 = S([1, 2, 3]) + i0 = s1[0] + i1 = s1[1] + i2 = s1[2] + s2 = S([i0, i1, i2]) + self.failUnless(s1 == s2) + + def testGetslice(self): + s1 = S([1, 2, 3]) + slice = s1[0:2] + self.failUnless(len(slice) == 2) + item = s1[2] + slice.append(item) + s2 = S(slice) + self.failUnless(s1 == s2) + + def testDelitem(self): + s1 = S([1, 2, 3]) + del s1[0] + i1 = s1[0] + i2 = s1[1] + self.failUnless(i1 != i2) + self.failUnless(i1 == 1 or i1 == 2 or i1 == 3) + self.failUnless(i2 == 1 or i2 == 2 or i2 == 3) + + def testDelslice(self): + s1 = S([1, 2, 3]) + del s1[0:2] + i1 = s1[0] + self.failUnless(i1 == 1 or i1 == 2 or i1 == 3) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_tokenizer.py dnspython-1.12.0/tests/test_tokenizer.py --- dnspython-1.11.1/tests/test_tokenizer.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_tokenizer.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,190 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.exception +import dns.tokenizer + +Token = dns.tokenizer.Token + +class TokenizerTestCase(unittest.TestCase): + + def testQuotedString1(self): + tok = dns.tokenizer.Tokenizer(r'"foo"') + token = tok.get() + self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, 'foo')) + + def testQuotedString2(self): + tok = dns.tokenizer.Tokenizer(r'""') + token = tok.get() + self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, '')) + + def testQuotedString3(self): + tok = dns.tokenizer.Tokenizer(r'"\"foo\""') + token = tok.get() + self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, '"foo"')) + + def testQuotedString4(self): + tok = dns.tokenizer.Tokenizer(r'"foo\010bar"') + token = tok.get() + self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, 'foo\x0abar')) + + def testQuotedString5(self): + def bad(): + tok = dns.tokenizer.Tokenizer(r'"foo') + token = tok.get() + self.failUnlessRaises(dns.exception.UnexpectedEnd, bad) + + def testQuotedString6(self): + def bad(): + tok = dns.tokenizer.Tokenizer(r'"foo\01') + token = tok.get() + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testQuotedString7(self): + def bad(): + tok = dns.tokenizer.Tokenizer('"foo\nbar"') + token = tok.get() + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testEmpty1(self): + tok = dns.tokenizer.Tokenizer('') + token = tok.get() + self.failUnless(token.is_eof()) + + def testEmpty2(self): + tok = dns.tokenizer.Tokenizer('') + token1 = tok.get() + token2 = tok.get() + self.failUnless(token1.is_eof() and token2.is_eof()) + + def testEOL(self): + tok = dns.tokenizer.Tokenizer('\n') + token1 = tok.get() + token2 = tok.get() + self.failUnless(token1.is_eol() and token2.is_eof()) + + def testWS1(self): + tok = dns.tokenizer.Tokenizer(' \n') + token1 = tok.get() + self.failUnless(token1.is_eol()) + + def testWS2(self): + tok = dns.tokenizer.Tokenizer(' \n') + token1 = tok.get(want_leading=True) + self.failUnless(token1.is_whitespace()) + + def testComment1(self): + tok = dns.tokenizer.Tokenizer(' ;foo\n') + token1 = tok.get() + self.failUnless(token1.is_eol()) + + def testComment2(self): + tok = dns.tokenizer.Tokenizer(' ;foo\n') + token1 = tok.get(want_comment = True) + token2 = tok.get() + self.failUnless(token1 == Token(dns.tokenizer.COMMENT, 'foo') and + token2.is_eol()) + + def testComment3(self): + tok = dns.tokenizer.Tokenizer(' ;foo bar\n') + token1 = tok.get(want_comment = True) + token2 = tok.get() + self.failUnless(token1 == Token(dns.tokenizer.COMMENT, 'foo bar') and + token2.is_eol()) + + def testMultiline1(self): + tok = dns.tokenizer.Tokenizer('( foo\n\n bar\n)') + tokens = list(iter(tok)) + self.failUnless(tokens == [Token(dns.tokenizer.IDENTIFIER, 'foo'), + Token(dns.tokenizer.IDENTIFIER, 'bar')]) + + def testMultiline2(self): + tok = dns.tokenizer.Tokenizer('( foo\n\n bar\n)\n') + tokens = list(iter(tok)) + self.failUnless(tokens == [Token(dns.tokenizer.IDENTIFIER, 'foo'), + Token(dns.tokenizer.IDENTIFIER, 'bar'), + Token(dns.tokenizer.EOL, '\n')]) + def testMultiline3(self): + def bad(): + tok = dns.tokenizer.Tokenizer('foo)') + tokens = list(iter(tok)) + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testMultiline4(self): + def bad(): + tok = dns.tokenizer.Tokenizer('((foo)') + tokens = list(iter(tok)) + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testUnget1(self): + tok = dns.tokenizer.Tokenizer('foo') + t1 = tok.get() + tok.unget(t1) + t2 = tok.get() + self.failUnless(t1 == t2 and t1.ttype == dns.tokenizer.IDENTIFIER and \ + t1.value == 'foo') + + def testUnget2(self): + def bad(): + tok = dns.tokenizer.Tokenizer('foo') + t1 = tok.get() + tok.unget(t1) + tok.unget(t1) + self.failUnlessRaises(dns.tokenizer.UngetBufferFull, bad) + + def testGetEOL1(self): + tok = dns.tokenizer.Tokenizer('\n') + t = tok.get_eol() + self.failUnless(t == '\n') + + def testGetEOL2(self): + tok = dns.tokenizer.Tokenizer('') + t = tok.get_eol() + self.failUnless(t == '') + + def testEscapedDelimiter1(self): + tok = dns.tokenizer.Tokenizer(r'ch\ ld') + t = tok.get() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\ ld') + + def testEscapedDelimiter2(self): + tok = dns.tokenizer.Tokenizer(r'ch\032ld') + t = tok.get() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\032ld') + + def testEscapedDelimiter3(self): + tok = dns.tokenizer.Tokenizer(r'ch\ild') + t = tok.get() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\ild') + + def testEscapedDelimiter1u(self): + tok = dns.tokenizer.Tokenizer(r'ch\ ld') + t = tok.get().unescape() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch ld') + + def testEscapedDelimiter2u(self): + tok = dns.tokenizer.Tokenizer(r'ch\032ld') + t = tok.get().unescape() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == 'ch ld') + + def testEscapedDelimiter3u(self): + tok = dns.tokenizer.Tokenizer(r'ch\ild') + t = tok.get().unescape() + self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'child') + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_update.py dnspython-1.12.0/tests/test_update.py --- dnspython-1.11.1/tests/test_update.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_update.py 2011-07-09 14:05:21.000000000 +0000 @@ -0,0 +1,114 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import unittest + +import dns.update +import dns.rdata +import dns.rdataset + +goodhex = '0001 2800 0001 0005 0007 0000' \ + '076578616d706c6500 0006 0001' \ + '03666f6fc00c 00ff 00ff 00000000 0000' \ + 'c019 0001 00ff 00000000 0000' \ + '03626172c00c 0001 0001 00000000 0004 0a000005' \ + '05626c617a32c00c 00ff 00fe 00000000 0000' \ + 'c049 0001 00fe 00000000 0000' \ + 'c019 0001 00ff 00000000 0000' \ + 'c019 0001 0001 0000012c 0004 0a000001' \ + 'c019 0001 0001 0000012c 0004 0a000002' \ + 'c035 0001 0001 0000012c 0004 0a000003' \ + 'c035 0001 00fe 00000000 0004 0a000004' \ + '04626c617ac00c 0001 00ff 00000000 0000' \ + 'c049 00ff 00ff 00000000 0000' + +goodwire = goodhex.replace(' ', '').decode('hex_codec') + +update_text="""id 1 +opcode UPDATE +rcode NOERROR +;ZONE +example. IN SOA +;PREREQ +foo ANY ANY +foo ANY A +bar 0 IN A 10.0.0.5 +blaz2 NONE ANY +blaz2 NONE A +;UPDATE +foo ANY A +foo 300 IN A 10.0.0.1 +foo 300 IN A 10.0.0.2 +bar 300 IN A 10.0.0.3 +bar 0 NONE A 10.0.0.4 +blaz ANY A +blaz2 ANY ANY +""" + +class UpdateTestCase(unittest.TestCase): + + def test_to_wire1(self): + update = dns.update.Update('example') + update.id = 1 + update.present('foo') + update.present('foo', 'a') + update.present('bar', 'a', '10.0.0.5') + update.absent('blaz2') + update.absent('blaz2', 'a') + update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') + update.add('bar', 300, 'a', '10.0.0.3') + update.delete('bar', 'a', '10.0.0.4') + update.delete('blaz','a') + update.delete('blaz2') + self.failUnless(update.to_wire() == goodwire) + + def test_to_wire2(self): + update = dns.update.Update('example') + update.id = 1 + update.present('foo') + update.present('foo', 'a') + update.present('bar', 'a', '10.0.0.5') + update.absent('blaz2') + update.absent('blaz2', 'a') + update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') + update.add('bar', 300, dns.rdata.from_text(1, 1, '10.0.0.3')) + update.delete('bar', 'a', '10.0.0.4') + update.delete('blaz','a') + update.delete('blaz2') + self.failUnless(update.to_wire() == goodwire) + + def test_to_wire3(self): + update = dns.update.Update('example') + update.id = 1 + update.present('foo') + update.present('foo', 'a') + update.present('bar', 'a', '10.0.0.5') + update.absent('blaz2') + update.absent('blaz2', 'a') + update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') + update.add('bar', dns.rdataset.from_text(1, 1, 300, '10.0.0.3')) + update.delete('bar', 'a', '10.0.0.4') + update.delete('blaz','a') + update.delete('blaz2') + self.failUnless(update.to_wire() == goodwire) + + def test_from_text1(self): + update = dns.message.from_text(update_text) + w = update.to_wire(origin=dns.name.from_text('example'), + want_shuffle=False) + self.failUnless(w == goodwire) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/test_zone.py dnspython-1.12.0/tests/test_zone.py --- dnspython-1.11.1/tests/test_zone.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/test_zone.py 2014-07-22 14:17:53.000000000 +0000 @@ -0,0 +1,412 @@ +# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. +# +# Permission to use, copy, modify, and distribute this software and its +# documentation for any purpose with or without fee is hereby granted, +# provided that the above copyright notice and this permission notice +# appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +import cStringIO +import filecmp +import os +import unittest + +import dns.exception +import dns.rdata +import dns.rdataclass +import dns.rdatatype +import dns.rrset +import dns.zone + +example_text = """$TTL 3600 +$ORIGIN example. +@ soa foo bar 1 2 3 4 5 +@ ns ns1 +@ ns ns2 +ns1 a 10.0.0.1 +ns2 a 10.0.0.2 +$TTL 300 +$ORIGIN foo.example. +bar mx 0 blaz +""" + +example_text_output = """@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.2 +""" + +something_quite_similar = """@ 3600 IN SOA foo bar 1 2 3 4 5 +@ 3600 IN NS ns1 +@ 3600 IN NS ns2 +bar.foo 300 IN MX 0 blaz.foo +ns1 3600 IN A 10.0.0.1 +ns2 3600 IN A 10.0.0.3 +""" + +something_different = """@ 3600 IN SOA fooa bar 1 2 3 4 5 +@ 3600 IN NS ns11 +@ 3600 IN NS ns21 +bar.fooa 300 IN MX 0 blaz.fooa +ns11 3600 IN A 10.0.0.11 +ns21 3600 IN A 10.0.0.21 +""" + +ttl_example_text = """$TTL 1h +$ORIGIN example. +@ soa foo bar 1 2 3 4 5 +@ ns ns1 +@ ns ns2 +ns1 1d1s a 10.0.0.1 +ns2 1w1D1h1m1S a 10.0.0.2 +""" + +no_soa_text = """$TTL 1h +$ORIGIN example. +@ ns ns1 +@ ns ns2 +ns1 1d1s a 10.0.0.1 +ns2 1w1D1h1m1S a 10.0.0.2 +""" + +no_ns_text = """$TTL 1h +$ORIGIN example. +@ soa foo bar 1 2 3 4 5 +""" + +include_text = """$INCLUDE "example" +""" + +bad_directive_text = """$FOO bar +$ORIGIN example. +@ soa foo bar 1 2 3 4 5 +@ ns ns1 +@ ns ns2 +ns1 1d1s a 10.0.0.1 +ns2 1w1D1h1m1S a 10.0.0.2 +""" + +_keep_output = False + +class ZoneTestCase(unittest.TestCase): + + def testFromFile1(self): + z = dns.zone.from_file('example', 'example') + ok = False + try: + z.to_file('example1.out', nl='\x0a') + ok = filecmp.cmp('example1.out', 'example1.good') + finally: + if not _keep_output: + os.unlink('example1.out') + self.failUnless(ok) + + def testFromFile2(self): + z = dns.zone.from_file('example', 'example', relativize=False) + ok = False + try: + z.to_file('example2.out', relativize=False, nl='\x0a') + ok = filecmp.cmp('example2.out', 'example2.good') + finally: + if not _keep_output: + os.unlink('example2.out') + self.failUnless(ok) + + def testToText(self): + z = dns.zone.from_file('example', 'example') + ok = False + try: + text_zone = z.to_text(nl='\x0a') + f = open('example3.out', 'wb') + f.write(text_zone) + f.close() + ok = filecmp.cmp('example3.out', 'example3.good') + finally: + if not _keep_output: + os.unlink('example3.out') + self.failUnless(ok) + + def testFromText(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + f = cStringIO.StringIO() + names = z.nodes.keys() + names.sort() + for n in names: + print >> f, z[n].to_text(n) + self.failUnless(f.getvalue() == example_text_output) + + def testTorture1(self): + # + # Read a zone containing all our supported RR types, and + # for each RR in the zone, convert the rdata into wire format + # and then back out, and see if we get equal rdatas. + # + f = cStringIO.StringIO() + o = dns.name.from_text('example.') + z = dns.zone.from_file('example', o) + for (name, node) in z.iteritems(): + for rds in node: + for rd in rds: + f.seek(0) + f.truncate() + rd.to_wire(f, origin=o) + wire = f.getvalue() + rd2 = dns.rdata.from_wire(rds.rdclass, rds.rdtype, + wire, 0, len(wire), + origin = o) + self.failUnless(rd == rd2) + + def testEqual(self): + z1 = dns.zone.from_text(example_text, 'example.', relativize=True) + z2 = dns.zone.from_text(example_text_output, 'example.', + relativize=True) + self.failUnless(z1 == z2) + + def testNotEqual1(self): + z1 = dns.zone.from_text(example_text, 'example.', relativize=True) + z2 = dns.zone.from_text(something_quite_similar, 'example.', + relativize=True) + self.failUnless(z1 != z2) + + def testNotEqual2(self): + z1 = dns.zone.from_text(example_text, 'example.', relativize=True) + z2 = dns.zone.from_text(something_different, 'example.', + relativize=True) + self.failUnless(z1 != z2) + + def testNotEqual3(self): + z1 = dns.zone.from_text(example_text, 'example.', relativize=True) + z2 = dns.zone.from_text(something_different, 'example2.', + relativize=True) + self.failUnless(z1 != z2) + + def testFindRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rds = z.find_rdataset('@', 'soa') + exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') + self.failUnless(rds == exrds) + + def testFindRdataset2(self): + def bad(): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rds = z.find_rdataset('@', 'loc') + self.failUnlessRaises(KeyError, bad) + + def testFindRRset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rrs = z.find_rrset('@', 'soa') + exrrs = dns.rrset.from_text('@', 300, 'IN', 'SOA', 'foo bar 1 2 3 4 5') + self.failUnless(rrs == exrrs) + + def testFindRRset2(self): + def bad(): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rrs = z.find_rrset('@', 'loc') + self.failUnlessRaises(KeyError, bad) + + def testGetRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rds = z.get_rdataset('@', 'soa') + exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') + self.failUnless(rds == exrds) + + def testGetRdataset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rds = z.get_rdataset('@', 'loc') + self.failUnless(rds == None) + + def testGetRRset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rrs = z.get_rrset('@', 'soa') + exrrs = dns.rrset.from_text('@', 300, 'IN', 'SOA', 'foo bar 1 2 3 4 5') + self.failUnless(rrs == exrrs) + + def testGetRRset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rrs = z.get_rrset('@', 'loc') + self.failUnless(rrs == None) + + def testReplaceRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rdataset = dns.rdataset.from_text('in', 'ns', 300, 'ns3', 'ns4') + z.replace_rdataset('@', rdataset) + rds = z.get_rdataset('@', 'ns') + self.failUnless(rds is rdataset) + + def testReplaceRdataset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + rdataset = dns.rdataset.from_text('in', 'txt', 300, '"foo"') + z.replace_rdataset('@', rdataset) + rds = z.get_rdataset('@', 'txt') + self.failUnless(rds is rdataset) + + def testDeleteRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + z.delete_rdataset('@', 'ns') + rds = z.get_rdataset('@', 'ns') + self.failUnless(rds is None) + + def testDeleteRdataset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + z.delete_rdataset('ns1', 'a') + node = z.get_node('ns1') + self.failUnless(node is None) + + def testNodeFindRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) + exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') + self.failUnless(rds == exrds) + + def testNodeFindRdataset2(self): + def bad(): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) + self.failUnlessRaises(KeyError, bad) + + def testNodeGetRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) + exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') + self.failUnless(rds == exrds) + + def testNodeGetRdataset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) + self.failUnless(rds == None) + + def testNodeDeleteRdataset1(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.delete_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) + rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) + self.failUnless(rds == None) + + def testNodeDeleteRdataset2(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + node = z['@'] + rds = node.delete_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) + rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) + self.failUnless(rds == None) + + def testIterateRdatasets(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + ns = [n for n, r in z.iterate_rdatasets('A')] + ns.sort() + self.failUnless(ns == [dns.name.from_text('ns1', None), + dns.name.from_text('ns2', None)]) + + def testIterateAllRdatasets(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + ns = [n for n, r in z.iterate_rdatasets()] + ns.sort() + self.failUnless(ns == [dns.name.from_text('@', None), + dns.name.from_text('@', None), + dns.name.from_text('bar.foo', None), + dns.name.from_text('ns1', None), + dns.name.from_text('ns2', None)]) + + def testIterateRdatas(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + l = list(z.iterate_rdatas('A')) + l.sort() + exl = [(dns.name.from_text('ns1', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2'))] + self.failUnless(l == exl) + + def testIterateAllRdatas(self): + z = dns.zone.from_text(example_text, 'example.', relativize=True) + l = list(z.iterate_rdatas()) + l.sort() + exl = [(dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns1')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, + 'ns2')), + (dns.name.from_text('@', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, + 'foo bar 1 2 3 4 5')), + (dns.name.from_text('bar.foo', None), + 300, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, + '0 blaz.foo')), + (dns.name.from_text('ns1', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.1')), + (dns.name.from_text('ns2', None), + 3600, + dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, + '10.0.0.2'))] + self.failUnless(l == exl) + + def testTTLs(self): + z = dns.zone.from_text(ttl_example_text, 'example.', relativize=True) + n = z['@'] + rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) + self.failUnless(rds.ttl == 3600) + n = z['ns1'] + rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) + self.failUnless(rds.ttl == 86401) + n = z['ns2'] + rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) + self.failUnless(rds.ttl == 694861) + + def testNoSOA(self): + def bad(): + z = dns.zone.from_text(no_soa_text, 'example.', + relativize=True) + self.failUnlessRaises(dns.zone.NoSOA, bad) + + def testNoNS(self): + def bad(): + z = dns.zone.from_text(no_ns_text, 'example.', + relativize=True) + self.failUnlessRaises(dns.zone.NoNS, bad) + + def testInclude(self): + z1 = dns.zone.from_text(include_text, 'example.', relativize=True, + allow_include=True) + z2 = dns.zone.from_file('example', 'example.', relativize=True) + self.failUnless(z1 == z2) + + def testBadDirective(self): + def bad(): + z = dns.zone.from_text(bad_directive_text, 'example.', + relativize=True) + self.failUnlessRaises(dns.exception.SyntaxError, bad) + + def testFirstRRStartsWithWhitespace(self): + # no name is specified, so default to the intial origin + # no ttl is specified, so default to the initial TTL of 0 + z = dns.zone.from_text(' IN A 10.0.0.1', origin='example.', + check_origin=False) + n = z['@'] + rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) + self.failUnless(rds.ttl == 0) + +if __name__ == '__main__': + unittest.main() diff -Nru dnspython-1.11.1/tests/tokenizer.py dnspython-1.12.0/tests/tokenizer.py --- dnspython-1.11.1/tests/tokenizer.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/tokenizer.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,190 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.exception -import dns.tokenizer - -Token = dns.tokenizer.Token - -class TokenizerTestCase(unittest.TestCase): - - def testQuotedString1(self): - tok = dns.tokenizer.Tokenizer(r'"foo"') - token = tok.get() - self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, 'foo')) - - def testQuotedString2(self): - tok = dns.tokenizer.Tokenizer(r'""') - token = tok.get() - self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, '')) - - def testQuotedString3(self): - tok = dns.tokenizer.Tokenizer(r'"\"foo\""') - token = tok.get() - self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, '"foo"')) - - def testQuotedString4(self): - tok = dns.tokenizer.Tokenizer(r'"foo\010bar"') - token = tok.get() - self.failUnless(token == Token(dns.tokenizer.QUOTED_STRING, 'foo\x0abar')) - - def testQuotedString5(self): - def bad(): - tok = dns.tokenizer.Tokenizer(r'"foo') - token = tok.get() - self.failUnlessRaises(dns.exception.UnexpectedEnd, bad) - - def testQuotedString6(self): - def bad(): - tok = dns.tokenizer.Tokenizer(r'"foo\01') - token = tok.get() - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testQuotedString7(self): - def bad(): - tok = dns.tokenizer.Tokenizer('"foo\nbar"') - token = tok.get() - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testEmpty1(self): - tok = dns.tokenizer.Tokenizer('') - token = tok.get() - self.failUnless(token.is_eof()) - - def testEmpty2(self): - tok = dns.tokenizer.Tokenizer('') - token1 = tok.get() - token2 = tok.get() - self.failUnless(token1.is_eof() and token2.is_eof()) - - def testEOL(self): - tok = dns.tokenizer.Tokenizer('\n') - token1 = tok.get() - token2 = tok.get() - self.failUnless(token1.is_eol() and token2.is_eof()) - - def testWS1(self): - tok = dns.tokenizer.Tokenizer(' \n') - token1 = tok.get() - self.failUnless(token1.is_eol()) - - def testWS2(self): - tok = dns.tokenizer.Tokenizer(' \n') - token1 = tok.get(want_leading=True) - self.failUnless(token1.is_whitespace()) - - def testComment1(self): - tok = dns.tokenizer.Tokenizer(' ;foo\n') - token1 = tok.get() - self.failUnless(token1.is_eol()) - - def testComment2(self): - tok = dns.tokenizer.Tokenizer(' ;foo\n') - token1 = tok.get(want_comment = True) - token2 = tok.get() - self.failUnless(token1 == Token(dns.tokenizer.COMMENT, 'foo') and - token2.is_eol()) - - def testComment3(self): - tok = dns.tokenizer.Tokenizer(' ;foo bar\n') - token1 = tok.get(want_comment = True) - token2 = tok.get() - self.failUnless(token1 == Token(dns.tokenizer.COMMENT, 'foo bar') and - token2.is_eol()) - - def testMultiline1(self): - tok = dns.tokenizer.Tokenizer('( foo\n\n bar\n)') - tokens = list(iter(tok)) - self.failUnless(tokens == [Token(dns.tokenizer.IDENTIFIER, 'foo'), - Token(dns.tokenizer.IDENTIFIER, 'bar')]) - - def testMultiline2(self): - tok = dns.tokenizer.Tokenizer('( foo\n\n bar\n)\n') - tokens = list(iter(tok)) - self.failUnless(tokens == [Token(dns.tokenizer.IDENTIFIER, 'foo'), - Token(dns.tokenizer.IDENTIFIER, 'bar'), - Token(dns.tokenizer.EOL, '\n')]) - def testMultiline3(self): - def bad(): - tok = dns.tokenizer.Tokenizer('foo)') - tokens = list(iter(tok)) - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testMultiline4(self): - def bad(): - tok = dns.tokenizer.Tokenizer('((foo)') - tokens = list(iter(tok)) - self.failUnlessRaises(dns.exception.SyntaxError, bad) - - def testUnget1(self): - tok = dns.tokenizer.Tokenizer('foo') - t1 = tok.get() - tok.unget(t1) - t2 = tok.get() - self.failUnless(t1 == t2 and t1.ttype == dns.tokenizer.IDENTIFIER and \ - t1.value == 'foo') - - def testUnget2(self): - def bad(): - tok = dns.tokenizer.Tokenizer('foo') - t1 = tok.get() - tok.unget(t1) - tok.unget(t1) - self.failUnlessRaises(dns.tokenizer.UngetBufferFull, bad) - - def testGetEOL1(self): - tok = dns.tokenizer.Tokenizer('\n') - t = tok.get_eol() - self.failUnless(t == '\n') - - def testGetEOL2(self): - tok = dns.tokenizer.Tokenizer('') - t = tok.get_eol() - self.failUnless(t == '') - - def testEscapedDelimiter1(self): - tok = dns.tokenizer.Tokenizer(r'ch\ ld') - t = tok.get() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\ ld') - - def testEscapedDelimiter2(self): - tok = dns.tokenizer.Tokenizer(r'ch\032ld') - t = tok.get() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\032ld') - - def testEscapedDelimiter3(self): - tok = dns.tokenizer.Tokenizer(r'ch\ild') - t = tok.get() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch\ild') - - def testEscapedDelimiter1u(self): - tok = dns.tokenizer.Tokenizer(r'ch\ ld') - t = tok.get().unescape() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'ch ld') - - def testEscapedDelimiter2u(self): - tok = dns.tokenizer.Tokenizer(r'ch\032ld') - t = tok.get().unescape() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == 'ch ld') - - def testEscapedDelimiter3u(self): - tok = dns.tokenizer.Tokenizer(r'ch\ild') - t = tok.get().unescape() - self.failUnless(t.ttype == dns.tokenizer.IDENTIFIER and t.value == r'child') - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/update.py dnspython-1.12.0/tests/update.py --- dnspython-1.11.1/tests/update.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/update.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,114 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import unittest - -import dns.update -import dns.rdata -import dns.rdataset - -goodhex = '0001 2800 0001 0005 0007 0000' \ - '076578616d706c6500 0006 0001' \ - '03666f6fc00c 00ff 00ff 00000000 0000' \ - 'c019 0001 00ff 00000000 0000' \ - '03626172c00c 0001 0001 00000000 0004 0a000005' \ - '05626c617a32c00c 00ff 00fe 00000000 0000' \ - 'c049 0001 00fe 00000000 0000' \ - 'c019 0001 00ff 00000000 0000' \ - 'c019 0001 0001 0000012c 0004 0a000001' \ - 'c019 0001 0001 0000012c 0004 0a000002' \ - 'c035 0001 0001 0000012c 0004 0a000003' \ - 'c035 0001 00fe 00000000 0004 0a000004' \ - '04626c617ac00c 0001 00ff 00000000 0000' \ - 'c049 00ff 00ff 00000000 0000' - -goodwire = goodhex.replace(' ', '').decode('hex_codec') - -update_text="""id 1 -opcode UPDATE -rcode NOERROR -;ZONE -example. IN SOA -;PREREQ -foo ANY ANY -foo ANY A -bar 0 IN A 10.0.0.5 -blaz2 NONE ANY -blaz2 NONE A -;UPDATE -foo ANY A -foo 300 IN A 10.0.0.1 -foo 300 IN A 10.0.0.2 -bar 300 IN A 10.0.0.3 -bar 0 NONE A 10.0.0.4 -blaz ANY A -blaz2 ANY ANY -""" - -class UpdateTestCase(unittest.TestCase): - - def test_to_wire1(self): - update = dns.update.Update('example') - update.id = 1 - update.present('foo') - update.present('foo', 'a') - update.present('bar', 'a', '10.0.0.5') - update.absent('blaz2') - update.absent('blaz2', 'a') - update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') - update.add('bar', 300, 'a', '10.0.0.3') - update.delete('bar', 'a', '10.0.0.4') - update.delete('blaz','a') - update.delete('blaz2') - self.failUnless(update.to_wire() == goodwire) - - def test_to_wire2(self): - update = dns.update.Update('example') - update.id = 1 - update.present('foo') - update.present('foo', 'a') - update.present('bar', 'a', '10.0.0.5') - update.absent('blaz2') - update.absent('blaz2', 'a') - update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') - update.add('bar', 300, dns.rdata.from_text(1, 1, '10.0.0.3')) - update.delete('bar', 'a', '10.0.0.4') - update.delete('blaz','a') - update.delete('blaz2') - self.failUnless(update.to_wire() == goodwire) - - def test_to_wire3(self): - update = dns.update.Update('example') - update.id = 1 - update.present('foo') - update.present('foo', 'a') - update.present('bar', 'a', '10.0.0.5') - update.absent('blaz2') - update.absent('blaz2', 'a') - update.replace('foo', 300, 'a', '10.0.0.1', '10.0.0.2') - update.add('bar', dns.rdataset.from_text(1, 1, 300, '10.0.0.3')) - update.delete('bar', 'a', '10.0.0.4') - update.delete('blaz','a') - update.delete('blaz2') - self.failUnless(update.to_wire() == goodwire) - - def test_from_text1(self): - update = dns.message.from_text(update_text) - w = update.to_wire(origin=dns.name.from_text('example'), - want_shuffle=False) - self.failUnless(w == goodwire) - -if __name__ == '__main__': - unittest.main() diff -Nru dnspython-1.11.1/tests/utest.py dnspython-1.12.0/tests/utest.py --- dnspython-1.11.1/tests/utest.py 1970-01-01 00:00:00.000000000 +0000 +++ dnspython-1.12.0/tests/utest.py 2014-05-31 18:04:19.000000000 +0000 @@ -0,0 +1,8 @@ +import os.path +import sys +import unittest + +if __name__ == '__main__': + sys.path.insert(0, os.path.realpath('..')) + suites = unittest.defaultTestLoader.discover('.') + unittest.TextTestRunner(verbosity=2).run(suites) diff -Nru dnspython-1.11.1/tests/zone.py dnspython-1.12.0/tests/zone.py --- dnspython-1.11.1/tests/zone.py 2011-07-09 14:05:21.000000000 +0000 +++ dnspython-1.12.0/tests/zone.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,389 +0,0 @@ -# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc. -# -# Permission to use, copy, modify, and distribute this software and its -# documentation for any purpose with or without fee is hereby granted, -# provided that the above copyright notice and this permission notice -# appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT -# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -import cStringIO -import filecmp -import os -import unittest - -import dns.exception -import dns.rdata -import dns.rdataclass -import dns.rdatatype -import dns.rrset -import dns.zone - -example_text = """$TTL 3600 -$ORIGIN example. -@ soa foo bar 1 2 3 4 5 -@ ns ns1 -@ ns ns2 -ns1 a 10.0.0.1 -ns2 a 10.0.0.2 -$TTL 300 -$ORIGIN foo.example. -bar mx 0 blaz -""" - -example_text_output = """@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.2 -""" - -something_quite_similar = """@ 3600 IN SOA foo bar 1 2 3 4 5 -@ 3600 IN NS ns1 -@ 3600 IN NS ns2 -bar.foo 300 IN MX 0 blaz.foo -ns1 3600 IN A 10.0.0.1 -ns2 3600 IN A 10.0.0.3 -""" - -something_different = """@ 3600 IN SOA fooa bar 1 2 3 4 5 -@ 3600 IN NS ns11 -@ 3600 IN NS ns21 -bar.fooa 300 IN MX 0 blaz.fooa -ns11 3600 IN A 10.0.0.11 -ns21 3600 IN A 10.0.0.21 -""" - -ttl_example_text = """$TTL 1h -$ORIGIN example. -@ soa foo bar 1 2 3 4 5 -@ ns ns1 -@ ns ns2 -ns1 1d1s a 10.0.0.1 -ns2 1w1D1h1m1S a 10.0.0.2 -""" - -no_soa_text = """$TTL 1h -$ORIGIN example. -@ ns ns1 -@ ns ns2 -ns1 1d1s a 10.0.0.1 -ns2 1w1D1h1m1S a 10.0.0.2 -""" - -no_ns_text = """$TTL 1h -$ORIGIN example. -@ soa foo bar 1 2 3 4 5 -""" - -include_text = """$INCLUDE "example" -""" - -bad_directive_text = """$FOO bar -$ORIGIN example. -@ soa foo bar 1 2 3 4 5 -@ ns ns1 -@ ns ns2 -ns1 1d1s a 10.0.0.1 -ns2 1w1D1h1m1S a 10.0.0.2 -""" - -_keep_output = False - -class ZoneTestCase(unittest.TestCase): - - def testFromFile1(self): - z = dns.zone.from_file('example', 'example') - ok = False - try: - z.to_file('example1.out', nl='\x0a') - ok = filecmp.cmp('example1.out', 'example1.good') - finally: - if not _keep_output: - os.unlink('example1.out') - self.failUnless(ok) - - def testFromFile2(self): - z = dns.zone.from_file('example', 'example', relativize=False) - ok = False - try: - z.to_file('example2.out', relativize=False, nl='\x0a') - ok = filecmp.cmp('example2.out', 'example2.good') - finally: - if not _keep_output: - os.unlink('example2.out') - self.failUnless(ok) - - def testFromText(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - f = cStringIO.StringIO() - names = z.nodes.keys() - names.sort() - for n in names: - print >> f, z[n].to_text(n) - self.failUnless(f.getvalue() == example_text_output) - - def testTorture1(self): - # - # Read a zone containing all our supported RR types, and - # for each RR in the zone, convert the rdata into wire format - # and then back out, and see if we get equal rdatas. - # - f = cStringIO.StringIO() - o = dns.name.from_text('example.') - z = dns.zone.from_file('example', o) - for (name, node) in z.iteritems(): - for rds in node: - for rd in rds: - f.seek(0) - f.truncate() - rd.to_wire(f, origin=o) - wire = f.getvalue() - rd2 = dns.rdata.from_wire(rds.rdclass, rds.rdtype, - wire, 0, len(wire), - origin = o) - self.failUnless(rd == rd2) - - def testEqual(self): - z1 = dns.zone.from_text(example_text, 'example.', relativize=True) - z2 = dns.zone.from_text(example_text_output, 'example.', - relativize=True) - self.failUnless(z1 == z2) - - def testNotEqual1(self): - z1 = dns.zone.from_text(example_text, 'example.', relativize=True) - z2 = dns.zone.from_text(something_quite_similar, 'example.', - relativize=True) - self.failUnless(z1 != z2) - - def testNotEqual2(self): - z1 = dns.zone.from_text(example_text, 'example.', relativize=True) - z2 = dns.zone.from_text(something_different, 'example.', - relativize=True) - self.failUnless(z1 != z2) - - def testNotEqual3(self): - z1 = dns.zone.from_text(example_text, 'example.', relativize=True) - z2 = dns.zone.from_text(something_different, 'example2.', - relativize=True) - self.failUnless(z1 != z2) - - def testFindRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rds = z.find_rdataset('@', 'soa') - exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') - self.failUnless(rds == exrds) - - def testFindRdataset2(self): - def bad(): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rds = z.find_rdataset('@', 'loc') - self.failUnlessRaises(KeyError, bad) - - def testFindRRset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rrs = z.find_rrset('@', 'soa') - exrrs = dns.rrset.from_text('@', 300, 'IN', 'SOA', 'foo bar 1 2 3 4 5') - self.failUnless(rrs == exrrs) - - def testFindRRset2(self): - def bad(): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rrs = z.find_rrset('@', 'loc') - self.failUnlessRaises(KeyError, bad) - - def testGetRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rds = z.get_rdataset('@', 'soa') - exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') - self.failUnless(rds == exrds) - - def testGetRdataset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rds = z.get_rdataset('@', 'loc') - self.failUnless(rds == None) - - def testGetRRset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rrs = z.get_rrset('@', 'soa') - exrrs = dns.rrset.from_text('@', 300, 'IN', 'SOA', 'foo bar 1 2 3 4 5') - self.failUnless(rrs == exrrs) - - def testGetRRset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rrs = z.get_rrset('@', 'loc') - self.failUnless(rrs == None) - - def testReplaceRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rdataset = dns.rdataset.from_text('in', 'ns', 300, 'ns3', 'ns4') - z.replace_rdataset('@', rdataset) - rds = z.get_rdataset('@', 'ns') - self.failUnless(rds is rdataset) - - def testReplaceRdataset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - rdataset = dns.rdataset.from_text('in', 'txt', 300, '"foo"') - z.replace_rdataset('@', rdataset) - rds = z.get_rdataset('@', 'txt') - self.failUnless(rds is rdataset) - - def testDeleteRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - z.delete_rdataset('@', 'ns') - rds = z.get_rdataset('@', 'ns') - self.failUnless(rds is None) - - def testDeleteRdataset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - z.delete_rdataset('ns1', 'a') - node = z.get_node('ns1') - self.failUnless(node is None) - - def testNodeFindRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) - exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') - self.failUnless(rds == exrds) - - def testNodeFindRdataset2(self): - def bad(): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.find_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) - self.failUnlessRaises(KeyError, bad) - - def testNodeGetRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) - exrds = dns.rdataset.from_text('IN', 'SOA', 300, 'foo bar 1 2 3 4 5') - self.failUnless(rds == exrds) - - def testNodeGetRdataset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) - self.failUnless(rds == None) - - def testNodeDeleteRdataset1(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.delete_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) - rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) - self.failUnless(rds == None) - - def testNodeDeleteRdataset2(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - node = z['@'] - rds = node.delete_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) - rds = node.get_rdataset(dns.rdataclass.IN, dns.rdatatype.LOC) - self.failUnless(rds == None) - - def testIterateRdatasets(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - ns = [n for n, r in z.iterate_rdatasets('A')] - ns.sort() - self.failUnless(ns == [dns.name.from_text('ns1', None), - dns.name.from_text('ns2', None)]) - - def testIterateAllRdatasets(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - ns = [n for n, r in z.iterate_rdatasets()] - ns.sort() - self.failUnless(ns == [dns.name.from_text('@', None), - dns.name.from_text('@', None), - dns.name.from_text('bar.foo', None), - dns.name.from_text('ns1', None), - dns.name.from_text('ns2', None)]) - - def testIterateRdatas(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - l = list(z.iterate_rdatas('A')) - l.sort() - exl = [(dns.name.from_text('ns1', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2'))] - self.failUnless(l == exl) - - def testIterateAllRdatas(self): - z = dns.zone.from_text(example_text, 'example.', relativize=True) - l = list(z.iterate_rdatas()) - l.sort() - exl = [(dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns1')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.NS, - 'ns2')), - (dns.name.from_text('@', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.SOA, - 'foo bar 1 2 3 4 5')), - (dns.name.from_text('bar.foo', None), - 300, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX, - '0 blaz.foo')), - (dns.name.from_text('ns1', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.1')), - (dns.name.from_text('ns2', None), - 3600, - dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.A, - '10.0.0.2'))] - self.failUnless(l == exl) - - def testTTLs(self): - z = dns.zone.from_text(ttl_example_text, 'example.', relativize=True) - n = z['@'] - rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.SOA) - self.failUnless(rds.ttl == 3600) - n = z['ns1'] - rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) - self.failUnless(rds.ttl == 86401) - n = z['ns2'] - rds = n.get_rdataset(dns.rdataclass.IN, dns.rdatatype.A) - self.failUnless(rds.ttl == 694861) - - def testNoSOA(self): - def bad(): - z = dns.zone.from_text(no_soa_text, 'example.', - relativize=True) - self.failUnlessRaises(dns.zone.NoSOA, bad) - - def testNoNS(self): - def bad(): - z = dns.zone.from_text(no_ns_text, 'example.', - relativize=True) - self.failUnlessRaises(dns.zone.NoNS, bad) - - def testInclude(self): - z1 = dns.zone.from_text(include_text, 'example.', relativize=True, - allow_include=True) - z2 = dns.zone.from_file('example', 'example.', relativize=True) - self.failUnless(z1 == z2) - - def testBadDirective(self): - def bad(): - z = dns.zone.from_text(bad_directive_text, 'example.', - relativize=True) - self.failUnlessRaises(dns.exception.SyntaxError, bad) - -if __name__ == '__main__': - unittest.main()