aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/tests/unit/moduleapi/usercall.tcl
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:52:54 +0100
commitdcacc00e3750300617ba6e16eb346713f91a783a (patch)
tree38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/tests/unit/moduleapi/usercall.tcl
parent58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff)
downloadcrep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz
Remove testing data
Diffstat (limited to 'examples/redis-unstable/tests/unit/moduleapi/usercall.tcl')
-rw-r--r--examples/redis-unstable/tests/unit/moduleapi/usercall.tcl186
1 files changed, 0 insertions, 186 deletions
diff --git a/examples/redis-unstable/tests/unit/moduleapi/usercall.tcl b/examples/redis-unstable/tests/unit/moduleapi/usercall.tcl
deleted file mode 100644
index 16b4ff1..0000000
--- a/examples/redis-unstable/tests/unit/moduleapi/usercall.tcl
+++ /dev/null
@@ -1,186 +0,0 @@
1set testmodule [file normalize tests/modules/usercall.so]
2
3set test_script_set "#!lua
4redis.call('set','x',1)
5return 1"
6
7set test_script_get "#!lua
8redis.call('get','x')
9return 1"
10
11start_server {tags {"modules usercall external:skip"}} {
12 r module load $testmodule
13
14 # baseline test that module isn't doing anything weird
15 test {test module check regular redis command without user/acl} {
16 assert_equal [r usercall.reset_user] OK
17 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
18 assert_equal [r usercall.call_without_user set x 5] OK
19 assert_equal [r usercall.reset_user] OK
20 }
21
22 # call with user with acl set on it, but without testing the acl
23 test {test module check regular redis command with user} {
24 assert_equal [r set x 5] OK
25
26 assert_equal [r usercall.reset_user] OK
27 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
28 # off and sanitize-payload because module user / default value
29 assert_equal [r usercall.get_acl] "off sanitize-payload ~* &* +@all -set"
30
31 # doesn't fail for regular commands as just testing acl here
32 assert_equal [r usercall.call_with_user_flag {} set x 10] OK
33
34 assert_equal [r get x] 10
35 assert_equal [r usercall.reset_user] OK
36 }
37
38 # call with user with acl set on it, but with testing the acl in rm_call (for cmd itself)
39 test {test module check regular redis command with user and acl} {
40 assert_equal [r set x 5] OK
41
42 r ACL LOG RESET
43 assert_equal [r usercall.reset_user] OK
44 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
45 # off and sanitize-payload because module user / default value
46 assert_equal [r usercall.get_acl] "off sanitize-payload ~* &* +@all -set"
47
48 # fails here as testing acl in rm call
49 assert_error {*NOPERM User module_user has no permissions*} {r usercall.call_with_user_flag C set x 10}
50
51 assert_equal [r usercall.call_with_user_flag C get x] 5
52
53 # verify that new log entry added
54 set entry [lindex [r ACL LOG] 0]
55 assert_equal [dict get $entry username] {module_user}
56 assert_equal [dict get $entry context] {module}
57 assert_equal [dict get $entry object] {set}
58 assert_equal [dict get $entry reason] {command}
59 assert_match {*cmd=usercall.call_with_user_flag*} [dict get $entry client-info]
60
61 assert_equal [r usercall.reset_user] OK
62 }
63
64 # call with user with acl set on it, but with testing the acl in rm_call (for cmd itself)
65 test {test module check regular redis command with user and acl from blocked background thread} {
66 assert_equal [r set x 5] OK
67
68 r ACL LOG RESET
69 assert_equal [r usercall.reset_user] OK
70 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
71
72 # fails here as testing acl in rm call from a background thread
73 assert_error {*NOPERM User module_user has no permissions*} {r usercall.call_with_user_bg C set x 10}
74
75 assert_equal [r usercall.call_with_user_bg C get x] 5
76
77 # verify that new log entry added
78 set entry [lindex [r ACL LOG] 0]
79 assert_equal [dict get $entry username] {module_user}
80 assert_equal [dict get $entry context] {module}
81 assert_equal [dict get $entry object] {set}
82 assert_equal [dict get $entry reason] {command}
83 assert_match {*cmd=NULL*} [dict get $entry client-info]
84
85 assert_equal [r usercall.reset_user] OK
86 }
87
88 # baseline script test, call without user on script
89 test {test module check eval script without user} {
90 set sha_set [r script load $test_script_set]
91 set sha_get [r script load $test_script_get]
92
93 assert_equal [r usercall.call_without_user evalsha $sha_set 0] 1
94 assert_equal [r usercall.call_without_user evalsha $sha_get 0] 1
95 }
96
97 # baseline script test, call without user on script
98 test {test module check eval script with user being set, but not acl testing} {
99 set sha_set [r script load $test_script_set]
100 set sha_get [r script load $test_script_get]
101
102 assert_equal [r usercall.reset_user] OK
103 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
104 # off and sanitize-payload because module user / default value
105 assert_equal [r usercall.get_acl] "off sanitize-payload ~* &* +@all -set"
106
107 # passes as not checking ACL
108 assert_equal [r usercall.call_with_user_flag {} evalsha $sha_set 0] 1
109 assert_equal [r usercall.call_with_user_flag {} evalsha $sha_get 0] 1
110 }
111
112 # call with user on script (without rm_call acl check) to ensure user carries through to script execution
113 # we already tested the check in rm_call above, here we are checking the script itself will enforce ACL
114 test {test module check eval script with user and acl} {
115 set sha_set [r script load $test_script_set]
116 set sha_get [r script load $test_script_get]
117
118 r ACL LOG RESET
119 assert_equal [r usercall.reset_user] OK
120 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
121
122 # fails here in script, as rm_call will permit the eval call
123 catch {r usercall.call_with_user_flag C evalsha $sha_set 0} e
124 assert_match {*ERR ACL failure in script*} $e
125
126 assert_equal [r usercall.call_with_user_flag C evalsha $sha_get 0] 1
127
128 # verify that new log entry added
129 set entry [lindex [r ACL LOG] 0]
130 assert_equal [dict get $entry username] {module_user}
131 assert_equal [dict get $entry context] {lua}
132 assert_equal [dict get $entry object] {set}
133 assert_equal [dict get $entry reason] {command}
134 assert_match {*cmd=usercall.call_with_user_flag*} [dict get $entry client-info]
135 }
136
137 test {server not crashing when MONITOR is fed from spawned thread} {
138 set rd [redis_deferring_client]
139 $rd monitor
140
141 r ACL LOG RESET
142 assert_equal [r usercall.reset_user] OK
143 assert_equal [r usercall.add_to_acl "~* &* +@all -set"] OK
144
145 r flushdb
146 r set x x
147
148 # This is enough. This checks that we don't crash inside
149 # updateClientMemUsageAndBucket
150 assert_equal x [r usercall.call_with_user_bg C get x]
151
152 $rd close
153 }
154
155 start_server {tags {"wait aof network external:skip"}} {
156 set slave [srv 0 client]
157 set slave_host [srv 0 host]
158 set slave_port [srv 0 port]
159 set slave_pid [srv 0 pid]
160 set master [srv -1 client]
161 set master_host [srv -1 host]
162 set master_port [srv -1 port]
163
164 $master config set appendonly yes
165 $master config set appendfsync everysec
166 $slave config set appendonly yes
167 $slave config set appendfsync everysec
168
169 test {Setup slave} {
170 $slave slaveof $master_host $master_port
171 wait_for_condition 50 100 {
172 [s 0 master_link_status] eq {up}
173 } else {
174 fail "Replication not started."
175 }
176 }
177
178 test {test module replicate only to replicas and WAITAOF} {
179 $master set x 1
180 assert_equal [$master waitaof 1 1 10000] {1 1}
181 $master usercall.call_with_user_flag A! config set loglevel notice
182 # Make sure WAITAOF doesn't hang
183 assert_equal [$master waitaof 1 1 10000] {1 1}
184 }
185 }
186}