@@ -357,7 +357,7 @@ def test_constants(self):
357357 ssl .OP_NO_COMPRESSION
358358 self .assertEqual (ssl .HAS_SNI , True )
359359 self .assertEqual (ssl .HAS_ECDH , True )
360- self .assertEqual (ssl .HAS_TLSv1_2 , True )
360+ self .assertIsInstance (ssl .HAS_TLSv1_2 , bool )
361361 self .assertEqual (ssl .HAS_TLSv1_3 , True )
362362 ssl .OP_NO_SSLv2
363363 ssl .OP_NO_SSLv3
@@ -547,11 +547,11 @@ def test_openssl_version(self):
547547 # Some sanity checks follow
548548 # >= 1.1.1
549549 self .assertGreaterEqual (n , 0x10101000 )
550- # < 4 .0
551- self .assertLess (n , 0x40000000 )
550+ # < 5 .0
551+ self .assertLess (n , 0x50000000 )
552552 major , minor , fix , patch , status = t
553553 self .assertGreaterEqual (major , 1 )
554- self .assertLess (major , 4 )
554+ self .assertLess (major , 5 )
555555 self .assertGreaterEqual (minor , 0 )
556556 self .assertLess (minor , 256 )
557557 self .assertGreaterEqual (fix , 0 )
@@ -617,12 +617,14 @@ def test_openssl111_deprecations(self):
617617 ssl .OP_NO_TLSv1_2 ,
618618 ssl .OP_NO_TLSv1_3
619619 ]
620- protocols = [
621- ssl .PROTOCOL_TLSv1 ,
622- ssl .PROTOCOL_TLSv1_1 ,
623- ssl .PROTOCOL_TLSv1_2 ,
624- ssl .PROTOCOL_TLS
625- ]
620+ protocols = []
621+ if hasattr (ssl , 'PROTOCOL_TLSv1' ):
622+ protocols .append (ssl .PROTOCOL_TLSv1 )
623+ if hasattr (ssl , 'PROTOCOL_TLSv1_1' ):
624+ protocols .append (ssl .PROTOCOL_TLSv1_1 )
625+ if hasattr (ssl , 'PROTOCOL_TLSv1_2' ):
626+ protocols .append (ssl .PROTOCOL_TLSv1_2 )
627+ protocols .append (ssl .PROTOCOL_TLS )
626628 versions = [
627629 ssl .TLSVersion .SSLv3 ,
628630 ssl .TLSVersion .TLSv1 ,
@@ -1116,6 +1118,7 @@ def test_min_max_version(self):
11161118 ssl .TLSVersion .TLSv1 ,
11171119 ssl .TLSVersion .TLSv1_1 ,
11181120 ssl .TLSVersion .TLSv1_2 ,
1121+ ssl .TLSVersion .TLSv1_3 ,
11191122 ssl .TLSVersion .SSLv3 ,
11201123 }
11211124 )
@@ -1129,7 +1132,7 @@ def test_min_max_version(self):
11291132 with self .assertRaises (ValueError ):
11301133 ctx .minimum_version = 42
11311134
1132- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
1135+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
11331136 ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
11341137
11351138 self .assertIn (
@@ -1582,23 +1585,24 @@ def test__create_stdlib_context(self):
15821585 self .assertFalse (ctx .check_hostname )
15831586 self ._assert_context_options (ctx )
15841587
1585- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
1588+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
15861589 with warnings_helper .check_warnings ():
15871590 ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
15881591 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
15891592 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
15901593 self ._assert_context_options (ctx )
15911594
1592- with warnings_helper .check_warnings ():
1593- ctx = ssl ._create_stdlib_context (
1594- ssl .PROTOCOL_TLSv1_2 ,
1595- cert_reqs = ssl .CERT_REQUIRED ,
1596- check_hostname = True
1597- )
1598- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1599- self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1600- self .assertTrue (ctx .check_hostname )
1601- self ._assert_context_options (ctx )
1595+ if has_tls_protocol ('PROTOCOL_TLSv1_2' ):
1596+ with warnings_helper .check_warnings ():
1597+ ctx = ssl ._create_stdlib_context (
1598+ ssl .PROTOCOL_TLSv1_2 ,
1599+ cert_reqs = ssl .CERT_REQUIRED ,
1600+ check_hostname = True
1601+ )
1602+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1603+ self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1604+ self .assertTrue (ctx .check_hostname )
1605+ self ._assert_context_options (ctx )
16021606
16031607 ctx = ssl ._create_stdlib_context (purpose = ssl .Purpose .CLIENT_AUTH )
16041608 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_SERVER )
@@ -3460,10 +3464,10 @@ def test_protocol_tlsv1_2(self):
34603464 client_options = ssl .OP_NO_TLSv1_2 )
34613465
34623466 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3463- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
3467+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
34643468 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
34653469 try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3466- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
3470+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
34673471 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
34683472 try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
34693473
0 commit comments