summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_uuid.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-17 17:36:44 (GMT)
committerGitHub <noreply@github.com>2020-03-17 17:36:44 (GMT)
commitebf6bb9f5ef032d1646b418ebbb645ea0b217da6 (patch)
treed6573ddced3ee130edab9765eb87a4283bfd1a1a /Lib/test/test_uuid.py
parent5b1ef200d31a74a9b478d0217d73ed0a659a8a06 (diff)
downloadcpython-ebf6bb9f5ef032d1646b418ebbb645ea0b217da6.zip
cpython-ebf6bb9f5ef032d1646b418ebbb645ea0b217da6.tar.gz
cpython-ebf6bb9f5ef032d1646b418ebbb645ea0b217da6.tar.bz2
bpo-39991: Enhance uuid parser for MAC address (GH-19045)
Reject valid IPv6 addresses which doesn't contain "::" but have a length of 17 characters.
Diffstat (limited to 'Lib/test/test_uuid.py')
-rw-r--r--Lib/test/test_uuid.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/test/test_uuid.py b/Lib/test/test_uuid.py
index 3b013a8..27fc56d 100644
--- a/Lib/test/test_uuid.py
+++ b/Lib/test/test_uuid.py
@@ -679,6 +679,58 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
class BaseTestInternals:
_uuid = py_uuid
+ def check_parse_mac(self, aix):
+ if not aix:
+ patch = mock.patch.multiple(self.uuid,
+ _MAC_DELIM=b':',
+ _MAC_OMITS_LEADING_ZEROES=False)
+ else:
+ patch = mock.patch.multiple(self.uuid,
+ _MAC_DELIM=b'.',
+ _MAC_OMITS_LEADING_ZEROES=True)
+
+ with patch:
+ # Valid MAC addresses
+ if not aix:
+ tests = (
+ (b'52:54:00:9d:0e:67', 0x5254009d0e67),
+ (b'12:34:56:78:90:ab', 0x1234567890ab),
+ )
+ else:
+ # AIX format
+ tests = (
+ (b'fe.ad.c.1.23.4', 0xfead0c012304),
+ )
+ for mac, expected in tests:
+ self.assertEqual(self.uuid._parse_mac(mac), expected)
+
+ # Invalid MAC addresses
+ for mac in (
+ b'',
+ # IPv6 addresses with same length than valid MAC address
+ # (17 characters)
+ b'fe80::5054:ff:fe9',
+ b'123:2:3:4:5:6:7:8',
+ # empty 5rd field
+ b'52:54:00:9d::67',
+ # only 5 fields instead of 6
+ b'52:54:00:9d:0e'
+ # invalid character 'x'
+ b'52:54:00:9d:0e:6x'
+ # dash separator
+ b'52-54-00-9d-0e-67',
+ ):
+ if aix:
+ mac = mac.replace(b':', b'.')
+ with self.subTest(mac=mac):
+ self.assertIsNone(self.uuid._parse_mac(mac))
+
+ def test_parse_mac(self):
+ self.check_parse_mac(False)
+
+ def test_parse_mac_aix(self):
+ self.check_parse_mac(True)
+
def test_find_under_heading(self):
data = '''\
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll