Skip to content

Commit 84fd04e

Browse files
authored
PYTHON-1852 Use TLS option names in test suite ClientContext (#442)
1 parent 7420245 commit 84fd04e

File tree

5 files changed

+21
-33
lines changed

5 files changed

+21
-33
lines changed

test/__init__.py

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,12 @@
8181
CLIENT_PEM = os.environ.get('CLIENT_PEM',
8282
os.path.join(CERT_PATH, 'client.pem'))
8383
CA_PEM = os.environ.get('CA_PEM', os.path.join(CERT_PATH, 'ca.pem'))
84-
CERT_REQS = validate_cert_reqs('CERT_REQS', os.environ.get('CERT_REQS'))
8584

86-
_SSL_OPTIONS = dict(ssl=True)
85+
TLS_OPTIONS = dict(tls=True)
8786
if CLIENT_PEM:
88-
_SSL_OPTIONS['ssl_certfile'] = CLIENT_PEM
87+
TLS_OPTIONS['tlsCertificateKeyFile'] = CLIENT_PEM
8988
if CA_PEM:
90-
_SSL_OPTIONS['ssl_ca_certs'] = CA_PEM
91-
if CERT_REQS is not None:
92-
_SSL_OPTIONS['ssl_cert_reqs'] = CERT_REQS
89+
TLS_OPTIONS['tlsCAFile'] = CA_PEM
9390

9491
COMPRESSORS = os.environ.get("COMPRESSORS")
9592

@@ -187,8 +184,7 @@ def __init__(self):
187184
self.mongoses = []
188185
self.is_rs = False
189186
self.has_ipv6 = False
190-
self.ssl = False
191-
self.ssl_cert_none = False
187+
self.tls = False
192188
self.ssl_certfile = False
193189
self.server_is_resolvable = is_server_resolvable()
194190
self.default_client_options = {}
@@ -235,13 +231,11 @@ def _init_client(self):
235231
self.client = self._connect(host, port)
236232
if HAVE_SSL and not self.client:
237233
# Is MongoDB configured for SSL?
238-
self.client = self._connect(host, port, **_SSL_OPTIONS)
234+
self.client = self._connect(host, port, **TLS_OPTIONS)
239235
if self.client:
240-
self.ssl = True
241-
self.default_client_options.update(_SSL_OPTIONS)
236+
self.tls = True
237+
self.default_client_options.update(TLS_OPTIONS)
242238
self.ssl_certfile = True
243-
if _SSL_OPTIONS.get('ssl_cert_reqs') == ssl.CERT_NONE:
244-
self.ssl_cert_none = True
245239

246240
if self.client:
247241
self.connected = True
@@ -608,22 +602,16 @@ def require_failCommand_fail_point(self, func):
608602
"failCommand fail point must be supported",
609603
func=func)
610604

611-
def require_ssl(self, func):
612-
"""Run a test only if the client can connect over SSL."""
613-
return self._require(lambda: self.ssl,
614-
"Must be able to connect via SSL",
605+
def require_tls(self, func):
606+
"""Run a test only if the client can connect over TLS."""
607+
return self._require(lambda: self.tls,
608+
"Must be able to connect via TLS",
615609
func=func)
616610

617-
def require_no_ssl(self, func):
618-
"""Run a test only if the client can connect over SSL."""
619-
return self._require(lambda: not self.ssl,
620-
"Must be able to connect without SSL",
621-
func=func)
622-
623-
def require_ssl_cert_none(self, func):
624-
"""Run a test only if the client can connect with ssl.CERT_NONE."""
625-
return self._require(lambda: self.ssl_cert_none,
626-
"Must be able to connect with ssl.CERT_NONE",
611+
def require_no_tls(self, func):
612+
"""Run a test only if the client can connect over TLS."""
613+
return self._require(lambda: not self.tls,
614+
"Must be able to connect without TLS",
627615
func=func)
628616

629617
def require_ssl_certfile(self, func):

test/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ def test_lazy_auth_raises_operation_failure(self):
919919
assertRaisesExactly(
920920
OperationFailure, lazy_client.test.collection.find_one)
921921

922-
@client_context.require_no_ssl
922+
@client_context.require_no_tls
923923
def test_unix_socket(self):
924924
if not hasattr(socket, "AF_UNIX"):
925925
raise SkipTest("UNIX-sockets are not supported on this system")
@@ -1086,7 +1086,7 @@ def test_tz_aware(self):
10861086

10871087
@client_context.require_ipv6
10881088
def test_ipv6(self):
1089-
if client_context.ssl:
1089+
if client_context.tls:
10901090
if not HAVE_IPADDRESS:
10911091
raise SkipTest("Need the ipaddress module to test with SSL")
10921092

test/test_dns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TestDNS(unittest.TestCase):
4040
def create_test(test_case):
4141

4242
@client_context.require_replica_set
43-
@client_context.require_ssl
43+
@client_context.require_tls
4444
def run_test(self):
4545
if not _HAVE_DNSPYTHON:
4646
raise unittest.SkipTest("DNS tests require the dnspython module")
@@ -68,7 +68,7 @@ def run_test(self):
6868
# The replica set members must be configured as 'localhost'.
6969
if hostname == 'localhost':
7070
copts = client_context.default_client_options.copy()
71-
if client_context.ssl is True:
71+
if client_context.tls is True:
7272
# Our test certs don't support the SRV hosts used in these tests.
7373
copts['ssl_match_hostname'] = False
7474

test/test_replica_set_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_timeout_does_not_mark_member_down(self):
195195

196196
@client_context.require_ipv6
197197
def test_ipv6(self):
198-
if client_context.ssl:
198+
if client_context.tls:
199199
if not HAVE_IPADDRESS:
200200
raise SkipTest("Need the ipaddress module to test with SSL")
201201

test/test_ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def tearDownClass(cls):
196196
MongoClient.PORT = cls.saved_port
197197
super(TestSSL, cls).tearDownClass()
198198

199-
@client_context.require_ssl
199+
@client_context.require_tls
200200
def test_simple_ssl(self):
201201
# Expects the server to be running with ssl and with
202202
# no --sslPEMKeyFile or with --sslWeakCertificateValidation

0 commit comments

Comments
 (0)