2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library. The
15 # focus of this script is testing the ATTACH and DETACH commands
16 # and related functionality.
18 # $Id: auth.test,v 1.12 2003/12/07 00:24:35 drh Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
25 # defined during compilation.
29 set ::DB [sqlite db test.db]
30 proc auth {code arg1 arg2 arg3 arg4} {
31 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
37 catchsql {CREATE TABLE t1(a,b,c)}
38 } {1 {not authorized}}
43 execsql {SELECT name FROM sqlite_master}
46 proc auth {code arg1 arg2 arg3 arg4} {
47 if {$code=="SQLITE_CREATE_TABLE"} {
48 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
53 catchsql {CREATE TABLE t1(a,b,c)}
54 } {1 {not authorized}}
62 execsql {SELECT name FROM sqlite_master}
66 proc auth {code arg1 arg2 arg3 arg4} {
67 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
72 catchsql {CREATE TEMP TABLE t1(a,b,c)}
73 } {1 {not authorized}}
75 execsql {SELECT name FROM sqlite_temp_master}
78 proc auth {code arg1 arg2 arg3 arg4} {
79 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
80 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
85 catchsql {CREATE TEMP TABLE t1(a,b,c)}
86 } {1 {not authorized}}
91 execsql {SELECT name FROM sqlite_temp_master}
95 proc auth {code arg1 arg2 arg3 arg4} {
96 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
101 catchsql {CREATE TABLE t1(a,b,c)}
104 execsql {SELECT name FROM sqlite_master}
107 proc auth {code arg1 arg2 arg3 arg4} {
108 if {$code=="SQLITE_CREATE_TABLE"} {
109 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
114 catchsql {CREATE TABLE t1(a,b,c)}
117 execsql {SELECT name FROM sqlite_master}
120 proc auth {code arg1 arg2 arg3 arg4} {
121 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
126 catchsql {CREATE TEMP TABLE t1(a,b,c)}
129 execsql {SELECT name FROM sqlite_temp_master}
132 proc auth {code arg1 arg2 arg3 arg4} {
133 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
134 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
139 catchsql {CREATE TEMP TABLE t1(a,b,c)}
142 execsql {SELECT name FROM sqlite_temp_master}
146 proc auth {code arg1 arg2 arg3 arg4} {
147 if {$code=="SQLITE_CREATE_TABLE"} {
148 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
153 catchsql {CREATE TEMP TABLE t1(a,b,c)}
156 execsql {SELECT name FROM sqlite_temp_master}
158 do_test auth-1.19.1 {
160 proc auth {code arg1 arg2 arg3 arg4} {
161 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
162 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
167 catchsql {CREATE TABLE t2(a,b,c)}
169 do_test auth-1.19.2 {
173 execsql {SELECT name FROM sqlite_master}
176 do_test auth-1.21.1 {
177 proc auth {code arg1 arg2 arg3 arg4} {
178 if {$code=="SQLITE_DROP_TABLE"} {
179 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
184 catchsql {DROP TABLE t2}
185 } {1 {not authorized}}
186 do_test auth-1.21.2 {
190 execsql {SELECT name FROM sqlite_master}
192 do_test auth-1.23.1 {
193 proc auth {code arg1 arg2 arg3 arg4} {
194 if {$code=="SQLITE_DROP_TABLE"} {
195 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
200 catchsql {DROP TABLE t2}
202 do_test auth-1.23.2 {
206 execsql {SELECT name FROM sqlite_master}
210 proc auth {code arg1 arg2 arg3 arg4} {
211 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
212 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
217 catchsql {DROP TABLE t1}
218 } {1 {not authorized}}
220 execsql {SELECT name FROM sqlite_temp_master}
223 proc auth {code arg1 arg2 arg3 arg4} {
224 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
225 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
230 catchsql {DROP TABLE t1}
233 execsql {SELECT name FROM sqlite_temp_master}
237 proc auth {code arg1 arg2 arg3 arg4} {
238 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
243 catchsql {INSERT INTO t2 VALUES(1,2,3)}
244 } {1 {not authorized}}
246 execsql {SELECT * FROM t2}
249 proc auth {code arg1 arg2 arg3 arg4} {
250 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
255 catchsql {INSERT INTO t2 VALUES(1,2,3)}
258 execsql {SELECT * FROM t2}
261 proc auth {code arg1 arg2 arg3 arg4} {
262 if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
267 catchsql {INSERT INTO t2 VALUES(1,2,3)}
270 execsql {SELECT * FROM t2}
273 do_test auth-1.35.1 {
274 proc auth {code arg1 arg2 arg3 arg4} {
275 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
280 catchsql {SELECT * FROM t2}
281 } {1 {access to t2.b is prohibited}}
282 do_test auth-1.35.2 {
283 execsql {ATTACH DATABASE 'test.db' AS two}
284 catchsql {SELECT * FROM two.t2}
285 } {1 {access to two.t2.b is prohibited}}
286 execsql {DETACH DATABASE two}
288 proc auth {code arg1 arg2 arg3 arg4} {
289 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
294 catchsql {SELECT * FROM t2}
297 proc auth {code arg1 arg2 arg3 arg4} {
298 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
303 catchsql {SELECT * FROM t2 WHERE b=2}
306 proc auth {code arg1 arg2 arg3 arg4} {
307 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
312 catchsql {SELECT * FROM t2 WHERE b=2}
315 proc auth {code arg1 arg2 arg3 arg4} {
316 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
321 catchsql {SELECT * FROM t2 WHERE b IS NULL}
324 proc auth {code arg1 arg2 arg3 arg4} {
325 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
330 catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
331 } {1 {access to t2.b is prohibited}}
334 proc auth {code arg1 arg2 arg3 arg4} {
335 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
340 catchsql {UPDATE t2 SET a=11}
343 execsql {SELECT * FROM t2}
346 proc auth {code arg1 arg2 arg3 arg4} {
347 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
352 catchsql {UPDATE t2 SET b=22, c=33}
353 } {1 {not authorized}}
355 execsql {SELECT * FROM t2}
358 proc auth {code arg1 arg2 arg3 arg4} {
359 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
364 catchsql {UPDATE t2 SET b=22, c=33}
367 execsql {SELECT * FROM t2}
371 proc auth {code arg1 arg2 arg3 arg4} {
372 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
377 catchsql {DELETE FROM t2 WHERE a=11}
378 } {1 {not authorized}}
380 execsql {SELECT * FROM t2}
383 proc auth {code arg1 arg2 arg3 arg4} {
384 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
389 catchsql {DELETE FROM t2 WHERE a=11}
392 execsql {SELECT * FROM t2}
396 proc auth {code arg1 arg2 arg3 arg4} {
397 if {$code=="SQLITE_SELECT"} {
402 catchsql {SELECT * FROM t2}
403 } {1 {not authorized}}
405 proc auth {code arg1 arg2 arg3 arg4} {
406 if {$code=="SQLITE_SELECT"} {
411 catchsql {SELECT * FROM t2}
414 proc auth {code arg1 arg2 arg3 arg4} {
415 if {$code=="SQLITE_SELECT"} {
420 catchsql {SELECT * FROM t2}
423 set f [open data1.txt w]
427 proc auth {code arg1 arg2 arg3 arg4} {
428 if {$code=="SQLITE_COPY"} {
429 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
434 catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
435 } {1 {not authorized}}
438 } {t2 data1.txt main {}}
440 execsql {SELECT * FROM t2}
443 proc auth {code arg1 arg2 arg3 arg4} {
444 if {$code=="SQLITE_COPY"} {
445 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
450 catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
454 } {t2 data1.txt main {}}
456 execsql {SELECT * FROM t2}
459 proc auth {code arg1 arg2 arg3 arg4} {
460 if {$code=="SQLITE_COPY"} {
461 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
466 catchsql {COPY t2 FROM 'data1.txt' USING DELIMITERS ':'}
470 } {t2 data1.txt main {}}
472 execsql {SELECT * FROM t2}
476 proc auth {code arg1 arg2 arg3 arg4} {
477 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
482 catchsql {DROP TABLE t2}
483 } {1 {not authorized}}
485 execsql {SELECT name FROM sqlite_master}
488 proc auth {code arg1 arg2 arg3 arg4} {
489 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
494 catchsql {DROP TABLE t2}
495 } {1 {not authorized}}
497 execsql {SELECT name FROM sqlite_master}
500 proc auth {code arg1 arg2 arg3 arg4} {
501 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
506 catchsql {DROP TABLE t1}
507 } {1 {not authorized}}
509 execsql {SELECT name FROM sqlite_temp_master}
512 proc auth {code arg1 arg2 arg3 arg4} {
513 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
518 catchsql {DROP TABLE t1}
519 } {1 {not authorized}}
521 execsql {SELECT name FROM sqlite_temp_master}
525 proc auth {code arg1 arg2 arg3 arg4} {
526 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
531 catchsql {DROP TABLE t2}
534 execsql {SELECT name FROM sqlite_master}
537 proc auth {code arg1 arg2 arg3 arg4} {
538 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
543 catchsql {DROP TABLE t2}
546 execsql {SELECT name FROM sqlite_master}
549 proc auth {code arg1 arg2 arg3 arg4} {
550 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
555 catchsql {DROP TABLE t1}
558 execsql {SELECT name FROM sqlite_temp_master}
561 proc auth {code arg1 arg2 arg3 arg4} {
562 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
567 catchsql {DROP TABLE t1}
570 execsql {SELECT name FROM sqlite_temp_master}
574 proc auth {code arg1 arg2 arg3 arg4} {
575 if {$code=="SQLITE_CREATE_VIEW"} {
576 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
581 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
582 } {1 {not authorized}}
587 execsql {SELECT name FROM sqlite_master}
590 proc auth {code arg1 arg2 arg3 arg4} {
591 if {$code=="SQLITE_CREATE_VIEW"} {
592 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
597 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
603 execsql {SELECT name FROM sqlite_master}
607 proc auth {code arg1 arg2 arg3 arg4} {
608 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
609 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
614 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
615 } {1 {not authorized}}
620 execsql {SELECT name FROM sqlite_temp_master}
623 proc auth {code arg1 arg2 arg3 arg4} {
624 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
625 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
630 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
636 execsql {SELECT name FROM sqlite_temp_master}
640 proc auth {code arg1 arg2 arg3 arg4} {
641 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
646 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
647 } {1 {not authorized}}
649 execsql {SELECT name FROM sqlite_master}
652 proc auth {code arg1 arg2 arg3 arg4} {
653 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
658 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
661 execsql {SELECT name FROM sqlite_master}
665 proc auth {code arg1 arg2 arg3 arg4} {
666 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
671 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
672 } {1 {not authorized}}
674 execsql {SELECT name FROM sqlite_temp_master}
677 proc auth {code arg1 arg2 arg3 arg4} {
678 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
683 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
686 execsql {SELECT name FROM sqlite_temp_master}
690 proc auth {code arg1 arg2 arg3 arg4} {
691 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
697 CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
700 } {1 {not authorized}}
702 execsql {SELECT name FROM sqlite_master}
705 proc auth {code arg1 arg2 arg3 arg4} {
706 if {$code=="SQLITE_DROP_VIEW"} {
707 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
712 catchsql {DROP VIEW v2}
713 } {1 {not authorized}}
718 execsql {SELECT name FROM sqlite_master}
721 proc auth {code arg1 arg2 arg3 arg4} {
722 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
727 catchsql {DROP VIEW v2}
730 execsql {SELECT name FROM sqlite_master}
733 proc auth {code arg1 arg2 arg3 arg4} {
734 if {$code=="SQLITE_DROP_VIEW"} {
735 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
740 catchsql {DROP VIEW v2}
746 execsql {SELECT name FROM sqlite_master}
749 proc auth {code arg1 arg2 arg3 arg4} {
750 if {$code=="SQLITE_DROP_VIEW"} {
751 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
756 catchsql {DROP VIEW v2}
762 execsql {SELECT name FROM sqlite_master}
767 proc auth {code arg1 arg2 arg3 arg4} {
768 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
774 CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
777 } {1 {not authorized}}
779 execsql {SELECT name FROM sqlite_temp_master}
782 proc auth {code arg1 arg2 arg3 arg4} {
783 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
784 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
789 catchsql {DROP VIEW v1}
790 } {1 {not authorized}}
795 execsql {SELECT name FROM sqlite_temp_master}
798 proc auth {code arg1 arg2 arg3 arg4} {
799 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
804 catchsql {DROP VIEW v1}
807 execsql {SELECT name FROM sqlite_temp_master}
810 proc auth {code arg1 arg2 arg3 arg4} {
811 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
812 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
817 catchsql {DROP VIEW v1}
823 execsql {SELECT name FROM sqlite_temp_master}
826 proc auth {code arg1 arg2 arg3 arg4} {
827 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
828 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
833 catchsql {DROP VIEW v1}
839 execsql {SELECT name FROM sqlite_temp_master}
843 proc auth {code arg1 arg2 arg3 arg4} {
844 if {$code=="SQLITE_CREATE_TRIGGER"} {
845 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
851 CREATE TRIGGER r2 DELETE on t2 BEGIN
855 } {1 {not authorized}}
860 execsql {SELECT name FROM sqlite_master}
863 proc auth {code arg1 arg2 arg3 arg4} {
864 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
870 CREATE TRIGGER r2 DELETE on t2 BEGIN
874 } {1 {not authorized}}
876 execsql {SELECT name FROM sqlite_master}
879 proc auth {code arg1 arg2 arg3 arg4} {
880 if {$code=="SQLITE_CREATE_TRIGGER"} {
881 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
887 CREATE TRIGGER r2 DELETE on t2 BEGIN
896 execsql {SELECT name FROM sqlite_master}
899 proc auth {code arg1 arg2 arg3 arg4} {
900 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
906 CREATE TRIGGER r2 DELETE on t2 BEGIN
912 execsql {SELECT name FROM sqlite_master}
915 proc auth {code arg1 arg2 arg3 arg4} {
916 if {$code=="SQLITE_CREATE_TRIGGER"} {
917 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
924 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
925 INSERT INTO tx VALUES(NEW.rowid);
929 do_test auth-1.136.1 {
932 do_test auth-1.136.2 {
934 SELECT name FROM sqlite_master WHERE type='trigger'
937 do_test auth-1.136.3 {
938 proc auth {code arg1 arg2 arg3 arg4} {
939 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
944 INSERT INTO t2 VALUES(1,2,3);
947 } {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
948 do_test auth-1.136.4 {
954 execsql {SELECT name FROM sqlite_master}
957 proc auth {code arg1 arg2 arg3 arg4} {
958 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
959 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
965 CREATE TRIGGER r1 DELETE on t1 BEGIN
969 } {1 {not authorized}}
974 execsql {SELECT name FROM sqlite_temp_master}
977 proc auth {code arg1 arg2 arg3 arg4} {
978 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
984 CREATE TRIGGER r1 DELETE on t1 BEGIN
988 } {1 {not authorized}}
990 execsql {SELECT name FROM sqlite_temp_master}
993 proc auth {code arg1 arg2 arg3 arg4} {
994 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
995 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1001 CREATE TRIGGER r1 DELETE on t1 BEGIN
1006 do_test auth-1.144 {
1009 do_test auth-1.145 {
1010 execsql {SELECT name FROM sqlite_temp_master}
1012 do_test auth-1.146 {
1013 proc auth {code arg1 arg2 arg3 arg4} {
1014 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1015 return SQLITE_IGNORE
1020 CREATE TRIGGER r1 DELETE on t1 BEGIN
1025 do_test auth-1.147 {
1026 execsql {SELECT name FROM sqlite_temp_master}
1028 do_test auth-1.148 {
1029 proc auth {code arg1 arg2 arg3 arg4} {
1030 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1031 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1037 CREATE TRIGGER r1 DELETE on t1 BEGIN
1042 do_test auth-1.149 {
1045 do_test auth-1.150 {
1046 execsql {SELECT name FROM sqlite_temp_master}
1049 do_test auth-1.151 {
1050 proc auth {code arg1 arg2 arg3 arg4} {
1051 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1056 catchsql {DROP TRIGGER r2}
1057 } {1 {not authorized}}
1058 do_test auth-1.152 {
1059 execsql {SELECT name FROM sqlite_master}
1061 do_test auth-1.153 {
1062 proc auth {code arg1 arg2 arg3 arg4} {
1063 if {$code=="SQLITE_DROP_TRIGGER"} {
1064 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1069 catchsql {DROP TRIGGER r2}
1070 } {1 {not authorized}}
1071 do_test auth-1.154 {
1074 do_test auth-1.155 {
1075 execsql {SELECT name FROM sqlite_master}
1077 do_test auth-1.156 {
1078 proc auth {code arg1 arg2 arg3 arg4} {
1079 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1080 return SQLITE_IGNORE
1084 catchsql {DROP TRIGGER r2}
1086 do_test auth-1.157 {
1087 execsql {SELECT name FROM sqlite_master}
1089 do_test auth-1.158 {
1090 proc auth {code arg1 arg2 arg3 arg4} {
1091 if {$code=="SQLITE_DROP_TRIGGER"} {
1092 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1093 return SQLITE_IGNORE
1097 catchsql {DROP TRIGGER r2}
1099 do_test auth-1.159 {
1102 do_test auth-1.160 {
1103 execsql {SELECT name FROM sqlite_master}
1105 do_test auth-1.161 {
1106 proc auth {code arg1 arg2 arg3 arg4} {
1107 if {$code=="SQLITE_DROP_TRIGGER"} {
1108 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1113 catchsql {DROP TRIGGER r2}
1115 do_test auth-1.162 {
1118 do_test auth-1.163 {
1121 DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1122 SELECT name FROM sqlite_master;
1126 do_test auth-1.164 {
1127 proc auth {code arg1 arg2 arg3 arg4} {
1128 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1133 catchsql {DROP TRIGGER r1}
1134 } {1 {not authorized}}
1135 do_test auth-1.165 {
1136 execsql {SELECT name FROM sqlite_temp_master}
1138 do_test auth-1.166 {
1139 proc auth {code arg1 arg2 arg3 arg4} {
1140 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1141 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1146 catchsql {DROP TRIGGER r1}
1147 } {1 {not authorized}}
1148 do_test auth-1.167 {
1151 do_test auth-1.168 {
1152 execsql {SELECT name FROM sqlite_temp_master}
1154 do_test auth-1.169 {
1155 proc auth {code arg1 arg2 arg3 arg4} {
1156 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1157 return SQLITE_IGNORE
1161 catchsql {DROP TRIGGER r1}
1163 do_test auth-1.170 {
1164 execsql {SELECT name FROM sqlite_temp_master}
1166 do_test auth-1.171 {
1167 proc auth {code arg1 arg2 arg3 arg4} {
1168 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1169 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1170 return SQLITE_IGNORE
1174 catchsql {DROP TRIGGER r1}
1176 do_test auth-1.172 {
1179 do_test auth-1.173 {
1180 execsql {SELECT name FROM sqlite_temp_master}
1182 do_test auth-1.174 {
1183 proc auth {code arg1 arg2 arg3 arg4} {
1184 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1185 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1190 catchsql {DROP TRIGGER r1}
1192 do_test auth-1.175 {
1195 do_test auth-1.176 {
1196 execsql {SELECT name FROM sqlite_temp_master}
1199 do_test auth-1.177 {
1200 proc auth {code arg1 arg2 arg3 arg4} {
1201 if {$code=="SQLITE_CREATE_INDEX"} {
1202 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1207 catchsql {CREATE INDEX i2 ON t2(a)}
1208 } {1 {not authorized}}
1209 do_test auth-1.178 {
1212 do_test auth-1.179 {
1213 execsql {SELECT name FROM sqlite_master}
1215 do_test auth-1.180 {
1216 proc auth {code arg1 arg2 arg3 arg4} {
1217 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1222 catchsql {CREATE INDEX i2 ON t2(a)}
1223 } {1 {not authorized}}
1224 do_test auth-1.181 {
1225 execsql {SELECT name FROM sqlite_master}
1227 do_test auth-1.182 {
1228 proc auth {code arg1 arg2 arg3 arg4} {
1229 if {$code=="SQLITE_CREATE_INDEX"} {
1230 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1231 return SQLITE_IGNORE
1235 catchsql {CREATE INDEX i2 ON t2(b)}
1237 do_test auth-1.183 {
1240 do_test auth-1.184 {
1241 execsql {SELECT name FROM sqlite_master}
1243 do_test auth-1.185 {
1244 proc auth {code arg1 arg2 arg3 arg4} {
1245 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1246 return SQLITE_IGNORE
1250 catchsql {CREATE INDEX i2 ON t2(b)}
1252 do_test auth-1.186 {
1253 execsql {SELECT name FROM sqlite_master}
1255 do_test auth-1.187 {
1256 proc auth {code arg1 arg2 arg3 arg4} {
1257 if {$code=="SQLITE_CREATE_INDEX"} {
1258 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1263 catchsql {CREATE INDEX i2 ON t2(a)}
1265 do_test auth-1.188 {
1268 do_test auth-1.189 {
1269 execsql {SELECT name FROM sqlite_master}
1272 do_test auth-1.190 {
1273 proc auth {code arg1 arg2 arg3 arg4} {
1274 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1275 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1280 catchsql {CREATE INDEX i1 ON t1(a)}
1281 } {1 {not authorized}}
1282 do_test auth-1.191 {
1285 do_test auth-1.192 {
1286 execsql {SELECT name FROM sqlite_temp_master}
1288 do_test auth-1.193 {
1289 proc auth {code arg1 arg2 arg3 arg4} {
1290 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1295 catchsql {CREATE INDEX i1 ON t1(b)}
1296 } {1 {not authorized}}
1297 do_test auth-1.194 {
1298 execsql {SELECT name FROM sqlite_temp_master}
1300 do_test auth-1.195 {
1301 proc auth {code arg1 arg2 arg3 arg4} {
1302 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1303 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1304 return SQLITE_IGNORE
1308 catchsql {CREATE INDEX i1 ON t1(b)}
1310 do_test auth-1.196 {
1313 do_test auth-1.197 {
1314 execsql {SELECT name FROM sqlite_temp_master}
1316 do_test auth-1.198 {
1317 proc auth {code arg1 arg2 arg3 arg4} {
1318 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1319 return SQLITE_IGNORE
1323 catchsql {CREATE INDEX i1 ON t1(c)}
1325 do_test auth-1.199 {
1326 execsql {SELECT name FROM sqlite_temp_master}
1328 do_test auth-1.200 {
1329 proc auth {code arg1 arg2 arg3 arg4} {
1330 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1331 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1336 catchsql {CREATE INDEX i1 ON t1(a)}
1338 do_test auth-1.201 {
1341 do_test auth-1.202 {
1342 execsql {SELECT name FROM sqlite_temp_master}
1345 do_test auth-1.203 {
1346 proc auth {code arg1 arg2 arg3 arg4} {
1347 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1352 catchsql {DROP INDEX i2}
1353 } {1 {not authorized}}
1354 do_test auth-1.204 {
1355 execsql {SELECT name FROM sqlite_master}
1357 do_test auth-1.205 {
1358 proc auth {code arg1 arg2 arg3 arg4} {
1359 if {$code=="SQLITE_DROP_INDEX"} {
1360 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1365 catchsql {DROP INDEX i2}
1366 } {1 {not authorized}}
1367 do_test auth-1.206 {
1370 do_test auth-1.207 {
1371 execsql {SELECT name FROM sqlite_master}
1373 do_test auth-1.208 {
1374 proc auth {code arg1 arg2 arg3 arg4} {
1375 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1376 return SQLITE_IGNORE
1380 catchsql {DROP INDEX i2}
1382 do_test auth-1.209 {
1383 execsql {SELECT name FROM sqlite_master}
1385 do_test auth-1.210 {
1386 proc auth {code arg1 arg2 arg3 arg4} {
1387 if {$code=="SQLITE_DROP_INDEX"} {
1388 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1389 return SQLITE_IGNORE
1393 catchsql {DROP INDEX i2}
1395 do_test auth-1.211 {
1398 do_test auth-1.212 {
1399 execsql {SELECT name FROM sqlite_master}
1401 do_test auth-1.213 {
1402 proc auth {code arg1 arg2 arg3 arg4} {
1403 if {$code=="SQLITE_DROP_INDEX"} {
1404 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1409 catchsql {DROP INDEX i2}
1411 do_test auth-1.214 {
1414 do_test auth-1.215 {
1415 execsql {SELECT name FROM sqlite_master}
1418 do_test auth-1.216 {
1419 proc auth {code arg1 arg2 arg3 arg4} {
1420 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1425 catchsql {DROP INDEX i1}
1426 } {1 {not authorized}}
1427 do_test auth-1.217 {
1428 execsql {SELECT name FROM sqlite_temp_master}
1430 do_test auth-1.218 {
1431 proc auth {code arg1 arg2 arg3 arg4} {
1432 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1433 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1438 catchsql {DROP INDEX i1}
1439 } {1 {not authorized}}
1440 do_test auth-1.219 {
1443 do_test auth-1.220 {
1444 execsql {SELECT name FROM sqlite_temp_master}
1446 do_test auth-1.221 {
1447 proc auth {code arg1 arg2 arg3 arg4} {
1448 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1449 return SQLITE_IGNORE
1453 catchsql {DROP INDEX i1}
1455 do_test auth-1.222 {
1456 execsql {SELECT name FROM sqlite_temp_master}
1458 do_test auth-1.223 {
1459 proc auth {code arg1 arg2 arg3 arg4} {
1460 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1461 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1462 return SQLITE_IGNORE
1466 catchsql {DROP INDEX i1}
1468 do_test auth-1.224 {
1471 do_test auth-1.225 {
1472 execsql {SELECT name FROM sqlite_temp_master}
1474 do_test auth-1.226 {
1475 proc auth {code arg1 arg2 arg3 arg4} {
1476 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1477 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1482 catchsql {DROP INDEX i1}
1484 do_test auth-1.227 {
1487 do_test auth-1.228 {
1488 execsql {SELECT name FROM sqlite_temp_master}
1491 do_test auth-1.229 {
1492 proc auth {code arg1 arg2 arg3 arg4} {
1493 if {$code=="SQLITE_PRAGMA"} {
1494 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1499 catchsql {PRAGMA full_column_names=on}
1500 } {1 {not authorized}}
1501 do_test auth-1.230 {
1503 } {full_column_names on {} {}}
1504 do_test auth-1.231 {
1505 execsql2 {SELECT a FROM t2}
1507 do_test auth-1.232 {
1508 proc auth {code arg1 arg2 arg3 arg4} {
1509 if {$code=="SQLITE_PRAGMA"} {
1510 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1511 return SQLITE_IGNORE
1515 catchsql {PRAGMA full_column_names=on}
1517 do_test auth-1.233 {
1519 } {full_column_names on {} {}}
1520 do_test auth-1.234 {
1521 execsql2 {SELECT a FROM t2}
1523 do_test auth-1.235 {
1524 proc auth {code arg1 arg2 arg3 arg4} {
1525 if {$code=="SQLITE_PRAGMA"} {
1526 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1531 catchsql {PRAGMA full_column_names=on}
1533 do_test auth-1.236 {
1534 execsql2 {SELECT a FROM t2}
1536 do_test auth-1.237 {
1537 proc auth {code arg1 arg2 arg3 arg4} {
1538 if {$code=="SQLITE_PRAGMA"} {
1539 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1544 catchsql {PRAGMA full_column_names=OFF}
1546 do_test auth-1.238 {
1548 } {full_column_names OFF {} {}}
1549 do_test auth-1.239 {
1550 execsql2 {SELECT a FROM t2}
1553 do_test auth-1.240 {
1554 proc auth {code arg1 arg2 arg3 arg4} {
1555 if {$code=="SQLITE_TRANSACTION"} {
1556 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1562 } {1 {not authorized}}
1563 do_test auth-1.241 {
1566 do_test auth-1.242 {
1567 proc auth {code arg1 arg2 arg3 arg4} {
1568 if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
1569 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1574 catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1575 } {1 {not authorized}}
1576 do_test auth-1.243 {
1579 do_test auth-1.244 {
1580 execsql {SELECT * FROM t2}
1581 } {11 2 33 7 8 9 44 55 66}
1582 do_test auth-1.245 {
1584 } {1 {not authorized}}
1585 do_test auth-1.246 {
1587 } {ROLLBACK {} {} {}}
1588 do_test auth-1.247 {
1589 catchsql {END TRANSACTION}
1590 } {1 {not authorized}}
1591 do_test auth-1.248 {
1594 do_test auth-1.249 {
1598 do_test auth-1.250 {
1599 execsql {SELECT * FROM t2}
1602 # ticket #340 - authorization for ATTACH and DETACH.
1604 do_test auth-1.251 {
1605 db authorizer ::auth
1606 proc auth {code arg1 arg2 arg3 arg4} {
1607 if {$code=="SQLITE_ATTACH"} {
1608 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1613 ATTACH DATABASE ':memory:' AS test1
1616 do_test auth-1.252 {
1618 } {:memory: {} {} {}}
1619 do_test auth-1.253 {
1620 catchsql {DETACH DATABASE test1}
1621 proc auth {code arg1 arg2 arg3 arg4} {
1622 if {$code=="SQLITE_ATTACH"} {
1623 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1629 ATTACH DATABASE ':memory:' AS test1;
1631 } {1 {not authorized}}
1632 do_test auth-1.254 {
1633 lindex [execsql {PRAGMA database_list}] 7
1635 do_test auth-1.255 {
1636 catchsql {DETACH DATABASE test1}
1637 proc auth {code arg1 arg2 arg3 arg4} {
1638 if {$code=="SQLITE_ATTACH"} {
1639 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1640 return SQLITE_IGNORE
1645 ATTACH DATABASE ':memory:' AS test1;
1648 do_test auth-1.256 {
1649 lindex [execsql {PRAGMA database_list}] 7
1651 do_test auth-1.257 {
1652 proc auth {code arg1 arg2 arg3 arg4} {
1653 if {$code=="SQLITE_DETACH"} {
1654 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1659 execsql {ATTACH DATABASE ':memory:' AS test1}
1661 DETACH DATABASE test1;
1664 do_test auth-1.258 {
1665 lindex [execsql {PRAGMA database_list}] 7
1667 do_test auth-1.259 {
1668 execsql {ATTACH DATABASE ':memory:' AS test1}
1669 proc auth {code arg1 arg2 arg3 arg4} {
1670 if {$code=="SQLITE_DETACH"} {
1671 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1672 return SQLITE_IGNORE
1677 DETACH DATABASE test1;
1680 do_test auth-1.260 {
1681 lindex [execsql {PRAGMA database_list}] 7
1683 do_test auth-1.261 {
1684 proc auth {code arg1 arg2 arg3 arg4} {
1685 if {$code=="SQLITE_DETACH"} {
1686 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1692 DETACH DATABASE test1;
1694 } {1 {not authorized}}
1695 do_test auth-1.262 {
1696 lindex [execsql {PRAGMA database_list}] 7
1699 execsql {DETACH DATABASE test1}
1703 proc auth {code arg1 arg2 arg3 arg4} {
1704 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1709 db authorizer ::auth
1710 execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
1711 catchsql {SELECT * FROM t3}
1712 } {1 {access to t3.x is prohibited}}
1714 catchsql {SELECT y,z FROM t3}
1717 catchsql {SELECT ROWID,y,z FROM t3}
1718 } {1 {access to t3.x is prohibited}}
1720 catchsql {SELECT OID,y,z FROM t3}
1721 } {1 {access to t3.x is prohibited}}
1723 proc auth {code arg1 arg2 arg3 arg4} {
1724 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
1725 return SQLITE_IGNORE
1729 execsql {INSERT INTO t3 VALUES(44,55,66)}
1730 catchsql {SELECT * FROM t3}
1733 catchsql {SELECT rowid,y,z FROM t3}
1736 proc auth {code arg1 arg2 arg3 arg4} {
1737 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
1738 return SQLITE_IGNORE
1742 catchsql {SELECT * FROM t3}
1745 catchsql {SELECT ROWID,y,z FROM t3}
1748 proc auth {code arg1 arg2 arg3 arg4} {
1749 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1750 return SQLITE_IGNORE
1754 catchsql {SELECT ROWID,b,c FROM t2}
1755 } {0 {{} 2 33 {} 8 9}}
1756 do_test auth-2.9.1 {
1757 proc auth {code arg1 arg2 arg3 arg4} {
1758 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
1763 catchsql {SELECT ROWID,b,c FROM t2}
1764 } {1 {illegal return value (999) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
1765 do_test auth-2.9.2 {
1769 proc auth {code arg1 arg2 arg3 arg4} {
1770 if {$code=="SQLITE_SELECT"} {
1775 catchsql {SELECT ROWID,b,c FROM t2}
1776 } {1 {illegal return value (1) from the authorization function - should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY}}
1777 do_test auth-2.11.1 {
1778 proc auth {code arg1 arg2 arg3 arg4} {
1779 if {$code=="SQLITE_READ" && $arg2=="a"} {
1780 return SQLITE_IGNORE
1784 catchsql {SELECT * FROM t2, t3}
1785 } {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
1786 do_test auth-2.11.2 {
1787 proc auth {code arg1 arg2 arg3 arg4} {
1788 if {$code=="SQLITE_READ" && $arg2=="x"} {
1789 return SQLITE_IGNORE
1793 catchsql {SELECT * FROM t2, t3}
1794 } {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
1796 # Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
1799 proc auth {code arg1 arg2 arg3 arg4} {
1803 CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
1804 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
1805 INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
1807 UPDATE t2 SET a=a+1;
1810 } {11 12 2 2 33 33 7 8 8 8 9 9}
1812 proc auth {code arg1 arg2 arg3 arg4} {
1813 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
1814 return SQLITE_IGNORE
1820 UPDATE t2 SET a=a+100;
1823 } {12 112 2 2 {} {} 8 108 8 8 {} {}}
1825 # Make sure the names of views and triggers are passed on on arg4.
1828 proc auth {code arg1 arg2 arg3 arg4} {
1829 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
1834 UPDATE t2 SET a=a+1;
1838 SQLITE_READ t2 a main {} \
1839 SQLITE_UPDATE t2 a main {} \
1840 SQLITE_INSERT tx {} main r1 \
1841 SQLITE_READ t2 a main r1 \
1842 SQLITE_READ t2 a main r1 \
1843 SQLITE_READ t2 b main r1 \
1844 SQLITE_READ t2 b main r1 \
1845 SQLITE_READ t2 c main r1 \
1846 SQLITE_READ t2 c main r1]
1849 CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
1850 CREATE TABLE v1chng(x1,x2);
1851 CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
1852 INSERT INTO v1chng VALUES(OLD.x,NEW.x);
1860 UPDATE v1 SET x=1 WHERE x=117
1864 SQLITE_UPDATE v1 x main {} \
1865 SQLITE_READ v1 x main {} \
1866 SQLITE_SELECT {} {} {} v1 \
1867 SQLITE_READ t2 a main v1 \
1868 SQLITE_READ t2 b main v1 \
1869 SQLITE_INSERT v1chng {} main r2 \
1870 SQLITE_READ v1 x main r2 \
1871 SQLITE_READ v1 x main r2]
1874 CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
1875 INSERT INTO v1chng VALUES(OLD.x,NULL);
1883 DELETE FROM v1 WHERE x=117
1887 SQLITE_DELETE v1 {} main {} \
1888 SQLITE_READ v1 x main {} \
1889 SQLITE_SELECT {} {} {} v1 \
1890 SQLITE_READ t2 a main v1 \
1891 SQLITE_READ t2 b main v1 \
1892 SQLITE_INSERT v1chng {} main r3 \
1893 SQLITE_READ v1 x main r3]