MCPcopy
hub / github.com/redis/redis-py / test_acl_log

Method test_acl_log

tests/test_cluster.py:2700–2741  ·  view source on GitHub ↗
(self, r, request)

Source from the content-addressed store, hash-verified

2698 @skip_if_server_version_lt("6.0.0")
2699 @skip_if_redis_enterprise()
2700 def test_acl_log(self, r, request):
2701 key = "{cache}:"
2702 node = r.get_node_from_key(key)
2703 username = "redis-py-user"
2704
2705 def teardown():
2706 r.acl_deluser(username, target_nodes="primaries")
2707
2708 request.addfinalizer(teardown)
2709 r.acl_setuser(
2710 username,
2711 enabled=True,
2712 reset=True,
2713 commands=["+get", "+set", "+select", "+cluster", "+command", "+info"],
2714 keys=["{cache}:*"],
2715 nopass=True,
2716 target_nodes="primaries",
2717 )
2718 r.acl_log_reset(target_nodes=node)
2719
2720 user_client = _get_client(
2721 RedisCluster, request, flushdb=False, username=username
2722 )
2723
2724 # Valid operation and key
2725 assert user_client.set("{cache}:0", 1)
2726 assert user_client.get("{cache}:0") == b"1"
2727
2728 # Invalid key
2729 with pytest.raises(NoPermissionError):
2730 user_client.get("{cache}violated_cache:0")
2731
2732 # Invalid operation
2733 with pytest.raises(NoPermissionError):
2734 user_client.hset("{cache}:0", "hkey", "hval")
2735
2736 assert isinstance(r.acl_log(target_nodes=node), list)
2737 assert len(r.acl_log(target_nodes=node)) == 3
2738 assert len(r.acl_log(count=1, target_nodes=node)) == 1
2739 assert isinstance(r.acl_log(target_nodes=node)[0], dict)
2740 assert "client-info" in r.acl_log(count=1, target_nodes=node)[0]
2741 assert r.acl_log_reset(target_nodes=node)
2742
2743 def generate_lib_code(self, lib_name):
2744 return f"""#!js api_version=1.0 name={lib_name}\n redis.registerFunction('foo', ()=>{{return 'bar'}})""" # noqa

Callers

nothing calls this directly

Calls 8

_get_clientFunction · 0.85
acl_setuserMethod · 0.80
acl_log_resetMethod · 0.80
hsetMethod · 0.80
acl_logMethod · 0.80
get_node_from_keyMethod · 0.45
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected