Skip to content

Commit 8ccb5e2

Browse files
committed
Test case for no extra auth required for udf
Signed-off-by: mkhullar <mohit.khullar@gmail.com>
1 parent dcfd4cf commit 8ccb5e2

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

  • tests/simpleauth.test

tests/simpleauth.test/runit

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,76 @@ run_expect_success "$OP" "insert into comdb2_simple_auth(cluster, user, bpkg, ve
126126
run_expect_success "$OP" "delete from comdb2_simple_auth where user != '*'" \
127127
"clean up user-specific rules"
128128

129+
#---------------------------------------------------------------
130+
echo "Test: UDF access bypasses simpleauth, stored procedures do not"
131+
#---------------------------------------------------------------
132+
133+
# Create procedures and register UDFs while wildcard allows it
134+
run_expect_success "$OP" "create procedure myadd version 'test' {local function myadd(a, b) return a + b end}" \
135+
"create myadd procedure for scalar UDF"
136+
run_expect_success "$OP" "create lua scalar function myadd" \
137+
"register myadd as scalar UDF"
138+
run_expect_success "$OP" "create procedure mysum version 'test' {local agg = 0 local function step(v) agg = agg + v end local function final() return agg end}" \
139+
"create mysum procedure for aggregate UDF"
140+
run_expect_success "$OP" "create lua aggregate function mysum" \
141+
"register mysum as aggregate UDF"
142+
run_expect_success "$OP" "create procedure myproc version 'test' {local function main() db:column_name('result', 1) db:column_type('text', 1) db:emit('hello') end}" \
143+
"create myproc stored procedure"
144+
run_expect_success "$OP" "create table if not exists t_udf(i int)" \
145+
"create t_udf table"
146+
run_expect_success "$OP" "insert into t_udf values(10),(20),(30)" \
147+
"populate t_udf"
148+
149+
# Verify everything works with wildcard in place
150+
run_expect_success "$MARK" "select myadd(1, 2)" \
151+
"mk can call scalar UDF (wildcard allows)"
152+
run_expect_success "$MARK" "select mysum(i) from t_udf" \
153+
"mk can call aggregate UDF (wildcard allows)"
154+
run_expect_success "$MARK" "exec procedure myproc()" \
155+
"mk can exec procedure (wildcard allows)"
156+
157+
# Set up restricted access: remove wildcard, grant mk only table access
158+
run_expect_success "$OP" "insert into comdb2_simple_auth(cluster, user, bpkg, verb, resourcetype, resourcename) values('*', 'op', '*', 'Write', 'table', 'comdb2_simple_auth') on conflict do nothing" \
159+
"grant op write on auth table"
160+
run_expect_success "$OP" "insert into comdb2_simple_auth(cluster, user, bpkg, verb, resourcetype, resourcename) values('*', 'op', '*', 'Read', 'table', 'comdb2_simple_auth') on conflict do nothing" \
161+
"grant op read on auth table"
162+
run_expect_success "$OP" "delete from comdb2_simple_auth where cluster='*' and user='*' and bpkg='*' and verb='*' and resourcetype='*' and resourcename='*'" \
163+
"remove wildcard rule"
164+
165+
# Give mk Read access to t_udf table only (no stored-procedure access)
166+
run_expect_success "$OP" "insert into comdb2_simple_auth(cluster, user, bpkg, verb, resourcetype, resourcename) values('*', 'mk', '*', 'Read', 'table', 't_udf') on conflict do nothing" \
167+
"add mk Read rule for t_udf"
168+
169+
# mk can call scalar UDF (no table involved, UDFs bypass auth entirely)
170+
run_expect_success "$MARK" "select myadd(1, 2)" \
171+
"mk can call scalar UDF without stored-procedure access (UDFs bypass auth)"
172+
173+
# mk can call aggregate UDF on t_udf (table Read is enough, UDF itself needs no auth)
174+
run_expect_success "$MARK" "select mysum(i) from t_udf" \
175+
"mk can call aggregate UDF with table access (UDFs bypass auth)"
176+
177+
# mk cannot exec stored procedure (stored procedures check auth, no matching rule)
178+
run_expect_failure "$MARK" "exec procedure myproc()" \
179+
"mk cannot exec procedure without stored-procedure Read rule"
180+
181+
# Restore and cleanup
182+
run_expect_success "$OP" "insert into comdb2_simple_auth(cluster, user, bpkg, verb, resourcetype, resourcename) values('*', '*', '*', '*', '*', '*') on conflict do nothing" \
183+
"restore wildcard rule"
184+
run_expect_success "$OP" "delete from comdb2_simple_auth where user = 'op' or user = 'mk'" \
185+
"clean up user-specific rules"
186+
run_expect_success "$OP" "drop lua scalar function myadd" \
187+
"drop myadd UDF"
188+
run_expect_success "$OP" "drop lua aggregate function mysum" \
189+
"drop mysum UDF"
190+
run_expect_success "$OP" "drop procedure myadd version 'test'" \
191+
"drop myadd procedure"
192+
run_expect_success "$OP" "drop procedure mysum version 'test'" \
193+
"drop mysum procedure"
194+
run_expect_success "$OP" "drop procedure myproc version 'test'" \
195+
"drop myproc procedure"
196+
run_expect_success "$OP" "drop table if exists t_udf" \
197+
"drop t_udf table"
198+
129199
#---------------------------------------------------------------
130200
echo "Test: cleanup"
131201
#---------------------------------------------------------------

0 commit comments

Comments
 (0)