Skip to content

Commit c27c361

Browse files
committed
BUG24953913: Fix SSL connection failing tests
This patch fixes the connection error using older Python versions or when using a non SSL enabled connection settings and the Python installation doesn't have support for SSL. The SSL connection tests were disabled for Python versions < 2.7.9.
1 parent eeae989 commit c27c361

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/mysqlx/connection.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
except:
3030
SSL_AVAILABLE = False
3131

32+
import sys
3233
import socket
3334

3435
from functools import wraps
@@ -84,6 +85,11 @@ def set_ssl(self, ssl_opts={}):
8485
self.close()
8586
raise RuntimeError("Python installation has no SSL support.")
8687

88+
if sys.version_info < (2, 7, 9):
89+
self.close()
90+
raise RuntimeError("The support for SSL is not available for this "
91+
"Python version.")
92+
8793
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
8894
context.load_default_certs()
8995
if "ssl-ca" in ssl_opts:
@@ -163,8 +169,10 @@ def _handle_capabilities(self):
163169
raise OperationalError("SSL not enabled at server.")
164170
return
165171

166-
self.protocol.set_capabilities(tls=True)
167-
self.stream.set_ssl(self.settings)
172+
ssl_opts_keys = ("ssl-ca", "ssl-crl", "ssl-cert", "ssl-key",)
173+
if any(key in self.settings for key in ssl_opts_keys):
174+
self.protocol.set_capabilities(tls=True)
175+
self.stream.set_ssl(self.settings)
168176

169177
def _authenticate(self):
170178
plugin = MySQL41AuthPlugin(self._user, self._password)

tests/test_mysqlx_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import logging
2929
import unittest
30-
30+
import sys
3131
import tests
3232
import mysqlx
3333

@@ -320,6 +320,8 @@ def test_bind_to_default_shard(self):
320320
tests.MYSQL_SERVERS[0].start()
321321
tests.MYSQL_SERVERS[0].wait_up()
322322

323+
@unittest.skipIf(sys.version_info < (2, 7, 9), "The support for SSL is "
324+
"not available for Python versions < 2.7.9.")
323325
def test_ssl_connection(self):
324326
config = {}
325327
config.update(self.connect_kwargs)
@@ -492,6 +494,8 @@ def test_commit(self):
492494

493495
schema.drop_table(table_name)
494496

497+
@unittest.skipIf(sys.version_info < (2, 7, 9), "The support for SSL is "
498+
"not available for Python versions < 2.7.9.")
495499
def test_ssl_connection(self):
496500
config = {}
497501
config.update(self.connect_kwargs)

0 commit comments

Comments
 (0)