summaryrefslogtreecommitdiff
path: root/tests/unit/moduleapi/misc.tcl
diff options
context:
space:
mode:
authorShaya Potter <shaya@redislabs.com>2022-10-16 09:01:37 +0300
committerGitHub <noreply@github.com>2022-10-16 09:01:37 +0300
commit3193f086ca0e167e89b6c5cf14133c03213b8378 (patch)
tree4f7243a90017fdb890625cd3bbd91f4c0ce88b57 /tests/unit/moduleapi/misc.tcl
parent56f97bfa5fb082f812c711676d5a77d29af56940 (diff)
downloadredis-3193f086ca0e167e89b6c5cf14133c03213b8378.tar.gz
Unify ACL failure error messaging. (#11160)
Motivation: for applications that use RM ACL verification functions, they would want to return errors back to the user, in ways that are consistent with Redis. While investigating how we should return ACL errors to the user, we realized that Redis isn't consistent, and currently returns ACL error strings in 3 primary ways. [For the actual implications of this change, see the "Impact" section at the bottom] 1. how it returns an error when calling a command normally ACL_DENIED_CMD -> "this user has no permissions to run the '%s' command" ACL_DENIED_KEY -> "this user has no permissions to access one of the keys used as arguments" ACL_DENIED_CHANNEL -> "this user has no permissions to access one of the channels used as arguments" 2. how it returns an error when calling via 'acl dryrun' command ACL_DENIED_CMD -> "This user has no permissions to run the '%s' command" ACL_DENIED_KEY -> "This user has no permissions to access the '%s' key" ACL_DENIED_CHANNEL -> "This user has no permissions to access the '%s' channel" 3. how it returns an error via RM_Call (and scripting is similar). ACL_DENIED_CMD -> "can't run this command or subcommand"; ACL_DENIED_KEY -> "can't access at least one of the keys mentioned in the command arguments"; ACL_DENIED_CHANNEL -> "can't publish to the channel mentioned in the command"; In addition, if one wants to use RM_Call's "dry run" capability instead of the RM ACL functions directly, one also sees a different problem than it returns ACL errors with a -ERR, not a -PERM, so it can't be returned directly to the caller. This PR modifies the code to generate a base message in a common manner with the ability to set verbose flag for acl dry run errors, and keep it unset for normal/rm_call/script cases ```c sds getAclErrorMessage(int acl_res, user *user, struct redisCommand *cmd, sds errored_val, int verbose) { switch (acl_res) { case ACL_DENIED_CMD: return sdscatfmt(sdsempty(), "User %S has no permissions to run " "the '%S' command", user->name, cmd->fullname); case ACL_DENIED_KEY: if (verbose) { return sdscatfmt(sdsempty(), "User %S has no permissions to access " "the '%S' key", user->name, errored_val); } else { return sdsnew("No permissions to access a key"); } case ACL_DENIED_CHANNEL: if (verbose) { return sdscatfmt(sdsempty(), "User %S has no permissions to access " "the '%S' channel", user->name, errored_val); } else { return sdsnew("No permissions to access a channel"); } } ``` The caller can append/prepend the message (adding NOPERM for normal/RM_Call or indicating it's within a script). Impact: - Plain commands, as well as scripts and RM_Call now include the user name. - ACL DRYRUN remains the only one that's verbose (mentions the offending channel or key name) - Changes RM_Call ACL errors from being a `-ERR` to being `-NOPERM` (besides for textual changes) **This somewhat a breaking change, but it only affects the RM_Call with both `C` and `E`, or `D`** - Changes ACL errors in scripts textually from being `The user executing the script <old non unified text>` to `ACL failure in script: <new unified text>`
Diffstat (limited to 'tests/unit/moduleapi/misc.tcl')
-rw-r--r--tests/unit/moduleapi/misc.tcl4
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/unit/moduleapi/misc.tcl b/tests/unit/moduleapi/misc.tcl
index 8aa5b9198..15e4f4c6c 100644
--- a/tests/unit/moduleapi/misc.tcl
+++ b/tests/unit/moduleapi/misc.tcl
@@ -444,7 +444,7 @@ start_server {tags {"modules"}} {
r acl setuser default resetkeys
catch {r test.rm_call_flags DC set x 10} e
- assert_match {*ERR acl verification failed, can't access at least one of the keys*} $e
+ assert_match {*NOPERM No permissions to access a key*} $e
r acl setuser default +@all ~*
assert_equal [r get x] $x
}
@@ -452,4 +452,4 @@ start_server {tags {"modules"}} {
test "Unload the module - misc" {
assert_equal {OK} [r module unload misc]
}
-} \ No newline at end of file
+}