8000 disable VERIFY_X509_STRICT for Python 3.13 support by methane · Pull Request #1198 · PyMySQL/PyMySQL · GitHub
[go: up one dir, main page]

Skip to content

disable VERIFY_X509_STRICT for Python 3.13 support #1198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
6 changes: 6 additions & 0 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ def _create_ssl_ctx(self, sslp):
capath = sslp.get("capath")
hasnoca = ca is None and capath is None
ctx = ssl.create_default_context(cafile=ca, capath=capath)

# Python 3.13 enables VERIFY_X509_STRICT by default.
# But self signed certificates that are generated by MySQL automatically
# doesn't pass the verification.
ctx.verify_flags &= ~ssl.VERIFY_X509_STRICT

ctx.check_hostname = not hasnoca and sslp.get("check_hostname", True)
verify_mode_value = sslp.get("verify_mode")
if verify_mode_value is None:
Expand Down
24 changes: 12 additions & 12 deletions pymysql/tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_defer_connect(self):
sock.close()

def test_ssl_connect(self):
dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -581,7 +581,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_called_with("cipher")

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -603,7 +603,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -626,7 +626,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -640,7 +640,7 @@ def test_ssl_connect(self):
dummy_ssl_context.load_cert_chain.assert_not_called
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -661,7 +661,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

for ssl_verify_cert in (True, "1", "yes", "true"):
dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -682,7 +682,7 @@ def test_ssl_connect(self):
dummy_ssl_context.set_ciphers.assert_not_called

for ssl_verify_cert in (None, False, "0", "no", "false"):
dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -704,7 +704,7 @@ def test_ssl_connect(self):

for ssl_ca in ("ca", None):
for ssl_verify_cert in ("foo", "bar", ""):
dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -727,7 +727,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -748,7 +748,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -770,7 +770,7 @@ def test_ssl_connect(self):
)
dummy_ssl_context.set_ciphers.assert_not_called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand All @@ -785,7 +785,7 @@ def test_ssl_connect(self):
)
assert not create_default_context.called

dummy_ssl_context = mock.Mock(options=0)
dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
with mock.patch("pymysql.connections.Connection.connect"), mock.patch(
"pymysql.connections.ssl.create_default_context",
new=mock.Mock(return_value=dummy_ssl_context),
Expand Down
Loading
0