diff options
author | 杨博东 <bodong.ybd@alibaba-inc.com> | 2020-09-09 22:13:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 17:13:35 +0300 |
commit | 0666267d2771b1a46cdf36eef27d8a7a393c0c7a (patch) | |
tree | df861a9aee9b16c64adaf10bf4e128f0f3eeb42e | |
parent | 042189fd8707544139337b3ddcf38b5c5fea1bf0 (diff) | |
download | redis-0666267d2771b1a46cdf36eef27d8a7a393c0c7a.tar.gz |
Tests: Add aclfile load and save tests (#7765)
improves test coverage
-rw-r--r-- | tests/assets/user.acl | 2 | ||||
-rw-r--r-- | tests/unit/acl.tcl | 39 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/assets/user.acl b/tests/assets/user.acl new file mode 100644 index 000000000..2f065dab6 --- /dev/null +++ b/tests/assets/user.acl @@ -0,0 +1,2 @@ +user alice on allcommands allkeys >alice +user bob on -@all +@set +acl ~set* >bob
\ No newline at end of file diff --git a/tests/unit/acl.tcl b/tests/unit/acl.tcl index e81280995..381f2f95f 100644 --- a/tests/unit/acl.tcl +++ b/tests/unit/acl.tcl @@ -261,3 +261,42 @@ start_server {tags {"acl"}} { assert_match "*Unknown subcommand or wrong number of arguments*" $e } } + +set server_path [tmpdir "server.acl"] +exec cp -f tests/assets/user.acl $server_path +start_server [list overrides [list "dir" $server_path "aclfile" "user.acl"]] { + # user alice on allcommands allkeys >alice + # user bob on -@all +@set +acl ~set* >bob + + test "Alice: can excute all command" { + r AUTH alice alice + assert_equal "alice" [r acl whoami] + r SET key value + } + + test "Bob: just excute @set and acl command" { + r AUTH bob bob + assert_equal "bob" [r acl whoami] + assert_equal "3" [r sadd set 1 2 3] + catch {r SET key value} e + set e + } {*NOPERM*} + + test "ACL load and save" { + r ACL setuser eve +get allkeys >eve on + r ACL save + + # ACL load will free user and kill clients + r ACL load + catch {r ACL LIST} e + assert_match {*I/O error*} $e + + reconnect + r AUTH alice alice + r SET key value + r AUTH eve eve + r GET key + catch {r SET key value} e + set e + } {*NOPERM*} +} |