3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the sqlite3_set_authorizer() API
13 # and related functionality.
15 # $Id: auth.test,v 1.46 2009/07/02 18:40:35 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
22 # defined during compilation.
23 if {[catch {db auth {}} msg]} {
29 proc_real proc {name arguments script} {
30 proc_real $name $arguments $script
38 set ::DB [sqlite3 db test.db]
39 proc auth {code arg1 arg2 arg3 arg4 args} {
40 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
46 catchsql {CREATE TABLE t1(a,b,c)}
47 } {1 {not authorized}}
59 } {1 {no such column: x}}
61 execsql {SELECT name FROM sqlite_master}
64 proc auth {code arg1 arg2 arg3 arg4 args} {
65 if {$code=="SQLITE_CREATE_TABLE"} {
66 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
71 catchsql {CREATE TABLE t1(a,b,c)}
72 } {1 {not authorized}}
80 execsql {SELECT name FROM sqlite_master}
85 proc auth {code arg1 arg2 arg3 arg4 args} {
86 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
91 catchsql {CREATE TEMP TABLE t1(a,b,c)}
92 } {1 {not authorized}}
94 execsql {SELECT name FROM sqlite_temp_master}
97 proc auth {code arg1 arg2 arg3 arg4 args} {
98 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
99 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
104 catchsql {CREATE TEMP TABLE t1(a,b,c)}
105 } {1 {not authorized}}
110 execsql {SELECT name FROM sqlite_temp_master}
115 proc auth {code arg1 arg2 arg3 arg4 args} {
116 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
121 catchsql {CREATE TABLE t1(a,b,c)}
124 execsql {SELECT name FROM sqlite_master}
127 proc auth {code arg1 arg2 arg3 arg4 args} {
128 if {$code=="SQLITE_CREATE_TABLE"} {
129 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
134 catchsql {CREATE TABLE t1(a,b,c)}
137 execsql {SELECT name FROM sqlite_master}
142 proc auth {code arg1 arg2 arg3 arg4 args} {
143 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
148 catchsql {CREATE TEMP TABLE t1(a,b,c)}
151 execsql {SELECT name FROM sqlite_temp_master}
154 proc auth {code arg1 arg2 arg3 arg4 args} {
155 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
156 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
161 catchsql {CREATE TEMP TABLE t1(a,b,c)}
164 execsql {SELECT name FROM sqlite_temp_master}
168 proc auth {code arg1 arg2 arg3 arg4 args} {
169 if {$code=="SQLITE_CREATE_TABLE"} {
170 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
175 catchsql {CREATE TEMP TABLE t1(a,b,c)}
178 execsql {SELECT name FROM sqlite_temp_master}
182 do_test auth-1.19.1 {
184 proc auth {code arg1 arg2 arg3 arg4 args} {
185 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
186 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
191 catchsql {CREATE TABLE t2(a,b,c)}
193 do_test auth-1.19.2 {
197 execsql {SELECT name FROM sqlite_master}
200 do_test auth-1.21.1 {
201 proc auth {code arg1 arg2 arg3 arg4 args} {
202 if {$code=="SQLITE_DROP_TABLE"} {
203 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
208 catchsql {DROP TABLE t2}
209 } {1 {not authorized}}
210 do_test auth-1.21.2 {
214 execsql {SELECT name FROM sqlite_master}
216 do_test auth-1.23.1 {
217 proc auth {code arg1 arg2 arg3 arg4 args} {
218 if {$code=="SQLITE_DROP_TABLE"} {
219 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
224 catchsql {DROP TABLE t2}
226 do_test auth-1.23.2 {
230 execsql {SELECT name FROM sqlite_master}
235 proc auth {code arg1 arg2 arg3 arg4 args} {
236 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
237 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
242 catchsql {DROP TABLE t1}
243 } {1 {not authorized}}
245 execsql {SELECT name FROM sqlite_temp_master}
248 proc auth {code arg1 arg2 arg3 arg4 args} {
249 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
250 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
255 catchsql {DROP TABLE t1}
258 execsql {SELECT name FROM sqlite_temp_master}
263 proc auth {code arg1 arg2 arg3 arg4 args} {
264 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
269 catchsql {INSERT INTO t2 VALUES(1,2,3)}
270 } {1 {not authorized}}
272 execsql {SELECT * FROM t2}
275 proc auth {code arg1 arg2 arg3 arg4 args} {
276 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
281 catchsql {INSERT INTO t2 VALUES(1,2,3)}
284 execsql {SELECT * FROM t2}
287 proc auth {code arg1 arg2 arg3 arg4 args} {
288 if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
293 catchsql {INSERT INTO t2 VALUES(1,2,3)}
296 execsql {SELECT * FROM t2}
299 do_test auth-1.35.1 {
300 proc auth {code arg1 arg2 arg3 arg4 args} {
301 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
306 catchsql {SELECT * FROM t2}
307 } {1 {access to t2.b is prohibited}}
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}
316 proc auth {code arg1 arg2 arg3 arg4 args} {
317 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
322 catchsql {SELECT * FROM t2}
325 proc auth {code arg1 arg2 arg3 arg4 args} {
326 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
331 catchsql {SELECT * FROM t2 WHERE b=2}
334 proc auth {code arg1 arg2 arg3 arg4 args} {
335 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
340 catchsql {SELECT * FROM t2 WHERE b=2}
343 proc auth {code arg1 arg2 arg3 arg4 args} {
344 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
349 catchsql {SELECT * FROM t2 WHERE b IS NULL}
352 proc auth {code arg1 arg2 arg3 arg4 args} {
353 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
358 catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
359 } {1 {access to t2.b is prohibited}}
362 proc auth {code arg1 arg2 arg3 arg4 args} {
363 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
368 catchsql {UPDATE t2 SET a=11}
371 execsql {SELECT * FROM t2}
374 proc auth {code arg1 arg2 arg3 arg4 args} {
375 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
380 catchsql {UPDATE t2 SET b=22, c=33}
381 } {1 {not authorized}}
383 execsql {SELECT * FROM t2}
386 proc auth {code arg1 arg2 arg3 arg4 args} {
387 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
392 catchsql {UPDATE t2 SET b=22, c=33}
395 execsql {SELECT * FROM t2}
399 proc auth {code arg1 arg2 arg3 arg4 args} {
400 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
405 catchsql {DELETE FROM t2 WHERE a=11}
406 } {1 {not authorized}}
408 execsql {SELECT * FROM t2}
411 proc auth {code arg1 arg2 arg3 arg4 args} {
412 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
417 catchsql {DELETE FROM t2 WHERE a=11}
420 execsql {SELECT * FROM t2}
422 do_test auth-1.50.2 {
423 execsql {INSERT INTO t2 VALUES(11, 2, 33)}
427 proc auth {code arg1 arg2 arg3 arg4 args} {
428 if {$code=="SQLITE_SELECT"} {
433 catchsql {SELECT * FROM t2}
434 } {1 {not authorized}}
436 proc auth {code arg1 arg2 arg3 arg4 args} {
437 if {$code=="SQLITE_SELECT"} {
442 catchsql {SELECT * FROM t2}
445 proc auth {code arg1 arg2 arg3 arg4 args} {
446 if {$code=="SQLITE_SELECT"} {
451 catchsql {SELECT * FROM t2}
454 # Update for version 3: There used to be a handful of test here that
455 # tested the authorisation callback with the COPY command. The following
456 # test makes the same database modifications as they used to.
458 execsql {INSERT INTO t2 VALUES(7, 8, 9);}
461 execsql {SELECT * FROM t2}
465 proc auth {code arg1 arg2 arg3 arg4 args} {
466 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
471 catchsql {DROP TABLE t2}
472 } {1 {not authorized}}
474 execsql {SELECT name FROM sqlite_master}
477 proc auth {code arg1 arg2 arg3 arg4 args} {
478 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
483 catchsql {DROP TABLE t2}
484 } {1 {not authorized}}
486 execsql {SELECT name FROM sqlite_master}
491 proc auth {code arg1 arg2 arg3 arg4 args} {
492 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
497 catchsql {DROP TABLE t1}
498 } {1 {not authorized}}
500 execsql {SELECT name FROM sqlite_temp_master}
503 proc auth {code arg1 arg2 arg3 arg4 args} {
504 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
509 catchsql {DROP TABLE t1}
510 } {1 {not authorized}}
512 execsql {SELECT name FROM sqlite_temp_master}
517 proc auth {code arg1 arg2 arg3 arg4 args} {
518 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
523 catchsql {DROP TABLE t2}
526 execsql {SELECT name FROM sqlite_master}
529 proc auth {code arg1 arg2 arg3 arg4 args} {
530 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
535 catchsql {DROP TABLE t2}
538 execsql {SELECT name FROM sqlite_master}
543 proc auth {code arg1 arg2 arg3 arg4 args} {
544 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
549 catchsql {DROP TABLE t1}
552 execsql {SELECT name FROM sqlite_temp_master}
555 proc auth {code arg1 arg2 arg3 arg4 args} {
556 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
561 catchsql {DROP TABLE t1}
564 execsql {SELECT name FROM sqlite_temp_master}
568 # Test cases auth-1.79 to auth-1.124 test creating and dropping views.
569 # Omit these if the library was compiled with views omitted.
572 proc auth {code arg1 arg2 arg3 arg4 args} {
573 if {$code=="SQLITE_CREATE_VIEW"} {
574 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
579 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
580 } {1 {not authorized}}
585 execsql {SELECT name FROM sqlite_master}
588 proc auth {code arg1 arg2 arg3 arg4 args} {
589 if {$code=="SQLITE_CREATE_VIEW"} {
590 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
595 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
601 execsql {SELECT name FROM sqlite_master}
606 proc auth {code arg1 arg2 arg3 arg4 args} {
607 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
608 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
613 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
614 } {1 {not authorized}}
619 execsql {SELECT name FROM sqlite_temp_master}
622 proc auth {code arg1 arg2 arg3 arg4 args} {
623 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
624 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
629 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
635 execsql {SELECT name FROM sqlite_temp_master}
640 proc auth {code arg1 arg2 arg3 arg4 args} {
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 args} {
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}
666 proc auth {code arg1 arg2 arg3 arg4 args} {
667 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
672 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
673 } {1 {not authorized}}
675 execsql {SELECT name FROM sqlite_temp_master}
678 proc auth {code arg1 arg2 arg3 arg4 args} {
679 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
684 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
687 execsql {SELECT name FROM sqlite_temp_master}
692 proc auth {code arg1 arg2 arg3 arg4 args} {
693 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
699 CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
702 } {1 {not authorized}}
704 execsql {SELECT name FROM sqlite_master}
707 proc auth {code arg1 arg2 arg3 arg4 args} {
708 if {$code=="SQLITE_DROP_VIEW"} {
709 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
714 catchsql {DROP VIEW v2}
715 } {1 {not authorized}}
720 execsql {SELECT name FROM sqlite_master}
723 proc auth {code arg1 arg2 arg3 arg4 args} {
724 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
729 catchsql {DROP VIEW v2}
732 execsql {SELECT name FROM sqlite_master}
735 proc auth {code arg1 arg2 arg3 arg4 args} {
736 if {$code=="SQLITE_DROP_VIEW"} {
737 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
742 catchsql {DROP VIEW v2}
748 execsql {SELECT name FROM sqlite_master}
751 proc auth {code arg1 arg2 arg3 arg4 args} {
752 if {$code=="SQLITE_DROP_VIEW"} {
753 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
758 catchsql {DROP VIEW v2}
764 execsql {SELECT name FROM sqlite_master}
770 proc auth {code arg1 arg2 arg3 arg4 args} {
771 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
777 CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
780 } {1 {not authorized}}
782 execsql {SELECT name FROM sqlite_temp_master}
785 proc auth {code arg1 arg2 arg3 arg4 args} {
786 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
787 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
792 catchsql {DROP VIEW v1}
793 } {1 {not authorized}}
798 execsql {SELECT name FROM sqlite_temp_master}
801 proc auth {code arg1 arg2 arg3 arg4 args} {
802 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
807 catchsql {DROP VIEW v1}
810 execsql {SELECT name FROM sqlite_temp_master}
813 proc auth {code arg1 arg2 arg3 arg4 args} {
814 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
815 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
820 catchsql {DROP VIEW v1}
826 execsql {SELECT name FROM sqlite_temp_master}
829 proc auth {code arg1 arg2 arg3 arg4 args} {
830 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
831 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
836 catchsql {DROP VIEW v1}
842 execsql {SELECT name FROM sqlite_temp_master}
847 # Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
848 # Omit these if the library was compiled with triggers omitted.
850 ifcapable trigger&&tempdb {
852 proc auth {code arg1 arg2 arg3 arg4 args} {
853 if {$code=="SQLITE_CREATE_TRIGGER"} {
854 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
860 CREATE TRIGGER r2 DELETE on t2 BEGIN
864 } {1 {not authorized}}
869 execsql {SELECT name FROM sqlite_master}
872 proc auth {code arg1 arg2 arg3 arg4 args} {
873 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
879 CREATE TRIGGER r2 DELETE on t2 BEGIN
883 } {1 {not authorized}}
885 execsql {SELECT name FROM sqlite_master}
888 proc auth {code arg1 arg2 arg3 arg4 args} {
889 if {$code=="SQLITE_CREATE_TRIGGER"} {
890 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
896 CREATE TRIGGER r2 DELETE on t2 BEGIN
905 execsql {SELECT name FROM sqlite_master}
908 proc auth {code arg1 arg2 arg3 arg4 args} {
909 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
915 CREATE TRIGGER r2 DELETE on t2 BEGIN
921 execsql {SELECT name FROM sqlite_master}
924 proc auth {code arg1 arg2 arg3 arg4 args} {
925 if {$code=="SQLITE_CREATE_TRIGGER"} {
926 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
933 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
934 INSERT INTO tx VALUES(NEW.rowid);
938 do_test auth-1.136.1 {
941 do_test auth-1.136.2 {
943 SELECT name FROM sqlite_master WHERE type='trigger'
946 do_test auth-1.136.3 {
947 proc auth {code arg1 arg2 arg3 arg4 args} {
948 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
953 INSERT INTO t2 VALUES(1,2,3);
956 } {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
957 do_test auth-1.136.4 {
963 execsql {SELECT name FROM sqlite_master}
966 proc auth {code arg1 arg2 arg3 arg4 args} {
967 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
968 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
974 CREATE TRIGGER r1 DELETE on t1 BEGIN
978 } {1 {not authorized}}
983 execsql {SELECT name FROM sqlite_temp_master}
986 proc auth {code arg1 arg2 arg3 arg4 args} {
987 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
993 CREATE TRIGGER r1 DELETE on t1 BEGIN
997 } {1 {not authorized}}
999 execsql {SELECT name FROM sqlite_temp_master}
1001 do_test auth-1.143 {
1002 proc auth {code arg1 arg2 arg3 arg4 args} {
1003 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1004 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1005 return SQLITE_IGNORE
1010 CREATE TRIGGER r1 DELETE on t1 BEGIN
1015 do_test auth-1.144 {
1018 do_test auth-1.145 {
1019 execsql {SELECT name FROM sqlite_temp_master}
1021 do_test auth-1.146 {
1022 proc auth {code arg1 arg2 arg3 arg4 args} {
1023 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1024 return SQLITE_IGNORE
1029 CREATE TRIGGER r1 DELETE on t1 BEGIN
1034 do_test auth-1.147 {
1035 execsql {SELECT name FROM sqlite_temp_master}
1037 do_test auth-1.148 {
1038 proc auth {code arg1 arg2 arg3 arg4 args} {
1039 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1040 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1046 CREATE TRIGGER r1 DELETE on t1 BEGIN
1051 do_test auth-1.149 {
1054 do_test auth-1.150 {
1055 execsql {SELECT name FROM sqlite_temp_master}
1058 do_test auth-1.151 {
1059 proc auth {code arg1 arg2 arg3 arg4 args} {
1060 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1065 catchsql {DROP TRIGGER r2}
1066 } {1 {not authorized}}
1067 do_test auth-1.152 {
1068 execsql {SELECT name FROM sqlite_master}
1070 do_test auth-1.153 {
1071 proc auth {code arg1 arg2 arg3 arg4 args} {
1072 if {$code=="SQLITE_DROP_TRIGGER"} {
1073 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1078 catchsql {DROP TRIGGER r2}
1079 } {1 {not authorized}}
1080 do_test auth-1.154 {
1083 do_test auth-1.155 {
1084 execsql {SELECT name FROM sqlite_master}
1086 do_test auth-1.156 {
1087 proc auth {code arg1 arg2 arg3 arg4 args} {
1088 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1089 return SQLITE_IGNORE
1093 catchsql {DROP TRIGGER r2}
1095 do_test auth-1.157 {
1096 execsql {SELECT name FROM sqlite_master}
1098 do_test auth-1.158 {
1099 proc auth {code arg1 arg2 arg3 arg4 args} {
1100 if {$code=="SQLITE_DROP_TRIGGER"} {
1101 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1102 return SQLITE_IGNORE
1106 catchsql {DROP TRIGGER r2}
1108 do_test auth-1.159 {
1111 do_test auth-1.160 {
1112 execsql {SELECT name FROM sqlite_master}
1114 do_test auth-1.161 {
1115 proc auth {code arg1 arg2 arg3 arg4 args} {
1116 if {$code=="SQLITE_DROP_TRIGGER"} {
1117 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1122 catchsql {DROP TRIGGER r2}
1124 do_test auth-1.162 {
1127 do_test auth-1.163 {
1130 DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1131 SELECT name FROM sqlite_master;
1135 do_test auth-1.164 {
1136 proc auth {code arg1 arg2 arg3 arg4 args} {
1137 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1142 catchsql {DROP TRIGGER r1}
1143 } {1 {not authorized}}
1144 do_test auth-1.165 {
1145 execsql {SELECT name FROM sqlite_temp_master}
1147 do_test auth-1.166 {
1148 proc auth {code arg1 arg2 arg3 arg4 args} {
1149 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1150 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1155 catchsql {DROP TRIGGER r1}
1156 } {1 {not authorized}}
1157 do_test auth-1.167 {
1160 do_test auth-1.168 {
1161 execsql {SELECT name FROM sqlite_temp_master}
1163 do_test auth-1.169 {
1164 proc auth {code arg1 arg2 arg3 arg4 args} {
1165 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1166 return SQLITE_IGNORE
1170 catchsql {DROP TRIGGER r1}
1172 do_test auth-1.170 {
1173 execsql {SELECT name FROM sqlite_temp_master}
1175 do_test auth-1.171 {
1176 proc auth {code arg1 arg2 arg3 arg4 args} {
1177 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1178 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1179 return SQLITE_IGNORE
1183 catchsql {DROP TRIGGER r1}
1185 do_test auth-1.172 {
1188 do_test auth-1.173 {
1189 execsql {SELECT name FROM sqlite_temp_master}
1191 do_test auth-1.174 {
1192 proc auth {code arg1 arg2 arg3 arg4 args} {
1193 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1194 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1199 catchsql {DROP TRIGGER r1}
1201 do_test auth-1.175 {
1204 do_test auth-1.176 {
1205 execsql {SELECT name FROM sqlite_temp_master}
1207 } ;# ifcapable trigger
1209 do_test auth-1.177 {
1210 proc auth {code arg1 arg2 arg3 arg4 args} {
1211 if {$code=="SQLITE_CREATE_INDEX"} {
1212 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1217 catchsql {CREATE INDEX i2 ON t2(a)}
1218 } {1 {not authorized}}
1219 do_test auth-1.178 {
1222 do_test auth-1.179 {
1223 execsql {SELECT name FROM sqlite_master}
1225 do_test auth-1.180 {
1226 proc auth {code arg1 arg2 arg3 arg4 args} {
1227 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1232 catchsql {CREATE INDEX i2 ON t2(a)}
1233 } {1 {not authorized}}
1234 do_test auth-1.181 {
1235 execsql {SELECT name FROM sqlite_master}
1237 do_test auth-1.182 {
1238 proc auth {code arg1 arg2 arg3 arg4 args} {
1239 if {$code=="SQLITE_CREATE_INDEX"} {
1240 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1241 return SQLITE_IGNORE
1245 catchsql {CREATE INDEX i2 ON t2(b)}
1247 do_test auth-1.183 {
1250 do_test auth-1.184 {
1251 execsql {SELECT name FROM sqlite_master}
1253 do_test auth-1.185 {
1254 proc auth {code arg1 arg2 arg3 arg4 args} {
1255 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1256 return SQLITE_IGNORE
1260 catchsql {CREATE INDEX i2 ON t2(b)}
1262 do_test auth-1.186 {
1263 execsql {SELECT name FROM sqlite_master}
1265 do_test auth-1.187 {
1266 proc auth {code arg1 arg2 arg3 arg4 args} {
1267 if {$code=="SQLITE_CREATE_INDEX"} {
1268 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1273 catchsql {CREATE INDEX i2 ON t2(a)}
1275 do_test auth-1.188 {
1278 do_test auth-1.189 {
1279 execsql {SELECT name FROM sqlite_master}
1283 do_test auth-1.190 {
1284 proc auth {code arg1 arg2 arg3 arg4 args} {
1285 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1286 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1291 catchsql {CREATE INDEX i1 ON t1(a)}
1292 } {1 {not authorized}}
1293 do_test auth-1.191 {
1296 do_test auth-1.192 {
1297 execsql {SELECT name FROM sqlite_temp_master}
1299 do_test auth-1.193 {
1300 proc auth {code arg1 arg2 arg3 arg4 args} {
1301 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1306 catchsql {CREATE INDEX i1 ON t1(b)}
1307 } {1 {not authorized}}
1308 do_test auth-1.194 {
1309 execsql {SELECT name FROM sqlite_temp_master}
1311 do_test auth-1.195 {
1312 proc auth {code arg1 arg2 arg3 arg4 args} {
1313 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1314 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1315 return SQLITE_IGNORE
1319 catchsql {CREATE INDEX i1 ON t1(b)}
1321 do_test auth-1.196 {
1324 do_test auth-1.197 {
1325 execsql {SELECT name FROM sqlite_temp_master}
1327 do_test auth-1.198 {
1328 proc auth {code arg1 arg2 arg3 arg4 args} {
1329 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1330 return SQLITE_IGNORE
1334 catchsql {CREATE INDEX i1 ON t1(c)}
1336 do_test auth-1.199 {
1337 execsql {SELECT name FROM sqlite_temp_master}
1339 do_test auth-1.200 {
1340 proc auth {code arg1 arg2 arg3 arg4 args} {
1341 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1342 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1347 catchsql {CREATE INDEX i1 ON t1(a)}
1349 do_test auth-1.201 {
1352 do_test auth-1.202 {
1353 execsql {SELECT name FROM sqlite_temp_master}
1357 do_test auth-1.203 {
1358 proc auth {code arg1 arg2 arg3 arg4 args} {
1359 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1364 catchsql {DROP INDEX i2}
1365 } {1 {not authorized}}
1366 do_test auth-1.204 {
1367 execsql {SELECT name FROM sqlite_master}
1369 do_test auth-1.205 {
1370 proc auth {code arg1 arg2 arg3 arg4 args} {
1371 if {$code=="SQLITE_DROP_INDEX"} {
1372 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1377 catchsql {DROP INDEX i2}
1378 } {1 {not authorized}}
1379 do_test auth-1.206 {
1382 do_test auth-1.207 {
1383 execsql {SELECT name FROM sqlite_master}
1385 do_test auth-1.208 {
1386 proc auth {code arg1 arg2 arg3 arg4 args} {
1387 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1388 return SQLITE_IGNORE
1392 catchsql {DROP INDEX i2}
1394 do_test auth-1.209 {
1395 execsql {SELECT name FROM sqlite_master}
1397 do_test auth-1.210 {
1398 proc auth {code arg1 arg2 arg3 arg4 args} {
1399 if {$code=="SQLITE_DROP_INDEX"} {
1400 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1401 return SQLITE_IGNORE
1405 catchsql {DROP INDEX i2}
1407 do_test auth-1.211 {
1410 do_test auth-1.212 {
1411 execsql {SELECT name FROM sqlite_master}
1413 do_test auth-1.213 {
1414 proc auth {code arg1 arg2 arg3 arg4 args} {
1415 if {$code=="SQLITE_DROP_INDEX"} {
1416 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1421 catchsql {DROP INDEX i2}
1423 do_test auth-1.214 {
1426 do_test auth-1.215 {
1427 execsql {SELECT name FROM sqlite_master}
1431 do_test auth-1.216 {
1432 proc auth {code arg1 arg2 arg3 arg4 args} {
1433 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1438 catchsql {DROP INDEX i1}
1439 } {1 {not authorized}}
1440 do_test auth-1.217 {
1441 execsql {SELECT name FROM sqlite_temp_master}
1443 do_test auth-1.218 {
1444 proc auth {code arg1 arg2 arg3 arg4 args} {
1445 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1446 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1451 catchsql {DROP INDEX i1}
1452 } {1 {not authorized}}
1453 do_test auth-1.219 {
1456 do_test auth-1.220 {
1457 execsql {SELECT name FROM sqlite_temp_master}
1459 do_test auth-1.221 {
1460 proc auth {code arg1 arg2 arg3 arg4 args} {
1461 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1462 return SQLITE_IGNORE
1466 catchsql {DROP INDEX i1}
1468 do_test auth-1.222 {
1469 execsql {SELECT name FROM sqlite_temp_master}
1471 do_test auth-1.223 {
1472 proc auth {code arg1 arg2 arg3 arg4 args} {
1473 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1474 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1475 return SQLITE_IGNORE
1479 catchsql {DROP INDEX i1}
1481 do_test auth-1.224 {
1484 do_test auth-1.225 {
1485 execsql {SELECT name FROM sqlite_temp_master}
1487 do_test auth-1.226 {
1488 proc auth {code arg1 arg2 arg3 arg4 args} {
1489 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1490 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1495 catchsql {DROP INDEX i1}
1497 do_test auth-1.227 {
1500 do_test auth-1.228 {
1501 execsql {SELECT name FROM sqlite_temp_master}
1505 do_test auth-1.229 {
1506 proc auth {code arg1 arg2 arg3 arg4 args} {
1507 if {$code=="SQLITE_PRAGMA"} {
1508 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1513 catchsql {PRAGMA full_column_names=on}
1514 } {1 {not authorized}}
1515 do_test auth-1.230 {
1517 } {full_column_names on {} {}}
1518 do_test auth-1.231 {
1519 execsql2 {SELECT a FROM t2}
1521 do_test auth-1.232 {
1522 proc auth {code arg1 arg2 arg3 arg4 args} {
1523 if {$code=="SQLITE_PRAGMA"} {
1524 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1525 return SQLITE_IGNORE
1529 catchsql {PRAGMA full_column_names=on}
1531 do_test auth-1.233 {
1533 } {full_column_names on {} {}}
1534 do_test auth-1.234 {
1535 execsql2 {SELECT a FROM t2}
1537 do_test auth-1.235 {
1538 proc auth {code arg1 arg2 arg3 arg4 args} {
1539 if {$code=="SQLITE_PRAGMA"} {
1540 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1545 catchsql {PRAGMA full_column_names=on}
1547 do_test auth-1.236 {
1548 execsql2 {SELECT a FROM t2}
1550 do_test auth-1.237 {
1551 proc auth {code arg1 arg2 arg3 arg4 args} {
1552 if {$code=="SQLITE_PRAGMA"} {
1553 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1558 catchsql {PRAGMA full_column_names=OFF}
1560 do_test auth-1.238 {
1562 } {full_column_names OFF {} {}}
1563 do_test auth-1.239 {
1564 execsql2 {SELECT a FROM t2}
1567 do_test auth-1.240 {
1568 proc auth {code arg1 arg2 arg3 arg4 args} {
1569 if {$code=="SQLITE_TRANSACTION"} {
1570 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1576 } {1 {not authorized}}
1577 do_test auth-1.241 {
1580 do_test auth-1.242 {
1581 proc auth {code arg1 arg2 arg3 arg4 args} {
1582 if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
1583 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1588 catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1589 } {1 {not authorized}}
1590 do_test auth-1.243 {
1593 do_test auth-1.244 {
1594 execsql {SELECT * FROM t2}
1595 } {11 2 33 7 8 9 44 55 66}
1596 do_test auth-1.245 {
1598 } {1 {not authorized}}
1599 do_test auth-1.246 {
1601 } {ROLLBACK {} {} {}}
1602 do_test auth-1.247 {
1603 catchsql {END TRANSACTION}
1604 } {1 {not authorized}}
1605 do_test auth-1.248 {
1608 do_test auth-1.249 {
1612 do_test auth-1.250 {
1613 execsql {SELECT * FROM t2}
1616 # ticket #340 - authorization for ATTACH and DETACH.
1619 do_test auth-1.251 {
1620 db authorizer ::auth
1621 proc auth {code arg1 arg2 arg3 arg4 args} {
1622 if {$code=="SQLITE_ATTACH"} {
1623 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1628 ATTACH DATABASE ':memory:' AS test1
1631 do_test auth-1.252a {
1633 } {:memory: {} {} {}}
1634 do_test auth-1.252b {
1635 db eval {DETACH test1}
1636 set ::attachfilename :memory:
1637 db eval {ATTACH $::attachfilename AS test1}
1640 do_test auth-1.252c {
1641 db eval {DETACH test1}
1642 db eval {ATTACH ':mem' || 'ory:' AS test1}
1645 do_test auth-1.253 {
1646 catchsql {DETACH DATABASE test1}
1647 proc auth {code arg1 arg2 arg3 arg4 args} {
1648 if {$code=="SQLITE_ATTACH"} {
1649 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1655 ATTACH DATABASE ':memory:' AS test1;
1657 } {1 {not authorized}}
1658 do_test auth-1.254 {
1659 lindex [execsql {PRAGMA database_list}] 7
1661 do_test auth-1.255 {
1662 catchsql {DETACH DATABASE test1}
1663 proc auth {code arg1 arg2 arg3 arg4 args} {
1664 if {$code=="SQLITE_ATTACH"} {
1665 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1666 return SQLITE_IGNORE
1671 ATTACH DATABASE ':memory:' AS test1;
1674 do_test auth-1.256 {
1675 lindex [execsql {PRAGMA database_list}] 7
1677 do_test auth-1.257 {
1678 proc auth {code arg1 arg2 arg3 arg4 args} {
1679 if {$code=="SQLITE_DETACH"} {
1680 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1685 execsql {ATTACH DATABASE ':memory:' AS test1}
1687 DETACH DATABASE test1;
1690 do_test auth-1.258 {
1691 lindex [execsql {PRAGMA database_list}] 7
1693 do_test auth-1.259 {
1694 execsql {ATTACH DATABASE ':memory:' AS test1}
1695 proc auth {code arg1 arg2 arg3 arg4 args} {
1696 if {$code=="SQLITE_DETACH"} {
1697 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1698 return SQLITE_IGNORE
1703 DETACH DATABASE test1;
1707 ifcapable schema_pragmas {
1708 do_test auth-1.260 {
1709 lindex [execsql {PRAGMA database_list}] 7
1711 } ;# ifcapable schema_pragmas
1712 do_test auth-1.261 {
1713 proc auth {code arg1 arg2 arg3 arg4 args} {
1714 if {$code=="SQLITE_DETACH"} {
1715 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1721 DETACH DATABASE test1;
1723 } {1 {not authorized}}
1724 ifcapable schema_pragmas {
1725 do_test auth-1.262 {
1726 lindex [execsql {PRAGMA database_list}] 7
1728 } ;# ifcapable schema_pragmas
1730 execsql {DETACH DATABASE test1}
1731 db authorizer ::auth
1733 # Authorization for ALTER TABLE. These tests are omitted if the library
1734 # was built without ALTER TABLE support.
1735 ifcapable altertable {
1737 do_test auth-1.263 {
1738 proc auth {code arg1 arg2 arg3 arg4 args} {
1739 if {$code=="SQLITE_ALTER_TABLE"} {
1740 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1746 ALTER TABLE t1 RENAME TO t1x
1749 do_test auth-1.264 {
1750 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1752 do_test auth-1.265 {
1755 do_test auth-1.266 {
1756 proc auth {code arg1 arg2 arg3 arg4 args} {
1757 if {$code=="SQLITE_ALTER_TABLE"} {
1758 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1759 return SQLITE_IGNORE
1764 ALTER TABLE t1x RENAME TO t1
1767 do_test auth-1.267 {
1768 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1770 do_test auth-1.268 {
1773 do_test auth-1.269 {
1774 proc auth {code arg1 arg2 arg3 arg4 args} {
1775 if {$code=="SQLITE_ALTER_TABLE"} {
1776 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1782 ALTER TABLE t1x RENAME TO t1
1784 } {1 {not authorized}}
1785 do_test auth-1.270 {
1786 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1789 do_test auth-1.271 {
1792 } ;# ifcapable altertable
1797 DETACH DATABASE test1;
1802 ifcapable altertable {
1804 catchsql {ALTER TABLE t1x RENAME TO t1}
1805 db authorizer ::auth
1806 do_test auth-1.272 {
1807 proc auth {code arg1 arg2 arg3 arg4 args} {
1808 if {$code=="SQLITE_ALTER_TABLE"} {
1809 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1815 ALTER TABLE t2 RENAME TO t2x
1818 do_test auth-1.273 {
1819 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1821 do_test auth-1.274 {
1824 do_test auth-1.275 {
1825 proc auth {code arg1 arg2 arg3 arg4 args} {
1826 if {$code=="SQLITE_ALTER_TABLE"} {
1827 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1828 return SQLITE_IGNORE
1833 ALTER TABLE t2x RENAME TO t2
1836 do_test auth-1.276 {
1837 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1839 do_test auth-1.277 {
1842 do_test auth-1.278 {
1843 proc auth {code arg1 arg2 arg3 arg4 args} {
1844 if {$code=="SQLITE_ALTER_TABLE"} {
1845 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1851 ALTER TABLE t2x RENAME TO t2
1853 } {1 {not authorized}}
1854 do_test auth-1.279 {
1855 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1857 do_test auth-1.280 {
1861 catchsql {ALTER TABLE t2x RENAME TO t2}
1863 } ;# ifcapable altertable
1865 # Test the authorization callbacks for the REINDEX command.
1868 proc auth {code args} {
1869 if {$code=="SQLITE_REINDEX"} {
1870 set ::authargs [concat $::authargs [lrange $args 0 3]]
1875 do_test auth-1.281 {
1877 CREATE TABLE t3(a PRIMARY KEY, b, c);
1878 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1879 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1882 do_test auth-1.282 {
1888 } {t3_idx1 {} main {}}
1889 do_test auth-1.283 {
1895 } {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1896 do_test auth-1.284 {
1902 } {t3_idx2 {} main {}}
1903 do_test auth-1.285 {
1909 } {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1910 do_test auth-1.286 {
1916 do_test auth-1.287 {
1918 CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
1919 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1920 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1923 do_test auth-1.288 {
1926 REINDEX temp.t3_idx1;
1929 } {t3_idx1 {} temp {}}
1930 do_test auth-1.289 {
1936 } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1937 do_test auth-1.290 {
1943 } {t3_idx2 {} temp {}}
1944 do_test auth-1.291 {
1950 } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1951 proc auth {code args} {
1952 if {$code=="SQLITE_REINDEX"} {
1953 set ::authargs [concat $::authargs [lrange $args 0 3]]
1958 do_test auth-1.292 {
1963 } {1 {not authorized}}
1964 do_test auth-1.293 {
1971 } ;# ifcapable reindex
1974 proc auth {code args} {
1975 if {$code=="SQLITE_ANALYZE"} {
1976 set ::authargs [concat $::authargs [lrange $args 0 3]]
1980 do_test auth-1.294 {
1983 CREATE TABLE t4(a,b,c);
1984 CREATE INDEX t4i1 ON t4(a);
1985 CREATE INDEX t4i2 ON t4(b,a,c);
1986 INSERT INTO t4 VALUES(1,2,3);
1990 } {t4 {} main {} t2 {} main {}}
1991 do_test auth-1.295 {
1993 SELECT count(*) FROM sqlite_stat1;
1996 proc auth {code args} {
1997 if {$code=="SQLITE_ANALYZE"} {
1998 set ::authargs [concat $::authargs $args]
2003 do_test auth-1.296 {
2008 } {1 {not authorized}}
2009 do_test auth-1.297 {
2011 SELECT count(*) FROM sqlite_stat1;
2014 } ;# ifcapable analyze
2017 # Authorization for ALTER TABLE ADD COLUMN.
2018 # These tests are omitted if the library
2019 # was built without ALTER TABLE support.
2020 ifcapable {altertable} {
2021 do_test auth-1.300 {
2022 execsql {CREATE TABLE t5(x)}
2023 proc auth {code arg1 arg2 arg3 arg4 args} {
2024 if {$code=="SQLITE_ALTER_TABLE"} {
2025 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2031 ALTER TABLE t5 ADD COLUMN new_col_1;
2034 do_test auth-1.301 {
2035 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2038 do_test auth-1.302 {
2041 do_test auth-1.303 {
2042 proc auth {code arg1 arg2 arg3 arg4 args} {
2043 if {$code=="SQLITE_ALTER_TABLE"} {
2044 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2045 return SQLITE_IGNORE
2050 ALTER TABLE t5 ADD COLUMN new_col_2;
2053 do_test auth-1.304 {
2054 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2057 do_test auth-1.305 {
2060 do_test auth-1.306 {
2061 proc auth {code arg1 arg2 arg3 arg4 args} {
2062 if {$code=="SQLITE_ALTER_TABLE"} {
2063 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2069 ALTER TABLE t5 ADD COLUMN new_col_3
2071 } {1 {not authorized}}
2072 do_test auth-1.307 {
2073 set x [execsql {SELECT sql FROM sqlite_temp_master WHERE type='t5'}]
2077 do_test auth-1.308 {
2080 execsql {DROP TABLE t5}
2081 } ;# ifcapable altertable
2084 do_test auth-1.310 {
2085 proc auth {code arg1 arg2 arg3 arg4 args} {
2086 if {$code=="SQLITE_RECURSIVE"} {
2092 DROP TABLE IF EXISTS t1;
2093 CREATE TABLE t1(a,b);
2094 INSERT INTO t1 VALUES(1,2),(3,4),(5,6);
2097 do_catchsql_test auth-1.311 {
2099 auth1311(x,y) AS (SELECT a+b, b-a FROM t1)
2100 SELECT * FROM auth1311 ORDER BY x;
2101 } {0 {3 1 7 1 11 1}}
2102 do_catchsql_test auth-1.312 {
2104 auth1312(x,y) AS (SELECT a+b, b-a FROM t1)
2105 SELECT x, y FROM auth1312 ORDER BY x;
2106 } {0 {3 1 7 1 11 1}}
2107 do_catchsql_test auth-1.313 {
2109 auth1313(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1313 WHERE x<5)
2112 do_catchsql_test auth-1.314 {
2114 auth1314(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1314 WHERE x<5)
2115 SELECT * FROM t1 LEFT JOIN auth1314;
2116 } {1 {not authorized}}
2120 proc auth {code arg1 arg2 arg3 arg4 args} {
2121 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2126 db authorizer ::auth
2127 execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
2128 catchsql {SELECT * FROM t3}
2129 } {1 {access to t3.x is prohibited}}
2131 catchsql {SELECT y,z FROM t3}
2134 catchsql {SELECT ROWID,y,z FROM t3}
2135 } {1 {access to t3.x is prohibited}}
2137 catchsql {SELECT OID,y,z FROM t3}
2138 } {1 {access to t3.x is prohibited}}
2140 proc auth {code arg1 arg2 arg3 arg4 args} {
2141 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2142 return SQLITE_IGNORE
2146 execsql {INSERT INTO t3 VALUES(44,55,66)}
2147 catchsql {SELECT * FROM t3}
2150 catchsql {SELECT rowid,y,z FROM t3}
2153 proc auth {code arg1 arg2 arg3 arg4 args} {
2154 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
2155 return SQLITE_IGNORE
2159 catchsql {SELECT * FROM t3}
2162 catchsql {SELECT ROWID,y,z FROM t3}
2165 proc auth {code arg1 arg2 arg3 arg4 args} {
2166 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2167 return SQLITE_IGNORE
2171 catchsql {SELECT ROWID,b,c FROM t2}
2172 } {0 {{} 2 33 {} 8 9}}
2173 do_test auth-2.9.1 {
2174 # We have to flush the cache here in case the Tcl interface tries to
2175 # reuse a statement compiled with sqlite3_prepare_v2(). In this case,
2176 # the first error encountered is an SQLITE_SCHEMA error. Then, when
2177 # trying to recompile the statement, the authorization error is encountered.
2178 # If we do not flush the cache, the correct error message is returned, but
2179 # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test
2180 # case after this one.
2184 proc auth {code arg1 arg2 arg3 arg4 args} {
2185 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2190 catchsql {SELECT ROWID,b,c FROM t2}
2191 } {1 {authorizer malfunction}}
2192 do_test auth-2.9.2 {
2196 proc auth {code arg1 arg2 arg3 arg4 args} {
2197 if {$code=="SQLITE_SELECT"} {
2202 catchsql {SELECT ROWID,b,c FROM t2}
2203 } {1 {authorizer malfunction}}
2204 do_test auth-2.11.1 {
2205 proc auth {code arg1 arg2 arg3 arg4 args} {
2206 if {$code=="SQLITE_READ" && $arg2=="a"} {
2207 return SQLITE_IGNORE
2211 catchsql {SELECT * FROM t2, t3}
2212 } {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
2213 do_test auth-2.11.2 {
2214 proc auth {code arg1 arg2 arg3 arg4 args} {
2215 if {$code=="SQLITE_READ" && $arg2=="x"} {
2216 return SQLITE_IGNORE
2220 catchsql {SELECT * FROM t2, t3}
2221 } {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
2223 # Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
2227 proc auth {code arg1 arg2 arg3 arg4 args} {
2231 CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
2232 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
2233 INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
2235 UPDATE t2 SET a=a+1;
2238 } {11 12 2 2 33 33 7 8 8 8 9 9}
2240 proc auth {code arg1 arg2 arg3 arg4 args} {
2241 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
2242 return SQLITE_IGNORE
2248 UPDATE t2 SET a=a+100;
2251 } {12 112 2 2 {} {} 8 108 8 8 {} {}}
2252 } ;# ifcapable trigger
2254 # Make sure the names of views and triggers are passed on on arg4.
2258 proc auth {code arg1 arg2 arg3 arg4 args} {
2259 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2264 UPDATE t2 SET a=a+1;
2268 SQLITE_READ t2 a main {} \
2269 SQLITE_UPDATE t2 a main {} \
2270 SQLITE_INSERT tx {} main r1 \
2271 SQLITE_READ t2 a main r1 \
2272 SQLITE_READ t2 a main r1 \
2273 SQLITE_READ t2 b main r1 \
2274 SQLITE_READ t2 b main r1 \
2275 SQLITE_READ t2 c main r1 \
2276 SQLITE_READ t2 c main r1]
2279 ifcapable {view && trigger} {
2282 CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
2283 CREATE TABLE v1chng(x1,x2);
2284 CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
2285 INSERT INTO v1chng VALUES(OLD.x,NEW.x);
2293 UPDATE v1 SET x=1 WHERE x=117
2297 SQLITE_UPDATE v1 x main {} \
2298 SQLITE_SELECT {} {} {} v1 \
2299 SQLITE_READ t2 a main v1 \
2300 SQLITE_READ t2 b main v1 \
2301 SQLITE_READ v1 x main v1 \
2302 SQLITE_READ v1 x main v1 \
2303 SQLITE_SELECT {} {} {} v1 \
2304 SQLITE_READ v1 x main v1 \
2305 SQLITE_INSERT v1chng {} main r2 \
2306 SQLITE_READ v1 x main r2 \
2307 SQLITE_READ v1 x main r2 \
2312 CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
2313 INSERT INTO v1chng VALUES(OLD.x,NULL);
2321 DELETE FROM v1 WHERE x=117
2325 SQLITE_DELETE v1 {} main {} \
2326 SQLITE_SELECT {} {} {} v1 \
2327 SQLITE_READ t2 a main v1 \
2328 SQLITE_READ t2 b main v1 \
2329 SQLITE_READ v1 x main v1 \
2330 SQLITE_READ v1 x main v1 \
2331 SQLITE_SELECT {} {} {} v1 \
2332 SQLITE_READ v1 x main v1 \
2333 SQLITE_INSERT v1chng {} main r3 \
2334 SQLITE_READ v1 x main r3 \
2337 } ;# ifcapable view && trigger
2339 # Ticket #1338: Make sure authentication works in the presence of an AS
2343 proc auth {code arg1 arg2 arg3 arg4 args} {
2347 SELECT count(a) AS cnt FROM t4 ORDER BY cnt
2353 ifcapable compound&&subquery {
2365 set stat4 "sqlite_stat4 "
2368 set stat4 "sqlite_stat3 "
2376 SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
2380 } "sqlite_stat1 ${stat4}t1 t2 t3 t4"
2386 do_test auth-5.3.1 {
2388 CREATE TABLE t5 ( x );
2389 CREATE TRIGGER t5_tr1 AFTER INSERT ON t5 BEGIN
2390 UPDATE t5 SET x = 1 WHERE NEW.x = 0;
2394 set ::authargs [list]
2396 eval lappend ::authargs [lrange $args 0 4]
2399 do_test auth-5.3.2 {
2400 execsql { INSERT INTO t5 (x) values(0) }
2402 } [list SQLITE_INSERT t5 {} main {} \
2403 SQLITE_UPDATE t5 x main t5_tr1 \
2404 SQLITE_READ t5 x main t5_tr1 \
2406 do_test auth-5.3.2 {
2407 execsql { SELECT * FROM t5 }
2411 # Ticket [0eb70d77cb05bb22720]: Invalid pointer passsed to the authorizer
2412 # callback when updating a ROWID.
2416 CREATE TABLE t6(a,b,c,d,e,f,g,h);
2417 INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8);
2420 set ::authargs [list]
2422 eval lappend ::authargs [lrange $args 0 4]
2426 execsql {UPDATE t6 SET rowID=rowID+100}
2428 } [list SQLITE_READ t6 ROWID main {} \
2429 SQLITE_UPDATE t6 ROWID main {} \
2432 execsql {SELECT rowid, * FROM t6}
2433 } {101 1 2 3 4 5 6 7 8}
2436 rename proc_real proc