@@ -395,7 +395,7 @@ def test_constants(self):
395395 ssl .OP_NO_COMPRESSION
396396 self .assertEqual (ssl .HAS_SNI , True )
397397 self .assertEqual (ssl .HAS_ECDH , True )
398- self . assertEqual ( ssl .HAS_TLSv1_2 , True )
398+ ssl .HAS_TLSv1_2
399399 self .assertEqual (ssl .HAS_TLSv1_3 , True )
400400 ssl .OP_NO_SSLv2
401401 ssl .OP_NO_SSLv3
@@ -656,12 +656,14 @@ def test_openssl111_deprecations(self):
656656 ssl .OP_NO_TLSv1_2 ,
657657 ssl .OP_NO_TLSv1_3
658658 ]
659- protocols = [
660- ssl .PROTOCOL_TLSv1 ,
661- ssl .PROTOCOL_TLSv1_1 ,
662- ssl .PROTOCOL_TLSv1_2 ,
663- ssl .PROTOCOL_TLS
664- ]
659+ protocols = []
660+ if hasattr (ssl , 'PROTOCOL_TLSv1' ):
661+ protocols .append (ssl .PROTOCOL_TLSv1 )
662+ if hasattr (ssl , 'PROTOCOL_TLSv1_1' ):
663+ protocols .append (ssl .PROTOCOL_TLSv1_1 )
664+ if hasattr (ssl , 'PROTOCOL_TLSv1_2' ):
665+ protocols .append (ssl .PROTOCOL_TLSv1_2 )
666+ protocols .append (ssl .PROTOCOL_TLS )
665667 versions = [
666668 ssl .TLSVersion .SSLv3 ,
667669 ssl .TLSVersion .TLSv1 ,
@@ -1205,6 +1207,7 @@ def test_min_max_version(self):
12051207 ssl .TLSVersion .TLSv1 ,
12061208 ssl .TLSVersion .TLSv1_1 ,
12071209 ssl .TLSVersion .TLSv1_2 ,
1210+ ssl .TLSVersion .TLSv1_3 ,
12081211 ssl .TLSVersion .SSLv3 ,
12091212 }
12101213 )
@@ -1218,7 +1221,7 @@ def test_min_max_version(self):
12181221 with self .assertRaises (ValueError ):
12191222 ctx .minimum_version = 42
12201223
1221- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
1224+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
12221225 ctx = ssl .SSLContext (ssl .PROTOCOL_TLSv1_1 )
12231226
12241227 self .assertIn (
@@ -1675,23 +1678,24 @@ def test__create_stdlib_context(self):
16751678 self .assertFalse (ctx .check_hostname )
16761679 self ._assert_context_options (ctx )
16771680
1678- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
1681+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
16791682 with warnings_helper .check_warnings ():
16801683 ctx = ssl ._create_stdlib_context (ssl .PROTOCOL_TLSv1 )
16811684 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1 )
16821685 self .assertEqual (ctx .verify_mode , ssl .CERT_NONE )
16831686 self ._assert_context_options (ctx )
16841687
1685- with warnings_helper .check_warnings ():
1686- ctx = ssl ._create_stdlib_context (
1687- ssl .PROTOCOL_TLSv1_2 ,
1688- cert_reqs = ssl .CERT_REQUIRED ,
1689- check_hostname = True
1690- )
1691- self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1692- self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1693- self .assertTrue (ctx .check_hostname )
1694- self ._assert_context_options (ctx )
1688+ if has_tls_protocol ('PROTOCOL_TLSv1_2' ):
1689+ with warnings_helper .check_warnings ():
1690+ ctx = ssl ._create_stdlib_context (
1691+ ssl .PROTOCOL_TLSv1_2 ,
1692+ cert_reqs = ssl .CERT_REQUIRED ,
1693+ check_hostname = True
1694+ )
1695+ self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLSv1_2 )
1696+ self .assertEqual (ctx .verify_mode , ssl .CERT_REQUIRED )
1697+ self .assertTrue (ctx .check_hostname )
1698+ self ._assert_context_options (ctx )
16951699
16961700 ctx = ssl ._create_stdlib_context (purpose = ssl .Purpose .CLIENT_AUTH )
16971701 self .assertEqual (ctx .protocol , ssl .PROTOCOL_TLS_SERVER )
@@ -3654,10 +3658,10 @@ def test_protocol_tlsv1_2(self):
36543658 client_options = ssl .OP_NO_TLSv1_2 )
36553659
36563660 try_protocol_combo (ssl .PROTOCOL_TLS , ssl .PROTOCOL_TLSv1_2 , 'TLSv1.2' )
3657- if has_tls_protocol (ssl . PROTOCOL_TLSv1 ):
3661+ if has_tls_protocol (' PROTOCOL_TLSv1' ):
36583662 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1 , False )
36593663 try_protocol_combo (ssl .PROTOCOL_TLSv1 , ssl .PROTOCOL_TLSv1_2 , False )
3660- if has_tls_protocol (ssl . PROTOCOL_TLSv1_1 ):
3664+ if has_tls_protocol (' PROTOCOL_TLSv1_1' ):
36613665 try_protocol_combo (ssl .PROTOCOL_TLSv1_2 , ssl .PROTOCOL_TLSv1_1 , False )
36623666 try_protocol_combo (ssl .PROTOCOL_TLSv1_1 , ssl .PROTOCOL_TLSv1_2 , False )
36633667
0 commit comments