Skip to content

Commit c1e31f5

Browse files
committed
Non-linearizable is executed before auth command
1 parent d4b74f2 commit c1e31f5

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/sqlitecloud/driver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ def _internal_config_apply(
430430

431431
buffer = ""
432432

433+
# it must be executed before authentication command
434+
if config.non_linearizable:
435+
buffer += "SET CLIENT KEY NONLINEARIZABLE TO 1;"
436+
433437
if config.account.apikey:
434438
buffer += f"AUTH APIKEY {config.account.apikey};"
435439

@@ -448,9 +452,6 @@ def _internal_config_apply(
448452
if config.zerotext:
449453
buffer += "SET CLIENT KEY ZEROTEXT TO 1;"
450454

451-
if config.non_linearizable:
452-
buffer += "SET CLIENT KEY NONLINEARIZABLE TO 1;"
453-
454455
if config.noblob:
455456
buffer += "SET CLIENT KEY NOBLOB TO 1;"
456457

src/tests/unit/test_driver.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
2+
from pytest_mock import MockerFixture
23

34
from sqlitecloud.driver import Driver
5+
from sqlitecloud.types import SQCloudConfig, SqliteCloudAccount
46

57

68
class TestDriver:
@@ -212,3 +214,46 @@ def test_escape_sql_parameter_with_dict(self):
212214
driver.escape_sql_parameter(param)
213215

214216
assert expected_result
217+
218+
def test_nonlinearizable_command_before_auth_with_account(
219+
self, mocker: MockerFixture
220+
):
221+
driver = Driver()
222+
223+
config = SQCloudConfig()
224+
config.account = SqliteCloudAccount()
225+
config.account.username = "pippo"
226+
config.account.password = "pluto"
227+
config.non_linearizable = True
228+
229+
mocker.patch.object(driver, "_internal_connect", return_value=None)
230+
run_command_mock = mocker.patch.object(driver, "_internal_run_command")
231+
232+
driver.connect("myhost", 8860, config)
233+
234+
expected_buffer = (
235+
"SET CLIENT KEY NONLINEARIZABLE TO 1;AUTH USER pippo PASSWORD pluto;"
236+
)
237+
238+
run_command_mock.assert_called_once()
239+
assert run_command_mock.call_args[0][1] == expected_buffer
240+
241+
def test_nonlinearizable_command_before_auth_with_apikey(
242+
self, mocker: MockerFixture
243+
):
244+
driver = Driver()
245+
246+
config = SQCloudConfig()
247+
config.account = SqliteCloudAccount()
248+
config.account.apikey = "abc123"
249+
config.non_linearizable = True
250+
251+
mocker.patch.object(driver, "_internal_connect", return_value=None)
252+
run_command_mock = mocker.patch.object(driver, "_internal_run_command")
253+
254+
driver.connect("myhost", 8860, config)
255+
256+
expected_buffer = "SET CLIENT KEY NONLINEARIZABLE TO 1;AUTH APIKEY abc123;"
257+
258+
run_command_mock.assert_called_once()
259+
assert run_command_mock.call_args[0][1] == expected_buffer

0 commit comments

Comments
 (0)