blob: 63ed7ba20abca4f589be77b015fc8525dbd211a2 [file] [log] [blame]
drh2d458342003-04-05 03:42:26 +00001# 2003 April 4
drh1962bda2003-01-12 19:33:52 +00002#
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
drh2d458342003-04-05 03:42:26 +000012# focus of this script is testing the ATTACH and DETACH commands
13# and related functionality.
drh1962bda2003-01-12 19:33:52 +000014#
danielk19771d54df82004-11-23 15:41:16 +000015# $Id: auth.test,v 1.25 2004/11/23 15:41:17 danielk1977 Exp $
drh1962bda2003-01-12 19:33:52 +000016#
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
drhe22a3342003-04-22 20:30:37 +000021# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
22# defined during compilation.
drh1211de32004-07-26 12:24:22 +000023if {[catch {db auth {}} msg]} {
24 finish_test
25 return
26}
drh1962bda2003-01-12 19:33:52 +000027
drhdcd997e2003-01-31 17:21:49 +000028do_test auth-1.1.1 {
drh1962bda2003-01-12 19:33:52 +000029 db close
drhef4ac8f2004-06-19 00:16:31 +000030 set ::DB [sqlite3 db test.db]
drhe22a3342003-04-22 20:30:37 +000031 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +000032 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
drh1962bda2003-01-12 19:33:52 +000033 return SQLITE_DENY
34 }
35 return SQLITE_OK
36 }
drhe22a3342003-04-22 20:30:37 +000037 db authorizer ::auth
drh1962bda2003-01-12 19:33:52 +000038 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +000039} {1 {not authorized}}
drhdcd997e2003-01-31 17:21:49 +000040do_test auth-1.1.2 {
41 db errorcode
42} {23}
drh0f14e2e2004-06-29 12:39:08 +000043do_test auth-1.1.3 {
44 db authorizer
45} {::auth}
drh56891232004-09-09 13:55:50 +000046do_test auth-1.1.4 {
47 # Ticket #896.
48 catchsql {
49 SELECT x;
50 }
51} {1 {no such column: x}}
drh1962bda2003-01-12 19:33:52 +000052do_test auth-1.2 {
drhe5f9c642003-01-13 23:27:31 +000053 execsql {SELECT name FROM sqlite_master}
54} {}
drh77ad4e42003-01-14 02:49:27 +000055do_test auth-1.3.1 {
drhe22a3342003-04-22 20:30:37 +000056 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +000057 if {$code=="SQLITE_CREATE_TABLE"} {
drhe22a3342003-04-22 20:30:37 +000058 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +000059 return SQLITE_DENY
60 }
61 return SQLITE_OK
62 }
63 catchsql {CREATE TABLE t1(a,b,c)}
64} {1 {not authorized}}
drh77ad4e42003-01-14 02:49:27 +000065do_test auth-1.3.2 {
drhdcd997e2003-01-31 17:21:49 +000066 db errorcode
67} {23}
68do_test auth-1.3.3 {
drh77ad4e42003-01-14 02:49:27 +000069 set ::authargs
drhe22a3342003-04-22 20:30:37 +000070} {t1 {} main {}}
drhe5f9c642003-01-13 23:27:31 +000071do_test auth-1.4 {
72 execsql {SELECT name FROM sqlite_master}
73} {}
74
75do_test auth-1.5 {
drhe22a3342003-04-22 20:30:37 +000076 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +000077 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
drhe5f9c642003-01-13 23:27:31 +000078 return SQLITE_DENY
79 }
80 return SQLITE_OK
81 }
82 catchsql {CREATE TEMP TABLE t1(a,b,c)}
83} {1 {not authorized}}
84do_test auth-1.6 {
85 execsql {SELECT name FROM sqlite_temp_master}
86} {}
drh77ad4e42003-01-14 02:49:27 +000087do_test auth-1.7.1 {
drhe22a3342003-04-22 20:30:37 +000088 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +000089 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +000090 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +000091 return SQLITE_DENY
92 }
93 return SQLITE_OK
94 }
95 catchsql {CREATE TEMP TABLE t1(a,b,c)}
96} {1 {not authorized}}
drh77ad4e42003-01-14 02:49:27 +000097do_test auth-1.7.2 {
98 set ::authargs
drhe22a3342003-04-22 20:30:37 +000099} {t1 {} temp {}}
drhe5f9c642003-01-13 23:27:31 +0000100do_test auth-1.8 {
101 execsql {SELECT name FROM sqlite_temp_master}
102} {}
103
104do_test auth-1.9 {
drhe22a3342003-04-22 20:30:37 +0000105 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000106 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
drh1962bda2003-01-12 19:33:52 +0000107 return SQLITE_IGNORE
108 }
109 return SQLITE_OK
110 }
111 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +0000112} {0 {}}
113do_test auth-1.10 {
114 execsql {SELECT name FROM sqlite_master}
115} {}
116do_test auth-1.11 {
drhe22a3342003-04-22 20:30:37 +0000117 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000118 if {$code=="SQLITE_CREATE_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000119 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +0000120 return SQLITE_IGNORE
drh1962bda2003-01-12 19:33:52 +0000121 }
122 return SQLITE_OK
123 }
124 catchsql {CREATE TABLE t1(a,b,c)}
125} {0 {}}
drhe5f9c642003-01-13 23:27:31 +0000126do_test auth-1.12 {
drh1962bda2003-01-12 19:33:52 +0000127 execsql {SELECT name FROM sqlite_master}
drhe5f9c642003-01-13 23:27:31 +0000128} {}
129do_test auth-1.13 {
drhe22a3342003-04-22 20:30:37 +0000130 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000131 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
drhe5f9c642003-01-13 23:27:31 +0000132 return SQLITE_IGNORE
133 }
134 return SQLITE_OK
135 }
136 catchsql {CREATE TEMP TABLE t1(a,b,c)}
137} {0 {}}
138do_test auth-1.14 {
139 execsql {SELECT name FROM sqlite_temp_master}
140} {}
141do_test auth-1.15 {
drhe22a3342003-04-22 20:30:37 +0000142 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000143 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000144 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +0000145 return SQLITE_IGNORE
146 }
147 return SQLITE_OK
148 }
149 catchsql {CREATE TEMP TABLE t1(a,b,c)}
150} {0 {}}
151do_test auth-1.16 {
152 execsql {SELECT name FROM sqlite_temp_master}
153} {}
154
155do_test auth-1.17 {
drhe22a3342003-04-22 20:30:37 +0000156 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000157 if {$code=="SQLITE_CREATE_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000158 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000159 return SQLITE_DENY
drhe5f9c642003-01-13 23:27:31 +0000160 }
161 return SQLITE_OK
162 }
163 catchsql {CREATE TEMP TABLE t1(a,b,c)}
164} {0 {}}
165do_test auth-1.18 {
166 execsql {SELECT name FROM sqlite_temp_master}
167} {t1}
drh77ad4e42003-01-14 02:49:27 +0000168do_test auth-1.19.1 {
169 set ::authargs {}
drhe22a3342003-04-22 20:30:37 +0000170 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000171 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000172 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000173 return SQLITE_DENY
drh1962bda2003-01-12 19:33:52 +0000174 }
175 return SQLITE_OK
176 }
177 catchsql {CREATE TABLE t2(a,b,c)}
drh1962bda2003-01-12 19:33:52 +0000178} {0 {}}
drh77ad4e42003-01-14 02:49:27 +0000179do_test auth-1.19.2 {
180 set ::authargs
181} {}
drh1962bda2003-01-12 19:33:52 +0000182do_test auth-1.20 {
drhe5f9c642003-01-13 23:27:31 +0000183 execsql {SELECT name FROM sqlite_master}
184} {t2}
drh1962bda2003-01-12 19:33:52 +0000185
drh77ad4e42003-01-14 02:49:27 +0000186do_test auth-1.21.1 {
drhe22a3342003-04-22 20:30:37 +0000187 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000188 if {$code=="SQLITE_DROP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000189 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000190 return SQLITE_DENY
191 }
192 return SQLITE_OK
193 }
194 catchsql {DROP TABLE t2}
195} {1 {not authorized}}
196do_test auth-1.21.2 {
197 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000198} {t2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000199do_test auth-1.22 {
200 execsql {SELECT name FROM sqlite_master}
201} {t2}
202do_test auth-1.23.1 {
drhe22a3342003-04-22 20:30:37 +0000203 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000204 if {$code=="SQLITE_DROP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000205 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000206 return SQLITE_IGNORE
207 }
208 return SQLITE_OK
209 }
210 catchsql {DROP TABLE t2}
211} {0 {}}
212do_test auth-1.23.2 {
213 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000214} {t2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000215do_test auth-1.24 {
216 execsql {SELECT name FROM sqlite_master}
217} {t2}
drhe5f9c642003-01-13 23:27:31 +0000218
drh77ad4e42003-01-14 02:49:27 +0000219do_test auth-1.25 {
drhe22a3342003-04-22 20:30:37 +0000220 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000221 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000222 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000223 return SQLITE_DENY
224 }
225 return SQLITE_OK
226 }
227 catchsql {DROP TABLE t1}
228} {1 {not authorized}}
229do_test auth-1.26 {
230 execsql {SELECT name FROM sqlite_temp_master}
231} {t1}
232do_test auth-1.27 {
drhe22a3342003-04-22 20:30:37 +0000233 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000234 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000235 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000236 return SQLITE_IGNORE
237 }
238 return SQLITE_OK
239 }
240 catchsql {DROP TABLE t1}
241} {0 {}}
242do_test auth-1.28 {
243 execsql {SELECT name FROM sqlite_temp_master}
244} {t1}
245
246do_test auth-1.29 {
drhe22a3342003-04-22 20:30:37 +0000247 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000248 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
249 return SQLITE_DENY
250 }
251 return SQLITE_OK
252 }
253 catchsql {INSERT INTO t2 VALUES(1,2,3)}
254} {1 {not authorized}}
255do_test auth-1.30 {
256 execsql {SELECT * FROM t2}
257} {}
258do_test auth-1.31 {
drhe22a3342003-04-22 20:30:37 +0000259 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000260 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
261 return SQLITE_IGNORE
262 }
263 return SQLITE_OK
264 }
265 catchsql {INSERT INTO t2 VALUES(1,2,3)}
266} {0 {}}
267do_test auth-1.32 {
268 execsql {SELECT * FROM t2}
269} {}
270do_test auth-1.33 {
drhe22a3342003-04-22 20:30:37 +0000271 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000272 if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
273 return SQLITE_IGNORE
274 }
275 return SQLITE_OK
276 }
277 catchsql {INSERT INTO t2 VALUES(1,2,3)}
278} {0 {}}
279do_test auth-1.34 {
280 execsql {SELECT * FROM t2}
281} {1 2 3}
282
drh4925ca02003-11-27 00:48:57 +0000283do_test auth-1.35.1 {
drhe22a3342003-04-22 20:30:37 +0000284 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000285 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
286 return SQLITE_DENY
287 }
288 return SQLITE_OK
289 }
290 catchsql {SELECT * FROM t2}
291} {1 {access to t2.b is prohibited}}
drh4925ca02003-11-27 00:48:57 +0000292do_test auth-1.35.2 {
293 execsql {ATTACH DATABASE 'test.db' AS two}
294 catchsql {SELECT * FROM two.t2}
295} {1 {access to two.t2.b is prohibited}}
296execsql {DETACH DATABASE two}
drh77ad4e42003-01-14 02:49:27 +0000297do_test auth-1.36 {
drhe22a3342003-04-22 20:30:37 +0000298 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000299 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
300 return SQLITE_IGNORE
301 }
302 return SQLITE_OK
303 }
304 catchsql {SELECT * FROM t2}
305} {0 {1 {} 3}}
306do_test auth-1.37 {
drhe22a3342003-04-22 20:30:37 +0000307 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000308 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
309 return SQLITE_IGNORE
310 }
311 return SQLITE_OK
312 }
313 catchsql {SELECT * FROM t2 WHERE b=2}
314} {0 {}}
315do_test auth-1.38 {
drhe22a3342003-04-22 20:30:37 +0000316 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000317 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
318 return SQLITE_IGNORE
319 }
320 return SQLITE_OK
321 }
322 catchsql {SELECT * FROM t2 WHERE b=2}
323} {0 {{} 2 3}}
324do_test auth-1.39 {
drhe22a3342003-04-22 20:30:37 +0000325 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000326 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
327 return SQLITE_IGNORE
328 }
329 return SQLITE_OK
330 }
331 catchsql {SELECT * FROM t2 WHERE b IS NULL}
332} {0 {1 {} 3}}
333do_test auth-1.40 {
drhe22a3342003-04-22 20:30:37 +0000334 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000335 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
336 return SQLITE_DENY
337 }
338 return SQLITE_OK
339 }
340 catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
341} {1 {access to t2.b is prohibited}}
342
343do_test auth-1.41 {
drhe22a3342003-04-22 20:30:37 +0000344 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000345 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
346 return SQLITE_DENY
347 }
348 return SQLITE_OK
349 }
350 catchsql {UPDATE t2 SET a=11}
351} {0 {}}
352do_test auth-1.42 {
353 execsql {SELECT * FROM t2}
354} {11 2 3}
355do_test auth-1.43 {
drhe22a3342003-04-22 20:30:37 +0000356 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000357 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
358 return SQLITE_DENY
359 }
360 return SQLITE_OK
361 }
362 catchsql {UPDATE t2 SET b=22, c=33}
363} {1 {not authorized}}
364do_test auth-1.44 {
365 execsql {SELECT * FROM t2}
366} {11 2 3}
367do_test auth-1.45 {
drhe22a3342003-04-22 20:30:37 +0000368 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000369 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
370 return SQLITE_IGNORE
371 }
372 return SQLITE_OK
373 }
374 catchsql {UPDATE t2 SET b=22, c=33}
375} {0 {}}
376do_test auth-1.46 {
377 execsql {SELECT * FROM t2}
378} {11 2 33}
379
380do_test auth-1.47 {
drhe22a3342003-04-22 20:30:37 +0000381 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000382 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
383 return SQLITE_DENY
384 }
385 return SQLITE_OK
386 }
387 catchsql {DELETE FROM t2 WHERE a=11}
388} {1 {not authorized}}
389do_test auth-1.48 {
390 execsql {SELECT * FROM t2}
391} {11 2 33}
392do_test auth-1.49 {
drhe22a3342003-04-22 20:30:37 +0000393 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000394 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
395 return SQLITE_IGNORE
396 }
397 return SQLITE_OK
398 }
399 catchsql {DELETE FROM t2 WHERE a=11}
400} {0 {}}
401do_test auth-1.50 {
402 execsql {SELECT * FROM t2}
403} {11 2 33}
404
405do_test auth-1.51 {
drhe22a3342003-04-22 20:30:37 +0000406 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000407 if {$code=="SQLITE_SELECT"} {
408 return SQLITE_DENY
409 }
410 return SQLITE_OK
411 }
412 catchsql {SELECT * FROM t2}
413} {1 {not authorized}}
414do_test auth-1.52 {
drhe22a3342003-04-22 20:30:37 +0000415 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000416 if {$code=="SQLITE_SELECT"} {
417 return SQLITE_IGNORE
418 }
419 return SQLITE_OK
420 }
421 catchsql {SELECT * FROM t2}
422} {0 {}}
423do_test auth-1.53 {
drhe22a3342003-04-22 20:30:37 +0000424 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000425 if {$code=="SQLITE_SELECT"} {
426 return SQLITE_OK
427 }
428 return SQLITE_OK
429 }
430 catchsql {SELECT * FROM t2}
431} {0 {11 2 33}}
432
danielk19772ac79702004-06-14 11:54:18 +0000433# Update for version 3: There used to be a handful of test here that
434# tested the authorisation callback with the COPY command. The following
435# test makes the same database modifications as they used to.
436do_test auth-1.54 {
437 execsql {INSERT INTO t2 VALUES(7, 8, 9);}
438} {}
439do_test auth-1.55 {
440 execsql {SELECT * FROM t2}
441} {11 2 33 7 8 9}
drh77ad4e42003-01-14 02:49:27 +0000442
443do_test auth-1.63 {
drhe22a3342003-04-22 20:30:37 +0000444 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000445 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
446 return SQLITE_DENY
447 }
448 return SQLITE_OK
449 }
450 catchsql {DROP TABLE t2}
451} {1 {not authorized}}
452do_test auth-1.64 {
453 execsql {SELECT name FROM sqlite_master}
454} {t2}
455do_test auth-1.65 {
drhe22a3342003-04-22 20:30:37 +0000456 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000457 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
458 return SQLITE_DENY
459 }
460 return SQLITE_OK
461 }
462 catchsql {DROP TABLE t2}
463} {1 {not authorized}}
464do_test auth-1.66 {
465 execsql {SELECT name FROM sqlite_master}
466} {t2}
467do_test auth-1.67 {
drhe22a3342003-04-22 20:30:37 +0000468 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000469 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
470 return SQLITE_DENY
471 }
472 return SQLITE_OK
473 }
474 catchsql {DROP TABLE t1}
475} {1 {not authorized}}
476do_test auth-1.68 {
477 execsql {SELECT name FROM sqlite_temp_master}
478} {t1}
479do_test auth-1.69 {
drhe22a3342003-04-22 20:30:37 +0000480 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000481 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
482 return SQLITE_DENY
483 }
484 return SQLITE_OK
485 }
486 catchsql {DROP TABLE t1}
487} {1 {not authorized}}
488do_test auth-1.70 {
489 execsql {SELECT name FROM sqlite_temp_master}
490} {t1}
491
492do_test auth-1.71 {
drhe22a3342003-04-22 20:30:37 +0000493 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000494 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
495 return SQLITE_IGNORE
496 }
497 return SQLITE_OK
498 }
499 catchsql {DROP TABLE t2}
500} {0 {}}
501do_test auth-1.72 {
502 execsql {SELECT name FROM sqlite_master}
503} {t2}
504do_test auth-1.73 {
drhe22a3342003-04-22 20:30:37 +0000505 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000506 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
507 return SQLITE_IGNORE
508 }
509 return SQLITE_OK
510 }
511 catchsql {DROP TABLE t2}
512} {0 {}}
513do_test auth-1.74 {
514 execsql {SELECT name FROM sqlite_master}
515} {t2}
516do_test auth-1.75 {
drhe22a3342003-04-22 20:30:37 +0000517 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000518 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
519 return SQLITE_IGNORE
520 }
521 return SQLITE_OK
522 }
523 catchsql {DROP TABLE t1}
524} {0 {}}
525do_test auth-1.76 {
526 execsql {SELECT name FROM sqlite_temp_master}
527} {t1}
528do_test auth-1.77 {
drhe22a3342003-04-22 20:30:37 +0000529 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000530 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
531 return SQLITE_IGNORE
532 }
533 return SQLITE_OK
534 }
535 catchsql {DROP TABLE t1}
536} {0 {}}
537do_test auth-1.78 {
538 execsql {SELECT name FROM sqlite_temp_master}
539} {t1}
540
danielk197781650dc2004-11-22 11:51:13 +0000541# Test cases auth-1.79 to auth-1.124 test creating and dropping views.
danielk19770fa8ddb2004-11-22 08:43:32 +0000542# Omit these if the library was compiled with views omitted.
543ifcapable view {
drh77ad4e42003-01-14 02:49:27 +0000544do_test auth-1.79 {
drhe22a3342003-04-22 20:30:37 +0000545 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000546 if {$code=="SQLITE_CREATE_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000547 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000548 return SQLITE_DENY
549 }
550 return SQLITE_OK
551 }
552 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
553} {1 {not authorized}}
554do_test auth-1.80 {
555 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000556} {v1 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000557do_test auth-1.81 {
558 execsql {SELECT name FROM sqlite_master}
559} {t2}
560do_test auth-1.82 {
drhe22a3342003-04-22 20:30:37 +0000561 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000562 if {$code=="SQLITE_CREATE_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000563 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000564 return SQLITE_IGNORE
565 }
566 return SQLITE_OK
567 }
568 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
569} {0 {}}
570do_test auth-1.83 {
571 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000572} {v1 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000573do_test auth-1.84 {
574 execsql {SELECT name FROM sqlite_master}
575} {t2}
576
577do_test auth-1.85 {
drhe22a3342003-04-22 20:30:37 +0000578 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000579 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000580 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000581 return SQLITE_DENY
582 }
583 return SQLITE_OK
584 }
585 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
586} {1 {not authorized}}
587do_test auth-1.86 {
588 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000589} {v1 {} temp {}}
drh77ad4e42003-01-14 02:49:27 +0000590do_test auth-1.87 {
591 execsql {SELECT name FROM sqlite_temp_master}
592} {t1}
593do_test auth-1.88 {
drhe22a3342003-04-22 20:30:37 +0000594 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000595 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000596 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000597 return SQLITE_IGNORE
598 }
599 return SQLITE_OK
600 }
601 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
602} {0 {}}
603do_test auth-1.89 {
604 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000605} {v1 {} temp {}}
drh77ad4e42003-01-14 02:49:27 +0000606do_test auth-1.90 {
607 execsql {SELECT name FROM sqlite_temp_master}
608} {t1}
609
610do_test auth-1.91 {
drhe22a3342003-04-22 20:30:37 +0000611 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000612 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
613 return SQLITE_DENY
614 }
615 return SQLITE_OK
616 }
617 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
618} {1 {not authorized}}
619do_test auth-1.92 {
620 execsql {SELECT name FROM sqlite_master}
621} {t2}
622do_test auth-1.93 {
drhe22a3342003-04-22 20:30:37 +0000623 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000624 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
625 return SQLITE_IGNORE
626 }
627 return SQLITE_OK
628 }
629 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
630} {0 {}}
631do_test auth-1.94 {
632 execsql {SELECT name FROM sqlite_master}
633} {t2}
634
635do_test auth-1.95 {
drhe22a3342003-04-22 20:30:37 +0000636 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000637 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
638 return SQLITE_DENY
639 }
640 return SQLITE_OK
641 }
642 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
643} {1 {not authorized}}
644do_test auth-1.96 {
645 execsql {SELECT name FROM sqlite_temp_master}
646} {t1}
647do_test auth-1.97 {
drhe22a3342003-04-22 20:30:37 +0000648 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000649 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
650 return SQLITE_IGNORE
651 }
652 return SQLITE_OK
653 }
654 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
655} {0 {}}
656do_test auth-1.98 {
657 execsql {SELECT name FROM sqlite_temp_master}
658} {t1}
659
660do_test auth-1.99 {
drhe22a3342003-04-22 20:30:37 +0000661 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000662 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
663 return SQLITE_DENY
664 }
665 return SQLITE_OK
666 }
667 catchsql {
668 CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
669 DROP VIEW v2
670 }
671} {1 {not authorized}}
672do_test auth-1.100 {
673 execsql {SELECT name FROM sqlite_master}
674} {t2 v2}
675do_test auth-1.101 {
drhe22a3342003-04-22 20:30:37 +0000676 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000677 if {$code=="SQLITE_DROP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000678 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000679 return SQLITE_DENY
680 }
681 return SQLITE_OK
682 }
683 catchsql {DROP VIEW v2}
684} {1 {not authorized}}
685do_test auth-1.102 {
686 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000687} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000688do_test auth-1.103 {
689 execsql {SELECT name FROM sqlite_master}
690} {t2 v2}
691do_test auth-1.104 {
drhe22a3342003-04-22 20:30:37 +0000692 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000693 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
694 return SQLITE_IGNORE
695 }
696 return SQLITE_OK
697 }
698 catchsql {DROP VIEW v2}
699} {0 {}}
700do_test auth-1.105 {
701 execsql {SELECT name FROM sqlite_master}
702} {t2 v2}
703do_test auth-1.106 {
drhe22a3342003-04-22 20:30:37 +0000704 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000705 if {$code=="SQLITE_DROP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000706 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000707 return SQLITE_IGNORE
708 }
709 return SQLITE_OK
710 }
711 catchsql {DROP VIEW v2}
712} {0 {}}
713do_test auth-1.107 {
714 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000715} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000716do_test auth-1.108 {
717 execsql {SELECT name FROM sqlite_master}
718} {t2 v2}
719do_test auth-1.109 {
drhe22a3342003-04-22 20:30:37 +0000720 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000721 if {$code=="SQLITE_DROP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000722 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000723 return SQLITE_OK
724 }
725 return SQLITE_OK
726 }
727 catchsql {DROP VIEW v2}
728} {0 {}}
729do_test auth-1.110 {
730 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000731} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000732do_test auth-1.111 {
733 execsql {SELECT name FROM sqlite_master}
734} {t2}
735
736
737do_test auth-1.112 {
drhe22a3342003-04-22 20:30:37 +0000738 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000739 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
740 return SQLITE_DENY
741 }
742 return SQLITE_OK
743 }
744 catchsql {
745 CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
746 DROP VIEW v1
747 }
748} {1 {not authorized}}
749do_test auth-1.113 {
750 execsql {SELECT name FROM sqlite_temp_master}
751} {t1 v1}
752do_test auth-1.114 {
drhe22a3342003-04-22 20:30:37 +0000753 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000754 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000755 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000756 return SQLITE_DENY
757 }
758 return SQLITE_OK
759 }
760 catchsql {DROP VIEW v1}
761} {1 {not authorized}}
762do_test auth-1.115 {
763 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000764} {v1 {} temp {}}
drh77ad4e42003-01-14 02:49:27 +0000765do_test auth-1.116 {
766 execsql {SELECT name FROM sqlite_temp_master}
767} {t1 v1}
768do_test auth-1.117 {
drhe22a3342003-04-22 20:30:37 +0000769 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000770 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
771 return SQLITE_IGNORE
772 }
773 return SQLITE_OK
774 }
775 catchsql {DROP VIEW v1}
776} {0 {}}
777do_test auth-1.118 {
778 execsql {SELECT name FROM sqlite_temp_master}
779} {t1 v1}
780do_test auth-1.119 {
drhe22a3342003-04-22 20:30:37 +0000781 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000782 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000783 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000784 return SQLITE_IGNORE
785 }
786 return SQLITE_OK
787 }
788 catchsql {DROP VIEW v1}
789} {0 {}}
790do_test auth-1.120 {
791 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000792} {v1 {} temp {}}
drh77ad4e42003-01-14 02:49:27 +0000793do_test auth-1.121 {
794 execsql {SELECT name FROM sqlite_temp_master}
795} {t1 v1}
796do_test auth-1.122 {
drhe22a3342003-04-22 20:30:37 +0000797 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000798 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000799 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000800 return SQLITE_OK
801 }
802 return SQLITE_OK
803 }
804 catchsql {DROP VIEW v1}
805} {0 {}}
806do_test auth-1.123 {
807 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000808} {v1 {} temp {}}
drh77ad4e42003-01-14 02:49:27 +0000809do_test auth-1.124 {
810 execsql {SELECT name FROM sqlite_temp_master}
811} {t1}
danielk19770fa8ddb2004-11-22 08:43:32 +0000812} ;# ifcapable view
drh77ad4e42003-01-14 02:49:27 +0000813
danielk197781650dc2004-11-22 11:51:13 +0000814# Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
815# Omit these if the library was compiled with triggers omitted.
816#
817ifcapable trigger {
drh77ad4e42003-01-14 02:49:27 +0000818do_test auth-1.125 {
drhe22a3342003-04-22 20:30:37 +0000819 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000820 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000821 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000822 return SQLITE_DENY
823 }
824 return SQLITE_OK
825 }
826 catchsql {
827 CREATE TRIGGER r2 DELETE on t2 BEGIN
828 SELECT NULL;
829 END;
830 }
831} {1 {not authorized}}
832do_test auth-1.126 {
833 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000834} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +0000835do_test auth-1.127 {
836 execsql {SELECT name FROM sqlite_master}
837} {t2}
838do_test auth-1.128 {
drhe22a3342003-04-22 20:30:37 +0000839 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000840 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
841 return SQLITE_DENY
842 }
843 return SQLITE_OK
844 }
845 catchsql {
846 CREATE TRIGGER r2 DELETE on t2 BEGIN
847 SELECT NULL;
848 END;
849 }
850} {1 {not authorized}}
851do_test auth-1.129 {
852 execsql {SELECT name FROM sqlite_master}
853} {t2}
854do_test auth-1.130 {
drhe22a3342003-04-22 20:30:37 +0000855 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000856 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000857 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000858 return SQLITE_IGNORE
859 }
860 return SQLITE_OK
861 }
862 catchsql {
863 CREATE TRIGGER r2 DELETE on t2 BEGIN
864 SELECT NULL;
865 END;
866 }
867} {0 {}}
868do_test auth-1.131 {
869 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000870} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +0000871do_test auth-1.132 {
872 execsql {SELECT name FROM sqlite_master}
873} {t2}
874do_test auth-1.133 {
drhe22a3342003-04-22 20:30:37 +0000875 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000876 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
877 return SQLITE_IGNORE
878 }
879 return SQLITE_OK
880 }
881 catchsql {
882 CREATE TRIGGER r2 DELETE on t2 BEGIN
883 SELECT NULL;
884 END;
885 }
886} {0 {}}
887do_test auth-1.134 {
888 execsql {SELECT name FROM sqlite_master}
889} {t2}
890do_test auth-1.135 {
drhe22a3342003-04-22 20:30:37 +0000891 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000892 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000893 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000894 return SQLITE_OK
895 }
896 return SQLITE_OK
897 }
898 catchsql {
drhe22a3342003-04-22 20:30:37 +0000899 CREATE TABLE tx(id);
900 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
901 INSERT INTO tx VALUES(NEW.rowid);
drh77ad4e42003-01-14 02:49:27 +0000902 END;
903 }
904} {0 {}}
drhe22a3342003-04-22 20:30:37 +0000905do_test auth-1.136.1 {
drh77ad4e42003-01-14 02:49:27 +0000906 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000907} {r2 t2 main {}}
908do_test auth-1.136.2 {
909 execsql {
910 SELECT name FROM sqlite_master WHERE type='trigger'
911 }
912} {r2}
913do_test auth-1.136.3 {
914 proc auth {code arg1 arg2 arg3 arg4} {
915 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
916 return SQLITE_OK
917 }
918 set ::authargs {}
919 execsql {
920 INSERT INTO t2 VALUES(1,2,3);
921 }
922 set ::authargs
923} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
924do_test auth-1.136.4 {
925 execsql {
926 SELECT * FROM tx;
927 }
928} {3}
drh77ad4e42003-01-14 02:49:27 +0000929do_test auth-1.137 {
930 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +0000931} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +0000932do_test auth-1.138 {
drhe22a3342003-04-22 20:30:37 +0000933 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000934 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000935 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000936 return SQLITE_DENY
937 }
938 return SQLITE_OK
939 }
940 catchsql {
941 CREATE TRIGGER r1 DELETE on t1 BEGIN
942 SELECT NULL;
943 END;
944 }
945} {1 {not authorized}}
946do_test auth-1.139 {
947 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000948} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +0000949do_test auth-1.140 {
950 execsql {SELECT name FROM sqlite_temp_master}
951} {t1}
952do_test auth-1.141 {
drhe22a3342003-04-22 20:30:37 +0000953 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000954 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
955 return SQLITE_DENY
956 }
957 return SQLITE_OK
958 }
959 catchsql {
960 CREATE TRIGGER r1 DELETE on t1 BEGIN
961 SELECT NULL;
962 END;
963 }
964} {1 {not authorized}}
965do_test auth-1.142 {
966 execsql {SELECT name FROM sqlite_temp_master}
967} {t1}
968do_test auth-1.143 {
drhe22a3342003-04-22 20:30:37 +0000969 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000970 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000971 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000972 return SQLITE_IGNORE
973 }
974 return SQLITE_OK
975 }
976 catchsql {
977 CREATE TRIGGER r1 DELETE on t1 BEGIN
978 SELECT NULL;
979 END;
980 }
981} {0 {}}
982do_test auth-1.144 {
983 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000984} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +0000985do_test auth-1.145 {
986 execsql {SELECT name FROM sqlite_temp_master}
987} {t1}
988do_test auth-1.146 {
drhe22a3342003-04-22 20:30:37 +0000989 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000990 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
991 return SQLITE_IGNORE
992 }
993 return SQLITE_OK
994 }
995 catchsql {
996 CREATE TRIGGER r1 DELETE on t1 BEGIN
997 SELECT NULL;
998 END;
999 }
1000} {0 {}}
1001do_test auth-1.147 {
1002 execsql {SELECT name FROM sqlite_temp_master}
1003} {t1}
1004do_test auth-1.148 {
drhe22a3342003-04-22 20:30:37 +00001005 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001006 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001007 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001008 return SQLITE_OK
1009 }
1010 return SQLITE_OK
1011 }
1012 catchsql {
1013 CREATE TRIGGER r1 DELETE on t1 BEGIN
1014 SELECT NULL;
1015 END;
1016 }
1017} {0 {}}
1018do_test auth-1.149 {
1019 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001020} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001021do_test auth-1.150 {
1022 execsql {SELECT name FROM sqlite_temp_master}
1023} {t1 r1}
1024
1025do_test auth-1.151 {
drhe22a3342003-04-22 20:30:37 +00001026 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001027 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1028 return SQLITE_DENY
1029 }
1030 return SQLITE_OK
1031 }
1032 catchsql {DROP TRIGGER r2}
1033} {1 {not authorized}}
1034do_test auth-1.152 {
1035 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001036} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001037do_test auth-1.153 {
drhe22a3342003-04-22 20:30:37 +00001038 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001039 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001040 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001041 return SQLITE_DENY
1042 }
1043 return SQLITE_OK
1044 }
1045 catchsql {DROP TRIGGER r2}
1046} {1 {not authorized}}
1047do_test auth-1.154 {
1048 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001049} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001050do_test auth-1.155 {
1051 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001052} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001053do_test auth-1.156 {
drhe22a3342003-04-22 20:30:37 +00001054 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001055 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1056 return SQLITE_IGNORE
1057 }
1058 return SQLITE_OK
1059 }
1060 catchsql {DROP TRIGGER r2}
1061} {0 {}}
1062do_test auth-1.157 {
1063 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001064} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001065do_test auth-1.158 {
drhe22a3342003-04-22 20:30:37 +00001066 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001067 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001068 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001069 return SQLITE_IGNORE
1070 }
1071 return SQLITE_OK
1072 }
1073 catchsql {DROP TRIGGER r2}
1074} {0 {}}
1075do_test auth-1.159 {
1076 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001077} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001078do_test auth-1.160 {
1079 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001080} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001081do_test auth-1.161 {
drhe22a3342003-04-22 20:30:37 +00001082 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001083 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001084 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001085 return SQLITE_OK
1086 }
1087 return SQLITE_OK
1088 }
1089 catchsql {DROP TRIGGER r2}
1090} {0 {}}
1091do_test auth-1.162 {
1092 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001093} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001094do_test auth-1.163 {
drhe22a3342003-04-22 20:30:37 +00001095 execsql {
1096 DROP TABLE tx;
1097 DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1098 SELECT name FROM sqlite_master;
1099 }
drh77ad4e42003-01-14 02:49:27 +00001100} {t2}
1101
1102do_test auth-1.164 {
drhe22a3342003-04-22 20:30:37 +00001103 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001104 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1105 return SQLITE_DENY
1106 }
1107 return SQLITE_OK
1108 }
1109 catchsql {DROP TRIGGER r1}
1110} {1 {not authorized}}
1111do_test auth-1.165 {
1112 execsql {SELECT name FROM sqlite_temp_master}
1113} {t1 r1}
1114do_test auth-1.166 {
drhe22a3342003-04-22 20:30:37 +00001115 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001116 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001117 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001118 return SQLITE_DENY
1119 }
1120 return SQLITE_OK
1121 }
1122 catchsql {DROP TRIGGER r1}
1123} {1 {not authorized}}
1124do_test auth-1.167 {
1125 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001126} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001127do_test auth-1.168 {
1128 execsql {SELECT name FROM sqlite_temp_master}
1129} {t1 r1}
1130do_test auth-1.169 {
drhe22a3342003-04-22 20:30:37 +00001131 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001132 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1133 return SQLITE_IGNORE
1134 }
1135 return SQLITE_OK
1136 }
1137 catchsql {DROP TRIGGER r1}
1138} {0 {}}
1139do_test auth-1.170 {
1140 execsql {SELECT name FROM sqlite_temp_master}
1141} {t1 r1}
1142do_test auth-1.171 {
drhe22a3342003-04-22 20:30:37 +00001143 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001144 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001145 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001146 return SQLITE_IGNORE
1147 }
1148 return SQLITE_OK
1149 }
1150 catchsql {DROP TRIGGER r1}
1151} {0 {}}
1152do_test auth-1.172 {
1153 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001154} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001155do_test auth-1.173 {
1156 execsql {SELECT name FROM sqlite_temp_master}
1157} {t1 r1}
1158do_test auth-1.174 {
drhe22a3342003-04-22 20:30:37 +00001159 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001160 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001161 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001162 return SQLITE_OK
1163 }
1164 return SQLITE_OK
1165 }
1166 catchsql {DROP TRIGGER r1}
1167} {0 {}}
1168do_test auth-1.175 {
1169 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001170} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001171do_test auth-1.176 {
1172 execsql {SELECT name FROM sqlite_temp_master}
1173} {t1}
danielk197781650dc2004-11-22 11:51:13 +00001174} ;# ifcapable trigger
drh77ad4e42003-01-14 02:49:27 +00001175
1176do_test auth-1.177 {
drhe22a3342003-04-22 20:30:37 +00001177 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001178 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001179 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001180 return SQLITE_DENY
1181 }
1182 return SQLITE_OK
1183 }
1184 catchsql {CREATE INDEX i2 ON t2(a)}
1185} {1 {not authorized}}
1186do_test auth-1.178 {
1187 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001188} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001189do_test auth-1.179 {
1190 execsql {SELECT name FROM sqlite_master}
1191} {t2}
1192do_test auth-1.180 {
drhe22a3342003-04-22 20:30:37 +00001193 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001194 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1195 return SQLITE_DENY
1196 }
1197 return SQLITE_OK
1198 }
1199 catchsql {CREATE INDEX i2 ON t2(a)}
1200} {1 {not authorized}}
1201do_test auth-1.181 {
1202 execsql {SELECT name FROM sqlite_master}
1203} {t2}
1204do_test auth-1.182 {
drhe22a3342003-04-22 20:30:37 +00001205 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001206 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001207 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001208 return SQLITE_IGNORE
1209 }
1210 return SQLITE_OK
1211 }
1212 catchsql {CREATE INDEX i2 ON t2(b)}
1213} {0 {}}
1214do_test auth-1.183 {
1215 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001216} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001217do_test auth-1.184 {
1218 execsql {SELECT name FROM sqlite_master}
1219} {t2}
1220do_test auth-1.185 {
drhe22a3342003-04-22 20:30:37 +00001221 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001222 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1223 return SQLITE_IGNORE
1224 }
1225 return SQLITE_OK
1226 }
1227 catchsql {CREATE INDEX i2 ON t2(b)}
1228} {0 {}}
1229do_test auth-1.186 {
1230 execsql {SELECT name FROM sqlite_master}
1231} {t2}
1232do_test auth-1.187 {
drhe22a3342003-04-22 20:30:37 +00001233 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001234 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001235 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001236 return SQLITE_OK
1237 }
1238 return SQLITE_OK
1239 }
1240 catchsql {CREATE INDEX i2 ON t2(a)}
1241} {0 {}}
1242do_test auth-1.188 {
1243 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001244} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001245do_test auth-1.189 {
1246 execsql {SELECT name FROM sqlite_master}
1247} {t2 i2}
1248
1249do_test auth-1.190 {
drhe22a3342003-04-22 20:30:37 +00001250 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001251 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001252 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001253 return SQLITE_DENY
1254 }
1255 return SQLITE_OK
1256 }
1257 catchsql {CREATE INDEX i1 ON t1(a)}
1258} {1 {not authorized}}
1259do_test auth-1.191 {
1260 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001261} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001262do_test auth-1.192 {
1263 execsql {SELECT name FROM sqlite_temp_master}
1264} {t1}
1265do_test auth-1.193 {
drhe22a3342003-04-22 20:30:37 +00001266 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001267 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1268 return SQLITE_DENY
1269 }
1270 return SQLITE_OK
1271 }
1272 catchsql {CREATE INDEX i1 ON t1(b)}
1273} {1 {not authorized}}
1274do_test auth-1.194 {
1275 execsql {SELECT name FROM sqlite_temp_master}
1276} {t1}
1277do_test auth-1.195 {
drhe22a3342003-04-22 20:30:37 +00001278 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001279 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001280 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001281 return SQLITE_IGNORE
1282 }
1283 return SQLITE_OK
1284 }
1285 catchsql {CREATE INDEX i1 ON t1(b)}
1286} {0 {}}
1287do_test auth-1.196 {
1288 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001289} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001290do_test auth-1.197 {
1291 execsql {SELECT name FROM sqlite_temp_master}
1292} {t1}
1293do_test auth-1.198 {
drhe22a3342003-04-22 20:30:37 +00001294 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001295 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1296 return SQLITE_IGNORE
1297 }
1298 return SQLITE_OK
1299 }
1300 catchsql {CREATE INDEX i1 ON t1(c)}
1301} {0 {}}
1302do_test auth-1.199 {
1303 execsql {SELECT name FROM sqlite_temp_master}
1304} {t1}
1305do_test auth-1.200 {
drhe22a3342003-04-22 20:30:37 +00001306 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001307 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001308 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001309 return SQLITE_OK
1310 }
1311 return SQLITE_OK
1312 }
1313 catchsql {CREATE INDEX i1 ON t1(a)}
1314} {0 {}}
1315do_test auth-1.201 {
1316 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001317} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001318do_test auth-1.202 {
1319 execsql {SELECT name FROM sqlite_temp_master}
1320} {t1 i1}
1321
1322do_test auth-1.203 {
drhe22a3342003-04-22 20:30:37 +00001323 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001324 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1325 return SQLITE_DENY
1326 }
1327 return SQLITE_OK
1328 }
1329 catchsql {DROP INDEX i2}
1330} {1 {not authorized}}
1331do_test auth-1.204 {
1332 execsql {SELECT name FROM sqlite_master}
1333} {t2 i2}
1334do_test auth-1.205 {
drhe22a3342003-04-22 20:30:37 +00001335 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001336 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001337 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001338 return SQLITE_DENY
1339 }
1340 return SQLITE_OK
1341 }
1342 catchsql {DROP INDEX i2}
1343} {1 {not authorized}}
1344do_test auth-1.206 {
1345 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001346} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001347do_test auth-1.207 {
1348 execsql {SELECT name FROM sqlite_master}
1349} {t2 i2}
1350do_test auth-1.208 {
drhe22a3342003-04-22 20:30:37 +00001351 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001352 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1353 return SQLITE_IGNORE
1354 }
1355 return SQLITE_OK
1356 }
1357 catchsql {DROP INDEX i2}
1358} {0 {}}
1359do_test auth-1.209 {
1360 execsql {SELECT name FROM sqlite_master}
1361} {t2 i2}
1362do_test auth-1.210 {
drhe22a3342003-04-22 20:30:37 +00001363 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001364 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001365 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001366 return SQLITE_IGNORE
1367 }
1368 return SQLITE_OK
1369 }
1370 catchsql {DROP INDEX i2}
1371} {0 {}}
1372do_test auth-1.211 {
1373 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001374} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001375do_test auth-1.212 {
1376 execsql {SELECT name FROM sqlite_master}
1377} {t2 i2}
1378do_test auth-1.213 {
drhe22a3342003-04-22 20:30:37 +00001379 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001380 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001381 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001382 return SQLITE_OK
1383 }
1384 return SQLITE_OK
1385 }
1386 catchsql {DROP INDEX i2}
1387} {0 {}}
1388do_test auth-1.214 {
1389 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001390} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001391do_test auth-1.215 {
1392 execsql {SELECT name FROM sqlite_master}
1393} {t2}
1394
1395do_test auth-1.216 {
drhe22a3342003-04-22 20:30:37 +00001396 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001397 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1398 return SQLITE_DENY
1399 }
1400 return SQLITE_OK
1401 }
1402 catchsql {DROP INDEX i1}
1403} {1 {not authorized}}
1404do_test auth-1.217 {
1405 execsql {SELECT name FROM sqlite_temp_master}
1406} {t1 i1}
1407do_test auth-1.218 {
drhe22a3342003-04-22 20:30:37 +00001408 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001409 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001410 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001411 return SQLITE_DENY
1412 }
1413 return SQLITE_OK
1414 }
1415 catchsql {DROP INDEX i1}
1416} {1 {not authorized}}
1417do_test auth-1.219 {
1418 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001419} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001420do_test auth-1.220 {
1421 execsql {SELECT name FROM sqlite_temp_master}
1422} {t1 i1}
1423do_test auth-1.221 {
drhe22a3342003-04-22 20:30:37 +00001424 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001425 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1426 return SQLITE_IGNORE
1427 }
1428 return SQLITE_OK
1429 }
1430 catchsql {DROP INDEX i1}
1431} {0 {}}
1432do_test auth-1.222 {
1433 execsql {SELECT name FROM sqlite_temp_master}
1434} {t1 i1}
1435do_test auth-1.223 {
drhe22a3342003-04-22 20:30:37 +00001436 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001437 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001438 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001439 return SQLITE_IGNORE
1440 }
1441 return SQLITE_OK
1442 }
1443 catchsql {DROP INDEX i1}
1444} {0 {}}
1445do_test auth-1.224 {
1446 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001447} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001448do_test auth-1.225 {
1449 execsql {SELECT name FROM sqlite_temp_master}
1450} {t1 i1}
1451do_test auth-1.226 {
drhe22a3342003-04-22 20:30:37 +00001452 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001453 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001454 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001455 return SQLITE_OK
1456 }
1457 return SQLITE_OK
1458 }
1459 catchsql {DROP INDEX i1}
1460} {0 {}}
1461do_test auth-1.227 {
1462 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001463} {i1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001464do_test auth-1.228 {
1465 execsql {SELECT name FROM sqlite_temp_master}
1466} {t1}
1467
1468do_test auth-1.229 {
drhe22a3342003-04-22 20:30:37 +00001469 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001470 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001471 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001472 return SQLITE_DENY
1473 }
1474 return SQLITE_OK
1475 }
1476 catchsql {PRAGMA full_column_names=on}
1477} {1 {not authorized}}
1478do_test auth-1.230 {
1479 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001480} {full_column_names on {} {}}
drh77ad4e42003-01-14 02:49:27 +00001481do_test auth-1.231 {
1482 execsql2 {SELECT a FROM t2}
1483} {a 11 a 7}
1484do_test auth-1.232 {
drhe22a3342003-04-22 20:30:37 +00001485 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001486 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001487 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001488 return SQLITE_IGNORE
1489 }
1490 return SQLITE_OK
1491 }
1492 catchsql {PRAGMA full_column_names=on}
1493} {0 {}}
1494do_test auth-1.233 {
1495 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001496} {full_column_names on {} {}}
drh77ad4e42003-01-14 02:49:27 +00001497do_test auth-1.234 {
1498 execsql2 {SELECT a FROM t2}
1499} {a 11 a 7}
1500do_test auth-1.235 {
drhe22a3342003-04-22 20:30:37 +00001501 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001502 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001503 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001504 return SQLITE_OK
1505 }
1506 return SQLITE_OK
1507 }
1508 catchsql {PRAGMA full_column_names=on}
1509} {0 {}}
1510do_test auth-1.236 {
1511 execsql2 {SELECT a FROM t2}
1512} {t2.a 11 t2.a 7}
1513do_test auth-1.237 {
drhe22a3342003-04-22 20:30:37 +00001514 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001515 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001516 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001517 return SQLITE_OK
1518 }
1519 return SQLITE_OK
1520 }
1521 catchsql {PRAGMA full_column_names=OFF}
1522} {0 {}}
1523do_test auth-1.238 {
1524 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001525} {full_column_names OFF {} {}}
drh77ad4e42003-01-14 02:49:27 +00001526do_test auth-1.239 {
1527 execsql2 {SELECT a FROM t2}
1528} {a 11 a 7}
drhe5f9c642003-01-13 23:27:31 +00001529
drh2c3831c2003-01-14 13:48:20 +00001530do_test auth-1.240 {
drhe22a3342003-04-22 20:30:37 +00001531 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001532 if {$code=="SQLITE_TRANSACTION"} {
drhe22a3342003-04-22 20:30:37 +00001533 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh2c3831c2003-01-14 13:48:20 +00001534 return SQLITE_DENY
1535 }
1536 return SQLITE_OK
1537 }
1538 catchsql {BEGIN}
1539} {1 {not authorized}}
1540do_test auth-1.241 {
1541 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001542} {BEGIN {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001543do_test auth-1.242 {
drhe22a3342003-04-22 20:30:37 +00001544 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001545 if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
drhe22a3342003-04-22 20:30:37 +00001546 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh2c3831c2003-01-14 13:48:20 +00001547 return SQLITE_DENY
1548 }
1549 return SQLITE_OK
1550 }
1551 catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1552} {1 {not authorized}}
1553do_test auth-1.243 {
1554 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001555} {COMMIT {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001556do_test auth-1.244 {
1557 execsql {SELECT * FROM t2}
1558} {11 2 33 7 8 9 44 55 66}
1559do_test auth-1.245 {
1560 catchsql {ROLLBACK}
1561} {1 {not authorized}}
1562do_test auth-1.246 {
1563 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001564} {ROLLBACK {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001565do_test auth-1.247 {
1566 catchsql {END TRANSACTION}
1567} {1 {not authorized}}
1568do_test auth-1.248 {
1569 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001570} {COMMIT {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001571do_test auth-1.249 {
drhe22a3342003-04-22 20:30:37 +00001572 db authorizer {}
drh2c3831c2003-01-14 13:48:20 +00001573 catchsql {ROLLBACK}
1574} {0 {}}
1575do_test auth-1.250 {
1576 execsql {SELECT * FROM t2}
1577} {11 2 33 7 8 9}
1578
drh81e293b2003-06-06 19:00:42 +00001579# ticket #340 - authorization for ATTACH and DETACH.
1580#
1581do_test auth-1.251 {
1582 db authorizer ::auth
1583 proc auth {code arg1 arg2 arg3 arg4} {
1584 if {$code=="SQLITE_ATTACH"} {
1585 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1586 }
1587 return SQLITE_OK
1588 }
1589 catchsql {
1590 ATTACH DATABASE ':memory:' AS test1
1591 }
1592} {0 {}}
1593do_test auth-1.252 {
1594 set ::authargs
1595} {:memory: {} {} {}}
1596do_test auth-1.253 {
1597 catchsql {DETACH DATABASE test1}
1598 proc auth {code arg1 arg2 arg3 arg4} {
1599 if {$code=="SQLITE_ATTACH"} {
1600 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1601 return SQLITE_DENY
1602 }
1603 return SQLITE_OK
1604 }
1605 catchsql {
1606 ATTACH DATABASE ':memory:' AS test1;
1607 }
1608} {1 {not authorized}}
1609do_test auth-1.254 {
1610 lindex [execsql {PRAGMA database_list}] 7
1611} {}
1612do_test auth-1.255 {
1613 catchsql {DETACH DATABASE test1}
1614 proc auth {code arg1 arg2 arg3 arg4} {
1615 if {$code=="SQLITE_ATTACH"} {
1616 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1617 return SQLITE_IGNORE
1618 }
1619 return SQLITE_OK
1620 }
1621 catchsql {
1622 ATTACH DATABASE ':memory:' AS test1;
1623 }
1624} {0 {}}
1625do_test auth-1.256 {
1626 lindex [execsql {PRAGMA database_list}] 7
1627} {}
1628do_test auth-1.257 {
1629 proc auth {code arg1 arg2 arg3 arg4} {
1630 if {$code=="SQLITE_DETACH"} {
1631 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1632 return SQLITE_OK
1633 }
1634 return SQLITE_OK
1635 }
1636 execsql {ATTACH DATABASE ':memory:' AS test1}
1637 catchsql {
1638 DETACH DATABASE test1;
1639 }
1640} {0 {}}
1641do_test auth-1.258 {
1642 lindex [execsql {PRAGMA database_list}] 7
1643} {}
1644do_test auth-1.259 {
1645 execsql {ATTACH DATABASE ':memory:' AS test1}
1646 proc auth {code arg1 arg2 arg3 arg4} {
1647 if {$code=="SQLITE_DETACH"} {
1648 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1649 return SQLITE_IGNORE
1650 }
1651 return SQLITE_OK
1652 }
1653 catchsql {
1654 DETACH DATABASE test1;
1655 }
1656} {0 {}}
danielk197727188fb2004-11-23 10:13:03 +00001657ifcapable schema_pragmas {
drh81e293b2003-06-06 19:00:42 +00001658do_test auth-1.260 {
1659 lindex [execsql {PRAGMA database_list}] 7
1660} {test1}
danielk197727188fb2004-11-23 10:13:03 +00001661} ;# ifcapable schema_pragmas
drh81e293b2003-06-06 19:00:42 +00001662do_test auth-1.261 {
1663 proc auth {code arg1 arg2 arg3 arg4} {
1664 if {$code=="SQLITE_DETACH"} {
1665 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1666 return SQLITE_DENY
1667 }
1668 return SQLITE_OK
1669 }
1670 catchsql {
1671 DETACH DATABASE test1;
1672 }
1673} {1 {not authorized}}
danielk197727188fb2004-11-23 10:13:03 +00001674ifcapable schema_pragmas {
drh81e293b2003-06-06 19:00:42 +00001675do_test auth-1.262 {
1676 lindex [execsql {PRAGMA database_list}] 7
1677} {test1}
danielk197727188fb2004-11-23 10:13:03 +00001678} ;# ifcapable schema_pragmas
drh81e293b2003-06-06 19:00:42 +00001679db authorizer {}
1680execsql {DETACH DATABASE test1}
danielk19771c8c23c2004-11-12 15:53:37 +00001681db authorizer ::auth
1682
danielk1977215e64d2004-11-22 03:34:21 +00001683# Authorization for ALTER TABLE. These tests are omitted if the library
1684# was built without ALTER TABLE support.
1685ifcapable altertable {
1686
danielk19771c8c23c2004-11-12 15:53:37 +00001687do_test auth-1.263 {
1688 proc auth {code arg1 arg2 arg3 arg4} {
1689 if {$code=="SQLITE_ALTER_TABLE"} {
1690 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1691 return SQLITE_OK
1692 }
1693 return SQLITE_OK
1694 }
1695 catchsql {
1696 ALTER TABLE t1 RENAME TO t1x
1697 }
1698} {0 {}}
1699do_test auth-1.264 {
1700 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1701} {t1x}
1702do_test auth-1.265 {
1703 set authargs
1704} {temp t1 {} {}}
1705do_test auth-1.266 {
1706 proc auth {code arg1 arg2 arg3 arg4} {
1707 if {$code=="SQLITE_ALTER_TABLE"} {
1708 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1709 return SQLITE_IGNORE
1710 }
1711 return SQLITE_OK
1712 }
1713 catchsql {
1714 ALTER TABLE t1x RENAME TO t1
1715 }
1716} {0 {}}
1717do_test auth-1.267 {
1718 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1719} {t1x}
1720do_test auth-1.268 {
1721 set authargs
1722} {temp t1x {} {}}
1723do_test auth-1.269 {
1724 proc auth {code arg1 arg2 arg3 arg4} {
1725 if {$code=="SQLITE_ALTER_TABLE"} {
1726 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1727 return SQLITE_DENY
1728 }
1729 return SQLITE_OK
1730 }
1731 catchsql {
1732 ALTER TABLE t1x RENAME TO t1
1733 }
1734} {1 {not authorized}}
1735do_test auth-1.270 {
1736 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1737} {t1x}
1738do_test auth-1.271 {
1739 set authargs
1740} {temp t1x {} {}}
1741db authorizer {}
1742catchsql {ALTER TABLE t1x RENAME TO t1}
1743db authorizer ::auth
1744do_test auth-1.272 {
1745 proc auth {code arg1 arg2 arg3 arg4} {
1746 if {$code=="SQLITE_ALTER_TABLE"} {
1747 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1748 return SQLITE_OK
1749 }
1750 return SQLITE_OK
1751 }
1752 catchsql {
1753 ALTER TABLE t2 RENAME TO t2x
1754 }
1755} {0 {}}
1756do_test auth-1.273 {
1757 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1758} {t2x}
1759do_test auth-1.274 {
1760 set authargs
1761} {main t2 {} {}}
1762do_test auth-1.275 {
1763 proc auth {code arg1 arg2 arg3 arg4} {
1764 if {$code=="SQLITE_ALTER_TABLE"} {
1765 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1766 return SQLITE_IGNORE
1767 }
1768 return SQLITE_OK
1769 }
1770 catchsql {
1771 ALTER TABLE t2x RENAME TO t2
1772 }
1773} {0 {}}
1774do_test auth-1.276 {
1775 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1776} {t2x}
1777do_test auth-1.277 {
1778 set authargs
1779} {main t2x {} {}}
1780do_test auth-1.278 {
1781 proc auth {code arg1 arg2 arg3 arg4} {
1782 if {$code=="SQLITE_ALTER_TABLE"} {
1783 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1784 return SQLITE_DENY
1785 }
1786 return SQLITE_OK
1787 }
1788 catchsql {
1789 ALTER TABLE t2x RENAME TO t2
1790 }
1791} {1 {not authorized}}
1792do_test auth-1.279 {
1793 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1794} {t2x}
1795do_test auth-1.280 {
1796 set authargs
1797} {main t2x {} {}}
1798db authorizer {}
1799catchsql {ALTER TABLE t2x RENAME TO t2}
drh81e293b2003-06-06 19:00:42 +00001800
danielk1977215e64d2004-11-22 03:34:21 +00001801} ;# ifcapable altertable
1802
danielk19771d54df82004-11-23 15:41:16 +00001803# Test the authorization callbacks for the REINDEX command.
1804ifcapable reindex {
1805
1806proc auth {code args} {
1807 if {$code=="SQLITE_REINDEX"} {
1808 set ::authargs [concat $::authargs $args]
1809 }
1810 return SQLITE_OK
1811}
1812db authorizer auth
1813do_test auth-1.281 {
1814 execsql {
1815 CREATE TABLE t3(a PRIMARY KEY, b, c);
1816 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1817 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1818 }
1819} {}
1820do_test auth-1.282 {
1821 set ::authargs {}
1822 execsql {
1823 REINDEX t3_idx1;
1824 }
1825 set ::authargs
1826} {t3_idx1 {} main {}}
1827do_test auth-1.283 {
1828 set ::authargs {}
1829 execsql {
1830 REINDEX BINARY;
1831 }
1832 set ::authargs
1833} {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1834do_test auth-1.284 {
1835 set ::authargs {}
1836 execsql {
1837 REINDEX NOCASE;
1838 }
1839 set ::authargs
1840} {t3_idx2 {} main {}}
1841do_test auth-1.285 {
1842 set ::authargs {}
1843 execsql {
1844 REINDEX t3;
1845 }
1846 set ::authargs
1847} {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1848do_test auth-1.286 {
1849 execsql {
1850 DROP TABLE t3;
1851 }
1852} {}
1853do_test auth-1.287 {
1854 execsql {
1855 CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
1856 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1857 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1858 }
1859} {}
1860do_test auth-1.288 {
1861 set ::authargs {}
1862 execsql {
1863 REINDEX temp.t3_idx1;
1864 }
1865 set ::authargs
1866} {t3_idx1 {} temp {}}
1867do_test auth-1.289 {
1868 set ::authargs {}
1869 execsql {
1870 REINDEX BINARY;
1871 }
1872 set ::authargs
1873} {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1874do_test auth-1.290 {
1875 set ::authargs {}
1876 execsql {
1877 REINDEX NOCASE;
1878 }
1879 set ::authargs
1880} {t3_idx2 {} temp {}}
1881do_test auth-1.291 {
1882 set ::authargs {}
1883 execsql {
1884 REINDEX temp.t3;
1885 }
1886 set ::authargs
1887} {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1888proc auth {code args} {
1889 if {$code=="SQLITE_REINDEX"} {
1890 set ::authargs [concat $::authargs $args]
1891 return SQLITE_DENY
1892 }
1893 return SQLITE_OK
1894}
1895do_test auth-1.292 {
1896 set ::authargs {}
1897 catchsql {
1898 REINDEX temp.t3;
1899 }
1900} {1 {not authorized}}
1901do_test auth-1.293 {
1902 execsql {
1903 DROP TABLE t3;
1904 }
1905} {}
1906
1907} ;# ifcapable reindex
1908
drh81e293b2003-06-06 19:00:42 +00001909
drh2c3831c2003-01-14 13:48:20 +00001910do_test auth-2.1 {
drhe22a3342003-04-22 20:30:37 +00001911 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001912 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1913 return SQLITE_DENY
1914 }
1915 return SQLITE_OK
1916 }
drhe22a3342003-04-22 20:30:37 +00001917 db authorizer ::auth
drh2c3831c2003-01-14 13:48:20 +00001918 execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
1919 catchsql {SELECT * FROM t3}
1920} {1 {access to t3.x is prohibited}}
1921do_test auth-2.1 {
1922 catchsql {SELECT y,z FROM t3}
1923} {0 {}}
1924do_test auth-2.2 {
1925 catchsql {SELECT ROWID,y,z FROM t3}
1926} {1 {access to t3.x is prohibited}}
1927do_test auth-2.3 {
1928 catchsql {SELECT OID,y,z FROM t3}
1929} {1 {access to t3.x is prohibited}}
1930do_test auth-2.4 {
drhe22a3342003-04-22 20:30:37 +00001931 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001932 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1933 return SQLITE_IGNORE
1934 }
1935 return SQLITE_OK
1936 }
1937 execsql {INSERT INTO t3 VALUES(44,55,66)}
1938 catchsql {SELECT * FROM t3}
1939} {0 {{} 55 66}}
1940do_test auth-2.5 {
1941 catchsql {SELECT rowid,y,z FROM t3}
1942} {0 {{} 55 66}}
1943do_test auth-2.6 {
drhe22a3342003-04-22 20:30:37 +00001944 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001945 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
1946 return SQLITE_IGNORE
1947 }
1948 return SQLITE_OK
1949 }
1950 catchsql {SELECT * FROM t3}
1951} {0 {44 55 66}}
1952do_test auth-2.7 {
1953 catchsql {SELECT ROWID,y,z FROM t3}
1954} {0 {44 55 66}}
1955do_test auth-2.8 {
drhe22a3342003-04-22 20:30:37 +00001956 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001957 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1958 return SQLITE_IGNORE
1959 }
1960 return SQLITE_OK
1961 }
1962 catchsql {SELECT ROWID,b,c FROM t2}
1963} {0 {{} 2 33 {} 8 9}}
drhdcd997e2003-01-31 17:21:49 +00001964do_test auth-2.9.1 {
drhe22a3342003-04-22 20:30:37 +00001965 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001966 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1967 return bogus
1968 }
1969 return SQLITE_OK
1970 }
1971 catchsql {SELECT ROWID,b,c FROM t2}
1972} {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
drhdcd997e2003-01-31 17:21:49 +00001973do_test auth-2.9.2 {
1974 db errorcode
drhc60d0442004-09-30 13:43:13 +00001975} {1}
drh2c3831c2003-01-14 13:48:20 +00001976do_test auth-2.10 {
drhe22a3342003-04-22 20:30:37 +00001977 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001978 if {$code=="SQLITE_SELECT"} {
1979 return bogus
1980 }
1981 return SQLITE_OK
1982 }
1983 catchsql {SELECT ROWID,b,c FROM t2}
1984} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
drh6f8c91c2003-12-07 00:24:35 +00001985do_test auth-2.11.1 {
drhe22a3342003-04-22 20:30:37 +00001986 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001987 if {$code=="SQLITE_READ" && $arg2=="a"} {
1988 return SQLITE_IGNORE
1989 }
1990 return SQLITE_OK
1991 }
1992 catchsql {SELECT * FROM t2, t3}
1993} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
drh6f8c91c2003-12-07 00:24:35 +00001994do_test auth-2.11.2 {
drhe22a3342003-04-22 20:30:37 +00001995 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001996 if {$code=="SQLITE_READ" && $arg2=="x"} {
1997 return SQLITE_IGNORE
1998 }
1999 return SQLITE_OK
2000 }
2001 catchsql {SELECT * FROM t2, t3}
2002} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
drhe5f9c642003-01-13 23:27:31 +00002003
drh027850b2003-04-16 20:24:52 +00002004# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
2005#
danielk197781650dc2004-11-22 11:51:13 +00002006ifcapable trigger {
drh027850b2003-04-16 20:24:52 +00002007do_test auth-3.1 {
drhe22a3342003-04-22 20:30:37 +00002008 proc auth {code arg1 arg2 arg3 arg4} {
drh027850b2003-04-16 20:24:52 +00002009 return SQLITE_OK
2010 }
2011 execsql {
2012 CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
2013 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
2014 INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
2015 END;
2016 UPDATE t2 SET a=a+1;
2017 SELECT * FROM tx;
2018 }
2019} {11 12 2 2 33 33 7 8 8 8 9 9}
2020do_test auth-3.2 {
drhe22a3342003-04-22 20:30:37 +00002021 proc auth {code arg1 arg2 arg3 arg4} {
drh027850b2003-04-16 20:24:52 +00002022 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
2023 return SQLITE_IGNORE
2024 }
2025 return SQLITE_OK
2026 }
2027 execsql {
2028 DELETE FROM tx;
2029 UPDATE t2 SET a=a+100;
2030 SELECT * FROM tx;
2031 }
2032} {12 112 2 2 {} {} 8 108 8 8 {} {}}
danielk197781650dc2004-11-22 11:51:13 +00002033} ;# ifcapable trigger
drh027850b2003-04-16 20:24:52 +00002034
drh85e20962003-04-25 17:52:11 +00002035# Make sure the names of views and triggers are passed on on arg4.
2036#
danielk197781650dc2004-11-22 11:51:13 +00002037ifcapable trigger {
drh85e20962003-04-25 17:52:11 +00002038do_test auth-4.1 {
2039 proc auth {code arg1 arg2 arg3 arg4} {
2040 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2041 return SQLITE_OK
2042 }
2043 set authargs {}
2044 execsql {
2045 UPDATE t2 SET a=a+1;
2046 }
2047 set authargs
2048} [list \
2049 SQLITE_READ t2 a main {} \
2050 SQLITE_UPDATE t2 a main {} \
2051 SQLITE_INSERT tx {} main r1 \
2052 SQLITE_READ t2 a main r1 \
2053 SQLITE_READ t2 a main r1 \
2054 SQLITE_READ t2 b main r1 \
2055 SQLITE_READ t2 b main r1 \
2056 SQLITE_READ t2 c main r1 \
2057 SQLITE_READ t2 c main r1]
danielk197781650dc2004-11-22 11:51:13 +00002058}
danielk19770fa8ddb2004-11-22 08:43:32 +00002059
danielk197781650dc2004-11-22 11:51:13 +00002060ifcapable {view && trigger} {
drh85e20962003-04-25 17:52:11 +00002061do_test auth-4.2 {
2062 execsql {
2063 CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
2064 CREATE TABLE v1chng(x1,x2);
2065 CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
2066 INSERT INTO v1chng VALUES(OLD.x,NEW.x);
2067 END;
2068 SELECT * FROM v1;
2069 }
2070} {115 117}
2071do_test auth-4.3 {
2072 set authargs {}
2073 execsql {
2074 UPDATE v1 SET x=1 WHERE x=117
2075 }
2076 set authargs
2077} [list \
2078 SQLITE_UPDATE v1 x main {} \
2079 SQLITE_READ v1 x main {} \
2080 SQLITE_SELECT {} {} {} v1 \
2081 SQLITE_READ t2 a main v1 \
2082 SQLITE_READ t2 b main v1 \
2083 SQLITE_INSERT v1chng {} main r2 \
2084 SQLITE_READ v1 x main r2 \
2085 SQLITE_READ v1 x main r2]
2086do_test auth-4.4 {
2087 execsql {
2088 CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
2089 INSERT INTO v1chng VALUES(OLD.x,NULL);
2090 END;
2091 SELECT * FROM v1;
2092 }
2093} {115 117}
2094do_test auth-4.5 {
2095 set authargs {}
2096 execsql {
2097 DELETE FROM v1 WHERE x=117
2098 }
2099 set authargs
2100} [list \
2101 SQLITE_DELETE v1 {} main {} \
2102 SQLITE_READ v1 x main {} \
2103 SQLITE_SELECT {} {} {} v1 \
2104 SQLITE_READ t2 a main v1 \
2105 SQLITE_READ t2 b main v1 \
2106 SQLITE_INSERT v1chng {} main r3 \
2107 SQLITE_READ v1 x main r3]
drh1962bda2003-01-12 19:33:52 +00002108
danielk197781650dc2004-11-22 11:51:13 +00002109} ;# ifcapable view && trigger
danielk19770fa8ddb2004-11-22 08:43:32 +00002110
drh1962bda2003-01-12 19:33:52 +00002111finish_test