blob: 320826980dd24676b902ba278494551120fd4b72 [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
drh5169bbc2006-08-24 14:59:45 +000012# focus of this script is testing the sqlite3_set_authorizer() API
drh2d458342003-04-05 03:42:26 +000013# and related functionality.
drh1962bda2003-01-12 19:33:52 +000014#
drh0f35a6b2008-02-12 16:52:14 +000015# $Id: auth.test,v 1.41 2008/02/12 16:52:14 drh 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
danielk1977a21c6b62005-01-24 10:25:59 +000028rename proc proc_real
29proc_real proc {name arguments script} {
30 proc_real $name $arguments $script
31 if {$name=="auth"} {
32 db authorizer ::auth
33 }
34}
35
drhdcd997e2003-01-31 17:21:49 +000036do_test auth-1.1.1 {
drh1962bda2003-01-12 19:33:52 +000037 db close
drhef4ac8f2004-06-19 00:16:31 +000038 set ::DB [sqlite3 db test.db]
drhe22a3342003-04-22 20:30:37 +000039 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +000040 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
drh1962bda2003-01-12 19:33:52 +000041 return SQLITE_DENY
42 }
43 return SQLITE_OK
44 }
drhe22a3342003-04-22 20:30:37 +000045 db authorizer ::auth
drh1962bda2003-01-12 19:33:52 +000046 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +000047} {1 {not authorized}}
drhdcd997e2003-01-31 17:21:49 +000048do_test auth-1.1.2 {
49 db errorcode
50} {23}
drh0f14e2e2004-06-29 12:39:08 +000051do_test auth-1.1.3 {
52 db authorizer
53} {::auth}
drh56891232004-09-09 13:55:50 +000054do_test auth-1.1.4 {
55 # Ticket #896.
56 catchsql {
57 SELECT x;
58 }
59} {1 {no such column: x}}
drh1962bda2003-01-12 19:33:52 +000060do_test auth-1.2 {
drhe5f9c642003-01-13 23:27:31 +000061 execsql {SELECT name FROM sqlite_master}
62} {}
drh77ad4e42003-01-14 02:49:27 +000063do_test auth-1.3.1 {
drhe22a3342003-04-22 20:30:37 +000064 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +000065 if {$code=="SQLITE_CREATE_TABLE"} {
drhe22a3342003-04-22 20:30:37 +000066 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +000067 return SQLITE_DENY
68 }
69 return SQLITE_OK
70 }
71 catchsql {CREATE TABLE t1(a,b,c)}
72} {1 {not authorized}}
drh77ad4e42003-01-14 02:49:27 +000073do_test auth-1.3.2 {
drhdcd997e2003-01-31 17:21:49 +000074 db errorcode
75} {23}
76do_test auth-1.3.3 {
drh77ad4e42003-01-14 02:49:27 +000077 set ::authargs
drhe22a3342003-04-22 20:30:37 +000078} {t1 {} main {}}
drhe5f9c642003-01-13 23:27:31 +000079do_test auth-1.4 {
80 execsql {SELECT name FROM sqlite_master}
81} {}
82
danielk197753c0f742005-03-29 03:10:59 +000083ifcapable tempdb {
84 do_test auth-1.5 {
85 proc auth {code arg1 arg2 arg3 arg4} {
86 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
87 return SQLITE_DENY
88 }
89 return SQLITE_OK
drhe5f9c642003-01-13 23:27:31 +000090 }
danielk197753c0f742005-03-29 03:10:59 +000091 catchsql {CREATE TEMP TABLE t1(a,b,c)}
92 } {1 {not authorized}}
93 do_test auth-1.6 {
94 execsql {SELECT name FROM sqlite_temp_master}
95 } {}
96 do_test auth-1.7.1 {
97 proc auth {code arg1 arg2 arg3 arg4} {
98 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
99 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
100 return SQLITE_DENY
101 }
102 return SQLITE_OK
drhe5f9c642003-01-13 23:27:31 +0000103 }
danielk197753c0f742005-03-29 03:10:59 +0000104 catchsql {CREATE TEMP TABLE t1(a,b,c)}
105 } {1 {not authorized}}
106 do_test auth-1.7.2 {
107 set ::authargs
108 } {t1 {} temp {}}
109 do_test auth-1.8 {
110 execsql {SELECT name FROM sqlite_temp_master}
111 } {}
112}
drhe5f9c642003-01-13 23:27:31 +0000113
114do_test auth-1.9 {
drhe22a3342003-04-22 20:30:37 +0000115 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000116 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
drh1962bda2003-01-12 19:33:52 +0000117 return SQLITE_IGNORE
118 }
119 return SQLITE_OK
120 }
121 catchsql {CREATE TABLE t1(a,b,c)}
drhe5f9c642003-01-13 23:27:31 +0000122} {0 {}}
123do_test auth-1.10 {
124 execsql {SELECT name FROM sqlite_master}
125} {}
126do_test auth-1.11 {
drhe22a3342003-04-22 20:30:37 +0000127 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000128 if {$code=="SQLITE_CREATE_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000129 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drhe5f9c642003-01-13 23:27:31 +0000130 return SQLITE_IGNORE
drh1962bda2003-01-12 19:33:52 +0000131 }
132 return SQLITE_OK
133 }
134 catchsql {CREATE TABLE t1(a,b,c)}
135} {0 {}}
drhe5f9c642003-01-13 23:27:31 +0000136do_test auth-1.12 {
drh1962bda2003-01-12 19:33:52 +0000137 execsql {SELECT name FROM sqlite_master}
drhe5f9c642003-01-13 23:27:31 +0000138} {}
drhe5f9c642003-01-13 23:27:31 +0000139
danielk197753c0f742005-03-29 03:10:59 +0000140ifcapable tempdb {
141 do_test auth-1.13 {
142 proc auth {code arg1 arg2 arg3 arg4} {
143 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
144 return SQLITE_IGNORE
145 }
146 return SQLITE_OK
drhe5f9c642003-01-13 23:27:31 +0000147 }
danielk197753c0f742005-03-29 03:10:59 +0000148 catchsql {CREATE TEMP TABLE t1(a,b,c)}
149 } {0 {}}
150 do_test auth-1.14 {
151 execsql {SELECT name FROM sqlite_temp_master}
152 } {}
153 do_test auth-1.15 {
154 proc auth {code arg1 arg2 arg3 arg4} {
155 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
156 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
157 return SQLITE_IGNORE
158 }
159 return SQLITE_OK
160 }
161 catchsql {CREATE TEMP TABLE t1(a,b,c)}
162 } {0 {}}
163 do_test auth-1.16 {
164 execsql {SELECT name FROM sqlite_temp_master}
165 } {}
166
167 do_test auth-1.17 {
168 proc auth {code arg1 arg2 arg3 arg4} {
169 if {$code=="SQLITE_CREATE_TABLE"} {
170 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
171 return SQLITE_DENY
172 }
173 return SQLITE_OK
174 }
175 catchsql {CREATE TEMP TABLE t1(a,b,c)}
176 } {0 {}}
177 do_test auth-1.18 {
178 execsql {SELECT name FROM sqlite_temp_master}
179 } {t1}
180}
181
drh77ad4e42003-01-14 02:49:27 +0000182do_test auth-1.19.1 {
183 set ::authargs {}
drhe22a3342003-04-22 20:30:37 +0000184 proc auth {code arg1 arg2 arg3 arg4} {
drhe5f9c642003-01-13 23:27:31 +0000185 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000186 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000187 return SQLITE_DENY
drh1962bda2003-01-12 19:33:52 +0000188 }
189 return SQLITE_OK
190 }
191 catchsql {CREATE TABLE t2(a,b,c)}
drh1962bda2003-01-12 19:33:52 +0000192} {0 {}}
drh77ad4e42003-01-14 02:49:27 +0000193do_test auth-1.19.2 {
194 set ::authargs
195} {}
drh1962bda2003-01-12 19:33:52 +0000196do_test auth-1.20 {
drhe5f9c642003-01-13 23:27:31 +0000197 execsql {SELECT name FROM sqlite_master}
198} {t2}
drh1962bda2003-01-12 19:33:52 +0000199
drh77ad4e42003-01-14 02:49:27 +0000200do_test auth-1.21.1 {
drhe22a3342003-04-22 20:30:37 +0000201 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000202 if {$code=="SQLITE_DROP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000203 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000204 return SQLITE_DENY
205 }
206 return SQLITE_OK
207 }
208 catchsql {DROP TABLE t2}
209} {1 {not authorized}}
210do_test auth-1.21.2 {
211 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000212} {t2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000213do_test auth-1.22 {
214 execsql {SELECT name FROM sqlite_master}
215} {t2}
216do_test auth-1.23.1 {
drhe22a3342003-04-22 20:30:37 +0000217 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000218 if {$code=="SQLITE_DROP_TABLE"} {
drhe22a3342003-04-22 20:30:37 +0000219 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000220 return SQLITE_IGNORE
221 }
222 return SQLITE_OK
223 }
224 catchsql {DROP TABLE t2}
225} {0 {}}
226do_test auth-1.23.2 {
227 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000228} {t2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000229do_test auth-1.24 {
230 execsql {SELECT name FROM sqlite_master}
231} {t2}
drhe5f9c642003-01-13 23:27:31 +0000232
danielk197753c0f742005-03-29 03:10:59 +0000233ifcapable tempdb {
234 do_test auth-1.25 {
235 proc auth {code arg1 arg2 arg3 arg4} {
236 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
237 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
238 return SQLITE_DENY
239 }
240 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000241 }
danielk197753c0f742005-03-29 03:10:59 +0000242 catchsql {DROP TABLE t1}
243 } {1 {not authorized}}
244 do_test auth-1.26 {
245 execsql {SELECT name FROM sqlite_temp_master}
246 } {t1}
247 do_test auth-1.27 {
248 proc auth {code arg1 arg2 arg3 arg4} {
249 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
250 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
251 return SQLITE_IGNORE
252 }
253 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000254 }
danielk197753c0f742005-03-29 03:10:59 +0000255 catchsql {DROP TABLE t1}
256 } {0 {}}
257 do_test auth-1.28 {
258 execsql {SELECT name FROM sqlite_temp_master}
259 } {t1}
260}
drh77ad4e42003-01-14 02:49:27 +0000261
262do_test auth-1.29 {
drhe22a3342003-04-22 20:30:37 +0000263 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000264 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
265 return SQLITE_DENY
266 }
267 return SQLITE_OK
268 }
269 catchsql {INSERT INTO t2 VALUES(1,2,3)}
270} {1 {not authorized}}
271do_test auth-1.30 {
272 execsql {SELECT * FROM t2}
273} {}
274do_test auth-1.31 {
drhe22a3342003-04-22 20:30:37 +0000275 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000276 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
277 return SQLITE_IGNORE
278 }
279 return SQLITE_OK
280 }
281 catchsql {INSERT INTO t2 VALUES(1,2,3)}
282} {0 {}}
283do_test auth-1.32 {
284 execsql {SELECT * FROM t2}
285} {}
286do_test auth-1.33 {
drhe22a3342003-04-22 20:30:37 +0000287 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000288 if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
289 return SQLITE_IGNORE
290 }
291 return SQLITE_OK
292 }
293 catchsql {INSERT INTO t2 VALUES(1,2,3)}
294} {0 {}}
295do_test auth-1.34 {
296 execsql {SELECT * FROM t2}
297} {1 2 3}
298
drh4925ca02003-11-27 00:48:57 +0000299do_test auth-1.35.1 {
drhe22a3342003-04-22 20:30:37 +0000300 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000301 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
302 return SQLITE_DENY
303 }
304 return SQLITE_OK
305 }
306 catchsql {SELECT * FROM t2}
307} {1 {access to t2.b is prohibited}}
danielk19775a8f9372007-10-09 08:29:32 +0000308ifcapable attach {
309 do_test auth-1.35.2 {
310 execsql {ATTACH DATABASE 'test.db' AS two}
311 catchsql {SELECT * FROM two.t2}
312 } {1 {access to two.t2.b is prohibited}}
313 execsql {DETACH DATABASE two}
314}
drh77ad4e42003-01-14 02:49:27 +0000315do_test auth-1.36 {
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=="b"} {
318 return SQLITE_IGNORE
319 }
320 return SQLITE_OK
321 }
322 catchsql {SELECT * FROM t2}
323} {0 {1 {} 3}}
324do_test auth-1.37 {
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=2}
332} {0 {}}
333do_test auth-1.38 {
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=="a"} {
336 return SQLITE_IGNORE
337 }
338 return SQLITE_OK
339 }
340 catchsql {SELECT * FROM t2 WHERE b=2}
341} {0 {{} 2 3}}
342do_test auth-1.39 {
drhe22a3342003-04-22 20:30:37 +0000343 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000344 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
345 return SQLITE_IGNORE
346 }
347 return SQLITE_OK
348 }
349 catchsql {SELECT * FROM t2 WHERE b IS NULL}
350} {0 {1 {} 3}}
351do_test auth-1.40 {
drhe22a3342003-04-22 20:30:37 +0000352 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000353 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
354 return SQLITE_DENY
355 }
356 return SQLITE_OK
357 }
358 catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
359} {1 {access to t2.b is prohibited}}
360
361do_test auth-1.41 {
drhe22a3342003-04-22 20:30:37 +0000362 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000363 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
364 return SQLITE_DENY
365 }
366 return SQLITE_OK
367 }
368 catchsql {UPDATE t2 SET a=11}
369} {0 {}}
370do_test auth-1.42 {
371 execsql {SELECT * FROM t2}
372} {11 2 3}
373do_test auth-1.43 {
drhe22a3342003-04-22 20:30:37 +0000374 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000375 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
376 return SQLITE_DENY
377 }
378 return SQLITE_OK
379 }
380 catchsql {UPDATE t2 SET b=22, c=33}
381} {1 {not authorized}}
382do_test auth-1.44 {
383 execsql {SELECT * FROM t2}
384} {11 2 3}
385do_test auth-1.45 {
drhe22a3342003-04-22 20:30:37 +0000386 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000387 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
388 return SQLITE_IGNORE
389 }
390 return SQLITE_OK
391 }
392 catchsql {UPDATE t2 SET b=22, c=33}
393} {0 {}}
394do_test auth-1.46 {
395 execsql {SELECT * FROM t2}
396} {11 2 33}
397
398do_test auth-1.47 {
drhe22a3342003-04-22 20:30:37 +0000399 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000400 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
401 return SQLITE_DENY
402 }
403 return SQLITE_OK
404 }
405 catchsql {DELETE FROM t2 WHERE a=11}
406} {1 {not authorized}}
407do_test auth-1.48 {
408 execsql {SELECT * FROM t2}
409} {11 2 33}
410do_test auth-1.49 {
drhe22a3342003-04-22 20:30:37 +0000411 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000412 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
413 return SQLITE_IGNORE
414 }
415 return SQLITE_OK
416 }
417 catchsql {DELETE FROM t2 WHERE a=11}
418} {0 {}}
419do_test auth-1.50 {
420 execsql {SELECT * FROM t2}
421} {11 2 33}
422
423do_test auth-1.51 {
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_DENY
427 }
428 return SQLITE_OK
429 }
430 catchsql {SELECT * FROM t2}
431} {1 {not authorized}}
432do_test auth-1.52 {
drhe22a3342003-04-22 20:30:37 +0000433 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000434 if {$code=="SQLITE_SELECT"} {
435 return SQLITE_IGNORE
436 }
437 return SQLITE_OK
438 }
439 catchsql {SELECT * FROM t2}
440} {0 {}}
441do_test auth-1.53 {
drhe22a3342003-04-22 20:30:37 +0000442 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000443 if {$code=="SQLITE_SELECT"} {
444 return SQLITE_OK
445 }
446 return SQLITE_OK
447 }
448 catchsql {SELECT * FROM t2}
449} {0 {11 2 33}}
450
danielk19772ac79702004-06-14 11:54:18 +0000451# Update for version 3: There used to be a handful of test here that
452# tested the authorisation callback with the COPY command. The following
453# test makes the same database modifications as they used to.
454do_test auth-1.54 {
455 execsql {INSERT INTO t2 VALUES(7, 8, 9);}
456} {}
457do_test auth-1.55 {
458 execsql {SELECT * FROM t2}
459} {11 2 33 7 8 9}
drh77ad4e42003-01-14 02:49:27 +0000460
461do_test auth-1.63 {
drhe22a3342003-04-22 20:30:37 +0000462 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000463 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
464 return SQLITE_DENY
465 }
466 return SQLITE_OK
467 }
468 catchsql {DROP TABLE t2}
469} {1 {not authorized}}
470do_test auth-1.64 {
471 execsql {SELECT name FROM sqlite_master}
472} {t2}
473do_test auth-1.65 {
drhe22a3342003-04-22 20:30:37 +0000474 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000475 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
476 return SQLITE_DENY
477 }
478 return SQLITE_OK
479 }
480 catchsql {DROP TABLE t2}
481} {1 {not authorized}}
482do_test auth-1.66 {
483 execsql {SELECT name FROM sqlite_master}
484} {t2}
danielk197753c0f742005-03-29 03:10:59 +0000485
486ifcapable tempdb {
487 do_test auth-1.67 {
488 proc auth {code arg1 arg2 arg3 arg4} {
489 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
490 return SQLITE_DENY
491 }
492 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000493 }
danielk197753c0f742005-03-29 03:10:59 +0000494 catchsql {DROP TABLE t1}
495 } {1 {not authorized}}
496 do_test auth-1.68 {
497 execsql {SELECT name FROM sqlite_temp_master}
498 } {t1}
499 do_test auth-1.69 {
500 proc auth {code arg1 arg2 arg3 arg4} {
501 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
502 return SQLITE_DENY
503 }
504 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000505 }
danielk197753c0f742005-03-29 03:10:59 +0000506 catchsql {DROP TABLE t1}
507 } {1 {not authorized}}
508 do_test auth-1.70 {
509 execsql {SELECT name FROM sqlite_temp_master}
510 } {t1}
511}
drh77ad4e42003-01-14 02:49:27 +0000512
513do_test auth-1.71 {
drhe22a3342003-04-22 20:30:37 +0000514 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000515 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
516 return SQLITE_IGNORE
517 }
518 return SQLITE_OK
519 }
520 catchsql {DROP TABLE t2}
521} {0 {}}
522do_test auth-1.72 {
523 execsql {SELECT name FROM sqlite_master}
524} {t2}
525do_test auth-1.73 {
drhe22a3342003-04-22 20:30:37 +0000526 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000527 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
528 return SQLITE_IGNORE
529 }
530 return SQLITE_OK
531 }
532 catchsql {DROP TABLE t2}
533} {0 {}}
534do_test auth-1.74 {
535 execsql {SELECT name FROM sqlite_master}
536} {t2}
danielk197753c0f742005-03-29 03:10:59 +0000537
538ifcapable tempdb {
539 do_test auth-1.75 {
540 proc auth {code arg1 arg2 arg3 arg4} {
541 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
542 return SQLITE_IGNORE
543 }
544 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000545 }
danielk197753c0f742005-03-29 03:10:59 +0000546 catchsql {DROP TABLE t1}
547 } {0 {}}
548 do_test auth-1.76 {
549 execsql {SELECT name FROM sqlite_temp_master}
550 } {t1}
551 do_test auth-1.77 {
552 proc auth {code arg1 arg2 arg3 arg4} {
553 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
554 return SQLITE_IGNORE
555 }
556 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000557 }
danielk197753c0f742005-03-29 03:10:59 +0000558 catchsql {DROP TABLE t1}
559 } {0 {}}
560 do_test auth-1.78 {
561 execsql {SELECT name FROM sqlite_temp_master}
562 } {t1}
563}
drh77ad4e42003-01-14 02:49:27 +0000564
danielk197781650dc2004-11-22 11:51:13 +0000565# Test cases auth-1.79 to auth-1.124 test creating and dropping views.
danielk19770fa8ddb2004-11-22 08:43:32 +0000566# Omit these if the library was compiled with views omitted.
567ifcapable view {
drh77ad4e42003-01-14 02:49:27 +0000568do_test auth-1.79 {
drhe22a3342003-04-22 20:30:37 +0000569 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000570 if {$code=="SQLITE_CREATE_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000571 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000572 return SQLITE_DENY
573 }
574 return SQLITE_OK
575 }
576 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
577} {1 {not authorized}}
578do_test auth-1.80 {
579 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000580} {v1 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000581do_test auth-1.81 {
582 execsql {SELECT name FROM sqlite_master}
583} {t2}
584do_test auth-1.82 {
drhe22a3342003-04-22 20:30:37 +0000585 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000586 if {$code=="SQLITE_CREATE_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000587 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000588 return SQLITE_IGNORE
589 }
590 return SQLITE_OK
591 }
592 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
593} {0 {}}
594do_test auth-1.83 {
595 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000596} {v1 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000597do_test auth-1.84 {
598 execsql {SELECT name FROM sqlite_master}
599} {t2}
600
danielk197753c0f742005-03-29 03:10:59 +0000601ifcapable tempdb {
602 do_test auth-1.85 {
603 proc auth {code arg1 arg2 arg3 arg4} {
604 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
605 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
606 return SQLITE_DENY
607 }
608 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000609 }
danielk197753c0f742005-03-29 03:10:59 +0000610 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
611 } {1 {not authorized}}
612 do_test auth-1.86 {
613 set ::authargs
614 } {v1 {} temp {}}
615 do_test auth-1.87 {
616 execsql {SELECT name FROM sqlite_temp_master}
617 } {t1}
618 do_test auth-1.88 {
619 proc auth {code arg1 arg2 arg3 arg4} {
620 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
621 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
622 return SQLITE_IGNORE
623 }
624 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000625 }
danielk197753c0f742005-03-29 03:10:59 +0000626 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
627 } {0 {}}
628 do_test auth-1.89 {
629 set ::authargs
630 } {v1 {} temp {}}
631 do_test auth-1.90 {
632 execsql {SELECT name FROM sqlite_temp_master}
633 } {t1}
634}
drh77ad4e42003-01-14 02:49:27 +0000635
636do_test auth-1.91 {
drhe22a3342003-04-22 20:30:37 +0000637 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000638 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
639 return SQLITE_DENY
640 }
641 return SQLITE_OK
642 }
643 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
644} {1 {not authorized}}
645do_test auth-1.92 {
646 execsql {SELECT name FROM sqlite_master}
647} {t2}
648do_test auth-1.93 {
drhe22a3342003-04-22 20:30:37 +0000649 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000650 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
651 return SQLITE_IGNORE
652 }
653 return SQLITE_OK
654 }
655 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
656} {0 {}}
657do_test auth-1.94 {
658 execsql {SELECT name FROM sqlite_master}
659} {t2}
660
danielk197753c0f742005-03-29 03:10:59 +0000661ifcapable tempdb {
662 do_test auth-1.95 {
663 proc auth {code arg1 arg2 arg3 arg4} {
664 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
665 return SQLITE_DENY
666 }
667 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000668 }
danielk197753c0f742005-03-29 03:10:59 +0000669 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
670 } {1 {not authorized}}
671 do_test auth-1.96 {
672 execsql {SELECT name FROM sqlite_temp_master}
673 } {t1}
674 do_test auth-1.97 {
675 proc auth {code arg1 arg2 arg3 arg4} {
676 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
677 return SQLITE_IGNORE
678 }
679 return SQLITE_OK
drh77ad4e42003-01-14 02:49:27 +0000680 }
danielk197753c0f742005-03-29 03:10:59 +0000681 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
682 } {0 {}}
683 do_test auth-1.98 {
684 execsql {SELECT name FROM sqlite_temp_master}
685 } {t1}
686}
drh77ad4e42003-01-14 02:49:27 +0000687
688do_test auth-1.99 {
drhe22a3342003-04-22 20:30:37 +0000689 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000690 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
691 return SQLITE_DENY
692 }
693 return SQLITE_OK
694 }
695 catchsql {
696 CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
697 DROP VIEW v2
698 }
699} {1 {not authorized}}
700do_test auth-1.100 {
701 execsql {SELECT name FROM sqlite_master}
702} {t2 v2}
703do_test auth-1.101 {
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_DENY
708 }
709 return SQLITE_OK
710 }
711 catchsql {DROP VIEW v2}
712} {1 {not authorized}}
713do_test auth-1.102 {
714 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000715} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000716do_test auth-1.103 {
717 execsql {SELECT name FROM sqlite_master}
718} {t2 v2}
719do_test auth-1.104 {
drhe22a3342003-04-22 20:30:37 +0000720 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000721 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
722 return SQLITE_IGNORE
723 }
724 return SQLITE_OK
725 }
726 catchsql {DROP VIEW v2}
727} {0 {}}
728do_test auth-1.105 {
729 execsql {SELECT name FROM sqlite_master}
730} {t2 v2}
731do_test auth-1.106 {
drhe22a3342003-04-22 20:30:37 +0000732 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000733 if {$code=="SQLITE_DROP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000734 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000735 return SQLITE_IGNORE
736 }
737 return SQLITE_OK
738 }
739 catchsql {DROP VIEW v2}
740} {0 {}}
741do_test auth-1.107 {
742 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000743} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000744do_test auth-1.108 {
745 execsql {SELECT name FROM sqlite_master}
746} {t2 v2}
747do_test auth-1.109 {
drhe22a3342003-04-22 20:30:37 +0000748 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000749 if {$code=="SQLITE_DROP_VIEW"} {
drhe22a3342003-04-22 20:30:37 +0000750 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000751 return SQLITE_OK
752 }
753 return SQLITE_OK
754 }
755 catchsql {DROP VIEW v2}
756} {0 {}}
757do_test auth-1.110 {
758 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000759} {v2 {} main {}}
drh77ad4e42003-01-14 02:49:27 +0000760do_test auth-1.111 {
761 execsql {SELECT name FROM sqlite_master}
762} {t2}
763
764
danielk197753c0f742005-03-29 03:10:59 +0000765ifcapable tempdb {
766 do_test auth-1.112 {
767 proc auth {code arg1 arg2 arg3 arg4} {
768 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
769 return SQLITE_DENY
770 }
drh77ad4e42003-01-14 02:49:27 +0000771 return SQLITE_OK
772 }
danielk197753c0f742005-03-29 03:10:59 +0000773 catchsql {
774 CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
775 DROP VIEW v1
776 }
777 } {1 {not authorized}}
778 do_test auth-1.113 {
779 execsql {SELECT name FROM sqlite_temp_master}
780 } {t1 v1}
781 do_test auth-1.114 {
782 proc auth {code arg1 arg2 arg3 arg4} {
783 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
784 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
785 return SQLITE_DENY
786 }
787 return SQLITE_OK
788 }
789 catchsql {DROP VIEW v1}
790 } {1 {not authorized}}
791 do_test auth-1.115 {
792 set ::authargs
793 } {v1 {} temp {}}
794 do_test auth-1.116 {
795 execsql {SELECT name FROM sqlite_temp_master}
796 } {t1 v1}
797 do_test auth-1.117 {
798 proc auth {code arg1 arg2 arg3 arg4} {
799 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
800 return SQLITE_IGNORE
801 }
802 return SQLITE_OK
803 }
804 catchsql {DROP VIEW v1}
805 } {0 {}}
806 do_test auth-1.118 {
807 execsql {SELECT name FROM sqlite_temp_master}
808 } {t1 v1}
809 do_test auth-1.119 {
810 proc auth {code arg1 arg2 arg3 arg4} {
811 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
812 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
813 return SQLITE_IGNORE
814 }
815 return SQLITE_OK
816 }
817 catchsql {DROP VIEW v1}
818 } {0 {}}
819 do_test auth-1.120 {
820 set ::authargs
821 } {v1 {} temp {}}
822 do_test auth-1.121 {
823 execsql {SELECT name FROM sqlite_temp_master}
824 } {t1 v1}
825 do_test auth-1.122 {
826 proc auth {code arg1 arg2 arg3 arg4} {
827 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
828 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
829 return SQLITE_OK
830 }
831 return SQLITE_OK
832 }
833 catchsql {DROP VIEW v1}
834 } {0 {}}
835 do_test auth-1.123 {
836 set ::authargs
837 } {v1 {} temp {}}
838 do_test auth-1.124 {
839 execsql {SELECT name FROM sqlite_temp_master}
840 } {t1}
841}
danielk19770fa8ddb2004-11-22 08:43:32 +0000842} ;# ifcapable view
drh77ad4e42003-01-14 02:49:27 +0000843
danielk197781650dc2004-11-22 11:51:13 +0000844# Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
845# Omit these if the library was compiled with triggers omitted.
846#
danielk197753c0f742005-03-29 03:10:59 +0000847ifcapable trigger&&tempdb {
drh77ad4e42003-01-14 02:49:27 +0000848do_test auth-1.125 {
drhe22a3342003-04-22 20:30:37 +0000849 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000850 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000851 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000852 return SQLITE_DENY
853 }
854 return SQLITE_OK
855 }
856 catchsql {
857 CREATE TRIGGER r2 DELETE on t2 BEGIN
858 SELECT NULL;
859 END;
860 }
861} {1 {not authorized}}
862do_test auth-1.126 {
863 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000864} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +0000865do_test auth-1.127 {
866 execsql {SELECT name FROM sqlite_master}
867} {t2}
868do_test auth-1.128 {
drhe22a3342003-04-22 20:30:37 +0000869 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000870 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
871 return SQLITE_DENY
872 }
873 return SQLITE_OK
874 }
875 catchsql {
876 CREATE TRIGGER r2 DELETE on t2 BEGIN
877 SELECT NULL;
878 END;
879 }
880} {1 {not authorized}}
881do_test auth-1.129 {
882 execsql {SELECT name FROM sqlite_master}
883} {t2}
884do_test auth-1.130 {
drhe22a3342003-04-22 20:30:37 +0000885 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000886 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000887 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000888 return SQLITE_IGNORE
889 }
890 return SQLITE_OK
891 }
892 catchsql {
893 CREATE TRIGGER r2 DELETE on t2 BEGIN
894 SELECT NULL;
895 END;
896 }
897} {0 {}}
898do_test auth-1.131 {
899 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000900} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +0000901do_test auth-1.132 {
902 execsql {SELECT name FROM sqlite_master}
903} {t2}
904do_test auth-1.133 {
drhe22a3342003-04-22 20:30:37 +0000905 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000906 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
907 return SQLITE_IGNORE
908 }
909 return SQLITE_OK
910 }
911 catchsql {
912 CREATE TRIGGER r2 DELETE on t2 BEGIN
913 SELECT NULL;
914 END;
915 }
916} {0 {}}
917do_test auth-1.134 {
918 execsql {SELECT name FROM sqlite_master}
919} {t2}
920do_test auth-1.135 {
drhe22a3342003-04-22 20:30:37 +0000921 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000922 if {$code=="SQLITE_CREATE_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000923 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000924 return SQLITE_OK
925 }
926 return SQLITE_OK
927 }
928 catchsql {
drhe22a3342003-04-22 20:30:37 +0000929 CREATE TABLE tx(id);
930 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
931 INSERT INTO tx VALUES(NEW.rowid);
drh77ad4e42003-01-14 02:49:27 +0000932 END;
933 }
934} {0 {}}
drhe22a3342003-04-22 20:30:37 +0000935do_test auth-1.136.1 {
drh77ad4e42003-01-14 02:49:27 +0000936 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000937} {r2 t2 main {}}
938do_test auth-1.136.2 {
939 execsql {
940 SELECT name FROM sqlite_master WHERE type='trigger'
941 }
942} {r2}
943do_test auth-1.136.3 {
944 proc auth {code arg1 arg2 arg3 arg4} {
945 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
946 return SQLITE_OK
947 }
948 set ::authargs {}
949 execsql {
950 INSERT INTO t2 VALUES(1,2,3);
951 }
952 set ::authargs
953} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
954do_test auth-1.136.4 {
955 execsql {
956 SELECT * FROM tx;
957 }
958} {3}
drh77ad4e42003-01-14 02:49:27 +0000959do_test auth-1.137 {
960 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +0000961} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +0000962do_test auth-1.138 {
drhe22a3342003-04-22 20:30:37 +0000963 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000964 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +0000965 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +0000966 return SQLITE_DENY
967 }
968 return SQLITE_OK
969 }
970 catchsql {
971 CREATE TRIGGER r1 DELETE on t1 BEGIN
972 SELECT NULL;
973 END;
974 }
975} {1 {not authorized}}
976do_test auth-1.139 {
977 set ::authargs
drhe22a3342003-04-22 20:30:37 +0000978} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +0000979do_test auth-1.140 {
980 execsql {SELECT name FROM sqlite_temp_master}
981} {t1}
982do_test auth-1.141 {
drhe22a3342003-04-22 20:30:37 +0000983 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +0000984 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
985 return SQLITE_DENY
986 }
987 return SQLITE_OK
988 }
989 catchsql {
990 CREATE TRIGGER r1 DELETE on t1 BEGIN
991 SELECT NULL;
992 END;
993 }
994} {1 {not authorized}}
995do_test auth-1.142 {
996 execsql {SELECT name FROM sqlite_temp_master}
997} {t1}
998do_test auth-1.143 {
drhe22a3342003-04-22 20:30:37 +0000999 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001000 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001001 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001002 return SQLITE_IGNORE
1003 }
1004 return SQLITE_OK
1005 }
1006 catchsql {
1007 CREATE TRIGGER r1 DELETE on t1 BEGIN
1008 SELECT NULL;
1009 END;
1010 }
1011} {0 {}}
1012do_test auth-1.144 {
1013 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001014} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001015do_test auth-1.145 {
1016 execsql {SELECT name FROM sqlite_temp_master}
1017} {t1}
1018do_test auth-1.146 {
drhe22a3342003-04-22 20:30:37 +00001019 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001020 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1021 return SQLITE_IGNORE
1022 }
1023 return SQLITE_OK
1024 }
1025 catchsql {
1026 CREATE TRIGGER r1 DELETE on t1 BEGIN
1027 SELECT NULL;
1028 END;
1029 }
1030} {0 {}}
1031do_test auth-1.147 {
1032 execsql {SELECT name FROM sqlite_temp_master}
1033} {t1}
1034do_test auth-1.148 {
drhe22a3342003-04-22 20:30:37 +00001035 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001036 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001037 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001038 return SQLITE_OK
1039 }
1040 return SQLITE_OK
1041 }
1042 catchsql {
1043 CREATE TRIGGER r1 DELETE on t1 BEGIN
1044 SELECT NULL;
1045 END;
1046 }
1047} {0 {}}
1048do_test auth-1.149 {
1049 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001050} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001051do_test auth-1.150 {
1052 execsql {SELECT name FROM sqlite_temp_master}
1053} {t1 r1}
1054
1055do_test auth-1.151 {
drhe22a3342003-04-22 20:30:37 +00001056 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001057 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1058 return SQLITE_DENY
1059 }
1060 return SQLITE_OK
1061 }
1062 catchsql {DROP TRIGGER r2}
1063} {1 {not authorized}}
1064do_test auth-1.152 {
1065 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001066} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001067do_test auth-1.153 {
drhe22a3342003-04-22 20:30:37 +00001068 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001069 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001070 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001071 return SQLITE_DENY
1072 }
1073 return SQLITE_OK
1074 }
1075 catchsql {DROP TRIGGER r2}
1076} {1 {not authorized}}
1077do_test auth-1.154 {
1078 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001079} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001080do_test auth-1.155 {
1081 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001082} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001083do_test auth-1.156 {
drhe22a3342003-04-22 20:30:37 +00001084 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001085 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1086 return SQLITE_IGNORE
1087 }
1088 return SQLITE_OK
1089 }
1090 catchsql {DROP TRIGGER r2}
1091} {0 {}}
1092do_test auth-1.157 {
1093 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001094} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001095do_test auth-1.158 {
drhe22a3342003-04-22 20:30:37 +00001096 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001097 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001098 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001099 return SQLITE_IGNORE
1100 }
1101 return SQLITE_OK
1102 }
1103 catchsql {DROP TRIGGER r2}
1104} {0 {}}
1105do_test auth-1.159 {
1106 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001107} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001108do_test auth-1.160 {
1109 execsql {SELECT name FROM sqlite_master}
drhe22a3342003-04-22 20:30:37 +00001110} {t2 tx r2}
drh77ad4e42003-01-14 02:49:27 +00001111do_test auth-1.161 {
drhe22a3342003-04-22 20:30:37 +00001112 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001113 if {$code=="SQLITE_DROP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001114 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001115 return SQLITE_OK
1116 }
1117 return SQLITE_OK
1118 }
1119 catchsql {DROP TRIGGER r2}
1120} {0 {}}
1121do_test auth-1.162 {
1122 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001123} {r2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001124do_test auth-1.163 {
drhe22a3342003-04-22 20:30:37 +00001125 execsql {
1126 DROP TABLE tx;
1127 DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1128 SELECT name FROM sqlite_master;
1129 }
drh77ad4e42003-01-14 02:49:27 +00001130} {t2}
1131
1132do_test auth-1.164 {
drhe22a3342003-04-22 20:30:37 +00001133 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001134 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1135 return SQLITE_DENY
1136 }
1137 return SQLITE_OK
1138 }
1139 catchsql {DROP TRIGGER r1}
1140} {1 {not authorized}}
1141do_test auth-1.165 {
1142 execsql {SELECT name FROM sqlite_temp_master}
1143} {t1 r1}
1144do_test auth-1.166 {
drhe22a3342003-04-22 20:30:37 +00001145 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001146 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001147 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001148 return SQLITE_DENY
1149 }
1150 return SQLITE_OK
1151 }
1152 catchsql {DROP TRIGGER r1}
1153} {1 {not authorized}}
1154do_test auth-1.167 {
1155 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001156} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001157do_test auth-1.168 {
1158 execsql {SELECT name FROM sqlite_temp_master}
1159} {t1 r1}
1160do_test auth-1.169 {
drhe22a3342003-04-22 20:30:37 +00001161 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001162 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1163 return SQLITE_IGNORE
1164 }
1165 return SQLITE_OK
1166 }
1167 catchsql {DROP TRIGGER r1}
1168} {0 {}}
1169do_test auth-1.170 {
1170 execsql {SELECT name FROM sqlite_temp_master}
1171} {t1 r1}
1172do_test auth-1.171 {
drhe22a3342003-04-22 20:30:37 +00001173 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001174 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001175 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001176 return SQLITE_IGNORE
1177 }
1178 return SQLITE_OK
1179 }
1180 catchsql {DROP TRIGGER r1}
1181} {0 {}}
1182do_test auth-1.172 {
1183 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001184} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001185do_test auth-1.173 {
1186 execsql {SELECT name FROM sqlite_temp_master}
1187} {t1 r1}
1188do_test auth-1.174 {
drhe22a3342003-04-22 20:30:37 +00001189 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001190 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
drhe22a3342003-04-22 20:30:37 +00001191 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001192 return SQLITE_OK
1193 }
1194 return SQLITE_OK
1195 }
1196 catchsql {DROP TRIGGER r1}
1197} {0 {}}
1198do_test auth-1.175 {
1199 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001200} {r1 t1 temp {}}
drh77ad4e42003-01-14 02:49:27 +00001201do_test auth-1.176 {
1202 execsql {SELECT name FROM sqlite_temp_master}
1203} {t1}
danielk197781650dc2004-11-22 11:51:13 +00001204} ;# ifcapable trigger
drh77ad4e42003-01-14 02:49:27 +00001205
1206do_test auth-1.177 {
drhe22a3342003-04-22 20:30:37 +00001207 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001208 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001209 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001210 return SQLITE_DENY
1211 }
1212 return SQLITE_OK
1213 }
1214 catchsql {CREATE INDEX i2 ON t2(a)}
1215} {1 {not authorized}}
1216do_test auth-1.178 {
1217 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001218} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001219do_test auth-1.179 {
1220 execsql {SELECT name FROM sqlite_master}
1221} {t2}
1222do_test auth-1.180 {
drhe22a3342003-04-22 20:30:37 +00001223 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001224 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1225 return SQLITE_DENY
1226 }
1227 return SQLITE_OK
1228 }
1229 catchsql {CREATE INDEX i2 ON t2(a)}
1230} {1 {not authorized}}
1231do_test auth-1.181 {
1232 execsql {SELECT name FROM sqlite_master}
1233} {t2}
1234do_test auth-1.182 {
drhe22a3342003-04-22 20:30:37 +00001235 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001236 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001237 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001238 return SQLITE_IGNORE
1239 }
1240 return SQLITE_OK
1241 }
1242 catchsql {CREATE INDEX i2 ON t2(b)}
1243} {0 {}}
1244do_test auth-1.183 {
1245 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001246} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001247do_test auth-1.184 {
1248 execsql {SELECT name FROM sqlite_master}
1249} {t2}
1250do_test auth-1.185 {
drhe22a3342003-04-22 20:30:37 +00001251 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001252 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1253 return SQLITE_IGNORE
1254 }
1255 return SQLITE_OK
1256 }
1257 catchsql {CREATE INDEX i2 ON t2(b)}
1258} {0 {}}
1259do_test auth-1.186 {
1260 execsql {SELECT name FROM sqlite_master}
1261} {t2}
1262do_test auth-1.187 {
drhe22a3342003-04-22 20:30:37 +00001263 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001264 if {$code=="SQLITE_CREATE_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001265 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001266 return SQLITE_OK
1267 }
1268 return SQLITE_OK
1269 }
1270 catchsql {CREATE INDEX i2 ON t2(a)}
1271} {0 {}}
1272do_test auth-1.188 {
1273 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001274} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001275do_test auth-1.189 {
1276 execsql {SELECT name FROM sqlite_master}
1277} {t2 i2}
1278
danielk197753c0f742005-03-29 03:10:59 +00001279ifcapable tempdb {
1280 do_test auth-1.190 {
1281 proc auth {code arg1 arg2 arg3 arg4} {
1282 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1283 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1284 return SQLITE_DENY
1285 }
drh77ad4e42003-01-14 02:49:27 +00001286 return SQLITE_OK
1287 }
danielk197753c0f742005-03-29 03:10:59 +00001288 catchsql {CREATE INDEX i1 ON t1(a)}
1289 } {1 {not authorized}}
1290 do_test auth-1.191 {
1291 set ::authargs
1292 } {i1 t1 temp {}}
1293 do_test auth-1.192 {
1294 execsql {SELECT name FROM sqlite_temp_master}
1295 } {t1}
1296 do_test auth-1.193 {
1297 proc auth {code arg1 arg2 arg3 arg4} {
1298 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1299 return SQLITE_DENY
1300 }
1301 return SQLITE_OK
1302 }
1303 catchsql {CREATE INDEX i1 ON t1(b)}
1304 } {1 {not authorized}}
1305 do_test auth-1.194 {
1306 execsql {SELECT name FROM sqlite_temp_master}
1307 } {t1}
1308 do_test auth-1.195 {
1309 proc auth {code arg1 arg2 arg3 arg4} {
1310 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1311 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1312 return SQLITE_IGNORE
1313 }
1314 return SQLITE_OK
1315 }
1316 catchsql {CREATE INDEX i1 ON t1(b)}
1317 } {0 {}}
1318 do_test auth-1.196 {
1319 set ::authargs
1320 } {i1 t1 temp {}}
1321 do_test auth-1.197 {
1322 execsql {SELECT name FROM sqlite_temp_master}
1323 } {t1}
1324 do_test auth-1.198 {
1325 proc auth {code arg1 arg2 arg3 arg4} {
1326 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1327 return SQLITE_IGNORE
1328 }
1329 return SQLITE_OK
1330 }
1331 catchsql {CREATE INDEX i1 ON t1(c)}
1332 } {0 {}}
1333 do_test auth-1.199 {
1334 execsql {SELECT name FROM sqlite_temp_master}
1335 } {t1}
1336 do_test auth-1.200 {
1337 proc auth {code arg1 arg2 arg3 arg4} {
1338 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1339 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1340 return SQLITE_OK
1341 }
1342 return SQLITE_OK
1343 }
1344 catchsql {CREATE INDEX i1 ON t1(a)}
1345 } {0 {}}
1346 do_test auth-1.201 {
1347 set ::authargs
1348 } {i1 t1 temp {}}
1349 do_test auth-1.202 {
1350 execsql {SELECT name FROM sqlite_temp_master}
1351 } {t1 i1}
1352}
drh77ad4e42003-01-14 02:49:27 +00001353
1354do_test auth-1.203 {
drhe22a3342003-04-22 20:30:37 +00001355 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001356 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1357 return SQLITE_DENY
1358 }
1359 return SQLITE_OK
1360 }
1361 catchsql {DROP INDEX i2}
1362} {1 {not authorized}}
1363do_test auth-1.204 {
1364 execsql {SELECT name FROM sqlite_master}
1365} {t2 i2}
1366do_test auth-1.205 {
drhe22a3342003-04-22 20:30:37 +00001367 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001368 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001369 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001370 return SQLITE_DENY
1371 }
1372 return SQLITE_OK
1373 }
1374 catchsql {DROP INDEX i2}
1375} {1 {not authorized}}
1376do_test auth-1.206 {
1377 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001378} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001379do_test auth-1.207 {
1380 execsql {SELECT name FROM sqlite_master}
1381} {t2 i2}
1382do_test auth-1.208 {
drhe22a3342003-04-22 20:30:37 +00001383 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001384 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1385 return SQLITE_IGNORE
1386 }
1387 return SQLITE_OK
1388 }
1389 catchsql {DROP INDEX i2}
1390} {0 {}}
1391do_test auth-1.209 {
1392 execsql {SELECT name FROM sqlite_master}
1393} {t2 i2}
1394do_test auth-1.210 {
drhe22a3342003-04-22 20:30:37 +00001395 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001396 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001397 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001398 return SQLITE_IGNORE
1399 }
1400 return SQLITE_OK
1401 }
1402 catchsql {DROP INDEX i2}
1403} {0 {}}
1404do_test auth-1.211 {
1405 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001406} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001407do_test auth-1.212 {
1408 execsql {SELECT name FROM sqlite_master}
1409} {t2 i2}
1410do_test auth-1.213 {
drhe22a3342003-04-22 20:30:37 +00001411 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001412 if {$code=="SQLITE_DROP_INDEX"} {
drhe22a3342003-04-22 20:30:37 +00001413 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001414 return SQLITE_OK
1415 }
1416 return SQLITE_OK
1417 }
1418 catchsql {DROP INDEX i2}
1419} {0 {}}
1420do_test auth-1.214 {
1421 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001422} {i2 t2 main {}}
drh77ad4e42003-01-14 02:49:27 +00001423do_test auth-1.215 {
1424 execsql {SELECT name FROM sqlite_master}
1425} {t2}
1426
danielk197753c0f742005-03-29 03:10:59 +00001427ifcapable tempdb {
1428 do_test auth-1.216 {
1429 proc auth {code arg1 arg2 arg3 arg4} {
1430 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1431 return SQLITE_DENY
1432 }
drh77ad4e42003-01-14 02:49:27 +00001433 return SQLITE_OK
1434 }
danielk197753c0f742005-03-29 03:10:59 +00001435 catchsql {DROP INDEX i1}
1436 } {1 {not authorized}}
1437 do_test auth-1.217 {
1438 execsql {SELECT name FROM sqlite_temp_master}
1439 } {t1 i1}
1440 do_test auth-1.218 {
1441 proc auth {code arg1 arg2 arg3 arg4} {
1442 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1443 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1444 return SQLITE_DENY
1445 }
1446 return SQLITE_OK
1447 }
1448 catchsql {DROP INDEX i1}
1449 } {1 {not authorized}}
1450 do_test auth-1.219 {
1451 set ::authargs
1452 } {i1 t1 temp {}}
1453 do_test auth-1.220 {
1454 execsql {SELECT name FROM sqlite_temp_master}
1455 } {t1 i1}
1456 do_test auth-1.221 {
1457 proc auth {code arg1 arg2 arg3 arg4} {
1458 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1459 return SQLITE_IGNORE
1460 }
1461 return SQLITE_OK
1462 }
1463 catchsql {DROP INDEX i1}
1464 } {0 {}}
1465 do_test auth-1.222 {
1466 execsql {SELECT name FROM sqlite_temp_master}
1467 } {t1 i1}
1468 do_test auth-1.223 {
1469 proc auth {code arg1 arg2 arg3 arg4} {
1470 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1471 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1472 return SQLITE_IGNORE
1473 }
1474 return SQLITE_OK
1475 }
1476 catchsql {DROP INDEX i1}
1477 } {0 {}}
1478 do_test auth-1.224 {
1479 set ::authargs
1480 } {i1 t1 temp {}}
1481 do_test auth-1.225 {
1482 execsql {SELECT name FROM sqlite_temp_master}
1483 } {t1 i1}
1484 do_test auth-1.226 {
1485 proc auth {code arg1 arg2 arg3 arg4} {
1486 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1487 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1488 return SQLITE_OK
1489 }
1490 return SQLITE_OK
1491 }
1492 catchsql {DROP INDEX i1}
1493 } {0 {}}
1494 do_test auth-1.227 {
1495 set ::authargs
1496 } {i1 t1 temp {}}
1497 do_test auth-1.228 {
1498 execsql {SELECT name FROM sqlite_temp_master}
1499 } {t1}
1500}
drh77ad4e42003-01-14 02:49:27 +00001501
1502do_test auth-1.229 {
drhe22a3342003-04-22 20:30:37 +00001503 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001504 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001505 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001506 return SQLITE_DENY
1507 }
1508 return SQLITE_OK
1509 }
1510 catchsql {PRAGMA full_column_names=on}
1511} {1 {not authorized}}
1512do_test auth-1.230 {
1513 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001514} {full_column_names on {} {}}
drh77ad4e42003-01-14 02:49:27 +00001515do_test auth-1.231 {
1516 execsql2 {SELECT a FROM t2}
1517} {a 11 a 7}
1518do_test auth-1.232 {
drhe22a3342003-04-22 20:30:37 +00001519 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001520 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001521 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001522 return SQLITE_IGNORE
1523 }
1524 return SQLITE_OK
1525 }
1526 catchsql {PRAGMA full_column_names=on}
1527} {0 {}}
1528do_test auth-1.233 {
1529 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001530} {full_column_names on {} {}}
drh77ad4e42003-01-14 02:49:27 +00001531do_test auth-1.234 {
1532 execsql2 {SELECT a FROM t2}
1533} {a 11 a 7}
1534do_test auth-1.235 {
drhe22a3342003-04-22 20:30:37 +00001535 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001536 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001537 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001538 return SQLITE_OK
1539 }
1540 return SQLITE_OK
1541 }
1542 catchsql {PRAGMA full_column_names=on}
1543} {0 {}}
1544do_test auth-1.236 {
1545 execsql2 {SELECT a FROM t2}
1546} {t2.a 11 t2.a 7}
1547do_test auth-1.237 {
drhe22a3342003-04-22 20:30:37 +00001548 proc auth {code arg1 arg2 arg3 arg4} {
drh77ad4e42003-01-14 02:49:27 +00001549 if {$code=="SQLITE_PRAGMA"} {
drhe22a3342003-04-22 20:30:37 +00001550 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh77ad4e42003-01-14 02:49:27 +00001551 return SQLITE_OK
1552 }
1553 return SQLITE_OK
1554 }
1555 catchsql {PRAGMA full_column_names=OFF}
1556} {0 {}}
1557do_test auth-1.238 {
1558 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001559} {full_column_names OFF {} {}}
drh77ad4e42003-01-14 02:49:27 +00001560do_test auth-1.239 {
1561 execsql2 {SELECT a FROM t2}
1562} {a 11 a 7}
drhe5f9c642003-01-13 23:27:31 +00001563
drh2c3831c2003-01-14 13:48:20 +00001564do_test auth-1.240 {
drhe22a3342003-04-22 20:30:37 +00001565 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001566 if {$code=="SQLITE_TRANSACTION"} {
drhe22a3342003-04-22 20:30:37 +00001567 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh2c3831c2003-01-14 13:48:20 +00001568 return SQLITE_DENY
1569 }
1570 return SQLITE_OK
1571 }
1572 catchsql {BEGIN}
1573} {1 {not authorized}}
1574do_test auth-1.241 {
1575 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001576} {BEGIN {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001577do_test auth-1.242 {
drhe22a3342003-04-22 20:30:37 +00001578 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00001579 if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
drhe22a3342003-04-22 20:30:37 +00001580 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
drh2c3831c2003-01-14 13:48:20 +00001581 return SQLITE_DENY
1582 }
1583 return SQLITE_OK
1584 }
1585 catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1586} {1 {not authorized}}
1587do_test auth-1.243 {
1588 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001589} {COMMIT {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001590do_test auth-1.244 {
1591 execsql {SELECT * FROM t2}
1592} {11 2 33 7 8 9 44 55 66}
1593do_test auth-1.245 {
1594 catchsql {ROLLBACK}
1595} {1 {not authorized}}
1596do_test auth-1.246 {
1597 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001598} {ROLLBACK {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001599do_test auth-1.247 {
1600 catchsql {END TRANSACTION}
1601} {1 {not authorized}}
1602do_test auth-1.248 {
1603 set ::authargs
drhe22a3342003-04-22 20:30:37 +00001604} {COMMIT {} {} {}}
drh2c3831c2003-01-14 13:48:20 +00001605do_test auth-1.249 {
drhe22a3342003-04-22 20:30:37 +00001606 db authorizer {}
drh2c3831c2003-01-14 13:48:20 +00001607 catchsql {ROLLBACK}
1608} {0 {}}
1609do_test auth-1.250 {
1610 execsql {SELECT * FROM t2}
1611} {11 2 33 7 8 9}
1612
drh81e293b2003-06-06 19:00:42 +00001613# ticket #340 - authorization for ATTACH and DETACH.
1614#
danielk19775a8f9372007-10-09 08:29:32 +00001615ifcapable attach {
1616 do_test auth-1.251 {
1617 db authorizer ::auth
1618 proc auth {code arg1 arg2 arg3 arg4} {
1619 if {$code=="SQLITE_ATTACH"} {
1620 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1621 }
drh81e293b2003-06-06 19:00:42 +00001622 return SQLITE_OK
1623 }
danielk19775a8f9372007-10-09 08:29:32 +00001624 catchsql {
1625 ATTACH DATABASE ':memory:' AS test1
drh81e293b2003-06-06 19:00:42 +00001626 }
danielk19775a8f9372007-10-09 08:29:32 +00001627 } {0 {}}
1628 do_test auth-1.252 {
1629 set ::authargs
1630 } {:memory: {} {} {}}
1631 do_test auth-1.253 {
1632 catchsql {DETACH DATABASE test1}
danielk197753c0f742005-03-29 03:10:59 +00001633 proc auth {code arg1 arg2 arg3 arg4} {
danielk19775a8f9372007-10-09 08:29:32 +00001634 if {$code=="SQLITE_ATTACH"} {
danielk197753c0f742005-03-29 03:10:59 +00001635 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1636 return SQLITE_DENY
1637 }
danielk19771c8c23c2004-11-12 15:53:37 +00001638 return SQLITE_OK
1639 }
danielk197753c0f742005-03-29 03:10:59 +00001640 catchsql {
danielk19775a8f9372007-10-09 08:29:32 +00001641 ATTACH DATABASE ':memory:' AS test1;
danielk19771c8c23c2004-11-12 15:53:37 +00001642 }
danielk197753c0f742005-03-29 03:10:59 +00001643 } {1 {not authorized}}
danielk19775a8f9372007-10-09 08:29:32 +00001644 do_test auth-1.254 {
danielk197753c0f742005-03-29 03:10:59 +00001645 lindex [execsql {PRAGMA database_list}] 7
danielk19775a8f9372007-10-09 08:29:32 +00001646 } {}
1647 do_test auth-1.255 {
1648 catchsql {DETACH DATABASE test1}
1649 proc auth {code arg1 arg2 arg3 arg4} {
1650 if {$code=="SQLITE_ATTACH"} {
1651 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1652 return SQLITE_IGNORE
1653 }
1654 return SQLITE_OK
1655 }
1656 catchsql {
1657 ATTACH DATABASE ':memory:' AS test1;
1658 }
1659 } {0 {}}
1660 do_test auth-1.256 {
1661 lindex [execsql {PRAGMA database_list}] 7
1662 } {}
1663 do_test auth-1.257 {
1664 proc auth {code arg1 arg2 arg3 arg4} {
1665 if {$code=="SQLITE_DETACH"} {
1666 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
danielk197753c0f742005-03-29 03:10:59 +00001667 return SQLITE_OK
1668 }
danielk19775a8f9372007-10-09 08:29:32 +00001669 return SQLITE_OK
1670 }
1671 execsql {ATTACH DATABASE ':memory:' AS test1}
1672 catchsql {
1673 DETACH DATABASE test1;
1674 }
1675 } {0 {}}
1676 do_test auth-1.258 {
1677 lindex [execsql {PRAGMA database_list}] 7
1678 } {}
1679 do_test auth-1.259 {
1680 execsql {ATTACH DATABASE ':memory:' AS test1}
1681 proc auth {code arg1 arg2 arg3 arg4} {
1682 if {$code=="SQLITE_DETACH"} {
1683 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1684 return SQLITE_IGNORE
danielk197753c0f742005-03-29 03:10:59 +00001685 }
danielk19775a8f9372007-10-09 08:29:32 +00001686 return SQLITE_OK
1687 }
1688 catchsql {
1689 DETACH DATABASE test1;
1690 }
1691 } {0 {}}
1692 ifcapable tempdb {
1693 ifcapable schema_pragmas {
1694 do_test auth-1.260 {
1695 lindex [execsql {PRAGMA database_list}] 7
1696 } {test1}
1697 } ;# ifcapable schema_pragmas
1698 do_test auth-1.261 {
danielk197753c0f742005-03-29 03:10:59 +00001699 proc auth {code arg1 arg2 arg3 arg4} {
danielk19775a8f9372007-10-09 08:29:32 +00001700 if {$code=="SQLITE_DETACH"} {
danielk197753c0f742005-03-29 03:10:59 +00001701 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1702 return SQLITE_DENY
1703 }
1704 return SQLITE_OK
1705 }
1706 catchsql {
danielk19775a8f9372007-10-09 08:29:32 +00001707 DETACH DATABASE test1;
danielk197753c0f742005-03-29 03:10:59 +00001708 }
1709 } {1 {not authorized}}
danielk19775a8f9372007-10-09 08:29:32 +00001710 ifcapable schema_pragmas {
1711 do_test auth-1.262 {
1712 lindex [execsql {PRAGMA database_list}] 7
1713 } {test1}
1714 } ;# ifcapable schema_pragmas
1715 db authorizer {}
1716 execsql {DETACH DATABASE test1}
1717 db authorizer ::auth
1718
1719 # Authorization for ALTER TABLE. These tests are omitted if the library
1720 # was built without ALTER TABLE support.
1721 ifcapable altertable {
1722
1723 do_test auth-1.263 {
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_OK
1728 }
1729 return SQLITE_OK
1730 }
1731 catchsql {
1732 ALTER TABLE t1 RENAME TO t1x
1733 }
1734 } {0 {}}
1735 do_test auth-1.264 {
1736 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1737 } {t1x}
1738 do_test auth-1.265 {
1739 set authargs
1740 } {temp t1 {} {}}
1741 do_test auth-1.266 {
1742 proc auth {code arg1 arg2 arg3 arg4} {
1743 if {$code=="SQLITE_ALTER_TABLE"} {
1744 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1745 return SQLITE_IGNORE
1746 }
1747 return SQLITE_OK
1748 }
1749 catchsql {
1750 ALTER TABLE t1x RENAME TO t1
1751 }
1752 } {0 {}}
1753 do_test auth-1.267 {
1754 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1755 } {t1x}
1756 do_test auth-1.268 {
1757 set authargs
1758 } {temp t1x {} {}}
1759 do_test auth-1.269 {
1760 proc auth {code arg1 arg2 arg3 arg4} {
1761 if {$code=="SQLITE_ALTER_TABLE"} {
1762 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1763 return SQLITE_DENY
1764 }
1765 return SQLITE_OK
1766 }
1767 catchsql {
1768 ALTER TABLE t1x RENAME TO t1
1769 }
1770 } {1 {not authorized}}
1771 do_test auth-1.270 {
1772 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1773 } {t1x}
1774
1775 do_test auth-1.271 {
1776 set authargs
1777 } {temp t1x {} {}}
1778 } ;# ifcapable altertable
1779
1780 } else {
1781 db authorizer {}
1782 db eval {
1783 DETACH DATABASE test1;
1784 }
danielk19771c8c23c2004-11-12 15:53:37 +00001785 }
danielk197753c0f742005-03-29 03:10:59 +00001786}
1787
1788ifcapable altertable {
danielk19771c8c23c2004-11-12 15:53:37 +00001789db authorizer {}
1790catchsql {ALTER TABLE t1x RENAME TO t1}
1791db authorizer ::auth
1792do_test auth-1.272 {
1793 proc auth {code arg1 arg2 arg3 arg4} {
1794 if {$code=="SQLITE_ALTER_TABLE"} {
1795 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1796 return SQLITE_OK
1797 }
1798 return SQLITE_OK
1799 }
1800 catchsql {
1801 ALTER TABLE t2 RENAME TO t2x
1802 }
1803} {0 {}}
1804do_test auth-1.273 {
1805 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1806} {t2x}
1807do_test auth-1.274 {
1808 set authargs
1809} {main t2 {} {}}
1810do_test auth-1.275 {
1811 proc auth {code arg1 arg2 arg3 arg4} {
1812 if {$code=="SQLITE_ALTER_TABLE"} {
1813 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1814 return SQLITE_IGNORE
1815 }
1816 return SQLITE_OK
1817 }
1818 catchsql {
1819 ALTER TABLE t2x RENAME TO t2
1820 }
1821} {0 {}}
1822do_test auth-1.276 {
1823 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1824} {t2x}
1825do_test auth-1.277 {
1826 set authargs
1827} {main t2x {} {}}
1828do_test auth-1.278 {
1829 proc auth {code arg1 arg2 arg3 arg4} {
1830 if {$code=="SQLITE_ALTER_TABLE"} {
1831 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1832 return SQLITE_DENY
1833 }
1834 return SQLITE_OK
1835 }
1836 catchsql {
1837 ALTER TABLE t2x RENAME TO t2
1838 }
1839} {1 {not authorized}}
1840do_test auth-1.279 {
1841 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1842} {t2x}
1843do_test auth-1.280 {
1844 set authargs
1845} {main t2x {} {}}
1846db authorizer {}
1847catchsql {ALTER TABLE t2x RENAME TO t2}
drh81e293b2003-06-06 19:00:42 +00001848
danielk1977215e64d2004-11-22 03:34:21 +00001849} ;# ifcapable altertable
1850
danielk19771d54df82004-11-23 15:41:16 +00001851# Test the authorization callbacks for the REINDEX command.
1852ifcapable reindex {
1853
1854proc auth {code args} {
1855 if {$code=="SQLITE_REINDEX"} {
1856 set ::authargs [concat $::authargs $args]
1857 }
1858 return SQLITE_OK
1859}
1860db authorizer auth
1861do_test auth-1.281 {
1862 execsql {
1863 CREATE TABLE t3(a PRIMARY KEY, b, c);
1864 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1865 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1866 }
1867} {}
1868do_test auth-1.282 {
1869 set ::authargs {}
1870 execsql {
1871 REINDEX t3_idx1;
1872 }
1873 set ::authargs
1874} {t3_idx1 {} main {}}
1875do_test auth-1.283 {
1876 set ::authargs {}
1877 execsql {
1878 REINDEX BINARY;
1879 }
1880 set ::authargs
1881} {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1882do_test auth-1.284 {
1883 set ::authargs {}
1884 execsql {
1885 REINDEX NOCASE;
1886 }
1887 set ::authargs
1888} {t3_idx2 {} main {}}
1889do_test auth-1.285 {
1890 set ::authargs {}
1891 execsql {
1892 REINDEX t3;
1893 }
1894 set ::authargs
1895} {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1896do_test auth-1.286 {
1897 execsql {
1898 DROP TABLE t3;
1899 }
1900} {}
danielk197753c0f742005-03-29 03:10:59 +00001901ifcapable tempdb {
1902 do_test auth-1.287 {
1903 execsql {
1904 CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
1905 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1906 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1907 }
1908 } {}
1909 do_test auth-1.288 {
1910 set ::authargs {}
1911 execsql {
1912 REINDEX temp.t3_idx1;
1913 }
1914 set ::authargs
1915 } {t3_idx1 {} temp {}}
1916 do_test auth-1.289 {
1917 set ::authargs {}
1918 execsql {
1919 REINDEX BINARY;
1920 }
1921 set ::authargs
1922 } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1923 do_test auth-1.290 {
1924 set ::authargs {}
1925 execsql {
1926 REINDEX NOCASE;
1927 }
1928 set ::authargs
1929 } {t3_idx2 {} temp {}}
1930 do_test auth-1.291 {
1931 set ::authargs {}
1932 execsql {
1933 REINDEX temp.t3;
1934 }
1935 set ::authargs
1936 } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1937 proc auth {code args} {
1938 if {$code=="SQLITE_REINDEX"} {
1939 set ::authargs [concat $::authargs $args]
1940 return SQLITE_DENY
1941 }
1942 return SQLITE_OK
danielk19771d54df82004-11-23 15:41:16 +00001943 }
danielk197753c0f742005-03-29 03:10:59 +00001944 do_test auth-1.292 {
1945 set ::authargs {}
1946 catchsql {
1947 REINDEX temp.t3;
1948 }
1949 } {1 {not authorized}}
1950 do_test auth-1.293 {
1951 execsql {
1952 DROP TABLE t3;
1953 }
1954 } {}
danielk19771d54df82004-11-23 15:41:16 +00001955}
danielk19771d54df82004-11-23 15:41:16 +00001956
1957} ;# ifcapable reindex
1958
drhe6e04962005-07-23 02:17:03 +00001959ifcapable analyze {
1960 proc auth {code args} {
1961 if {$code=="SQLITE_ANALYZE"} {
1962 set ::authargs [concat $::authargs $args]
1963 }
1964 return SQLITE_OK
1965 }
1966 do_test auth-1.294 {
1967 set ::authargs {}
1968 execsql {
1969 CREATE TABLE t4(a,b,c);
1970 CREATE INDEX t4i1 ON t4(a);
1971 CREATE INDEX t4i2 ON t4(b,a,c);
1972 INSERT INTO t4 VALUES(1,2,3);
1973 ANALYZE;
1974 }
1975 set ::authargs
1976 } {t4 {} main {}}
1977 do_test auth-1.295 {
1978 execsql {
1979 SELECT count(*) FROM sqlite_stat1;
1980 }
1981 } 2
1982 proc auth {code args} {
1983 if {$code=="SQLITE_ANALYZE"} {
1984 set ::authargs [concat $::authargs $args]
1985 return SQLITE_DENY
1986 }
1987 return SQLITE_OK
1988 }
1989 do_test auth-1.296 {
1990 set ::authargs {}
1991 catchsql {
1992 ANALYZE;
1993 }
1994 } {1 {not authorized}}
1995 do_test auth-1.297 {
1996 execsql {
1997 SELECT count(*) FROM sqlite_stat1;
1998 }
1999 } 2
2000} ;# ifcapable analyze
2001
drh81f2ccd2006-01-31 14:28:44 +00002002
2003# Authorization for ALTER TABLE ADD COLUMN.
2004# These tests are omitted if the library
2005# was built without ALTER TABLE support.
2006ifcapable {altertable} {
2007 do_test auth-1.300 {
2008 execsql {CREATE TABLE t5(x)}
2009 proc auth {code arg1 arg2 arg3 arg4} {
2010 if {$code=="SQLITE_ALTER_TABLE"} {
2011 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2012 return SQLITE_OK
2013 }
2014 return SQLITE_OK
2015 }
2016 catchsql {
2017 ALTER TABLE t5 ADD COLUMN new_col_1;
2018 }
2019 } {0 {}}
2020 do_test auth-1.301 {
2021 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2022 regexp new_col_1 $x
2023 } {1}
2024 do_test auth-1.302 {
2025 set authargs
2026 } {main t5 {} {}}
2027 do_test auth-1.303 {
2028 proc auth {code arg1 arg2 arg3 arg4} {
2029 if {$code=="SQLITE_ALTER_TABLE"} {
2030 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2031 return SQLITE_IGNORE
2032 }
2033 return SQLITE_OK
2034 }
2035 catchsql {
2036 ALTER TABLE t5 ADD COLUMN new_col_2;
2037 }
2038 } {0 {}}
2039 do_test auth-1.304 {
2040 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2041 regexp new_col_2 $x
2042 } {0}
2043 do_test auth-1.305 {
2044 set authargs
2045 } {main t5 {} {}}
2046 do_test auth-1.306 {
2047 proc auth {code arg1 arg2 arg3 arg4} {
2048 if {$code=="SQLITE_ALTER_TABLE"} {
2049 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2050 return SQLITE_DENY
2051 }
2052 return SQLITE_OK
2053 }
2054 catchsql {
2055 ALTER TABLE t5 ADD COLUMN new_col_3
2056 }
2057 } {1 {not authorized}}
2058 do_test auth-1.307 {
2059 set x [execsql {SELECT sql FROM sqlite_temp_master WHERE type='t5'}]
2060 regexp new_col_3 $x
2061 } {0}
2062
2063 do_test auth-1.308 {
2064 set authargs
2065 } {main t5 {} {}}
2066 execsql {DROP TABLE t5}
2067} ;# ifcapable altertable
2068
drh2c3831c2003-01-14 13:48:20 +00002069do_test auth-2.1 {
drhe22a3342003-04-22 20:30:37 +00002070 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002071 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2072 return SQLITE_DENY
2073 }
2074 return SQLITE_OK
2075 }
drhe22a3342003-04-22 20:30:37 +00002076 db authorizer ::auth
drh2c3831c2003-01-14 13:48:20 +00002077 execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
2078 catchsql {SELECT * FROM t3}
2079} {1 {access to t3.x is prohibited}}
2080do_test auth-2.1 {
2081 catchsql {SELECT y,z FROM t3}
2082} {0 {}}
2083do_test auth-2.2 {
2084 catchsql {SELECT ROWID,y,z FROM t3}
2085} {1 {access to t3.x is prohibited}}
2086do_test auth-2.3 {
2087 catchsql {SELECT OID,y,z FROM t3}
2088} {1 {access to t3.x is prohibited}}
2089do_test auth-2.4 {
drhe22a3342003-04-22 20:30:37 +00002090 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002091 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2092 return SQLITE_IGNORE
2093 }
2094 return SQLITE_OK
2095 }
2096 execsql {INSERT INTO t3 VALUES(44,55,66)}
2097 catchsql {SELECT * FROM t3}
2098} {0 {{} 55 66}}
2099do_test auth-2.5 {
2100 catchsql {SELECT rowid,y,z FROM t3}
2101} {0 {{} 55 66}}
2102do_test auth-2.6 {
drhe22a3342003-04-22 20:30:37 +00002103 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002104 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
2105 return SQLITE_IGNORE
2106 }
2107 return SQLITE_OK
2108 }
2109 catchsql {SELECT * FROM t3}
2110} {0 {44 55 66}}
2111do_test auth-2.7 {
2112 catchsql {SELECT ROWID,y,z FROM t3}
2113} {0 {44 55 66}}
2114do_test auth-2.8 {
drhe22a3342003-04-22 20:30:37 +00002115 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002116 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2117 return SQLITE_IGNORE
2118 }
2119 return SQLITE_OK
2120 }
2121 catchsql {SELECT ROWID,b,c FROM t2}
2122} {0 {{} 2 33 {} 8 9}}
drhdcd997e2003-01-31 17:21:49 +00002123do_test auth-2.9.1 {
danielk19778e556522007-11-13 10:30:24 +00002124 # We have to flush the cache here in case the Tcl interface tries to
2125 # reuse a statement compiled with sqlite3_prepare_v2(). In this case,
2126 # the first error encountered is an SQLITE_SCHEMA error. Then, when
2127 # trying to recompile the statement, the authorization error is encountered.
2128 # If we do not flush the cache, the correct error message is returned, but
2129 # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test
2130 # case after this one.
2131 #
2132 db cache flush
2133
drhe22a3342003-04-22 20:30:37 +00002134 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002135 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2136 return bogus
2137 }
2138 return SQLITE_OK
2139 }
2140 catchsql {SELECT ROWID,b,c FROM t2}
2141} {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
drhdcd997e2003-01-31 17:21:49 +00002142do_test auth-2.9.2 {
2143 db errorcode
drhc60d0442004-09-30 13:43:13 +00002144} {1}
drh2c3831c2003-01-14 13:48:20 +00002145do_test auth-2.10 {
drhe22a3342003-04-22 20:30:37 +00002146 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002147 if {$code=="SQLITE_SELECT"} {
2148 return bogus
2149 }
2150 return SQLITE_OK
2151 }
2152 catchsql {SELECT ROWID,b,c FROM t2}
2153} {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
drh6f8c91c2003-12-07 00:24:35 +00002154do_test auth-2.11.1 {
drhe22a3342003-04-22 20:30:37 +00002155 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002156 if {$code=="SQLITE_READ" && $arg2=="a"} {
2157 return SQLITE_IGNORE
2158 }
2159 return SQLITE_OK
2160 }
2161 catchsql {SELECT * FROM t2, t3}
2162} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
drh6f8c91c2003-12-07 00:24:35 +00002163do_test auth-2.11.2 {
drhe22a3342003-04-22 20:30:37 +00002164 proc auth {code arg1 arg2 arg3 arg4} {
drh2c3831c2003-01-14 13:48:20 +00002165 if {$code=="SQLITE_READ" && $arg2=="x"} {
2166 return SQLITE_IGNORE
2167 }
2168 return SQLITE_OK
2169 }
2170 catchsql {SELECT * FROM t2, t3}
2171} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
drhe5f9c642003-01-13 23:27:31 +00002172
drh027850b2003-04-16 20:24:52 +00002173# Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
2174#
danielk197781650dc2004-11-22 11:51:13 +00002175ifcapable trigger {
danielk19773bdca9c2006-01-17 09:35:01 +00002176 do_test auth-3.1 {
2177 proc auth {code arg1 arg2 arg3 arg4} {
2178 return SQLITE_OK
drh027850b2003-04-16 20:24:52 +00002179 }
danielk19773bdca9c2006-01-17 09:35:01 +00002180 execsql {
2181 CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
2182 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
2183 INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
2184 END;
2185 UPDATE t2 SET a=a+1;
2186 SELECT * FROM tx;
2187 }
2188 } {11 12 2 2 33 33 7 8 8 8 9 9}
2189 do_test auth-3.2 {
2190 proc auth {code arg1 arg2 arg3 arg4} {
2191 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
2192 return SQLITE_IGNORE
2193 }
2194 return SQLITE_OK
2195 }
2196 execsql {
2197 DELETE FROM tx;
2198 UPDATE t2 SET a=a+100;
2199 SELECT * FROM tx;
2200 }
2201 } {12 112 2 2 {} {} 8 108 8 8 {} {}}
danielk197781650dc2004-11-22 11:51:13 +00002202} ;# ifcapable trigger
drh027850b2003-04-16 20:24:52 +00002203
drh85e20962003-04-25 17:52:11 +00002204# Make sure the names of views and triggers are passed on on arg4.
2205#
danielk197781650dc2004-11-22 11:51:13 +00002206ifcapable trigger {
drh85e20962003-04-25 17:52:11 +00002207do_test auth-4.1 {
2208 proc auth {code arg1 arg2 arg3 arg4} {
2209 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2210 return SQLITE_OK
2211 }
2212 set authargs {}
2213 execsql {
2214 UPDATE t2 SET a=a+1;
2215 }
2216 set authargs
2217} [list \
2218 SQLITE_READ t2 a main {} \
2219 SQLITE_UPDATE t2 a main {} \
2220 SQLITE_INSERT tx {} main r1 \
2221 SQLITE_READ t2 a main r1 \
2222 SQLITE_READ t2 a main r1 \
2223 SQLITE_READ t2 b main r1 \
2224 SQLITE_READ t2 b main r1 \
2225 SQLITE_READ t2 c main r1 \
2226 SQLITE_READ t2 c main r1]
danielk197781650dc2004-11-22 11:51:13 +00002227}
danielk19770fa8ddb2004-11-22 08:43:32 +00002228
danielk197781650dc2004-11-22 11:51:13 +00002229ifcapable {view && trigger} {
drh85e20962003-04-25 17:52:11 +00002230do_test auth-4.2 {
2231 execsql {
2232 CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
2233 CREATE TABLE v1chng(x1,x2);
2234 CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
2235 INSERT INTO v1chng VALUES(OLD.x,NEW.x);
2236 END;
2237 SELECT * FROM v1;
2238 }
2239} {115 117}
2240do_test auth-4.3 {
2241 set authargs {}
2242 execsql {
2243 UPDATE v1 SET x=1 WHERE x=117
2244 }
2245 set authargs
2246} [list \
2247 SQLITE_UPDATE v1 x main {} \
drh85e20962003-04-25 17:52:11 +00002248 SQLITE_INSERT v1chng {} main r2 \
2249 SQLITE_READ v1 x main r2 \
danielk19778f2c54e2008-01-01 19:02:09 +00002250 SQLITE_READ v1 x main r2 \
2251 SQLITE_READ t2 a main v1 \
2252 SQLITE_READ t2 b main v1 \
drh0f35a6b2008-02-12 16:52:14 +00002253 SQLITE_SELECT {} {} {} v1 \
2254 SQLITE_SELECT {} {} {} v1 \
2255 SQLITE_READ v1 x main v1 \
2256]
drh85e20962003-04-25 17:52:11 +00002257do_test auth-4.4 {
2258 execsql {
2259 CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
2260 INSERT INTO v1chng VALUES(OLD.x,NULL);
2261 END;
2262 SELECT * FROM v1;
2263 }
2264} {115 117}
2265do_test auth-4.5 {
2266 set authargs {}
2267 execsql {
2268 DELETE FROM v1 WHERE x=117
2269 }
2270 set authargs
2271} [list \
2272 SQLITE_DELETE v1 {} main {} \
danielk19778f2c54e2008-01-01 19:02:09 +00002273 SQLITE_INSERT v1chng {} main r3 \
2274 SQLITE_READ v1 x main r3 \
drh85e20962003-04-25 17:52:11 +00002275 SQLITE_READ t2 a main v1 \
2276 SQLITE_READ t2 b main v1 \
drh0f35a6b2008-02-12 16:52:14 +00002277 SQLITE_SELECT {} {} {} v1 \
2278 SQLITE_SELECT {} {} {} v1 \
2279 SQLITE_READ v1 x main v1 \
2280]
drh1962bda2003-01-12 19:33:52 +00002281
danielk197781650dc2004-11-22 11:51:13 +00002282} ;# ifcapable view && trigger
danielk19770fa8ddb2004-11-22 08:43:32 +00002283
drh2ce99ec2005-07-29 15:36:14 +00002284# Ticket #1338: Make sure authentication works in the presence of an AS
2285# clause.
2286#
2287do_test auth-5.1 {
2288 proc auth {code arg1 arg2 arg3 arg4} {
2289 return SQLITE_OK
2290 }
2291 execsql {
2292 SELECT count(a) AS cnt FROM t4 ORDER BY cnt
2293 }
2294} {1}
2295
drha3e4d962006-01-13 13:55:44 +00002296# Ticket #1607
2297#
danielk19773bdca9c2006-01-17 09:35:01 +00002298ifcapable compound&&subquery {
2299 ifcapable trigger {
2300 execsql {
2301 DROP TABLE tx;
2302 }
2303 ifcapable view {
2304 execsql {
2305 DROP TABLE v1chng;
2306 }
2307 }
2308 }
danielk1977ff890792006-01-16 16:24:25 +00002309 do_test auth-5.2 {
2310 execsql {
2311 SELECT name FROM (
2312 SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
2313 WHERE type='table'
2314 ORDER BY name
2315 }
danielk19773bdca9c2006-01-17 09:35:01 +00002316 } {sqlite_stat1 t1 t2 t3 t4}
danielk1977ff890792006-01-16 16:24:25 +00002317}
drha3e4d962006-01-13 13:55:44 +00002318
drh2ce99ec2005-07-29 15:36:14 +00002319
danielk1977a21c6b62005-01-24 10:25:59 +00002320rename proc {}
2321rename proc_real proc
2322
drh2ce99ec2005-07-29 15:36:14 +00002323
drh1962bda2003-01-12 19:33:52 +00002324finish_test