diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2020-08-19 10:46:02 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2020-08-19 10:46:02 -0700 |
commit | b80d423cc531c5db972d35ba72424cf9cf8772ff (patch) | |
tree | d1af550e0d749fa3f53d31b03dd5e84e0537108e /tests/test_commands.py | |
parent | f9ab1d35f8ec633a25c223ed979cef34a68072fe (diff) | |
download | redis-py-b80d423cc531c5db972d35ba72424cf9cf8772ff.tar.gz |
Added the ACL LOG command available in Redis 6
`acl_log()` returns a list of dictionaries, each describing a log entry.
`acl_log_reset()` instructs the server to truncate the log.
Thanks @2014BDuck
Fixes #1307
Diffstat (limited to 'tests/test_commands.py')
-rw-r--r-- | tests/test_commands.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/tests/test_commands.py b/tests/test_commands.py index 38e2d1a..2113078 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -9,8 +9,13 @@ from string import ascii_letters from redis.client import parse_info from redis import exceptions -from .conftest import (skip_if_server_version_lt, skip_if_server_version_gte, - skip_unless_arch_bits, REDIS_6_VERSION) +from .conftest import ( + _get_client, + REDIS_6_VERSION, + skip_if_server_version_gte, + skip_if_server_version_lt, + skip_unless_arch_bits, +) @pytest.fixture() @@ -194,6 +199,41 @@ class TestRedisCommands: assert 'user %s off -@all' % username in users @skip_if_server_version_lt(REDIS_6_VERSION) + def test_acl_log(self, r, request): + username = 'redis-py-user' + + def teardown(): + r.acl_deluser(username) + + request.addfinalizer(teardown) + r.acl_setuser(username, enabled=True, reset=True, + commands=['+get', '+set', '+select'], + keys=['cache:*'], nopass=True) + r.acl_log_reset() + + user_client = _get_client(redis.Redis, request, flushdb=False, + username=username) + + # Valid operation and key + assert user_client.set('cache:0', 1) + assert user_client.get('cache:0') == b'1' + + # Invalid key + with pytest.raises(exceptions.NoPermissionError): + user_client.get('violated_cache:0') + + # Invalid operation + with pytest.raises(exceptions.NoPermissionError): + user_client.hset('cache:0', 'hkey', 'hval') + + assert isinstance(r.acl_log(), list) + assert len(r.acl_log()) == 2 + assert len(r.acl_log(count=1)) == 1 + assert isinstance(r.acl_log()[0], dict) + assert 'client-info' in r.acl_log(count=1)[0] + assert r.acl_log_reset() + + @skip_if_server_version_lt(REDIS_6_VERSION) def test_acl_setuser_categories_without_prefix_fails(self, r, request): username = 'redis-py-user' |