Skip to content

Commit 873dc39

Browse files
committed
Add test case for unexpecte LOAD_LOCAL packets
1 parent aa98494 commit 873dc39

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/test_load_local.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import os
33
from unittest.mock import patch, MagicMock
44

5+
import aiomysql
56
import pytest
7+
from pymysql.constants import CLIENT
68
from pymysql.err import OperationalError
79

810

@@ -81,3 +83,33 @@ async def test_load_warnings(cursor, table_local_file):
8183
with warnings.catch_warnings(record=True) as w:
8284
await cursor.execute(sql)
8385
assert "Incorrect integer value" in str(w[-1].message)
86+
87+
88+
@pytest.mark.run_loop
89+
async def test_load_local_disabled(mysql_params, table_local_file):
90+
# By setting the client flag, the server will be informed that we support
91+
# loading local files. This validates that the client side check catches
92+
# the server attempting to read files from us without having this
93+
# explicitly enabled on the connection. The local_infile parameter sets
94+
# the client flag, but not the other way round.
95+
params = mysql_params.copy()
96+
params["local_infile"] = False
97+
if "client_flag" in params:
98+
params["client_flag"] |= CLIENT.LOCAL_FILES
99+
else:
100+
params["client_flag"] = CLIENT.LOCAL_FILES
101+
102+
async with aiomysql.connect(**params) as conn:
103+
async with conn.cursor() as cursor:
104+
# Test load local infile with a valid file
105+
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
106+
'fixtures',
107+
'load_local_data.txt')
108+
with pytest.raises(
109+
RuntimeError,
110+
match="Received LOAD_LOCAL packet but local_infile option is false",
111+
):
112+
await cursor.execute(
113+
("LOAD DATA LOCAL INFILE '{0}' INTO TABLE " +
114+
"test_load_local FIELDS TERMINATED BY ','").format(filename)
115+
)

0 commit comments

Comments
 (0)