diff --git a/pymysql/tests/test_connection.py b/pymysql/tests/test_connection.py index 75db73cd..88bcbb22 100644 --- a/pymysql/tests/test_connection.py +++ b/pymysql/tests/test_connection.py @@ -577,6 +577,22 @@ 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) + with mock.patch( + "pymysql.connections.Connection.connect" + ) as connect, mock.patch( + "pymysql.connections.ssl.create_default_context", + new=mock.Mock(return_value=dummy_ssl_context), + ) as create_default_context: + pymysql.connect( + ssl_cadata="cadata", + ssl_verify_cert=True, + ssl_verify_identity=True, + ) + create_default_context.assert_called_with(cafile=None, capath=None, cadata="cadata") + assert dummy_ssl_context.verify_mode == ssl.CERT_REQUIRED + assert dummy_ssl_context.check_hostname + dummy_ssl_context = mock.Mock(options=0) with mock.patch( "pymysql.connections.Connection.connect" diff --git a/tests/test_auth.py b/tests/test_auth.py index e5e2a64e..9ae1ceed 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -10,7 +10,9 @@ port = 3306 ca = os.path.expanduser("~/ca.pem") +cadata = open(ca, "r").read() ssl = {"ca": ca, "check_hostname": False} +ssl_cadata = {"cadata": cadata, "check_hostname": False} pass_sha256 = "pass_sha256_01234567890123456789" pass_caching_sha2 = "pass_caching_sha2_01234567890123456789" @@ -26,6 +28,11 @@ def test_sha256_no_passowrd_ssl(): con.close() +def test_sha256_no_passowrd_ssl_cadata(): + con = pymysql.connect(user="nopass_sha256", host=host, port=port, ssl=ssl_cadata) + con.close() + + def test_sha256_password(): con = pymysql.connect( user="user_sha256", password=pass_sha256, host=host, port=port, ssl=None