1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/auth2.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,168 @@
1.4 +# 2006 Aug 24
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this script is testing the sqlite3_set_authorizer() API
1.16 +# and related functionality.
1.17 +#
1.18 +# $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $
1.19 +#
1.20 +
1.21 +set testdir [file dirname $argv0]
1.22 +source $testdir/tester.tcl
1.23 +
1.24 +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
1.25 +# defined during compilation.
1.26 +if {[catch {db auth {}} msg]} {
1.27 + finish_test
1.28 + return
1.29 +}
1.30 +
1.31 +do_test auth2-1.1 {
1.32 + execsql {
1.33 + CREATE TABLE t1(a,b,c);
1.34 + INSERT INTO t1 VALUES(1,2,3);
1.35 + }
1.36 + set ::flist {}
1.37 + proc auth {code arg1 arg2 arg3 arg4} {
1.38 + if {$code=="SQLITE_FUNCTION"} {
1.39 + lappend ::flist $arg2
1.40 + if {$arg2=="max"} {
1.41 + return SQLITE_DENY
1.42 + } elseif {$arg2=="min"} {
1.43 + return SQLITE_IGNORE
1.44 + } else {
1.45 + return SQLITE_OK
1.46 + }
1.47 + }
1.48 + return SQLITE_OK
1.49 + }
1.50 + db authorizer ::auth
1.51 + catchsql {SELECT max(a,b,c) FROM t1}
1.52 +} {1 {not authorized to use function: max}}
1.53 +do_test auth2-1.2 {
1.54 + set ::flist
1.55 +} max
1.56 +do_test auth2-1.3 {
1.57 + set ::flist {}
1.58 + catchsql {SELECT min(a,b,c) FROM t1}
1.59 +} {0 {{}}}
1.60 +do_test auth2-1.4 {
1.61 + set ::flist
1.62 +} min
1.63 +do_test auth2-1.5 {
1.64 + set ::flist {}
1.65 + catchsql {SELECT coalesce(min(a,b,c),999) FROM t1}
1.66 +} {0 999}
1.67 +do_test auth2-1.6 {
1.68 + set ::flist
1.69 +} {coalesce min}
1.70 +do_test auth2-1.7 {
1.71 + set ::flist {}
1.72 + catchsql {SELECT coalesce(a,b,c) FROM t1}
1.73 +} {0 1}
1.74 +do_test auth2-1.8 {
1.75 + set ::flist
1.76 +} coalesce
1.77 +
1.78 +# Make sure the authorizer is not called when parsing the schema
1.79 +# and when computing the result set of a view.
1.80 +#
1.81 +db close
1.82 +sqlite3 db test.db
1.83 +sqlite3 db2 test.db
1.84 +proc auth {args} {
1.85 + global authargs
1.86 + append authargs $args\n
1.87 + return SQLITE_OK
1.88 +}
1.89 +db auth auth
1.90 +do_test auth2-2.1 {
1.91 + set ::authargs {}
1.92 + db eval {
1.93 + CREATE TABLE t2(x,y,z);
1.94 + }
1.95 + set ::authargs
1.96 +} {SQLITE_INSERT sqlite_master {} main {}
1.97 +SQLITE_CREATE_TABLE t2 {} main {}
1.98 +SQLITE_UPDATE sqlite_master type main {}
1.99 +SQLITE_UPDATE sqlite_master name main {}
1.100 +SQLITE_UPDATE sqlite_master tbl_name main {}
1.101 +SQLITE_UPDATE sqlite_master rootpage main {}
1.102 +SQLITE_UPDATE sqlite_master sql main {}
1.103 +SQLITE_READ sqlite_master ROWID main {}
1.104 +SQLITE_READ sqlite_master name main {}
1.105 +SQLITE_READ sqlite_master rootpage main {}
1.106 +SQLITE_READ sqlite_master sql main {}
1.107 +SQLITE_READ sqlite_master tbl_name main {}
1.108 +}
1.109 +do_test auth2-2.2 {
1.110 + set ::authargs {}
1.111 + db eval {
1.112 + CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2;
1.113 + }
1.114 + set ::authargs
1.115 +} {SQLITE_INSERT sqlite_master {} main {}
1.116 +SQLITE_CREATE_VIEW v2 {} main {}
1.117 +SQLITE_UPDATE sqlite_master type main {}
1.118 +SQLITE_UPDATE sqlite_master name main {}
1.119 +SQLITE_UPDATE sqlite_master tbl_name main {}
1.120 +SQLITE_UPDATE sqlite_master rootpage main {}
1.121 +SQLITE_UPDATE sqlite_master sql main {}
1.122 +SQLITE_READ sqlite_master ROWID main {}
1.123 +SQLITE_READ sqlite_master name main {}
1.124 +SQLITE_READ sqlite_master rootpage main {}
1.125 +SQLITE_READ sqlite_master sql main {}
1.126 +SQLITE_READ sqlite_master tbl_name main {}
1.127 +}
1.128 +do_test auth2-2.3 {
1.129 + set ::authargs {}
1.130 + db eval {
1.131 + SELECT a, b FROM v2;
1.132 + }
1.133 + set ::authargs
1.134 +} {SQLITE_SELECT {} {} {} {}
1.135 +SQLITE_READ v2 a main {}
1.136 +SQLITE_READ v2 b main {}
1.137 +SQLITE_READ t2 x main v2
1.138 +SQLITE_READ t2 y main v2
1.139 +SQLITE_READ t2 y main v2
1.140 +SQLITE_READ t2 z main v2
1.141 +SQLITE_SELECT {} {} {} v2
1.142 +}
1.143 +do_test auth2-2.4 {
1.144 + db2 eval {
1.145 + CREATE TABLE t3(p,q,r);
1.146 + }
1.147 + set ::authargs {}
1.148 + db eval {
1.149 + SELECT b, a FROM v2;
1.150 + }
1.151 + set ::authargs
1.152 +} {SQLITE_SELECT {} {} {} {}
1.153 +SQLITE_READ v2 b main {}
1.154 +SQLITE_READ v2 a main {}
1.155 +SQLITE_READ t2 x main v2
1.156 +SQLITE_READ t2 y main v2
1.157 +SQLITE_READ t2 y main v2
1.158 +SQLITE_READ t2 z main v2
1.159 +SQLITE_SELECT {} {} {} v2
1.160 +SQLITE_SELECT {} {} {} {}
1.161 +SQLITE_READ v2 b main {}
1.162 +SQLITE_READ v2 a main {}
1.163 +SQLITE_READ t2 x main v2
1.164 +SQLITE_READ t2 y main v2
1.165 +SQLITE_READ t2 y main v2
1.166 +SQLITE_READ t2 z main v2
1.167 +SQLITE_SELECT {} {} {} v2
1.168 +}
1.169 +db2 close
1.170 +
1.171 +finish_test