Skip to content

Commit c224708

Browse files
committed
Use ssl.context for ftp client in ssl tests
1 parent de14407 commit c224708

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pyftpdlib/test/functional_ssl_client_certfile_tests.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from pyftpdlib.test import unittest
2525
from pyftpdlib.test import VERBOSITY
2626
from _ssl import SSLError
27+
import ssl
2728

2829

2930
FTPS_SUPPORT = hasattr(ftplib, 'FTP_TLS')
@@ -73,6 +74,11 @@ def setUp(self):
7374
self.server.start()
7475

7576
def tearDown(self):
77+
self.client.ssl_version = ssl.PROTOCOL_SSLv23
78+
with self.server.lock:
79+
self.server.handler.ssl_version = ssl.PROTOCOL_SSLv23
80+
self.server.handler.tls_control_required = False
81+
self.server.handler.tls_data_required = False
7682
self.client.close()
7783
self.server.stop()
7884

@@ -90,8 +96,18 @@ def assertRaisesWithMsg(self, excClass, msg, callableObj, *args, **kwargs):
9096
excName = str(excClass)
9197
raise self.failureException("%s not raised" % excName)
9298

99+
@classmethod
100+
def get_ssl_context(cls, certfile):
101+
ssl_context = ssl.create_default_context()
102+
ssl_context.check_hostname = False
103+
ssl_context.verify_mode = ssl.CERT_NONE
104+
if certfile:
105+
ssl_context.load_cert_chain(certfile)
106+
return ssl_context
107+
93108
def test_auth_client_cert(self):
94-
self.client = ftplib.FTP_TLS(timeout=TIMEOUT, certfile=CLIENT_CERTFILE)
109+
ctx = self.get_ssl_context(CLIENT_CERTFILE)
110+
self.client = ftplib.FTP_TLS(timeout=TIMEOUT, context=ctx)
95111
self.client.connect(self.server.host, self.server.port)
96112
# secured
97113
try:
@@ -115,7 +131,8 @@ def test_auth_client_nocert(self):
115131
self.fail("Client able to log in with no certificate")
116132

117133
def test_auth_client_badcert(self):
118-
self.client = ftplib.FTP_TLS(timeout=TIMEOUT, certfile=CERTFILE)
134+
ctx = self.get_ssl_context(CERTFILE)
135+
self.client = ftplib.FTP_TLS(timeout=TIMEOUT, context=ctx)
119136
self.client.connect(self.server.host, self.server.port)
120137
try:
121138
self.client.login()

0 commit comments

Comments
 (0)