@@ -287,6 +287,39 @@ def test_getnode(self):
287287 node2 = uuid .getnode ()
288288 self .assertEqual (node1 , node2 , '%012x != %012x' % (node1 , node2 ))
289289
290+ # bpo-32502: UUID1 requires a 48-bit identifier, but hardware identifiers
291+ # need not necessarily be 48 bits (e.g., EUI-64).
292+ def test_uuid1_eui64 (self ):
293+ # Confirm that uuid.getnode ignores hardware addresses larger than 48
294+ # bits. Mock out each platform's *_getnode helper functions to return
295+ # something just larger than 48 bits to test. This will cause
296+ # uuid.getnode to fall back on uuid._random_getnode, which will
297+ # generate a valid value.
298+ too_large_getter = lambda : 1 << 48
299+
300+ uuid_real__node = uuid ._node
301+ uuid_real__NODE_GETTERS_WIN32 = uuid ._NODE_GETTERS_WIN32
302+ uuid_real__NODE_GETTERS_UNIX = uuid ._NODE_GETTERS_UNIX
303+ uuid ._node = None
304+ uuid ._NODE_GETTERS_WIN32 = [too_large_getter ]
305+ uuid ._NODE_GETTERS_UNIX = [too_large_getter ]
306+ try :
307+ node = uuid .getnode ()
308+ finally :
309+ uuid ._node = uuid_real__node
310+ uuid ._NODE_GETTERS_WIN32 = uuid_real__NODE_GETTERS_WIN32
311+ uuid ._NODE_GETTERS_UNIX = uuid_real__NODE_GETTERS_UNIX
312+
313+ self .assertTrue (0 < node < (1 << 48 ), '%012x' % node )
314+
315+ # Confirm that uuid1 can use the generated node, i.e., the that
316+ # uuid.getnode fell back on uuid._random_getnode() rather than using
317+ # the value from too_large_getter above.
318+ try :
319+ uuid .uuid1 (node = node )
320+ except ValueError as e :
321+ self .fail ('uuid1 was given an invalid node ID' )
322+
290323 @unittest .skipUnless (importable ('ctypes' ), 'requires ctypes' )
291324 def test_uuid1 (self ):
292325 equal = self .assertEqual
0 commit comments