@@ -2656,6 +2656,8 @@ def testBadL2capAddr(self):
26562656 f .bind (socket .BDADDR_ANY )
26572657 with self .assertRaises (OSError ):
26582658 f .bind ((socket .BDADDR_ANY .encode (), 0x1001 ))
2659+ with self .assertRaises (OSError ):
2660+ f .bind (('\ud812 ' , 0x1001 ))
26592661
26602662 def testBindRfcommSocket (self ):
26612663 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_STREAM , socket .BTPROTO_RFCOMM ) as s :
@@ -2687,14 +2689,16 @@ def testBadRfcommAddr(self):
26872689 s .bind ((socket .BDADDR_ANY , channel , 0 ))
26882690 with self .assertRaises (OSError ):
26892691 s .bind ((socket .BDADDR_ANY + '\0 ' , channel ))
2692+ with self .assertRaises (OSError ):
2693+ s .bind ('\ud812 ' )
26902694 with self .assertRaises (OSError ):
26912695 s .bind (('invalid' , channel ))
26922696
26932697 @unittest .skipUnless (hasattr (socket , 'BTPROTO_HCI' ), 'Bluetooth HCI sockets required for this test' )
26942698 def testBindHciSocket (self ):
26952699 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
26962700 if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
2697- s .bind (socket .BDADDR_ANY . encode () )
2701+ s .bind (socket .BDADDR_ANY )
26982702 addr = s .getsockname ()
26992703 self .assertEqual (addr , socket .BDADDR_ANY )
27002704 else :
@@ -2713,14 +2717,17 @@ def testBadHciAddr(self):
27132717 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
27142718 if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
27152719 with self .assertRaises (OSError ):
2716- s .bind (socket .BDADDR_ANY )
2720+ s .bind (socket .BDADDR_ANY . encode () )
27172721 with self .assertRaises (OSError ):
2718- s .bind ((socket .BDADDR_ANY .encode (),))
2719- if sys .platform .startswith ('freebsd' ):
2720- with self .assertRaises (ValueError ):
2721- s .bind (socket .BDADDR_ANY .encode () + b'\0 ' )
2722- with self .assertRaises (ValueError ):
2723- s .bind (socket .BDADDR_ANY .encode () + b' ' * 100 )
2722+ s .bind ((socket .BDADDR_ANY ,))
2723+ with self .assertRaises (OSError ):
2724+ s .bind (socket .BDADDR_ANY + '\0 ' )
2725+ with self .assertRaises ((ValueError , OSError )):
2726+ s .bind (socket .BDADDR_ANY + ' ' * 100 )
2727+ with self .assertRaises (OSError ):
2728+ s .bind ('\ud812 ' )
2729+ with self .assertRaises (OSError ):
2730+ s .bind ('invalid' )
27242731 with self .assertRaises (OSError ):
27252732 s .bind (b'invalid' )
27262733 else :
@@ -2731,11 +2738,18 @@ def testBadHciAddr(self):
27312738 s .bind ((dev , 0 ))
27322739 with self .assertRaises (OSError ):
27332740 s .bind (dev )
2741+ with self .assertRaises (OSError ):
2742+ s .bind (socket .BDADDR_ANY )
27342743 with self .assertRaises (OSError ):
27352744 s .bind (socket .BDADDR_ANY .encode ())
27362745
27372746 @unittest .skipUnless (hasattr (socket , 'BTPROTO_SCO' ), 'Bluetooth SCO sockets required for this test' )
27382747 def testBindScoSocket (self ):
2748+ with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
2749+ s .bind (socket .BDADDR_ANY )
2750+ addr = s .getsockname ()
2751+ self .assertEqual (addr , socket .BDADDR_ANY )
2752+
27392753 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
27402754 s .bind (socket .BDADDR_ANY .encode ())
27412755 addr = s .getsockname ()
@@ -2745,9 +2759,17 @@ def testBindScoSocket(self):
27452759 def testBadScoAddr (self ):
27462760 with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
27472761 with self .assertRaises (OSError ):
2748- s .bind (socket .BDADDR_ANY )
2762+ s .bind (( socket .BDADDR_ANY ,) )
27492763 with self .assertRaises (OSError ):
27502764 s .bind ((socket .BDADDR_ANY .encode (),))
2765+ with self .assertRaises (ValueError ):
2766+ s .bind (socket .BDADDR_ANY + '\0 ' )
2767+ with self .assertRaises (ValueError ):
2768+ s .bind (socket .BDADDR_ANY .encode () + b'\0 ' )
2769+ with self .assertRaises (UnicodeEncodeError ):
2770+ s .bind ('\ud812 ' )
2771+ with self .assertRaises (OSError ):
2772+ s .bind ('invalid' )
27512773 with self .assertRaises (OSError ):
27522774 s .bind (b'invalid' )
27532775
0 commit comments