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