@@ -304,6 +304,32 @@ def test_getnode(self):
304304 node2 = uuid .getnode ()
305305 self .assertEqual (node1 , node2 , '%012x != %012x' % (node1 , node2 ))
306306
307+ # bpo-32502: UUID1 requires a 48-bit identifier, but hardware identifiers
308+ # need not necessarily be 48 bits (e.g., EUI-64).
309+ def test_uuid1_eui64 (self ):
310+ # Confirm that uuid.getnode ignores hardware addresses larger than 48
311+ # bits. Mock out each platform's *_getnode helper functions to return
312+ # something just larger than 48 bits to test. This will cause
313+ # uuid.getnode to fall back on uuid._random_getnode, which will
314+ # generate a valid value.
315+ too_large_getter = lambda : 1 << 48
316+ with unittest .mock .patch .multiple (
317+ uuid ,
318+ _node = None , # Ignore any cached node value.
319+ _NODE_GETTERS_WIN32 = [too_large_getter ],
320+ _NODE_GETTERS_UNIX = [too_large_getter ],
321+ ):
322+ node = uuid .getnode ()
323+ self .assertTrue (0 < node < (1 << 48 ), '%012x' % node )
324+
325+ # Confirm that uuid1 can use the generated node, i.e., the that
326+ # uuid.getnode fell back on uuid._random_getnode() rather than using
327+ # the value from too_large_getter above.
328+ try :
329+ uuid .uuid1 (node = node )
330+ except ValueError as e :
331+ self .fail ('uuid1 was given an invalid node ID' )
332+
307333 @unittest .skipUnless (importable ('ctypes' ), 'requires ctypes' )
308334 def test_uuid1 (self ):
309335 equal = self .assertEqual
0 commit comments