@@ -2681,6 +2681,8 @@ def testBadL2capAddr(self):
26812681 f .bind (socket .BDADDR_ANY )
26822682 with self .assertRaises (OSError ):
26832683 f .bind ((socket .BDADDR_ANY .encode (), 0x1001 ))
2684+ with self .assertRaises (OSError ):
2685+ f .bind (('\ud812 ' , 0x1001 ))
26842686
26852687 def testBindRfcommSocket (self ):
26862688 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_STREAM , socket .BTPROTO_RFCOMM ) as s :
@@ -2712,14 +2714,16 @@ def testBadRfcommAddr(self):
27122714 s .bind ((socket .BDADDR_ANY , channel , 0 ))
27132715 with self .assertRaises (OSError ):
27142716 s .bind ((socket .BDADDR_ANY + '\0 ' , channel ))
2717+ with self .assertRaises (OSError ):
2718+ s .bind ('\ud812 ' )
27152719 with self .assertRaises (OSError ):
27162720 s .bind (('invalid' , channel ))
27172721
27182722 @unittest .skipUnless (hasattr (socket , 'BTPROTO_HCI' ), 'Bluetooth HCI sockets required for this test' )
27192723 def testBindHciSocket (self ):
27202724 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
27212725 if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
2722- s .bind (socket .BDADDR_ANY . encode () )
2726+ s .bind (socket .BDADDR_ANY )
27232727 addr = s .getsockname ()
27242728 self .assertEqual (addr , socket .BDADDR_ANY )
27252729 else :
@@ -2738,14 +2742,17 @@ def testBadHciAddr(self):
27382742 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
27392743 if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
27402744 with self .assertRaises (OSError ):
2741- s .bind (socket .BDADDR_ANY )
2745+ s .bind (socket .BDADDR_ANY . encode () )
27422746 with self .assertRaises (OSError ):
2743- s .bind ((socket .BDADDR_ANY .encode (),))
2744- if sys .platform .startswith ('freebsd' ):
2745- with self .assertRaises (ValueError ):
2746- s .bind (socket .BDADDR_ANY .encode () + b'\0 ' )
2747- with self .assertRaises (ValueError ):
2748- s .bind (socket .BDADDR_ANY .encode () + b' ' * 100 )
2747+ s .bind ((socket .BDADDR_ANY ,))
2748+ with self .assertRaises (OSError ):
2749+ s .bind (socket .BDADDR_ANY + '\0 ' )
2750+ with self .assertRaises ((ValueError , OSError )):
2751+ s .bind (socket .BDADDR_ANY + ' ' * 100 )
2752+ with self .assertRaises (OSError ):
2753+ s .bind ('\ud812 ' )
2754+ with self .assertRaises (OSError ):
2755+ s .bind ('invalid' )
27492756 with self .assertRaises (OSError ):
27502757 s .bind (b'invalid' )
27512758 else :
@@ -2756,11 +2763,18 @@ def testBadHciAddr(self):
27562763 s .bind ((dev , 0 ))
27572764 with self .assertRaises (OSError ):
27582765 s .bind (dev )
2766+ with self .assertRaises (OSError ):
2767+ s .bind (socket .BDADDR_ANY )
27592768 with self .assertRaises (OSError ):
27602769 s .bind (socket .BDADDR_ANY .encode ())
27612770
27622771 @unittest .skipUnless (hasattr (socket , 'BTPROTO_SCO' ), 'Bluetooth SCO sockets required for this test' )
27632772 def testBindScoSocket (self ):
2773+ with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
2774+ s .bind (socket .BDADDR_ANY )
2775+ addr = s .getsockname ()
2776+ self .assertEqual (addr , socket .BDADDR_ANY )
2777+
27642778 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
27652779 s .bind (socket .BDADDR_ANY .encode ())
27662780 addr = s .getsockname ()
@@ -2770,9 +2784,17 @@ def testBindScoSocket(self):
27702784 def testBadScoAddr (self ):
27712785 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
27722786 with self .assertRaises (OSError ):
2773- s .bind (socket .BDADDR_ANY )
2787+ s .bind (( socket .BDADDR_ANY ,) )
27742788 with self .assertRaises (OSError ):
27752789 s .bind ((socket .BDADDR_ANY .encode (),))
2790+ with self .assertRaises (ValueError ):
2791+ s .bind (socket .BDADDR_ANY + '\0 ' )
2792+ with self .assertRaises (ValueError ):
2793+ s .bind (socket .BDADDR_ANY .encode () + b'\0 ' )
2794+ with self .assertRaises (UnicodeEncodeError ):
2795+ s .bind ('\ud812 ' )
2796+ with self .assertRaises (OSError ):
2797+ s .bind ('invalid' )
27762798 with self .assertRaises (OSError ):
27772799 s .bind (b'invalid' )
27782800
0 commit comments