Skip to content

Commit 7d4f985

Browse files
committed
test: Test password-only AUTH for Redis versions below 6.0.0 without HELLO command
1 parent 0eac7c8 commit 7d4f985

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/test_connection.py

+52
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,58 @@ def test_on_connect_fail_auth(self, mock_read_response, mock_send_command):
264264
mock_send_command.assert_called()
265265
mock_read_response.assert_called()
266266

267+
@patch.object(Connection, 'send_command')
268+
@patch.object(Connection, 'read_response')
269+
def test_on_connect_auth_with_password_only(
270+
self, mock_read_response, mock_send_command):
271+
"""Test on_connect handling of password-only AUTH for Redis versions below 6.0.0 without HELLO command"""
272+
conn = Connection()
273+
274+
conn._parser = MagicMock()
275+
conn._parser.on_connect.return_value = None
276+
conn.credential_provider = None
277+
conn.username = None
278+
conn.password = "password"
279+
conn.protocol = 1
280+
conn.client_name = "test-client"
281+
conn.lib_name = "test"
282+
conn.lib_version = "1234"
283+
conn.db = 1
284+
conn.client_cache = True
285+
286+
# command response to simulate Redis < 6.0.0 behavior
287+
mock_read_response.side_effect = itertools.cycle([
288+
Exception("ERR HELLO"), # HELLO (fails)
289+
b'QUEUED', # MULTI
290+
b'QUEUED', # AUTH
291+
b'QUEUED', # CLIENT SETNAME
292+
b'QUEUED', # CLIENT SETINFO LIB-NAME
293+
b'QUEUED', # CLIENT SETINFO LIB-VER
294+
b'QUEUED', # SELECT
295+
b'QUEUED', # CLIENT TRACKING ON
296+
[
297+
b'OK', # AUTH response
298+
b'OK', # CLIENT SETNAME response
299+
b'OK', # CLIENT SETINFO LIB-NAME response
300+
b'OK', # CLIENT SETINFO LIB-VER response
301+
b'OK', # SELECT response
302+
b'OK' # CLIENT TRACKING ON response
303+
]
304+
])
305+
306+
conn.on_connect()
307+
308+
mock_send_command.assert_any_call('HELLO', 1, 'AUTH', 'default', 'password'),
309+
mock_send_command.assert_any_call('MULTI'),
310+
mock_send_command.assert_any_call(
311+
'AUTH', 'default', 'password', check_health=False)
312+
mock_send_command.assert_any_call('CLIENT', 'SETNAME', 'test-client')
313+
mock_send_command.assert_any_call('CLIENT', 'SETINFO', 'LIB-NAME', 'test')
314+
mock_send_command.assert_any_call('CLIENT', 'SETINFO', 'LIB-VER', '1234')
315+
mock_send_command.assert_any_call('SELECT', 1)
316+
mock_send_command.assert_any_call('CLIENT', 'TRACKING', 'ON')
317+
mock_send_command.assert_any_call('EXEC')
318+
mock_read_response.assert_called()
267319

268320

269321
@pytest.mark.onlynoncluster

0 commit comments

Comments
 (0)