blob: 25eee7f557e6e94667252b59843e473a10e72ac7 [file] [log] [blame]
drh1962bda2003-01-12 19:33:52 +00001# 2003 January 12
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this script testing the sqlite_set_authorizer() API.
13#
drhe5f9c642003-01-13 23:27:31 +000014# $Id: auth.test,v 1.2 2003/01/13 23:27:34 drh Exp $
drh1962bda2003-01-12 19:33:52 +000015#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20if {[info command sqlite_set_authorizer]!=""} {
21
22do_test auth-1.1 {
23 db close
24 set ::DB [sqlite db test.db]
25 proc auth {code arg1 arg2} {
drhe5f9c642003-01-13 23:27:31 +000026 if {$code=="SQLITE_INSERT"
drh1962bda2003-01-12 19:33:52 +000027 && [string compare -nocase $arg1 sqlite_master]==0} {
28 return SQLITE_DENY
29 }
30 return SQLITE_OK
31 }
32 sqlite_set_authorizer $::DB ::auth
33 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +000034} {1 {not authorized}}
drh1962bda2003-01-12 19:33:52 +000035do_test auth-1.2 {
drhe5f9c642003-01-13 23:27:31 +000036 execsql {SELECT name FROM sqlite_master}
37} {}
38do_test auth-1.3 {
drh1962bda2003-01-12 19:33:52 +000039 proc auth {code arg1 arg2} {
drhe5f9c642003-01-13 23:27:31 +000040 if {$code=="SQLITE_CREATE_TABLE"} {
41 return SQLITE_DENY
42 }
43 return SQLITE_OK
44 }
45 catchsql {CREATE TABLE t1(a,b,c)}
46} {1 {not authorized}}
47do_test auth-1.4 {
48 execsql {SELECT name FROM sqlite_master}
49} {}
50
51do_test auth-1.5 {
52 proc auth {code arg1 arg2} {
53 if {$code=="SQLITE_INSERT"
54 && [string compare -nocase $arg1 sqlite_temp_master]==0} {
55 return SQLITE_DENY
56 }
57 return SQLITE_OK
58 }
59 catchsql {CREATE TEMP TABLE t1(a,b,c)}
60} {1 {not authorized}}
61do_test auth-1.6 {
62 execsql {SELECT name FROM sqlite_temp_master}
63} {}
64do_test auth-1.7 {
65 proc auth {code arg1 arg2} {
66 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
67 return SQLITE_DENY
68 }
69 return SQLITE_OK
70 }
71 catchsql {CREATE TEMP TABLE t1(a,b,c)}
72} {1 {not authorized}}
73do_test auth-1.8 {
74 execsql {SELECT name FROM sqlite_temp_master}
75} {}
76
77do_test auth-1.9 {
78 proc auth {code arg1 arg2} {
79 if {$code=="SQLITE_INSERT"
drh1962bda2003-01-12 19:33:52 +000080 && [string compare -nocase $arg1 sqlite_master]==0} {
81 return SQLITE_IGNORE
82 }
83 return SQLITE_OK
84 }
85 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +000086} {0 {}}
87do_test auth-1.10 {
88 execsql {SELECT name FROM sqlite_master}
89} {}
90do_test auth-1.11 {
drh1962bda2003-01-12 19:33:52 +000091 proc auth {code arg1 arg2} {
drhe5f9c642003-01-13 23:27:31 +000092 if {$code=="SQLITE_CREATE_TABLE"} {
93 return SQLITE_IGNORE
drh1962bda2003-01-12 19:33:52 +000094 }
95 return SQLITE_OK
96 }
97 catchsql {CREATE TABLE t1(a,b,c)}
98} {0 {}}
drhe5f9c642003-01-13 23:27:31 +000099do_test auth-1.12 {
drh1962bda2003-01-12 19:33:52 +0000100 execsql {SELECT name FROM sqlite_master}
drhe5f9c642003-01-13 23:27:31 +0000101} {}
102do_test auth-1.13 {
drh1962bda2003-01-12 19:33:52 +0000103 proc auth {code arg1 arg2} {
drhe5f9c642003-01-13 23:27:31 +0000104 if {$code=="SQLITE_INSERT"
105 && [string compare -nocase $arg1 sqlite_temp_master]==0} {
106 return SQLITE_IGNORE
107 }
108 return SQLITE_OK
109 }
110 catchsql {CREATE TEMP TABLE t1(a,b,c)}
111} {0 {}}
112do_test auth-1.14 {
113 execsql {SELECT name FROM sqlite_temp_master}
114} {}
115do_test auth-1.15 {
116 proc auth {code arg1 arg2} {
117 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
118 return SQLITE_IGNORE
119 }
120 return SQLITE_OK
121 }
122 catchsql {CREATE TEMP TABLE t1(a,b,c)}
123} {0 {}}
124do_test auth-1.16 {
125 execsql {SELECT name FROM sqlite_temp_master}
126} {}
127
128do_test auth-1.17 {
129 proc auth {code arg1 arg2} {
130 if {$code=="SQLITE_CREATE_TABLE"} {
131 return SQLITE_DEBY
132 }
133 return SQLITE_OK
134 }
135 catchsql {CREATE TEMP TABLE t1(a,b,c)}
136} {0 {}}
137do_test auth-1.18 {
138 execsql {SELECT name FROM sqlite_temp_master}
139} {t1}
140do_test auth-1.19 {
141 proc auth {code arg1 arg2} {
142 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
143 return SQLITE_DEBY
drh1962bda2003-01-12 19:33:52 +0000144 }
145 return SQLITE_OK
146 }
147 catchsql {CREATE TABLE t2(a,b,c)}
drh1962bda2003-01-12 19:33:52 +0000148} {0 {}}
drh1962bda2003-01-12 19:33:52 +0000149do_test auth-1.20 {
drhe5f9c642003-01-13 23:27:31 +0000150 execsql {SELECT name FROM sqlite_master}
151} {t2}
drh1962bda2003-01-12 19:33:52 +0000152
drhe5f9c642003-01-13 23:27:31 +0000153
154
155
drh1962bda2003-01-12 19:33:52 +0000156} ;# End of the "if( db command exists )"
157
158finish_test