Skip to content

Commit

Permalink
add py3.7 test
Browse files Browse the repository at this point in the history
  • Loading branch information
cunla committed Oct 29, 2024
1 parent 880045e commit c1bcff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions fakeredis/model/_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,26 @@ def as_array(self) -> List[Union[bytes, List[bytes]]]:
)
return results

def _get_selectors_for_rule(self) -> List[bytes]:
results: List[bytes] = list()
for command, selector in self._selectors.items():
s = b"-@all " + (b"+" if selector.allowed else b"-") + command
channels = b"resetchannels" + ((b" " + selector.channels) if selector.channels != b"" else b"")
results.append(b"(" + b" ".join([selector.keys, channels, s]) + b")")
return results

def as_rule(self) -> bytes:
selectors = self._get_selectors_for_rule()
channels = self._get_channel_patterns()
if channels != [b"&*"]:
channels = [b"resetchannels"] + channels
rule_parts: List[bytes] = (
self._get_flags()
+ list(self._passwords)
+ [b"#" + password for password in self._passwords]
+ self._get_commands()
+ self._get_key_patterns()
+ self._get_channel_patterns()
+ self._get_selectors()
+ channels
+ selectors
)
return b" ".join(rule_parts)

Expand Down
4 changes: 3 additions & 1 deletion test/test_mixins/test_acl_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def test_acl_list(r: redis.Redis):
assert "#e6c3da5b206634d7f3f3586d747ffdb36b5c675757b380c6a5fe5c570c714349" in user_rule
assert "#1ba3d16e9881959f8c9a9762854f72c6e6321cdd44358a10a4e939033117eab9" in user_rule
assert "on" in user_rule
assert "~cache:* ~objects:* resetchannels &message:*" in user_rule
assert "~cache:*" in user_rule
assert "~objects:*" in user_rule
assert "resetchannels &message:*" in user_rule
assert "(%W~app* resetchannels -@all +set)" in user_rule
assert "(~app* resetchannels &x -@all +get)" in user_rule
assert "(%W~app* resetchannels -@all -hset)" in user_rule
Expand Down

0 comments on commit c1bcff6

Please sign in to comment.