@@ -380,7 +380,7 @@ def test_constants(self):
380380 ssl .OP_NO_COMPRESSION
381381 self .assertEqual (ssl .HAS_SNI , True )
382382 self .assertEqual (ssl .HAS_ECDH , True )
383- self .assertEqual (ssl .HAS_TLSv1_2 , True )
383+ self .assertIsInstance (ssl .HAS_TLSv1_2 , bool )
384384 self .assertEqual (ssl .HAS_TLSv1_3 , True )
385385 ssl .OP_NO_SSLv2
386386 ssl .OP_NO_SSLv3
@@ -571,11 +571,11 @@ def test_openssl_version(self):
571571 # Some sanity checks follow
572572 # >= 1.1.1
573573 self .assertGreaterEqual (n , 0x10101000 )
574- # < 4 .0
575- self .assertLess (n , 0x40000000 )
574+ # < 5 .0
575+ self .assertLess (n , 0x50000000 )
576576 major , minor , fix , patch , status = t
577577 self .assertGreaterEqual (major , 1 )
578- self .assertLess (major , 4 )
578+ self .assertLess (major , 5 )
579579 self .assertGreaterEqual (minor , 0 )
580580 self .assertLess (minor , 256 )
581581 self .assertGreaterEqual (fix , 0 )
@@ -641,12 +641,14 @@ def test_openssl111_deprecations(self):
641641 ssl .OP_NO_TLSv1_2 ,
642642 ssl .OP_NO_TLSv1_3
643643 ]
644- protocols = [
645- ssl .PROTOCOL_TLSv1 ,
646- ssl .PROTOCOL_TLSv1_1 ,
647- ssl .PROTOCOL_TLSv1_2 ,
648- ssl .PROTOCOL_TLS
649- ]
644+ protocols = []
645+ if hasattr (ssl , 'PROTOCOL_TLSv1' ):
646+ protocols .append (ssl .PROTOCOL_TLSv1 )
647+ if hasattr (ssl , 'PROTOCOL_TLSv1_1' ):
648+ protocols .append (ssl .PROTOCOL_TLSv1_1 )
649+ if hasattr (ssl , 'PROTOCOL_TLSv1_2' ):
650+ protocols .append (ssl .PROTOCOL_TLSv1_2 )
651+ protocols .append (ssl .PROTOCOL_TLS )
650652 versions = [
651653 ssl .TLSVersion .SSLv3 ,
652654 ssl .TLSVersion .TLSv1 ,
@@ -1140,6 +1142,7 @@ def test_min_max_version(self):
11401142 ssl .TLSVersion .TLSv1 ,
11411143 ssl .TLSVersion .TLSv1_1 ,
11421144 ssl .TLSVersion .TLSv1_2 ,
1145+ ssl .TLSVersion .TLSv1_3 ,
11431146 ssl .TLSVersion .SSLv3 ,
11441147 }
11451148 )
@@ -1153,7 +1156,7 @@ def test_min_max_version(self):
11531156 with self .assertRaises (ValueError ):
11541157 ctx .minimum_version = 42
11551158
1156- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
1159+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
11571160 ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
11581161
11591162 self .assertIn (
@@ -1605,23 +1608,24 @@ def test__create_stdlib_context(self):
16051608 self .assertFalse (ctx .check_hostname )
16061609 self ._assert_context_options (ctx )
16071610
1608- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
1611+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
16091612 with warnings_helper .check_warnings ():
16101613 ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
16111614 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
16121615 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
16131616 self ._assert_context_options (ctx )
16141617
1615- with warnings_helper .check_warnings ():
1616- ctx = ssl ._create_stdlib_context (
1617- ssl .PROTOCOL_TLSv1_2 ,
1618- cert_reqs = ssl .CERT_REQUIRED ,
1619- check_hostname = True
1620- )
1621- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1622- self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1623- self .assertTrue (ctx .check_hostname )
1624- self ._assert_context_options (ctx )
1618+ if has_tls_protocol ('PROTOCOL_TLSv1_2' ):
1619+ with warnings_helper .check_warnings ():
1620+ ctx = ssl ._create_stdlib_context (
1621+ ssl .PROTOCOL_TLSv1_2 ,
1622+ cert_reqs = ssl .CERT_REQUIRED ,
1623+ check_hostname = True
1624+ )
1625+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1626+ self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1627+ self .assertTrue (ctx .check_hostname )
1628+ self ._assert_context_options (ctx )
16251629
16261630 ctx = ssl ._create_stdlib_context (purpose = ssl .Purpose .CLIENT_AUTH )
16271631 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_SERVER )
@@ -3517,10 +3521,10 @@ def test_protocol_tlsv1_2(self):
35173521 client_options = ssl .OP_NO_TLSv1_2 )
35183522
35193523 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3520- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
3524+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
35213525 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
35223526 try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3523- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
3527+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
35243528 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
35253529 try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
35263530
0 commit comments