Files
sqlite/test/trustschema1.test
T
drh 2eeca2046e Performance improvements and test cases added. Allow "PRAGMA trusted_schema=ON"
FossilOrigin-Name: 30882ca80f6c51f6bb7b2692c1ac3f19a7c61a23aa8730be79aec0ae3ef08d54
2020-01-08 20:37:45 +00:00

79 lines
1.9 KiB
Plaintext

# 2020-01-08
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test cases for managing execution of code snippets found in untrusted
# schemas.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix trustschema1
proc f1 {x} {return $x}
do_test 1.100 {
db function f1 -innocuous -deterministic f1
db function f2 -deterministic f1
db function f3 -directonly -deterministic f1
db eval {
CREATE TABLE t1(a, b AS (f1(a+1)), c AS (f2(a+2)));
INSERT INTO t1 VALUES(100),(200);
}
} {}
do_catchsql_test 1.110 {
SELECT a, b, c FROM t1;
} {0 {100 101 102 200 201 202}}
do_execsql_test 1.120 {
PRAGMA trusted_schema=OFF;
} {}
do_catchsql_test 1.130 {
SELECT a, b FROM t1;
} {0 {100 101 200 201}}
do_catchsql_test 1.140 {
SELECT a, b, c FROM t1;
} {1 {unsafe use of f2()}}
do_catchsql_test 1.200 {
CREATE TABLE t2(a,b,c,CHECK(f3(c)==c));
} {1 {unsafe use of f3()}}
do_catchsql_test 1.210 {
PRAGMA trusted_schema=Off;
CREATE TABLE t2(a,b,c,CHECK(f2(c)==c));
} {1 {unsafe use of f2()}}
do_catchsql_test 1.211 {
PRAGMA trusted_schema=On;
CREATE TABLE t2(a,b,c,CHECK(f2(c)==c));
} {0 {}}
do_catchsql_test 1.220 {
INSERT INTO t2 VALUES(1,2,3);
SELECT * FROM t2;
} {0 {1 2 3}}
do_catchsql_test 1.230 {
PRAGMA trusted_schema=off;
INSERT INTO t2 VALUES(4,5,6);
} {1 {unsafe use of f2()}}
do_execsql_test 1.231 {
SELECT * FROM t2;
} {1 2 3}
do_catchsql_test 1.300 {
CREATE TABLE t3(a,b DEFAULT(f2(25)));
} {0 {}}
do_catchsql_test 1.310 {
PRAGMA trusted_schema=Off;
INSERT INTO t3(a) VALUES(1);
} {1 {unsafe use of f2()}}
do_catchsql_test 1.311 {
INSERT INTO t3(a,b) VALUES(1,2);
} {0 {}}
finish_test