@@ -2656,6 +2656,8 @@ def testBadL2capAddr(self):
2656
2656
f .bind (socket .BDADDR_ANY )
2657
2657
with self .assertRaises (OSError ):
2658
2658
f .bind ((socket .BDADDR_ANY .encode (), 0x1001 ))
2659
+ with self .assertRaises (OSError ):
2660
+ f .bind (('\ud812 ' , 0x1001 ))
2659
2661
2660
2662
def testBindRfcommSocket (self ):
2661
2663
with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_STREAM , socket .BTPROTO_RFCOMM ) as s :
@@ -2687,14 +2689,16 @@ def testBadRfcommAddr(self):
2687
2689
s .bind ((socket .BDADDR_ANY , channel , 0 ))
2688
2690
with self .assertRaises (OSError ):
2689
2691
s .bind ((socket .BDADDR_ANY + '\0 ' , channel ))
2692
+ with self .assertRaises (OSError ):
2693
+ s .bind ('\ud812 ' )
2690
2694
with self .assertRaises (OSError ):
2691
2695
s .bind (('invalid' , channel ))
2692
2696
2693
2697
@unittest .skipUnless (hasattr (socket , 'BTPROTO_HCI' ), 'Bluetooth HCI sockets required for this test' )
2694
2698
def testBindHciSocket (self ):
2695
2699
with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
2696
2700
if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
2697
- s .bind (socket .BDADDR_ANY . encode () )
2701
+ s .bind (socket .BDADDR_ANY )
2698
2702
addr = s .getsockname ()
2699
2703
self .assertEqual (addr , socket .BDADDR_ANY )
2700
2704
else :
@@ -2713,14 +2717,17 @@ def testBadHciAddr(self):
2713
2717
with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_RAW , socket .BTPROTO_HCI ) as s :
2714
2718
if sys .platform .startswith (('netbsd' , 'dragonfly' , 'freebsd' )):
2715
2719
with self .assertRaises (OSError ):
2716
- s .bind (socket .BDADDR_ANY )
2720
+ s .bind (socket .BDADDR_ANY . encode () )
2717
2721
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' )
2724
2731
with self .assertRaises (OSError ):
2725
2732
s .bind (b'invalid' )
2726
2733
else :
@@ -2731,11 +2738,18 @@ def testBadHciAddr(self):
2731
2738
s .bind ((dev , 0 ))
2732
2739
with self .assertRaises (OSError ):
2733
2740
s .bind (dev )
2741
+ with self .assertRaises (OSError ):
2742
+ s .bind (socket .BDADDR_ANY )
2734
2743
with self .assertRaises (OSError ):
2735
2744
s .bind (socket .BDADDR_ANY .encode ())
2736
2745
2737
2746
@unittest .skipUnless (hasattr (socket , 'BTPROTO_SCO' ), 'Bluetooth SCO sockets required for this test' )
2738
2747
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
+
2739
2753
with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
2740
2754
s .bind (socket .BDADDR_ANY .encode ())
2741
2755
addr = s .getsockname ()
@@ -2745,9 +2759,17 @@ def testBindScoSocket(self):
2745
2759
def testBadScoAddr (self ):
2746
2760
with socket .socket (socket .AF_BLUETOOTH , socket .SOCK_SEQPACKET , socket .BTPROTO_SCO ) as s :
2747
2761
with self .assertRaises (OSError ):
2748
- s .bind (socket .BDADDR_ANY )
2762
+ s .bind (( socket .BDADDR_ANY ,) )
2749
2763
with self .assertRaises (OSError ):
2750
2764
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' )
2751
2773
with self .assertRaises (OSError ):
2752
2774
s .bind (b'invalid' )
2753
2775
0 commit comments