From 34500e1e2c1a1897ca38702cd43a777012977081 Mon Sep 17 00:00:00 2001 From: Matus Valo Date: Fri, 5 Nov 2021 23:47:06 +0100 Subject: [PATCH] Added integration test of failed authentication to redis --- t/integration/test_redis.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/t/integration/test_redis.py b/t/integration/test_redis.py index 0d38efb6..72ba803f 100644 --- a/t/integration/test_redis.py +++ b/t/integration/test_redis.py @@ -2,6 +2,7 @@ import os from time import sleep import pytest +import redis import kombu @@ -9,9 +10,15 @@ from .common import BaseExchangeTypes, BasePriority, BasicFunctionality def get_connection( - hostname, port, vhost, transport_options=None): + hostname, port, vhost, user_name=None, password=None, + transport_options=None): + + credentials = f'{user_name}:{password}@' if user_name else '' + return kombu.Connection( - f'redis://{hostname}:{port}', transport_options=transport_options) + f'redis://{credentials}{hostname}:{port}', + transport_options=transport_options + ) @pytest.fixture(params=[None, {'global_keyprefix': '_prefixed_'}]) @@ -32,6 +39,19 @@ def invalid_connection(): return kombu.Connection('redis://localhost:12345') +@pytest.mark.env('redis') +def test_failed_credentials(): + """Tests denied connection when wrong credentials were provided""" + with pytest.raises(redis.exceptions.ResponseError): + get_connection( + hostname=os.environ.get('REDIS_HOST', 'localhost'), + port=os.environ.get('REDIS_6379_TCP', '6379'), + vhost=None, + user_name='wrong_redis_user', + password='wrong_redis_password' + ).connect() + + @pytest.mark.env('redis') @pytest.mark.flaky(reruns=5, reruns_delay=2) class test_RedisBasicFunctionality(BasicFunctionality):