bpo-32502: Discard 64-bit (and other invalid) hardware addresses (#5254)

This commit is contained in:
Bo Bayles 2018-01-23 19:11:44 -06:00 committed by Barry Warsaw
parent 0bad4d63c6
commit 6b273f7f40
3 changed files with 38 additions and 6 deletions

View file

@ -311,6 +311,32 @@ class BaseTestUUID:
node2 = self.uuid.getnode()
self.assertEqual(node1, node2, '%012x != %012x' % (node1, node2))
# bpo-32502: UUID1 requires a 48-bit identifier, but hardware identifiers
# need not necessarily be 48 bits (e.g., EUI-64).
def test_uuid1_eui64(self):
# Confirm that uuid.getnode ignores hardware addresses larger than 48
# bits. Mock out each platform's *_getnode helper functions to return
# something just larger than 48 bits to test. This will cause
# uuid.getnode to fall back on uuid._random_getnode, which will
# generate a valid value.
too_large_getter = lambda: 1 << 48
with unittest.mock.patch.multiple(
self.uuid,
_node=None, # Ignore any cached node value.
_NODE_GETTERS_WIN32=[too_large_getter],
_NODE_GETTERS_UNIX=[too_large_getter],
):
node = self.uuid.getnode()
self.assertTrue(0 < node < (1 << 48), '%012x' % node)
# Confirm that uuid1 can use the generated node, i.e., the that
# uuid.getnode fell back on uuid._random_getnode() rather than using
# the value from too_large_getter above.
try:
self.uuid.uuid1(node=node)
except ValueError as e:
self.fail('uuid1 was given an invalid node ID')
def test_uuid1(self):
equal = self.assertEqual