diff options
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/getkeys.tcl')
| -rw-r--r-- | examples/redis-unstable/tests/unit/moduleapi/getkeys.tcl | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/getkeys.tcl b/examples/redis-unstable/tests/unit/moduleapi/getkeys.tcl new file mode 100644 index 0000000..2854b86 --- /dev/null +++ b/examples/redis-unstable/tests/unit/moduleapi/getkeys.tcl | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | set testmodule [file normalize tests/modules/getkeys.so] | ||
| 2 | |||
| 3 | start_server {tags {"modules external:skip"}} { | ||
| 4 | r module load $testmodule | ||
| 5 | |||
| 6 | test {COMMAND INFO correctly reports a movable keys module command} { | ||
| 7 | set info [lindex [r command info getkeys.command] 0] | ||
| 8 | |||
| 9 | assert_equal {module movablekeys} [lindex $info 2] | ||
| 10 | assert_equal {0} [lindex $info 3] | ||
| 11 | assert_equal {0} [lindex $info 4] | ||
| 12 | assert_equal {0} [lindex $info 5] | ||
| 13 | } | ||
| 14 | |||
| 15 | test {COMMAND GETKEYS correctly reports a movable keys module command} { | ||
| 16 | r command getkeys getkeys.command arg1 arg2 key key1 arg3 key key2 key key3 | ||
| 17 | } {key1 key2 key3} | ||
| 18 | |||
| 19 | test {COMMAND GETKEYS correctly reports a movable keys module command using flags} { | ||
| 20 | r command getkeys getkeys.command_with_flags arg1 arg2 key key1 arg3 key key2 key key3 | ||
| 21 | } {key1 key2 key3} | ||
| 22 | |||
| 23 | test {COMMAND GETKEYSANDFLAGS correctly reports a movable keys module command not using flags} { | ||
| 24 | r command getkeysandflags getkeys.command arg1 arg2 key key1 arg3 key key2 | ||
| 25 | } {{key1 {RW access update}} {key2 {RW access update}}} | ||
| 26 | |||
| 27 | test {COMMAND GETKEYSANDFLAGS correctly reports a movable keys module command using flags} { | ||
| 28 | r command getkeysandflags getkeys.command_with_flags arg1 arg2 key key1 arg3 key key2 key key3 | ||
| 29 | } {{key1 {RO access}} {key2 {RO access}} {key3 {RO access}}} | ||
| 30 | |||
| 31 | test {RM_GetCommandKeys on non-existing command} { | ||
| 32 | catch {r getkeys.introspect 0 non-command key1 key2} e | ||
| 33 | set _ $e | ||
| 34 | } {*ENOENT*} | ||
| 35 | |||
| 36 | test {RM_GetCommandKeys on built-in fixed keys command} { | ||
| 37 | r getkeys.introspect 0 set key1 value1 | ||
| 38 | } {key1} | ||
| 39 | |||
| 40 | test {RM_GetCommandKeys on built-in fixed keys command with flags} { | ||
| 41 | r getkeys.introspect 1 set key1 value1 | ||
| 42 | } {{key1 OW}} | ||
| 43 | |||
| 44 | test {RM_GetCommandKeys on EVAL} { | ||
| 45 | r getkeys.introspect 0 eval "" 4 key1 key2 key3 key4 arg1 arg2 | ||
| 46 | } {key1 key2 key3 key4} | ||
| 47 | |||
| 48 | test {RM_GetCommandKeys on a movable keys module command} { | ||
| 49 | r getkeys.introspect 0 getkeys.command arg1 arg2 key key1 arg3 key key2 key key3 | ||
| 50 | } {key1 key2 key3} | ||
| 51 | |||
| 52 | test {RM_GetCommandKeys on a non-movable module command} { | ||
| 53 | r getkeys.introspect 0 getkeys.fixed arg1 key1 key2 key3 arg2 | ||
| 54 | } {key1 key2 key3} | ||
| 55 | |||
| 56 | test {RM_GetCommandKeys with bad arity} { | ||
| 57 | catch {r getkeys.introspect 0 set key} e | ||
| 58 | set _ $e | ||
| 59 | } {*EINVAL*} | ||
| 60 | |||
| 61 | test "introspect with > MAX_KEYS_BUFFER keys triggers RM_GetCommandKeysWithFlags heap alloc" { | ||
| 62 | set args {} | ||
| 63 | for {set i 0} {$i < 7} {incr i} { | ||
| 64 | lappend args key k$i | ||
| 65 | } | ||
| 66 | set reply [r getkeys.introspect 1 getkeys.command_with_flags {*}$args] | ||
| 67 | assert_equal {{k0 RO} {k1 RO} {k2 RO} {k3 RO} {k4 RO} {k5 RO} {k6 RO}} $reply | ||
| 68 | } | ||
| 69 | |||
| 70 | # user that can only read from "read" keys, write to "write" keys, and read+write to "RW" keys | ||
| 71 | r ACL setuser testuser +@all %R~read* %W~write* %RW~rw* | ||
| 72 | |||
| 73 | test "module getkeys-api - ACL" { | ||
| 74 | # legacy triple didn't provide flags, so they require both read and write | ||
| 75 | assert_equal "OK" [r ACL DRYRUN testuser getkeys.command key rw] | ||
| 76 | assert_match {*has no permissions to access the 'read' key*} [r ACL DRYRUN testuser getkeys.command key read] | ||
| 77 | assert_match {*has no permissions to access the 'write' key*} [r ACL DRYRUN testuser getkeys.command key write] | ||
| 78 | } | ||
| 79 | |||
| 80 | test "module getkeys-api with flags - ACL" { | ||
| 81 | assert_equal "OK" [r ACL DRYRUN testuser getkeys.command_with_flags key rw] | ||
| 82 | assert_equal "OK" [r ACL DRYRUN testuser getkeys.command_with_flags key read] | ||
| 83 | assert_match {*has no permissions to access the 'write' key*} [r ACL DRYRUN testuser getkeys.command_with_flags key write] | ||
| 84 | } | ||
| 85 | |||
| 86 | test "Unload the module - getkeys" { | ||
| 87 | assert_equal {OK} [r module unload getkeys] | ||
| 88 | } | ||
| 89 | } | ||
