From d474d7a656c98a98d4ef97e4522bb808bb3c9930 Mon Sep 17 00:00:00 2001 From: Ken Cochrane Date: Wed, 22 Feb 2023 16:15:12 -0500 Subject: [PATCH] remove support for redis 4, add redis 7, and clean up in tests --- .github/workflows/test.yml | 2 +- README.rst | 2 +- defender/tests.py | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 505d635..5b5e272 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: max-parallel: 5 matrix: python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy-3.8'] - redis-version: [4, 5, 6] + redis-version: [5, 6, 7] steps: - uses: actions/checkout@v2 diff --git a/README.rst b/README.rst index 64bb320..81e5919 100644 --- a/README.rst +++ b/README.rst @@ -110,7 +110,7 @@ Requirements * Python: 3.7, 3.8, 3.9, 3.10, PyPy * Django: 3.x, 4.x -* Redis +* Redis: 5.x, 6.x, 7.x Installation diff --git a/defender/tests.py b/defender/tests.py index 388449c..a0f022f 100644 --- a/defender/tests.py +++ b/defender/tests.py @@ -1193,7 +1193,7 @@ class TestRedisConnection(TestCase): @patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_PLAIN) @patch("defender.config.MOCK_REDIS", False) def test_get_redis_connection(self): - """ make sure the IP address is stripped of its port number """ + """ get redis connection """ redis_client = get_redis_connection() self.assertIsInstance(redis_client, Redis) redis_client.set('test', 0) @@ -1204,7 +1204,7 @@ class TestRedisConnection(TestCase): @patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_PASS) @patch("defender.config.MOCK_REDIS", False) def test_get_redis_connection_with_password(self): - """ make sure the IP address is stripped of its port number """ + """ get redis connection with password """ connection = redis.Redis() connection.config_set('requirepass', 'mypass') @@ -1215,14 +1215,20 @@ class TestRedisConnection(TestCase): result = int(redis_client.get('test2')) self.assertEqual(result, 0) redis_client.delete('test2') + # clean up connection.config_set('requirepass', '') @patch("defender.config.DEFENDER_REDIS_URL", REDIS_URL_NAME_PASS) @patch("defender.config.MOCK_REDIS", False) def test_get_redis_connection_with_name_password(self): - """ make sure the IP address is stripped of its port number """ + """ get redis connection with password and name """ connection = redis.Redis() + + if connection.info().get('redis_version') < '6': + # redis versions before 6 don't have acl, so skip. + return + connection.acl_setuser( 'myname', enabled=True, @@ -1236,3 +1242,6 @@ class TestRedisConnection(TestCase): result = int(redis_client.get('test3')) self.assertEqual(result, 0) redis_client.delete('test3') + + # clean up + connection.acl_deluser('myname')