[3.13] gh-123409: fix IPv6Address.reverse_pointer for IPv4-mapped addresses (GH-123419) (#123606)

gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped addresses (GH-123419)

Fix functionality that was broken with better textual representation for IPv4-mapped addresses (gh-87799)
(cherry picked from commit 77a2fb4bf1)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-09-03 01:19:46 +02:00 committed by GitHub
parent f8124237e7
commit 7761ddcfed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 12 deletions

View file

@ -2585,12 +2585,42 @@ class IpaddrUnitTest(unittest.TestCase):
self.assertEqual('192.168.178.1', addr4.exploded)
def testReversePointer(self):
addr1 = ipaddress.IPv4Address('127.0.0.1')
addr2 = ipaddress.IPv6Address('2001:db8::1')
self.assertEqual('1.0.0.127.in-addr.arpa', addr1.reverse_pointer)
self.assertEqual('1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.' +
'b.d.0.1.0.0.2.ip6.arpa',
addr2.reverse_pointer)
for addr_v4, expected in [
('127.0.0.1', '1.0.0.127.in-addr.arpa'),
# test vector: https://www.rfc-editor.org/rfc/rfc1035, §3.5
('10.2.0.52', '52.0.2.10.in-addr.arpa'),
]:
with self.subTest('ipv4_reverse_pointer', addr=addr_v4):
addr = ipaddress.IPv4Address(addr_v4)
self.assertEqual(addr.reverse_pointer, expected)
for addr_v6, expected in [
(
'2001:db8::1', (
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.'
'ip6.arpa'
)
),
(
'::FFFF:192.168.1.35', (
'3.2.1.0.8.a.0.c.f.f.f.f.0.0.0.0.'
'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'ip6.arpa'
)
),
# test vector: https://www.rfc-editor.org/rfc/rfc3596, §2.5
(
'4321:0:1:2:3:4:567:89ab', (
'b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.'
'2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.'
'ip6.arpa'
)
)
]:
with self.subTest('ipv6_reverse_pointer', addr=addr_v6):
addr = ipaddress.IPv6Address(addr_v6)
self.assertEqual(addr.reverse_pointer, expected)
def testIntRepresentation(self):
self.assertEqual(16909060, int(self.ipv4_address))