MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / test_ssl_required_error

Method test_ssl_required_error

pymysql/tests/test_connection.py:826–853  ·  view source on GitHub ↗

REQUIRED mode raises OperationalError when server doesn't support SSL.

(self)

Source from the content-addressed store, hash-verified

824 assert dummy_ssl_context.verify_mode == ssl.CERT_NONE
825
826 def test_ssl_required_error(self):
827 """REQUIRED mode raises OperationalError when server doesn't support SSL."""
828 dummy_ssl_context = mock.Mock(options=0, verify_flags=0)
829 mock_create_ctx = mock.Mock(return_value=dummy_ssl_context)
830 with mock.patch(
831 "pymysql.connections.ssl.create_default_context",
832 new=mock_create_ctx,
833 ):
834 conn = pymysql.connect(ssl_ca="ca", defer_connect=True)
835 # Verify the context was created with the CA certificate
836 mock_create_ctx.assert_called_once_with(cafile="ca", capath=None)
837
838 assert conn.ssl is True
839 assert conn._ssl_required is True
840
841 # Simulate a server that doesn't advertise SSL support
842 conn.server_version = "8.0.0"
843 conn.server_capabilities = 0 # no CLIENT.SSL bit
844 conn.client_flag = 0
845 conn.charset = "utf8mb4"
846 conn.user = "root"
847 conn.encoding = "utf8"
848
849 with pytest.raises(
850 pymysql.err.OperationalError,
851 match="SSL is required but the server doesn't support it",
852 ):
853 conn._request_authentication()
854
855 def test_ssl_preferred_no_server_ssl(self):
856 """PREFERRED mode falls back silently when server doesn't support SSL."""

Callers

nothing calls this directly

Calls 2

connectMethod · 0.45

Tested by

no test coverage detected