From: Peter van Dijk Date: Tue, 17 Nov 2020 09:57:45 +0000 (+0100) Subject: auth-py tests: py3 X-Git-Tag: auth-4.4.0-beta1~9^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F9712%2Fhead;p=thirdparty%2Fpdns.git auth-py tests: py3 --- diff --git a/regression-tests.auth-py/clientsubnetoption.py b/regression-tests.auth-py/clientsubnetoption.py index c4f78f25d2..5da748ab0b 100644 --- a/regression-tests.auth-py/clientsubnetoption.py +++ b/regression-tests.auth-py/clientsubnetoption.py @@ -35,6 +35,7 @@ Requirements: from __future__ import print_function from __future__ import division +import math import socket import struct import dns @@ -125,7 +126,7 @@ class ClientSubnetOption(dns.edns.Option): """" Determines whether this instance is using the draft option code """ return self.option == DRAFT_OPTION_CODE - def to_wire(self, file): + def to_wire(self, file=None): """Create EDNS packet as defined in draft-vandergaast-edns-client-subnet-01.""" ip = self.calculate_ip() @@ -142,7 +143,10 @@ class ClientSubnetOption(dns.edns.Option): format = "!HBB%ds" % (mask_bits // 8) data = struct.pack(format, self.family, self.mask, self.scope, test) - file.write(data) + if file: + file.write(data) + else: + return data def from_wire(cls, otype, wire, current, olen): """Read EDNS packet as defined in draft-vandergaast-edns-client-subnet-01. @@ -173,6 +177,23 @@ class ClientSubnetOption(dns.edns.Option): from_wire = classmethod(from_wire) + # needed in 2.0.0.. + @classmethod + def from_wire_parser(cls, otype, parser): + family, src, scope = parser.get_struct('!HBB') + addrlen = int(math.ceil(src / 8.0)) + prefix = parser.get_bytes(addrlen) + if family == 1: + pad = 4 - addrlen + addr = dns.ipv4.inet_ntoa(prefix + b'\x00' * pad) + elif family == 2: + pad = 16 - addrlen + addr = dns.ipv6.inet_ntoa(prefix + b'\x00' * pad) + else: + raise ValueError('unsupported family') + + return cls(addr, src, scope, otype) + def __repr__(self): if self.family == FAMILY_IPV4: ip = socket.inet_ntop(socket.AF_INET, struct.pack('!L', self.ip)) @@ -189,6 +210,9 @@ class ClientSubnetOption(dns.edns.Option): self.scope ) + def to_text(self): + return self.__repr__() + def __eq__(self, other): """Rich comparison method for equality. diff --git a/regression-tests.auth-py/requirements.txt b/regression-tests.auth-py/requirements.txt index 27efa32341..6f6ac0bab0 100644 --- a/regression-tests.auth-py/requirements.txt +++ b/regression-tests.auth-py/requirements.txt @@ -2,4 +2,4 @@ dnspython>=1.11 nose>=1.3.7 Twisted>0.15.0 requests>=2.18.4 -git+https://github.com/PowerDNS/xfrserver.git@0.2 +git+https://github.com/PowerDNS/xfrserver.git@0.3 diff --git a/regression-tests.auth-py/test_IXFR.py b/regression-tests.auth-py/test_IXFR.py index 0970d92321..fa8c850822 100644 --- a/regression-tests.auth-py/test_IXFR.py +++ b/regression-tests.auth-py/test_IXFR.py @@ -239,6 +239,6 @@ newrecord.example. 8484 A 192.0.2.42 ret = subprocess.check_output([os.environ['PDNSUTIL'], '--config-dir=configs/auth', 'list-zone', 'example'], stderr=subprocess.STDOUT) - rets = ret.split('\n') + rets = ret.split(b'\n') - self.assertEqual(1, sum('SOA' in l for l in ret.split('\n'))) \ No newline at end of file + self.assertEqual(1, sum(b'SOA' in l for l in ret.split(b'\n'))) \ No newline at end of file