Remove superfluous option to Tcl 'lsort' in the vtabH test file.
[sqlite.git] / test / auth3.test
blob013486e5a03d1cd3c5e49a329d6203cd24001016
1 # 2008 October 27
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 #***********************************************************************
12 # Test that the truncate optimization is disabled if the SQLITE_DELETE
13 # authorization callback returns SQLITE_IGNORE.
15 # Test that authorizer is disabled during schema parsing.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
21 # defined during compilation.
22 if {[catch {db auth {}} msg]} {
23   finish_test
24   return
27 # Disable the statement cache for these tests.
28
29 db cache size 0
31 db authorizer ::auth
32 proc auth {code arg1 arg2 arg3 arg4 args} {
33   if {$code=="SQLITE_DELETE"} {
34     return $::authcode
35   }
36   return SQLITE_OK
39 #--------------------------------------------------------------------------
40 # The following tests - auth3-1.* - test that return values of SQLITE_DENY,
41 # SQLITE_IGNORE, SQLITE_OK and <invalid> are correctly handled when returned
42 # by an SQLITE_DELETE authorization callback triggered by a 
43 # "DELETE FROM <table-name>" statement.
45 do_test auth3-1.1 {
46   execsql {
47     CREATE TABLE t1(a,b,c);
48     INSERT INTO t1 VALUES(1, 2, 3);
49     INSERT INTO t1 VALUES(4, 5, 6);
50   }
51 } {}
52 do_test auth3.1.2 {
53   set ::authcode SQLITE_DENY
54   catchsql { DELETE FROM t1 }
55 } {1 {not authorized}}
56 do_test auth3.1.3 {
57   set ::authcode SQLITE_INVALID
58   catchsql { DELETE FROM t1 }
59 } {1 {authorizer malfunction}}
60 do_test auth3.1.4 {
61   execsql { SELECT * FROM t1 }
62 } {1 2 3 4 5 6}
63 do_test auth3-1.5 {
64   set ::authcode SQLITE_IGNORE
65   execsql { 
66     DELETE FROM t1;
67     SELECT * FROM t1;
68   }
69 } {}
70 do_test auth3-1.6 {
71   set ::authcode SQLITE_OK
72   execsql {
73     INSERT INTO t1 VALUES(1, 2, 3);
74     INSERT INTO t1 VALUES(4, 5, 6);
75     DELETE FROM t1;
76     SELECT * FROM t1;
77   }
78 } {}
80 #--------------------------------------------------------------------------
81 # These tests - auth3-2.* - test that returning SQLITE_IGNORE really does
82 # disable the truncate optimization.
84 do_test auth3-2.1 {
85   set ::authcode SQLITE_OK
86   execsql {
87     INSERT INTO t1 VALUES(1, 2, 3);
88     INSERT INTO t1 VALUES(4, 5, 6);
89   }
90   set sqlite_search_count 0
91   execsql {
92     DELETE FROM t1;
93   }
94   set sqlite_search_count
95 } {0}
97 do_test auth3-2.2 {
98   set ::authcode SQLITE_IGNORE
99   execsql {
100     INSERT INTO t1 VALUES(1, 2, 3);
101     INSERT INTO t1 VALUES(4, 5, 6);
102   }
103   set sqlite_search_count 0
104   execsql {
105     DELETE FROM t1;
106   }
107   set sqlite_search_count
108 } {1}
110 # 2016-07-28.  A problem report from a private client complaining about
111 # an authorizer failure during an ALTER TABLE.  The solution (I think) is
112 # to disable the authorizer during schema parsing.
114 proc auth {code args} {
115   if {$code=="SQLITE_READ" && [regexp {DoNotRead} $args]} {
116     return SQLITE_DENY
117   }
118   return SQLITE_OK
120 do_execsql_test auth3-3.0 {
121   CREATE TEMPORARY TABLE TempTable (
122       key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,
123       value TEXT NOT NULL ON CONFLICT FAIL);
124   ALTER TABLE TempTable RENAME TO DoNotRead;
125   SELECT name FROM temp.sqlite_master;
126 } {DoNotRead sqlite_autoindex_DoNotRead_1}
128 finish_test