@@ -23,6 +23,12 @@ def importable(name):
23
23
return False
24
24
25
25
26
+ def mock_get_command_stdout (data ):
27
+ def get_command_stdout (command , args ):
28
+ return io .BytesIO (data .encode ())
29
+ return get_command_stdout
30
+
31
+
26
32
class BaseTestUUID :
27
33
uuid = None
28
34
@@ -673,7 +679,6 @@ class TestUUIDWithExtModule(BaseTestUUID, unittest.TestCase):
673
679
class BaseTestInternals :
674
680
_uuid = py_uuid
675
681
676
-
677
682
def test_find_under_heading (self ):
678
683
data = '''\
679
684
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll
@@ -685,15 +690,12 @@ def test_find_under_heading(self):
685
690
224.0.0.1
686
691
'''
687
692
688
- def mock_get_command_stdout (command , args ):
689
- return io .BytesIO (data .encode ())
690
-
691
693
# The above data is from AIX - with '.' as _MAC_DELIM and strings
692
694
# shorter than 17 bytes (no leading 0). (_MAC_OMITS_LEADING_ZEROES=True)
693
695
with mock .patch .multiple (self .uuid ,
694
696
_MAC_DELIM = b'.' ,
695
697
_MAC_OMITS_LEADING_ZEROES = True ,
696
- _get_command_stdout = mock_get_command_stdout ):
698
+ _get_command_stdout = mock_get_command_stdout ( data ) ):
697
699
mac = self .uuid ._find_mac_under_heading (
698
700
command = 'netstat' ,
699
701
args = '-ian' ,
@@ -702,6 +704,43 @@ def mock_get_command_stdout(command, args):
702
704
703
705
self .assertEqual (mac , 0xfead0c012304 )
704
706
707
+ def test_find_under_heading_ipv6 (self ):
708
+ # bpo-39991: IPv6 address "fe80::5054:ff:fe9" looks like a MAC address
709
+ # (same string length) but must be skipped
710
+ data = '''\
711
+ Name Mtu Network Address Ipkts Ierrs Idrop Opkts Oerrs Coll
712
+ vtnet 1500 <Link#1> 52:54:00:9d:0e:67 10017 0 0 8174 0 0
713
+ vtnet - fe80::%vtnet0 fe80::5054:ff:fe9 0 - - 4 - -
714
+ vtnet - 192.168.122.0 192.168.122.45 8844 - - 8171 - -
715
+ lo0 16384 <Link#2> lo0 260148 0 0 260148 0 0
716
+ lo0 - ::1/128 ::1 193 - - 193 - -
717
+ ff01::1%lo0
718
+ ff02::2:2eb7:74fa
719
+ ff02::2:ff2e:b774
720
+ ff02::1%lo0
721
+ ff02::1:ff00:1%lo
722
+ lo0 - fe80::%lo0/64 fe80::1%lo0 0 - - 0 - -
723
+ ff01::1%lo0
724
+ ff02::2:2eb7:74fa
725
+ ff02::2:ff2e:b774
726
+ ff02::1%lo0
727
+ ff02::1:ff00:1%lo
728
+ lo0 - 127.0.0.0/8 127.0.0.1 259955 - - 259955 - -
729
+ 224.0.0.1
730
+ '''
731
+
732
+ with mock .patch .multiple (self .uuid ,
733
+ _MAC_DELIM = b':' ,
734
+ _MAC_OMITS_LEADING_ZEROES = False ,
735
+ _get_command_stdout = mock_get_command_stdout (data )):
736
+ mac = self .uuid ._find_mac_under_heading (
737
+ command = 'netstat' ,
738
+ args = '-ian' ,
739
+ heading = b'Address' ,
740
+ )
741
+
742
+ self .assertEqual (mac , 0x5254009d0e67 )
743
+
705
744
def test_find_mac_near_keyword (self ):
706
745
# key and value are on the same line
707
746
data = '''
@@ -710,14 +749,11 @@ def test_find_mac_near_keyword(self):
710
749
eth0 Link encap:Ethernet HWaddr 12:34:56:78:90:ab
711
750
'''
712
751
713
- def mock_get_command_stdout (command , args ):
714
- return io .BytesIO (data .encode ())
715
-
716
752
# The above data will only be parsed properly on non-AIX unixes.
717
753
with mock .patch .multiple (self .uuid ,
718
754
_MAC_DELIM = b':' ,
719
755
_MAC_OMITS_LEADING_ZEROES = False ,
720
- _get_command_stdout = mock_get_command_stdout ):
756
+ _get_command_stdout = mock_get_command_stdout ( data ) ):
721
757
mac = self .uuid ._find_mac_near_keyword (
722
758
command = 'ifconfig' ,
723
759
args = '' ,
0 commit comments