Skip to content

Commit

Permalink
update username completer for acl users command.
Browse files Browse the repository at this point in the history
  • Loading branch information
laixintao committed May 30, 2020
1 parent 0680556 commit 965f28c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions iredis/completers.py
Expand Up @@ -257,6 +257,8 @@ def update_completer_for_response(self, command_name, args, response):
# only update categoryname completer when `ACL CAT` without args.
if command_name == "ACL CAT" and not args:
self.catetoryname_completer.touch_words(response)
if command_name == "ACL USERS":
self.username_completer.touch_words(response)

def _touch_members(self, items):
_step = 1
Expand Down
17 changes: 17 additions & 0 deletions tests/cli_tests/test_completer.py
@@ -1,3 +1,6 @@
import pytest


def test_integer_type_completer(cli):
cli.expect("127.0.0.1")
cli.send("BITFIELD meykey GET ")
Expand Down Expand Up @@ -32,3 +35,17 @@ def test_command_completion_when_space_command(cli, clean_redis):

cli.send("command in")
cli.expect("command info")


@pytest.mark.skipif("int(os.environ['REDIS_VERSION']) < 6")
def test_username_completer(cli, iredis_client):
iredis_client.execute("acl setuser", "foo1")
iredis_client.execute("acl setuser", "bar2")

cli.expect("127.0.0.1")
cli.sendline("acl users")
cli.expect("foo1")

cli.send("acl deluser ")
cli.expect("foo1")
cli.expect("bar2")
11 changes: 11 additions & 0 deletions tests/unittests/test_completers.py
Expand Up @@ -333,3 +333,14 @@ def test_username_completer():
"antirez",
"laixintao",
]


def test_username_touch_for_response():
c = IRedisCompleter()
c.update_completer_for_response(
"acl users", (), [b"hello", b"world"],
)
assert sorted(c.username_completer.words) == [
"hello",
"world",
]

0 comments on commit 965f28c

Please sign in to comment.