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 authx {code arg1 arg2 arg3 arg4 args} {return SQLITE_DENY}
40 proc auth {code arg1 arg2 arg3 arg4 args} {
41 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
47 # EVIDENCE-OF: R-03993-24285 Only a single authorizer can be in place on
48 # a database connection at a time. Each call to sqlite3_set_authorizer
49 # overrides the previous call.
51 # The authx authorizer above is overridden by the auth authorizer below
52 # authx is never invoked.
54 catchsql {CREATE TABLE t1(a,b,c)}
55 } {1 {not authorized}}
67 } {1 {no such column: x}}
69 execsql {SELECT name FROM sqlite_master}
71 # EVIDENCE-OF: R-04452-49349 When the callback returns SQLITE_DENY, the
72 # sqlite3_prepare_v2() or equivalent call that triggered the authorizer
73 # will fail with an error message explaining that access is denied.
75 proc auth {code arg1 arg2 arg3 arg4 args} {
76 if {$code=="SQLITE_CREATE_TABLE"} {
77 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
82 catchsql {CREATE TABLE t1(a,b,c)}
83 } {1 {not authorized}}
91 execsql {SELECT name FROM sqlite_master}
96 proc auth {code arg1 arg2 arg3 arg4 args} {
97 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
102 catchsql {CREATE TEMP TABLE t1(a,b,c)}
103 } {1 {not authorized}}
105 execsql {SELECT name FROM temp.sqlite_master}
108 proc auth {code arg1 arg2 arg3 arg4 args} {
109 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
110 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
115 catchsql {CREATE TEMP TABLE t1(a,b,c)}
116 } {1 {not authorized}}
121 execsql {SELECT name FROM sqlite_temp_master}
126 proc auth {code arg1 arg2 arg3 arg4 args} {
127 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
132 catchsql {CREATE TABLE t1(a,b,c)}
135 execsql {SELECT name FROM sqlite_master}
138 proc auth {code arg1 arg2 arg3 arg4 args} {
139 if {$code=="SQLITE_CREATE_TABLE"} {
140 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
145 catchsql {CREATE TABLE t1(a,b,c)}
148 execsql {SELECT name FROM sqlite_master}
153 proc auth {code arg1 arg2 arg3 arg4 args} {
154 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
159 catchsql {CREATE TEMP TABLE t1(a,b,c)}
162 execsql {SELECT name FROM temp.sqlite_master}
165 proc auth {code arg1 arg2 arg3 arg4 args} {
166 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
167 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
172 catchsql {CREATE TEMP TABLE t1(a,b,c)}
175 execsql {SELECT name FROM sqlite_temp_master}
179 proc auth {code arg1 arg2 arg3 arg4 args} {
180 if {$code=="SQLITE_CREATE_TABLE"} {
181 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
186 catchsql {CREATE TEMP TABLE t1(a,b,c)}
189 execsql {SELECT name FROM sqlite_temp_master}
193 do_test auth-1.19.1 {
195 proc auth {code arg1 arg2 arg3 arg4 args} {
196 if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
197 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
202 catchsql {CREATE TABLE t2(a,b,c)}
204 do_test auth-1.19.2 {
208 execsql {SELECT name FROM sqlite_master}
211 do_test auth-1.21.1 {
212 proc auth {code arg1 arg2 arg3 arg4 args} {
213 if {$code=="SQLITE_DROP_TABLE"} {
214 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
219 catchsql {DROP TABLE t2}
220 } {1 {not authorized}}
221 do_test auth-1.21.2 {
225 execsql {SELECT name FROM sqlite_master}
227 do_test auth-1.23.1 {
228 proc auth {code arg1 arg2 arg3 arg4 args} {
229 if {$code=="SQLITE_DROP_TABLE"} {
230 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
235 catchsql {DROP TABLE t2}
237 do_test auth-1.23.2 {
241 execsql {SELECT name FROM sqlite_master}
246 proc auth {code arg1 arg2 arg3 arg4 args} {
247 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
248 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
253 catchsql {DROP TABLE t1}
254 } {1 {not authorized}}
256 execsql {SELECT name FROM sqlite_temp_master}
259 proc auth {code arg1 arg2 arg3 arg4 args} {
260 if {$code=="SQLITE_DROP_TEMP_TABLE"} {
261 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
266 catchsql {DROP TABLE t1}
269 execsql {SELECT name FROM sqlite_temp_master}
274 proc auth {code arg1 arg2 arg3 arg4 args} {
275 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
280 catchsql {INSERT INTO t2 VALUES(1,2,3)}
281 } {1 {not authorized}}
283 execsql {SELECT * FROM t2}
286 proc auth {code arg1 arg2 arg3 arg4 args} {
287 if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
292 catchsql {INSERT INTO t2 VALUES(1,2,3)}
295 execsql {SELECT * FROM t2}
298 proc auth {code arg1 arg2 arg3 arg4 args} {
299 if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
304 catchsql {INSERT INTO t2 VALUES(1,2,3)}
307 execsql {SELECT * FROM t2}
310 do_test auth-1.35.1 {
311 proc auth {code arg1 arg2 arg3 arg4 args} {
312 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
317 catchsql {SELECT * FROM t2}
318 } {1 {access to t2.b is prohibited}}
320 do_test auth-1.35.2 {
321 execsql {ATTACH DATABASE 'test.db' AS two}
322 catchsql {SELECT * FROM two.t2}
323 } {1 {access to two.t2.b is prohibited}}
324 execsql {DETACH DATABASE two}
326 # EVIDENCE-OF: R-38392-49970 If the action code is SQLITE_READ and the
327 # callback returns SQLITE_IGNORE then the prepared statement statement
328 # is constructed to substitute a NULL value in place of the table column
329 # that would have been read if SQLITE_OK had been returned.
331 proc auth {code arg1 arg2 arg3 arg4 args} {
332 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
337 catchsql {SELECT * FROM t2}
340 proc auth {code arg1 arg2 arg3 arg4 args} {
341 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
346 catchsql {SELECT * FROM t2 WHERE b=2}
349 proc auth {code arg1 arg2 arg3 arg4 args} {
350 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
355 catchsql {SELECT * FROM t2 WHERE b=2}
358 proc auth {code arg1 arg2 arg3 arg4 args} {
359 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
364 catchsql {SELECT * FROM t2 WHERE b IS NULL}
367 proc auth {code arg1 arg2 arg3 arg4 args} {
368 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
373 catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
374 } {1 {access to t2.b is prohibited}}
377 proc auth {code arg1 arg2 arg3 arg4 args} {
378 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
383 catchsql {UPDATE t2 SET a=11}
386 execsql {SELECT * FROM t2}
389 proc auth {code arg1 arg2 arg3 arg4 args} {
390 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
395 catchsql {UPDATE t2 SET b=22, c=33}
396 } {1 {not authorized}}
398 execsql {SELECT * FROM t2}
401 proc auth {code arg1 arg2 arg3 arg4 args} {
402 if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
407 catchsql {UPDATE t2 SET b=22, c=33}
410 execsql {SELECT * FROM t2}
414 proc auth {code arg1 arg2 arg3 arg4 args} {
415 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
420 catchsql {DELETE FROM t2 WHERE a=11}
421 } {1 {not authorized}}
423 execsql {SELECT * FROM t2}
426 proc auth {code arg1 arg2 arg3 arg4 args} {
427 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
432 catchsql {DELETE FROM t2 WHERE a=11}
435 execsql {SELECT * FROM t2}
437 do_test auth-1.50.2 {
438 execsql {INSERT INTO t2 VALUES(11, 2, 33)}
442 proc auth {code arg1 arg2 arg3 arg4 args} {
443 if {$code=="SQLITE_SELECT"} {
448 catchsql {SELECT * FROM t2}
449 } {1 {not authorized}}
451 proc auth {code arg1 arg2 arg3 arg4 args} {
452 if {$code=="SQLITE_SELECT"} {
457 catchsql {SELECT * FROM t2}
460 proc auth {code arg1 arg2 arg3 arg4 args} {
461 if {$code=="SQLITE_SELECT"} {
466 catchsql {SELECT * FROM t2}
469 # Update for version 3: There used to be a handful of test here that
470 # tested the authorisation callback with the COPY command. The following
471 # test makes the same database modifications as they used to.
473 execsql {INSERT INTO t2 VALUES(7, 8, 9);}
476 execsql {SELECT * FROM t2}
480 proc auth {code arg1 arg2 arg3 arg4 args} {
481 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
486 catchsql {DROP TABLE t2}
487 } {1 {not authorized}}
489 execsql {SELECT name FROM sqlite_master}
492 proc auth {code arg1 arg2 arg3 arg4 args} {
493 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
498 catchsql {DROP TABLE t2}
499 } {1 {not authorized}}
501 execsql {SELECT name FROM sqlite_master}
506 proc auth {code arg1 arg2 arg3 arg4 args} {
507 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
512 catchsql {DROP TABLE t1}
513 } {1 {not authorized}}
515 execsql {SELECT name FROM sqlite_temp_master}
518 proc auth {code arg1 arg2 arg3 arg4 args} {
519 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
524 catchsql {DROP TABLE t1}
525 } {1 {not authorized}}
527 execsql {SELECT name FROM sqlite_temp_master}
532 proc auth {code arg1 arg2 arg3 arg4 args} {
533 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
538 catchsql {DROP TABLE t2}
541 execsql {SELECT name FROM sqlite_master}
544 proc auth {code arg1 arg2 arg3 arg4 args} {
545 if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
550 catchsql {DROP TABLE t2}
553 execsql {SELECT name FROM sqlite_master}
558 proc auth {code arg1 arg2 arg3 arg4 args} {
559 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
564 catchsql {DROP TABLE t1}
567 execsql {SELECT name FROM sqlite_temp_master}
570 proc auth {code arg1 arg2 arg3 arg4 args} {
571 if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
576 catchsql {DROP TABLE t1}
579 execsql {SELECT name FROM temp.sqlite_master}
583 # Test cases auth-1.79 to auth-1.124 test creating and dropping views.
584 # Omit these if the library was compiled with views omitted.
587 proc auth {code arg1 arg2 arg3 arg4 args} {
588 if {$code=="SQLITE_CREATE_VIEW"} {
589 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
594 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
595 } {1 {not authorized}}
600 execsql {SELECT name FROM sqlite_master}
603 proc auth {code arg1 arg2 arg3 arg4 args} {
604 if {$code=="SQLITE_CREATE_VIEW"} {
605 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
610 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
616 execsql {SELECT name FROM sqlite_master}
621 proc auth {code arg1 arg2 arg3 arg4 args} {
622 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
623 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
628 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
629 } {1 {not authorized}}
634 execsql {SELECT name FROM sqlite_temp_master}
637 proc auth {code arg1 arg2 arg3 arg4 args} {
638 if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
639 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
644 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
650 execsql {SELECT name FROM temp.sqlite_master}
655 proc auth {code arg1 arg2 arg3 arg4 args} {
656 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
661 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
662 } {1 {not authorized}}
664 execsql {SELECT name FROM sqlite_master}
667 proc auth {code arg1 arg2 arg3 arg4 args} {
668 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
673 catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
676 execsql {SELECT name FROM sqlite_master}
681 proc auth {code arg1 arg2 arg3 arg4 args} {
682 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
687 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
688 } {1 {not authorized}}
690 execsql {SELECT name FROM sqlite_temp_master}
693 proc auth {code arg1 arg2 arg3 arg4 args} {
694 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
699 catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
702 execsql {SELECT name FROM sqlite_temp_master}
707 proc auth {code arg1 arg2 arg3 arg4 args} {
708 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
714 CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
717 } {1 {not authorized}}
719 execsql {SELECT name FROM sqlite_master}
722 proc auth {code arg1 arg2 arg3 arg4 args} {
723 if {$code=="SQLITE_DROP_VIEW"} {
724 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
729 catchsql {DROP VIEW v2}
730 } {1 {not authorized}}
735 execsql {SELECT name FROM sqlite_master}
738 proc auth {code arg1 arg2 arg3 arg4 args} {
739 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
744 catchsql {DROP VIEW v2}
747 execsql {SELECT name FROM sqlite_master}
750 proc auth {code arg1 arg2 arg3 arg4 args} {
751 if {$code=="SQLITE_DROP_VIEW"} {
752 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
757 catchsql {DROP VIEW v2}
763 execsql {SELECT name FROM sqlite_master}
766 proc auth {code arg1 arg2 arg3 arg4 args} {
767 if {$code=="SQLITE_DROP_VIEW"} {
768 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
773 catchsql {DROP VIEW v2}
779 execsql {SELECT name FROM sqlite_master}
785 proc auth {code arg1 arg2 arg3 arg4 args} {
786 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
792 CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
795 } {1 {not authorized}}
797 execsql {SELECT name FROM temp.sqlite_master}
800 proc auth {code arg1 arg2 arg3 arg4 args} {
801 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
802 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
807 catchsql {DROP VIEW v1}
808 } {1 {not authorized}}
813 execsql {SELECT name FROM sqlite_temp_master}
816 proc auth {code arg1 arg2 arg3 arg4 args} {
817 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
822 catchsql {DROP VIEW v1}
825 execsql {SELECT name FROM sqlite_temp_master}
828 proc auth {code arg1 arg2 arg3 arg4 args} {
829 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
830 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
835 catchsql {DROP VIEW v1}
841 execsql {SELECT name FROM temp.sqlite_master}
844 proc auth {code arg1 arg2 arg3 arg4 args} {
845 if {$code=="SQLITE_DROP_TEMP_VIEW"} {
846 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
851 catchsql {DROP VIEW v1}
857 execsql {SELECT name FROM sqlite_temp_master}
862 # Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
863 # Omit these if the library was compiled with triggers omitted.
865 ifcapable trigger&&tempdb {
867 proc auth {code arg1 arg2 arg3 arg4 args} {
868 if {$code=="SQLITE_CREATE_TRIGGER"} {
869 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
875 CREATE TRIGGER r2 DELETE on t2 BEGIN
879 } {1 {not authorized}}
884 execsql {SELECT name FROM sqlite_master}
887 proc auth {code arg1 arg2 arg3 arg4 args} {
888 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
894 CREATE TRIGGER r2 DELETE on t2 BEGIN
898 } {1 {not authorized}}
900 execsql {SELECT name FROM sqlite_master}
903 proc auth {code arg1 arg2 arg3 arg4 args} {
904 if {$code=="SQLITE_CREATE_TRIGGER"} {
905 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
911 CREATE TRIGGER r2 DELETE on t2 BEGIN
920 execsql {SELECT name FROM sqlite_master}
923 proc auth {code arg1 arg2 arg3 arg4 args} {
924 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
930 CREATE TRIGGER r2 DELETE on t2 BEGIN
936 execsql {SELECT name FROM sqlite_master}
939 proc auth {code arg1 arg2 arg3 arg4 args} {
940 if {$code=="SQLITE_CREATE_TRIGGER"} {
941 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
948 CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
949 INSERT INTO tx VALUES(NEW.rowid);
953 do_test auth-1.136.1 {
956 do_test auth-1.136.2 {
958 SELECT name FROM sqlite_master WHERE type='trigger'
961 do_test auth-1.136.3 {
962 proc auth {code arg1 arg2 arg3 arg4 args} {
963 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
968 INSERT INTO t2 VALUES(1,2,3);
971 } {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
972 do_test auth-1.136.4 {
978 execsql {SELECT name FROM sqlite_master}
981 proc auth {code arg1 arg2 arg3 arg4 args} {
982 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
983 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
989 CREATE TRIGGER r1 DELETE on t1 BEGIN
993 } {1 {not authorized}}
998 execsql {SELECT name FROM temp.sqlite_master}
1000 do_test auth-1.141 {
1001 proc auth {code arg1 arg2 arg3 arg4 args} {
1002 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1008 CREATE TRIGGER r1 DELETE on t1 BEGIN
1012 } {1 {not authorized}}
1013 do_test auth-1.142 {
1014 execsql {SELECT name FROM sqlite_temp_master}
1016 do_test auth-1.143 {
1017 proc auth {code arg1 arg2 arg3 arg4 args} {
1018 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1019 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1020 return SQLITE_IGNORE
1025 CREATE TRIGGER r1 DELETE on t1 BEGIN
1030 do_test auth-1.144 {
1033 do_test auth-1.145 {
1034 execsql {SELECT name FROM temp.sqlite_master}
1036 do_test auth-1.146 {
1037 proc auth {code arg1 arg2 arg3 arg4 args} {
1038 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1039 return SQLITE_IGNORE
1044 CREATE TRIGGER r1 DELETE on t1 BEGIN
1049 do_test auth-1.147 {
1050 execsql {SELECT name FROM sqlite_temp_master}
1052 do_test auth-1.148 {
1053 proc auth {code arg1 arg2 arg3 arg4 args} {
1054 if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
1055 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1061 CREATE TRIGGER r1 DELETE on t1 BEGIN
1066 do_test auth-1.149 {
1069 do_test auth-1.150 {
1070 execsql {SELECT name FROM temp.sqlite_master}
1073 do_test auth-1.151 {
1074 proc auth {code arg1 arg2 arg3 arg4 args} {
1075 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1080 catchsql {DROP TRIGGER r2}
1081 } {1 {not authorized}}
1082 do_test auth-1.152 {
1083 execsql {SELECT name FROM sqlite_master}
1085 do_test auth-1.153 {
1086 proc auth {code arg1 arg2 arg3 arg4 args} {
1087 if {$code=="SQLITE_DROP_TRIGGER"} {
1088 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1093 catchsql {DROP TRIGGER r2}
1094 } {1 {not authorized}}
1095 do_test auth-1.154 {
1098 do_test auth-1.155 {
1099 execsql {SELECT name FROM sqlite_master}
1101 do_test auth-1.156 {
1102 proc auth {code arg1 arg2 arg3 arg4 args} {
1103 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1104 return SQLITE_IGNORE
1108 catchsql {DROP TRIGGER r2}
1110 do_test auth-1.157 {
1111 execsql {SELECT name FROM sqlite_master}
1113 do_test auth-1.158 {
1114 proc auth {code arg1 arg2 arg3 arg4 args} {
1115 if {$code=="SQLITE_DROP_TRIGGER"} {
1116 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1117 return SQLITE_IGNORE
1121 catchsql {DROP TRIGGER r2}
1123 do_test auth-1.159 {
1126 do_test auth-1.160 {
1127 execsql {SELECT name FROM sqlite_master}
1129 do_test auth-1.161 {
1130 proc auth {code arg1 arg2 arg3 arg4 args} {
1131 if {$code=="SQLITE_DROP_TRIGGER"} {
1132 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1137 catchsql {DROP TRIGGER r2}
1139 do_test auth-1.162 {
1142 do_test auth-1.163 {
1145 DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
1146 SELECT name FROM sqlite_master;
1150 do_test auth-1.164 {
1151 proc auth {code arg1 arg2 arg3 arg4 args} {
1152 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1157 catchsql {DROP TRIGGER r1}
1158 } {1 {not authorized}}
1159 do_test auth-1.165 {
1160 execsql {SELECT name FROM temp.sqlite_master}
1162 do_test auth-1.166 {
1163 proc auth {code arg1 arg2 arg3 arg4 args} {
1164 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1165 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1170 catchsql {DROP TRIGGER r1}
1171 } {1 {not authorized}}
1172 do_test auth-1.167 {
1175 do_test auth-1.168 {
1176 execsql {SELECT name FROM sqlite_temp_master}
1178 do_test auth-1.169 {
1179 proc auth {code arg1 arg2 arg3 arg4 args} {
1180 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1181 return SQLITE_IGNORE
1185 catchsql {DROP TRIGGER r1}
1187 do_test auth-1.170 {
1188 execsql {SELECT name FROM temp.sqlite_master}
1190 do_test auth-1.171 {
1191 proc auth {code arg1 arg2 arg3 arg4 args} {
1192 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1193 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1194 return SQLITE_IGNORE
1198 catchsql {DROP TRIGGER r1}
1200 do_test auth-1.172 {
1203 do_test auth-1.173 {
1204 execsql {SELECT name FROM sqlite_temp_master}
1206 do_test auth-1.174 {
1207 proc auth {code arg1 arg2 arg3 arg4 args} {
1208 if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
1209 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1214 catchsql {DROP TRIGGER r1}
1216 do_test auth-1.175 {
1219 do_test auth-1.176 {
1220 execsql {SELECT name FROM temp.sqlite_master}
1222 } ;# ifcapable trigger
1224 do_test auth-1.177 {
1225 proc auth {code arg1 arg2 arg3 arg4 args} {
1226 if {$code=="SQLITE_CREATE_INDEX"} {
1227 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1232 catchsql {CREATE INDEX i2 ON t2(a)}
1233 } {1 {not authorized}}
1234 do_test auth-1.178 {
1237 do_test auth-1.179 {
1238 execsql {SELECT name FROM sqlite_master}
1240 do_test auth-1.180 {
1241 proc auth {code arg1 arg2 arg3 arg4 args} {
1242 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1247 catchsql {CREATE INDEX i2 ON t2(a)}
1248 } {1 {not authorized}}
1249 do_test auth-1.181 {
1250 execsql {SELECT name FROM sqlite_master}
1252 do_test auth-1.182 {
1253 proc auth {code arg1 arg2 arg3 arg4 args} {
1254 if {$code=="SQLITE_CREATE_INDEX"} {
1255 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1256 return SQLITE_IGNORE
1260 catchsql {CREATE INDEX i2 ON t2(b)}
1262 do_test auth-1.183 {
1265 do_test auth-1.184 {
1266 execsql {SELECT name FROM sqlite_master}
1268 do_test auth-1.185 {
1269 proc auth {code arg1 arg2 arg3 arg4 args} {
1270 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
1271 return SQLITE_IGNORE
1275 catchsql {CREATE INDEX i2 ON t2(b)}
1277 do_test auth-1.186 {
1278 execsql {SELECT name FROM sqlite_master}
1280 do_test auth-1.187 {
1281 proc auth {code arg1 arg2 arg3 arg4 args} {
1282 if {$code=="SQLITE_CREATE_INDEX"} {
1283 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1288 catchsql {CREATE INDEX i2 ON t2(a)}
1290 do_test auth-1.188 {
1293 do_test auth-1.189 {
1294 execsql {SELECT name FROM sqlite_master}
1298 do_test auth-1.190 {
1299 proc auth {code arg1 arg2 arg3 arg4 args} {
1300 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1301 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1306 catchsql {CREATE INDEX i1 ON t1(a)}
1307 } {1 {not authorized}}
1308 do_test auth-1.191 {
1311 do_test auth-1.192 {
1312 execsql {SELECT name FROM sqlite_temp_master}
1314 do_test auth-1.193 {
1315 proc auth {code arg1 arg2 arg3 arg4 args} {
1316 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1321 catchsql {CREATE INDEX i1 ON t1(b)}
1322 } {1 {not authorized}}
1323 do_test auth-1.194 {
1324 execsql {SELECT name FROM temp.sqlite_master}
1326 do_test auth-1.195 {
1327 proc auth {code arg1 arg2 arg3 arg4 args} {
1328 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1329 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1330 return SQLITE_IGNORE
1334 catchsql {CREATE INDEX i1 ON t1(b)}
1336 do_test auth-1.196 {
1339 do_test auth-1.197 {
1340 execsql {SELECT name FROM sqlite_temp_master}
1342 do_test auth-1.198 {
1343 proc auth {code arg1 arg2 arg3 arg4 args} {
1344 if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
1345 return SQLITE_IGNORE
1349 catchsql {CREATE INDEX i1 ON t1(c)}
1351 do_test auth-1.199 {
1352 execsql {SELECT name FROM sqlite_temp_master}
1354 do_test auth-1.200 {
1355 proc auth {code arg1 arg2 arg3 arg4 args} {
1356 if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
1357 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1362 catchsql {CREATE INDEX i1 ON t1(a)}
1364 do_test auth-1.201 {
1367 do_test auth-1.202 {
1368 execsql {SELECT name FROM temp.sqlite_master}
1372 do_test auth-1.203 {
1373 proc auth {code arg1 arg2 arg3 arg4 args} {
1374 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1379 catchsql {DROP INDEX i2}
1380 } {1 {not authorized}}
1381 do_test auth-1.204 {
1382 execsql {SELECT name FROM sqlite_master}
1384 do_test auth-1.205 {
1385 proc auth {code arg1 arg2 arg3 arg4 args} {
1386 if {$code=="SQLITE_DROP_INDEX"} {
1387 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1392 catchsql {DROP INDEX i2}
1393 } {1 {not authorized}}
1394 do_test auth-1.205a {
1398 ATTACH ':memory:' as di205;
1399 CREATE TABLE di205.t1(x);
1400 CREATE INDEX di205.t1x ON t1(x);
1402 do_catchsql_test auth-1.205b {
1403 DROP INDEX di205.t1x;
1404 } {1 {not authorized}}
1408 do_test auth-1.206 {
1411 do_test auth-1.207 {
1412 execsql {SELECT name FROM sqlite_master}
1414 do_test auth-1.208 {
1415 proc auth {code arg1 arg2 arg3 arg4 args} {
1416 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
1417 return SQLITE_IGNORE
1421 catchsql {DROP INDEX i2}
1423 do_test auth-1.209 {
1424 execsql {SELECT name FROM sqlite_master}
1426 do_test auth-1.210 {
1427 proc auth {code arg1 arg2 arg3 arg4 args} {
1428 if {$code=="SQLITE_DROP_INDEX"} {
1429 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1430 return SQLITE_IGNORE
1434 catchsql {DROP INDEX i2}
1436 do_test auth-1.211 {
1439 do_test auth-1.212 {
1440 execsql {SELECT name FROM sqlite_master}
1442 do_test auth-1.213 {
1443 proc auth {code arg1 arg2 arg3 arg4 args} {
1444 if {$code=="SQLITE_DROP_INDEX"} {
1445 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1450 catchsql {DROP INDEX i2}
1452 do_test auth-1.214 {
1455 do_test auth-1.215 {
1456 execsql {SELECT name FROM sqlite_master}
1460 do_test auth-1.216 {
1461 proc auth {code arg1 arg2 arg3 arg4 args} {
1462 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1467 catchsql {DROP INDEX i1}
1468 } {1 {not authorized}}
1469 do_test auth-1.217 {
1470 execsql {SELECT name FROM sqlite_temp_master}
1472 do_test auth-1.218 {
1473 proc auth {code arg1 arg2 arg3 arg4 args} {
1474 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1475 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1480 catchsql {DROP INDEX i1}
1481 } {1 {not authorized}}
1482 do_test auth-1.219 {
1485 do_test auth-1.220 {
1486 execsql {SELECT name FROM sqlite_temp_master}
1488 do_test auth-1.221 {
1489 proc auth {code arg1 arg2 arg3 arg4 args} {
1490 if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
1491 return SQLITE_IGNORE
1495 catchsql {DROP INDEX i1}
1497 do_test auth-1.222 {
1498 execsql {SELECT name FROM temp.sqlite_master}
1500 do_test auth-1.223 {
1501 proc auth {code arg1 arg2 arg3 arg4 args} {
1502 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1503 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1504 return SQLITE_IGNORE
1508 catchsql {DROP INDEX i1}
1510 do_test auth-1.224 {
1513 do_test auth-1.225 {
1514 execsql {SELECT name FROM temp.sqlite_master}
1516 do_test auth-1.226 {
1517 proc auth {code arg1 arg2 arg3 arg4 args} {
1518 if {$code=="SQLITE_DROP_TEMP_INDEX"} {
1519 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1524 catchsql {DROP INDEX i1}
1526 do_test auth-1.227 {
1529 do_test auth-1.228 {
1530 execsql {SELECT name FROM temp.sqlite_master}
1534 do_test auth-1.229 {
1535 proc auth {code arg1 arg2 arg3 arg4 args} {
1536 if {$code=="SQLITE_PRAGMA"} {
1537 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1542 catchsql {PRAGMA full_column_names=on}
1543 } {1 {not authorized}}
1544 do_test auth-1.230 {
1546 } {full_column_names on {} {}}
1547 do_test auth-1.231 {
1548 execsql2 {SELECT a FROM t2}
1550 do_test auth-1.232 {
1551 proc auth {code arg1 arg2 arg3 arg4 args} {
1552 if {$code=="SQLITE_PRAGMA"} {
1553 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1554 return SQLITE_IGNORE
1558 catchsql {PRAGMA full_column_names=on}
1560 do_test auth-1.233 {
1562 } {full_column_names on {} {}}
1563 do_test auth-1.234 {
1564 execsql2 {SELECT a FROM t2}
1566 do_test auth-1.235 {
1567 proc auth {code arg1 arg2 arg3 arg4 args} {
1568 if {$code=="SQLITE_PRAGMA"} {
1569 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1574 catchsql {PRAGMA full_column_names=on}
1576 do_test auth-1.236 {
1577 execsql2 {SELECT a FROM t2}
1579 do_test auth-1.237 {
1580 proc auth {code arg1 arg2 arg3 arg4 args} {
1581 if {$code=="SQLITE_PRAGMA"} {
1582 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1587 catchsql {PRAGMA full_column_names=OFF}
1589 do_test auth-1.238 {
1591 } {full_column_names OFF {} {}}
1592 do_test auth-1.239 {
1593 execsql2 {SELECT a FROM t2}
1596 do_test auth-1.240 {
1597 proc auth {code arg1 arg2 arg3 arg4 args} {
1598 if {$code=="SQLITE_TRANSACTION"} {
1599 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1605 } {1 {not authorized}}
1606 do_test auth-1.241 {
1609 do_test auth-1.242 {
1610 proc auth {code arg1 arg2 arg3 arg4 args} {
1611 if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
1612 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1617 catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
1618 } {1 {not authorized}}
1619 do_test auth-1.243 {
1622 do_test auth-1.244 {
1623 execsql {SELECT * FROM t2}
1624 } {11 2 33 7 8 9 44 55 66}
1625 do_test auth-1.245 {
1627 } {1 {not authorized}}
1628 do_test auth-1.246 {
1630 } {ROLLBACK {} {} {}}
1631 do_test auth-1.247 {
1632 catchsql {END TRANSACTION}
1633 } {1 {not authorized}}
1634 do_test auth-1.248 {
1637 do_test auth-1.249 {
1638 # EVIDENCE-OF: R-52112-44167 Disable the authorizer by installing a NULL
1643 do_test auth-1.250 {
1644 execsql {SELECT * FROM t2}
1647 # ticket #340 - authorization for ATTACH and DETACH.
1650 do_test auth-1.251 {
1651 db authorizer ::auth
1652 proc auth {code arg1 arg2 arg3 arg4 args} {
1653 if {$code=="SQLITE_ATTACH"} {
1654 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1659 ATTACH DATABASE ':memory:' AS test1
1662 do_test auth-1.252a {
1664 } {:memory: {} {} {}}
1665 do_test auth-1.252b {
1666 db eval {DETACH test1}
1667 set ::attachfilename :memory:
1668 db eval {ATTACH $::attachfilename AS test1}
1671 do_test auth-1.252c {
1672 db eval {DETACH test1}
1673 db eval {ATTACH ':mem' || 'ory:' AS test1}
1676 do_test auth-1.253 {
1677 catchsql {DETACH DATABASE test1}
1678 proc auth {code arg1 arg2 arg3 arg4 args} {
1679 if {$code=="SQLITE_ATTACH"} {
1680 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1686 ATTACH DATABASE ':memory:' AS test1;
1688 } {1 {not authorized}}
1689 do_test auth-1.254 {
1690 lindex [execsql {PRAGMA database_list}] 7
1692 do_test auth-1.255 {
1693 catchsql {DETACH DATABASE test1}
1694 proc auth {code arg1 arg2 arg3 arg4 args} {
1695 if {$code=="SQLITE_ATTACH"} {
1696 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1697 return SQLITE_IGNORE
1702 ATTACH DATABASE ':memory:' AS test1;
1705 do_test auth-1.256 {
1706 lindex [execsql {PRAGMA database_list}] 7
1708 do_test auth-1.257 {
1709 proc auth {code arg1 arg2 arg3 arg4 args} {
1710 if {$code=="SQLITE_DETACH"} {
1711 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1716 execsql {ATTACH DATABASE ':memory:' AS test1}
1718 DETACH DATABASE test1;
1721 do_test auth-1.258 {
1722 lindex [execsql {PRAGMA database_list}] 7
1724 do_test auth-1.259 {
1725 execsql {ATTACH DATABASE ':memory:' AS test1}
1726 proc auth {code arg1 arg2 arg3 arg4 args} {
1727 if {$code=="SQLITE_DETACH"} {
1728 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1729 return SQLITE_IGNORE
1734 DETACH DATABASE test1;
1738 ifcapable schema_pragmas {
1739 do_test auth-1.260 {
1740 lindex [execsql {PRAGMA database_list}] 7
1742 } ;# ifcapable schema_pragmas
1743 do_test auth-1.261 {
1744 proc auth {code arg1 arg2 arg3 arg4 args} {
1745 if {$code=="SQLITE_DETACH"} {
1746 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1752 DETACH DATABASE test1;
1754 } {1 {not authorized}}
1755 ifcapable schema_pragmas {
1756 do_test auth-1.262 {
1757 lindex [execsql {PRAGMA database_list}] 7
1759 } ;# ifcapable schema_pragmas
1761 execsql {DETACH DATABASE test1}
1762 db authorizer ::auth
1764 # Authorization for ALTER TABLE. These tests are omitted if the library
1765 # was built without ALTER TABLE support.
1766 ifcapable altertable {
1768 do_test auth-1.263 {
1769 proc auth {code arg1 arg2 arg3 arg4 args} {
1770 if {$code=="SQLITE_ALTER_TABLE"} {
1771 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1777 ALTER TABLE t1 RENAME TO t1x
1780 do_test auth-1.264 {
1781 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1783 do_test auth-1.265 {
1786 do_test auth-1.266 {
1787 proc auth {code arg1 arg2 arg3 arg4 args} {
1788 if {$code=="SQLITE_ALTER_TABLE"} {
1789 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1790 return SQLITE_IGNORE
1795 ALTER TABLE t1x RENAME TO t1
1798 do_test auth-1.267 {
1799 execsql {SELECT name FROM temp.sqlite_master WHERE type='table'}
1801 do_test auth-1.268 {
1804 do_test auth-1.269 {
1805 proc auth {code arg1 arg2 arg3 arg4 args} {
1806 if {$code=="SQLITE_ALTER_TABLE"} {
1807 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1813 ALTER TABLE t1x RENAME TO t1
1815 } {1 {not authorized}}
1816 do_test auth-1.270 {
1817 execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
1820 do_test auth-1.271 {
1823 } ;# ifcapable altertable
1828 DETACH DATABASE test1;
1833 ifcapable altertable {
1835 catchsql {ALTER TABLE t1x RENAME TO t1}
1836 db authorizer ::auth
1837 do_test auth-1.272 {
1838 proc auth {code arg1 arg2 arg3 arg4 args} {
1839 if {$code=="SQLITE_ALTER_TABLE"} {
1840 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1846 ALTER TABLE t2 RENAME TO t2x
1849 do_test auth-1.273 {
1850 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1852 do_test auth-1.274 {
1855 do_test auth-1.275 {
1856 proc auth {code arg1 arg2 arg3 arg4 args} {
1857 if {$code=="SQLITE_ALTER_TABLE"} {
1858 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1859 return SQLITE_IGNORE
1864 ALTER TABLE t2x RENAME TO t2
1867 do_test auth-1.276 {
1868 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1870 do_test auth-1.277 {
1873 do_test auth-1.278 {
1874 proc auth {code arg1 arg2 arg3 arg4 args} {
1875 if {$code=="SQLITE_ALTER_TABLE"} {
1876 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
1882 ALTER TABLE t2x RENAME TO t2
1884 } {1 {not authorized}}
1885 do_test auth-1.279 {
1886 execsql {SELECT name FROM sqlite_master WHERE type='table'}
1888 do_test auth-1.280 {
1892 catchsql {ALTER TABLE t2x RENAME TO t2}
1894 } ;# ifcapable altertable
1896 # Test the authorization callbacks for the REINDEX command.
1899 proc auth {code args} {
1900 if {$code=="SQLITE_REINDEX"} {
1901 set ::authargs [concat $::authargs [lrange $args 0 3]]
1906 do_test auth-1.281 {
1908 CREATE TABLE t3(a PRIMARY KEY, b, c);
1909 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1910 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1913 do_test auth-1.282 {
1919 } {t3_idx1 {} main {}}
1920 do_test auth-1.283 {
1926 } {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1927 do_test auth-1.284 {
1933 } {t3_idx2 {} main {}}
1934 do_test auth-1.285 {
1940 } {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
1941 do_test auth-1.286 {
1947 do_test auth-1.287 {
1949 CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
1950 CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
1951 CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
1954 do_test auth-1.288 {
1957 REINDEX temp.t3_idx1;
1960 } {t3_idx1 {} temp {}}
1961 do_test auth-1.289 {
1967 } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1968 do_test auth-1.290 {
1974 } {t3_idx2 {} temp {}}
1975 do_test auth-1.291 {
1981 } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
1982 proc auth {code args} {
1983 if {$code=="SQLITE_REINDEX"} {
1984 set ::authargs [concat $::authargs [lrange $args 0 3]]
1989 do_test auth-1.292 {
1994 } {1 {not authorized}}
1995 do_test auth-1.293 {
2002 } ;# ifcapable reindex
2005 proc auth {code args} {
2006 if {$code=="SQLITE_ANALYZE"} {
2007 set ::authargs [concat $::authargs [lrange $args 0 3]]
2011 do_test auth-1.294 {
2014 CREATE TABLE t4(a,b,c);
2015 CREATE INDEX t4i1 ON t4(a);
2016 CREATE INDEX t4i2 ON t4(b,a,c);
2017 INSERT INTO t4 VALUES(1,2,3);
2021 } {t4 {} main {} t2 {} main {}}
2022 do_test auth-1.295 {
2024 SELECT count(*) FROM sqlite_stat1;
2027 proc auth {code args} {
2028 if {$code=="SQLITE_ANALYZE"} {
2029 set ::authargs [concat $::authargs $args]
2034 do_test auth-1.296 {
2039 } {1 {not authorized}}
2040 do_test auth-1.297 {
2042 SELECT count(*) FROM sqlite_stat1;
2045 } ;# ifcapable analyze
2048 # Authorization for ALTER TABLE ADD COLUMN.
2049 # These tests are omitted if the library
2050 # was built without ALTER TABLE support.
2051 ifcapable {altertable} {
2052 do_test auth-1.300 {
2053 execsql {CREATE TABLE t5(x)}
2054 proc auth {code arg1 arg2 arg3 arg4 args} {
2055 if {$code=="SQLITE_ALTER_TABLE"} {
2056 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2062 ALTER TABLE t5 ADD COLUMN new_col_1;
2065 do_test auth-1.301 {
2066 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2069 do_test auth-1.302 {
2074 do_execsql_test auth-1.302-drop-1 {
2075 ALTER TABLE t5 DROP COLUMN new_col_1;
2078 do_test auth-1.302-drop-2 {
2080 } {main t5 new_col_1 {}}
2081 do_test auth-1.303 {
2082 proc auth {code arg1 arg2 arg3 arg4 args} {
2083 if {$code=="SQLITE_ALTER_TABLE"} {
2084 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2085 return SQLITE_IGNORE
2090 ALTER TABLE t5 ADD COLUMN new_col_2;
2093 do_test auth-1.304 {
2094 set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
2097 do_test auth-1.305 {
2102 do_execsql_test auth-1.305-drop-1 {
2103 ALTER TABLE t5 DROP COLUMN new_col_1;
2104 SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%';
2107 do_test auth-1.305-drop-2 {
2109 } {main t5 new_col_1 {}}
2110 do_test auth-1.306 {
2111 proc auth {code arg1 arg2 arg3 arg4 args} {
2112 if {$code=="SQLITE_ALTER_TABLE"} {
2113 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2119 ALTER TABLE t5 ADD COLUMN new_col_3
2121 } {1 {not authorized}}
2122 do_test auth-1.307 {
2123 set x [execsql {SELECT sql FROM temp.sqlite_master WHERE type='t5'}]
2126 do_test auth-1.308 {
2131 do_catchsql_test auth-1.308-drop-1 {
2132 ALTER TABLE t5 DROP COLUMN new_col_1;
2133 } {1 {not authorized}}
2134 do_execsql_test auth-1.308-drop-2 {
2135 SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%';
2137 do_test auth-1.308-drop-3 {
2139 } {main t5 new_col_1 {}}
2142 execsql {DROP TABLE t5}
2143 } ;# ifcapable altertable
2146 do_test auth-1.310 {
2147 proc auth {code arg1 arg2 arg3 arg4 args} {
2148 if {$code=="SQLITE_RECURSIVE"} {
2154 DROP TABLE IF EXISTS t1;
2155 CREATE TABLE t1(a,b);
2156 INSERT INTO t1 VALUES(1,2),(3,4),(5,6);
2159 do_catchsql_test auth-1.311 {
2161 auth1311(x,y) AS (SELECT a+b, b-a FROM t1)
2162 SELECT * FROM auth1311 ORDER BY x;
2163 } {0 {3 1 7 1 11 1}}
2164 do_catchsql_test auth-1.312 {
2166 auth1312(x,y) AS (SELECT a+b, b-a FROM t1)
2167 SELECT x, y FROM auth1312 ORDER BY x;
2168 } {0 {3 1 7 1 11 1}}
2169 do_catchsql_test auth-1.313 {
2171 auth1313(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1313 WHERE x<5)
2174 do_catchsql_test auth-1.314 {
2176 auth1314(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1314 WHERE x<5)
2177 SELECT * FROM t1 LEFT JOIN auth1314;
2178 } {1 {not authorized}}
2182 # db eval {SELECT sql FROM temp.sqlite_master} {puts "TEMP: $sql;"}
2183 # db eval {SELECT sql FROM main.sqlite_master} {puts "MAIN: $sql;"}
2185 # MAIN: CREATE TABLE "t2"(a,b,c);
2186 # MAIN: CREATE TABLE t4(a,b,c);
2187 # MAIN: CREATE INDEX t4i1 ON t4(a);
2188 # MAIN: CREATE INDEX t4i2 ON t4(b,a,c);
2189 # MAIN: CREATE TABLE sqlite_stat1(tbl,idx,stat);
2190 # MAIN: CREATE TABLE t1(a,b);
2192 ifcapable altertable&&vtab {
2193 do_test auth-1.350 {
2194 proc auth {code arg1 arg2 arg3 arg4 args} {
2195 if {$code=="SQLITE_ALTER_TABLE"} {
2196 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2202 ALTER TABLE t1 RENAME COLUMN b TO bcdefg;
2205 do_execsql_test auth-1.351 {
2206 SELECT name FROM pragma_table_info('t1') ORDER BY cid;
2208 do_test auth-1.352 {
2211 do_test auth-1.353 {
2212 proc auth {code arg1 arg2 arg3 arg4 args} {
2213 if {$code=="SQLITE_ALTER_TABLE"} {
2214 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2215 return SQLITE_IGNORE
2220 ALTER TABLE t1 RENAME COLUMN bcdefg TO b;
2223 do_execsql_test auth-1.354 {
2224 SELECT name FROM pragma_table_info('t1') ORDER BY cid;
2226 do_test auth-1.355 {
2229 do_test auth-1.356 {
2230 proc auth {code arg1 arg2 arg3 arg4 args} {
2231 if {$code=="SQLITE_ALTER_TABLE"} {
2232 set ::authargs [list $arg1 $arg2 $arg3 $arg4]
2238 ALTER TABLE t1 RENAME COLUMN bcdefg TO b;
2240 } {1 {not authorized}}
2241 do_execsql_test auth-1.357 {
2242 SELECT name FROM pragma_table_info('t1') ORDER BY cid;
2244 do_test auth-1.358 {
2250 # The sqlite3_declare_vtab() call that occurs during pragma_table_list
2251 # should not cause an authentication failure.
2254 do_test auth-1.359 {
2255 proc auth {code arg1 arg2 arg3 arg4 args} {
2256 if {$code=="SQLITE_UPDATE"} {
2261 catchsql {SELECT * FROM pragma_table_list WHERE name='xyzzy';}
2266 proc auth {code arg1 arg2 arg3 arg4 args} {
2267 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2272 db authorizer ::auth
2273 execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
2274 catchsql {SELECT * FROM t3}
2275 } {1 {access to t3.x is prohibited}}
2277 catchsql {SELECT y,z FROM t3}
2280 catchsql {SELECT ROWID,y,z FROM t3}
2281 } {1 {access to t3.x is prohibited}}
2283 catchsql {SELECT OID,y,z FROM t3}
2284 } {1 {access to t3.x is prohibited}}
2286 proc auth {code arg1 arg2 arg3 arg4 args} {
2287 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
2288 return SQLITE_IGNORE
2292 execsql {INSERT INTO t3 VALUES(44,55,66)}
2293 catchsql {SELECT * FROM t3}
2296 catchsql {SELECT rowid,y,z FROM t3}
2299 proc auth {code arg1 arg2 arg3 arg4 args} {
2300 if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
2301 return SQLITE_IGNORE
2305 catchsql {SELECT * FROM t3}
2308 catchsql {SELECT ROWID,y,z FROM t3}
2311 proc auth {code arg1 arg2 arg3 arg4 args} {
2312 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2313 return SQLITE_IGNORE
2317 catchsql {SELECT ROWID,b,c FROM t2}
2318 } {0 {{} 2 33 {} 8 9}}
2319 do_test auth-2.9.1 {
2320 # We have to flush the cache here in case the Tcl interface tries to
2321 # reuse a statement compiled with sqlite3_prepare_v2(). In this case,
2322 # the first error encountered is an SQLITE_SCHEMA error. Then, when
2323 # trying to recompile the statement, the authorization error is encountered.
2324 # If we do not flush the cache, the correct error message is returned, but
2325 # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test
2326 # case after this one.
2330 proc auth {code arg1 arg2 arg3 arg4 args} {
2331 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
2336 catchsql {SELECT ROWID,b,c FROM t2}
2337 } {1 {authorizer malfunction}}
2338 do_test auth-2.9.2 {
2342 proc auth {code arg1 arg2 arg3 arg4 args} {
2343 if {$code=="SQLITE_SELECT"} {
2348 catchsql {SELECT ROWID,b,c FROM t2}
2349 } {1 {authorizer malfunction}}
2350 do_test auth-2.11.1 {
2351 proc auth {code arg1 arg2 arg3 arg4 args} {
2352 if {$code=="SQLITE_READ" && $arg2=="a"} {
2353 return SQLITE_IGNORE
2357 catchsql {SELECT * FROM t2, t3}
2358 } {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
2359 do_test auth-2.11.2 {
2360 proc auth {code arg1 arg2 arg3 arg4 args} {
2361 if {$code=="SQLITE_READ" && $arg2=="x"} {
2362 return SQLITE_IGNORE
2366 catchsql {SELECT * FROM t2, t3}
2367 } {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
2369 # Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
2373 proc auth {code arg1 arg2 arg3 arg4 args} {
2377 CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
2378 CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
2379 INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
2381 UPDATE t2 SET a=a+1;
2384 } {11 12 2 2 33 33 7 8 8 8 9 9}
2386 proc auth {code arg1 arg2 arg3 arg4 args} {
2387 if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
2388 return SQLITE_IGNORE
2394 UPDATE t2 SET a=a+100;
2397 } {12 112 2 2 {} {} 8 108 8 8 {} {}}
2398 } ;# ifcapable trigger
2400 # Make sure the names of views and triggers are passed on on arg4.
2404 proc auth {code arg1 arg2 arg3 arg4 args} {
2405 lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
2410 UPDATE t2 SET a=a+1;
2414 SQLITE_READ t2 a main {} \
2415 SQLITE_UPDATE t2 a main {} \
2416 SQLITE_INSERT tx {} main r1 \
2417 SQLITE_READ t2 a main r1 \
2418 SQLITE_READ t2 a main r1 \
2419 SQLITE_READ t2 b main r1 \
2420 SQLITE_READ t2 b main r1 \
2421 SQLITE_READ t2 c main r1 \
2422 SQLITE_READ t2 c main r1]
2425 ifcapable {view && trigger} {
2428 CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
2429 CREATE TABLE v1chng(x1,x2);
2430 CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
2431 INSERT INTO v1chng VALUES(OLD.x,NEW.x);
2439 UPDATE v1 SET x=1 WHERE x=117
2443 SQLITE_UPDATE v1 x main {} \
2444 SQLITE_SELECT {} {} {} v1 \
2445 SQLITE_READ t2 a main v1 \
2446 SQLITE_READ t2 b main v1 \
2447 SQLITE_READ v1 x main v1 \
2448 SQLITE_READ v1 x main v1 \
2449 SQLITE_SELECT {} {} {} v1 \
2450 SQLITE_READ v1 x main v1 \
2451 SQLITE_INSERT v1chng {} main r2 \
2452 SQLITE_READ v1 x main r2 \
2453 SQLITE_READ v1 x main r2 \
2458 CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
2459 INSERT INTO v1chng VALUES(OLD.x,NULL);
2467 DELETE FROM v1 WHERE x=117
2471 SQLITE_DELETE v1 {} main {} \
2472 SQLITE_SELECT {} {} {} v1 \
2473 SQLITE_READ t2 a main v1 \
2474 SQLITE_READ t2 b main v1 \
2475 SQLITE_READ v1 x main v1 \
2476 SQLITE_READ v1 x main v1 \
2477 SQLITE_SELECT {} {} {} v1 \
2478 SQLITE_READ v1 x main v1 \
2479 SQLITE_INSERT v1chng {} main r3 \
2480 SQLITE_READ v1 x main r3 \
2483 } ;# ifcapable view && trigger
2485 # Ticket #1338: Make sure authentication works in the presence of an AS
2489 proc auth {code arg1 arg2 arg3 arg4 args} {
2493 SELECT count(a) AS cnt FROM t4 ORDER BY cnt
2499 ifcapable compound&&subquery {
2511 set stat4 "sqlite_stat4 "
2518 SELECT * FROM sqlite_master UNION ALL SELECT * FROM temp.sqlite_master)
2522 } "sqlite_stat1 ${stat4}t1 t2 t3 t4"
2528 do_test auth-5.3.1 {
2530 CREATE TABLE t5 ( x );
2531 CREATE TRIGGER t5_tr1 AFTER INSERT ON t5 BEGIN
2532 UPDATE t5 SET x = 1 WHERE NEW.x = 0;
2536 set ::authargs [list]
2538 eval lappend ::authargs [lrange $args 0 4]
2541 do_test auth-5.3.2 {
2542 execsql { INSERT INTO t5 (x) values(0) }
2544 } [list SQLITE_INSERT t5 {} main {} \
2545 SQLITE_UPDATE t5 x main t5_tr1 \
2546 SQLITE_READ t5 x main t5_tr1 \
2548 do_test auth-5.3.2 {
2549 execsql { SELECT * FROM t5 }
2553 # Ticket [0eb70d77cb05bb22720]: Invalid pointer passsed to the authorizer
2554 # callback when updating a ROWID.
2558 CREATE TABLE t6(a,b,c,d,e,f,g,h);
2559 INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8);
2562 set ::authargs [list]
2564 eval lappend ::authargs [lrange $args 0 4]
2568 execsql {UPDATE t6 SET rowID=rowID+100}
2570 } [list SQLITE_READ t6 ROWID main {} \
2571 SQLITE_UPDATE t6 ROWID main {} \
2574 execsql {SELECT rowid, * FROM t6}
2575 } {101 1 2 3 4 5 6 7 8}
2577 #-------------------------------------------------------------------------
2578 # Test that view names are included as zArg4.
2580 do_execsql_test auth-7.1 {
2581 CREATE TABLE t7(a, b, c);
2582 CREATE VIEW v7 AS SELECT * FROM t7;
2584 set ::authargs [list]
2586 eval lappend ::authargs [lrange $args 0 4]
2591 execsql {SELECT a, c FROM v7}
2594 SQLITE_SELECT {} {} {} {} \
2595 SQLITE_READ t7 a main v7 \
2596 SQLITE_READ t7 b main v7 \
2597 SQLITE_READ t7 c main v7 \
2598 SQLITE_READ v7 a main {} \
2599 SQLITE_READ v7 c main {} \
2600 SQLITE_SELECT {} {} {} v7 \
2603 set ::authargs [list]
2605 execsql {SELECT a, c FROM t7}
2608 SQLITE_SELECT {} {} {} {} \
2609 SQLITE_READ t7 a main {} \
2610 SQLITE_READ t7 c main {} \
2613 set ::authargs [list]
2615 execsql {SELECT a, c FROM t7 AS v7}
2618 SQLITE_SELECT {} {} {} {} \
2619 SQLITE_READ t7 a main {} \
2620 SQLITE_READ t7 c main {} \
2623 # If a table is referenced but no columns are read from the table,
2624 # that causes a single SQLITE_READ authorization with a NULL column
2627 # EVIDENCE-OF: R-31520-16302 When a table is referenced by a SELECT but
2628 # no column values are extracted from that table (for example in a query
2629 # like "SELECT count(*) FROM tab") then the SQLITE_READ authorizer
2630 # callback is invoked once for that table with a column name that is an
2633 set ::authargs [list]
2635 execsql {SELECT count(*) FROM t7}
2638 SQLITE_SELECT {} {} {} {} \
2639 SQLITE_FUNCTION {} count {} {} \
2640 SQLITE_READ t7 {} {} {} \
2642 set ::authargs [list]
2645 execsql {SELECT t6.a FROM t6, t7}
2648 SQLITE_SELECT {} {} {} {} \
2649 SQLITE_READ t6 a main {} \
2650 SQLITE_READ t7 {} {} {} \
2653 # Test also that if SQLITE_DENY is returned from an SQLITE_READ authorizer
2654 # invocation with no column name specified, compilation fails.
2656 set ::authargs [list]
2657 proc auth {op args} {
2658 foreach {a b c d} $args break
2659 lappend ::authargs $op $a $b $c $d
2660 if {$op == "SQLITE_READ"} { return "SQLITE_DENY" }
2663 set ::authargs [list]
2664 do_catchsql_test auth-8.3 {
2665 SELECT count(*) FROM t7
2666 } {1 {not authorized}}
2670 SQLITE_SELECT {} {} {} {} \
2671 SQLITE_FUNCTION {} count {} {} \
2672 SQLITE_READ t7 {} {} {} \
2677 rename proc_real proc